Package com.badlogic.gdx.tools.imagepacker

Examples of com.badlogic.gdx.tools.imagepacker.TexturePacker2


      BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
      newImage.getGraphics().drawImage(image, 0, 0, null);
      image = newImage;
    }

    Rect rect = null;
    if (name.endsWith(".9")) {
      // Strip ".9" from file name, read ninepatch split pixels, and strip ninepatch split pixels.
      name = name.substring(0, name.length() - 2);
      int[] splits = getSplits(image, name);
      int[] pads = getPads(image, name, splits);
      // Strip split pixels.
      BufferedImage newImage = new BufferedImage(image.getWidth() - 2, image.getHeight() - 2, BufferedImage.TYPE_4BYTE_ABGR);
      newImage.getGraphics().drawImage(image, 0, 0, newImage.getWidth(), newImage.getHeight(), 1, 1, image.getWidth() - 1,
        image.getHeight() - 1, null);
      image = newImage;
      // Ninepatches aren't rotated or whitespace stripped.
      rect = new Rect(image, 0, 0, image.getWidth(), image.getHeight(), 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

      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

  private String packFileName;
  private File root;
  ArrayList<File> ignoreDirs = new ArrayList();

  public TexturePackerFileProcessor () {
    this(new Settings(), "pack.atlas");
  }
View Full Code Here

        return file1.toString().length() - file2.toString().length();
      }
    });
    for (File settingsFile : settingsFiles) {
      // Find first parent with settings, or use defaults.
      Settings settings = null;
      File parent = settingsFile.getParentFile();
      while (true) {
        if (parent.equals(root)) break;
        parent = parent.getParentFile();
        settings = dirToSettings.get(parent);
        if (settings != null) {
          settings = new Settings(settings);
          break;
        }
      }
      if (settings == null) settings = new Settings(defaultSettings);
      // Merge settings from current directory.
      try {
        json.readFields(settings, new JsonReader().parse(new FileReader(settingsFile)));
      } catch (SerializationException ex) {
        throw new GdxRuntimeException("Error reading settings file: " + settingsFile, ex);
View Full Code Here

  protected void processDir (Entry inputDir, ArrayList<Entry> files) throws Exception {
    if (ignoreDirs.contains(inputDir.inputFile)) return;

    // Find first parent with settings, or use defaults.
    Settings settings = null;
    File parent = inputDir.inputFile;
    while (true) {
      settings = dirToSettings.get(parent);
      if (settings != null) break;
      if (parent.equals(root)) break;
View Full Code Here

  }

  public void render () {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    Settings settings = new Settings();
    settings.fast = false;
    settings.pot = false;
    settings.maxWidth = 1024;
    settings.maxHeight = 1024;
    settings.rotation = false;
View Full Code Here

    public void regenerateGenericAtlas() {

        String imageFolder = pathToGenericImages;
        String packedFolder = pathToPackedGenericImages;

        Settings settings = new Settings();
        settings.maxWidth = Detonator.INSTANCE.maxAtlasSizeX;
        settings.maxHeight = Detonator.INSTANCE.maxAtlasSizeY;

        new File(packedFolder).mkdirs();
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.tools.imagepacker.TexturePacker2

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.