Ejemplo n.º 1
0
    private BufferedImage shapenImage(BufferedImage in) {
      BufferedImage out =
          DrawManager.getInstance().createBlankBufferedImage(in.getWidth(), in.getHeight(), false);
      Graphics2D g = out.createGraphics();
      g.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

      g.drawImage(in, shapenOp, 0, 0);

      g.dispose();

      return out;
    }
Ejemplo n.º 2
0
    private BufferedImage reduceImageSizeByFactorOfTwo(BufferedImage in) {
      BufferedImage out =
          DrawManager.getInstance()
              .createBlankBufferedImage(in.getWidth() / 2, in.getHeight() / 2, false);
      Graphics2D g = out.createGraphics();
      g.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

      g.drawImage(in, 0, 0, in.getWidth() / 2, in.getHeight() / 2, null);

      g.dispose();

      return out;
    }
Ejemplo n.º 3
0
    @Override
    public void run() {
      // System.out.println("Render job \"" + levelData.getMapName() + "\" : start");

      // Wait for previous runnable job to complete first
      if (previousRunnable != null) {
        synchronized (previousRunnable.finishNotifer) {
          try {
            previousRunnable.finishNotifer.wait();
          } catch (InterruptedException e) {
            // The code should not reach here...
            e.printStackTrace();
          }
        }
      }

      // System.out.println("Render job \"" + levelData.getMapName() + "\" : rendering");

      BufferedImage renderImg =
          DrawManager.getInstance()
              .createBlankBufferedImage(RENDER_IMAGE_WIDTH, RENDER_IMAGE_HEIGHT, false);
      Graphics2D graphic = renderImg.createGraphics();
      graphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      graphic.setClip(0, 0, RENDER_IMAGE_WIDTH, RENDER_IMAGE_HEIGHT);

      GameStage renderStage = new GameStage(levelData, GameStageType.THUMBNAIL);
      renderStage.update(0);
      renderStage.draw(graphic, RENDER_IMAGE_WIDTH, RENDER_IMAGE_HEIGHT);
      graphic.dispose();

      // Resize image

      renderImg = shapenImage(renderImg);
      for (int i = 0; i < 3; i++) {
        renderImg = reduceImageSizeByFactorOfTwo(renderImg);
      }

      this.levelData.setThumbnail(renderImg);

      // System.out.println("Render job \"" + levelData.getMapName() + "\" : finished");

      synchronized (finishNotifer) {
        finishNotifer.notifyAll();
      }
    }