Package com.badlogic.gdx.tools.texturepacker.TexturePacker

Examples of com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect


    // Strip extension.
    int dotIndex = name.lastIndexOf('.');
    if (dotIndex != -1) name = name.substring(0, dotIndex);

    Rect rect = addImage(image, name);
    if (rect != null && settings.limitMemory) rect.unloadImage(file);
  }
View Full Code Here


  }

  /** The image will be kept in-memory during packing.
   * @see #addImage(File) */
  public Rect addImage (BufferedImage image, String name) {
    Rect rect = processImage(image, name);

    if (rect == null) {
      System.out.println("Ignoring blank input image: " + name);
      return null;
    }

    if (settings.alias) {
      String crc = hash(rect.getImage(this));
      Rect existing = crcs.get(crc);
      if (existing != null) {
        System.out.println(rect.name + " (alias of " + existing.name + ")");
        existing.aliases.add(new Alias(rect));
        return null;
      }
View Full Code Here

      image = newImage;
    }

    boolean isPatch = name.endsWith(".9");
    int[] splits = null, pads = null;
    Rect rect = null;
    if (isPatch) {
      // Strip ".9" from file name, read ninepatch split pixels, and strip ninepatch split pixels.
      name = name.substring(0, name.length() - 2);
      splits = getSplits(image, name);
      pads = getPads(image, name, splits);
      // Strip split pixels.
      width -= 2;
      height -= 2;
      BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
      newImage.getGraphics().drawImage(image, 0, 0, width, height, 1, 1, width + 1, height + 1, null);
      image = newImage;
    }

    // Scale image.
    if (scale != 1) {
      int originalWidth = width, originalHeight = height;
      width = Math.round(width * scale);
      height = Math.round(height * scale);
      BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
      if (scale < 1) {
        newImage.getGraphics().drawImage(image.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING), 0, 0, null);
      } else {
        Graphics2D g = (Graphics2D)newImage.getGraphics();
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.drawImage(image, 0, 0, width, height, null);
      }
      image = newImage;
    }

    if (isPatch) {
      // Ninepatches aren't rotated or whitespace stripped.
      rect = new Rect(image, 0, 0, width, height, true);
      rect.splits = splits;
      rect.pads = pads;
      rect.canRotate = false;
    } else {
      rect = stripWhitespace(image);
View Full Code Here

  /** Strips whitespace and returns the rect, or null if the image should be ignored. */
  private Rect stripWhitespace (BufferedImage source) {
    WritableRaster alphaRaster = source.getAlphaRaster();
    if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY))
      return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);
    final byte[] a = new byte[1];
    int top = 0;
    int bottom = source.getHeight();
    if (settings.stripWhitespaceX) {
      outer:
      for (int y = 0; y < source.getHeight(); y++) {
        for (int x = 0; x < source.getWidth(); x++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        top++;
      }
      outer:
      for (int y = source.getHeight(); --y >= top;) {
        for (int x = 0; x < source.getWidth(); x++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        bottom--;
      }
    }
    int left = 0;
    int right = source.getWidth();
    if (settings.stripWhitespaceY) {
      outer:
      for (int x = 0; x < source.getWidth(); x++) {
        for (int y = top; y < bottom; y++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        left++;
      }
      outer:
      for (int x = source.getWidth(); --x >= left;) {
        for (int y = top; y < bottom; y++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        right--;
      }
    }
    int newWidth = right - left;
    int newHeight = bottom - top;
    if (newWidth <= 0 || newHeight <= 0) {
      if (settings.ignoreBlankImages)
        return null;
      else
        return new Rect(emptyImage, 0, 0, 1, 1, false);
    }
    return new Rect(source, left, top, newWidth, newHeight, false);
  }
View Full Code Here

  public Array<Page> pack (Array<Rect> inputRects) {
    System.out.print("Packing");

    int cellWidth = 0, cellHeight = 0;
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
      Rect rect = inputRects.get(i);
      cellWidth = Math.max(cellWidth, rect.width);
      cellHeight = Math.max(cellHeight, rect.height);
    }
    cellWidth += settings.paddingX;
    cellHeight += settings.paddingY;
View Full Code Here

      if (x + cellWidth > maxWidth) {
        y += cellHeight;
        if (y > maxHeight - cellHeight) break;
        x = 0;
      }
      Rect rect = inputRects.removeIndex(i);
      rect.x = x;
      rect.y = y;
      rect.width += settings.paddingX;
      rect.height += settings.paddingY;
      page.outputRects.add(rect);
      x += cellWidth;
      page.width = Math.max(page.width, x);
      page.height = Math.max(page.height, y + cellHeight);
    }

    // Flip so rows start at top.
    for (int i = page.outputRects.size - 1; i >= 0; i--) {
      Rect rect = page.outputRects.get(i);
      rect.y = page.height - rect.y - rect.height;
    }
    return page;
  }
View Full Code Here

      throw new RuntimeException("Page min height cannot be higher than max height.");
  }

  public Array<Page> pack (Array<Rect> inputRects) {
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
      Rect rect = inputRects.get(i);
      rect.width += settings.paddingX;
      rect.height += settings.paddingY;
    }

    if (settings.fast) {
View Full Code Here

    }
    // Find min size.
    int minWidth = Integer.MAX_VALUE;
    int minHeight = Integer.MAX_VALUE;
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
      Rect rect = inputRects.get(i);
      minWidth = Math.min(minWidth, rect.width);
      minHeight = Math.min(minHeight, rect.height);
      if (settings.rotation) {
        if ((rect.width > settings.maxWidth || rect.height > settings.maxHeight)
          && (rect.width > settings.maxHeight || rect.height > settings.maxWidth)) {
View Full Code Here

      if (!settings.fast) {
        result = maxRects.pack(inputRects, methods[i]);
      } else {
        Array<Rect> remaining = new Array();
        for (int ii = 0, nn = inputRects.size; ii < nn; ii++) {
          Rect rect = inputRects.get(ii);
          if (maxRects.insert(rect, methods[i]) == null) {
            while (ii < nn)
              remaining.add(inputRects.get(ii++));
          }
        }
View Full Code Here

      binWidth = width;
      binHeight = height;

      usedRectangles.clear();
      freeRectangles.clear();
      Rect n = new Rect();
      n.x = 0;
      n.y = 0;
      n.width = width;
      n.height = height;
      freeRectangles.add(n);
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.