Package com.badlogic.gdx.graphics.g2d

Examples of com.badlogic.gdx.graphics.g2d.PixmapPacker$Page


      data.down = -data.down;
    }

    boolean ownsAtlas = false;

    PixmapPacker packer = parameter.packer;

    if (packer == null) {
      // generate the glyphs
      int maxGlyphHeight = (int)Math.ceil(data.lineHeight);
      int pageWidth = MathUtils
        .nextPowerOfTwo((int)Math.sqrt(maxGlyphHeight * maxGlyphHeight * parameter.characters.length()));

      if (maxTextureSize > 0) pageWidth = Math.min(pageWidth, maxTextureSize);

      ownsAtlas = true;
      packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, false);
    }

    // to minimize collisions we'll use this format : pathWithoutExtension_size[_flip]_glyph
    String packPrefix = ownsAtlas ? "" : (filePath + '_' + parameter.size + (parameter.flip ? "_flip_" : '_'));

    for (int i = 0; i < parameter.characters.length(); i++) {
      char c = parameter.characters.charAt(i);
      if (!FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't load char '" + c + "'");
        continue;
      }
      if (!FreeType.renderGlyph(face.getGlyph(), FreeType.FT_RENDER_MODE_NORMAL)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't render char '" + c + "'");
        continue;
      }
      GlyphSlot slot = face.getGlyph();
      GlyphMetrics metrics = slot.getMetrics();
      Bitmap bitmap = slot.getBitmap();
      Pixmap pixmap = bitmap.getPixmap(Format.RGBA8888);
      Glyph glyph = new Glyph();
      glyph.id = (int)c;
      glyph.width = pixmap.getWidth();
      glyph.height = pixmap.getHeight();
      glyph.xoffset = slot.getBitmapLeft();
      glyph.yoffset = parameter.flip ? -slot.getBitmapTop() + (int)baseLine : -(glyph.height - slot.getBitmapTop())
        - (int)baseLine;
      glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance());

      if (bitmapped) {
        pixmap.setColor(Color.CLEAR);
        pixmap.fill();
        ByteBuffer buf = bitmap.getBuffer();
        for (int h = 0; h < glyph.height; h++) {
          int idx = h * bitmap.getPitch();
          for (int w = 0; w < (glyph.width + glyph.xoffset); w++) {
            int bit = (buf.get(idx + (w / 8)) >>> (7 - (w % 8))) & 1;
            pixmap.drawPixel(w, h, ((bit == 1) ? Color.WHITE.toIntBits() : Color.CLEAR.toIntBits()));
          }
        }

      }

      String name = packPrefix + c;
      Rectangle rect = packer.pack(name, pixmap);

      // determine which page it was packed into
      int pIndex = packer.getPageIndex(name);
      if (pIndex == -1) // we should not get here
        throw new IllegalStateException("packer was not able to insert '" + name + "' into a page");

      glyph.page = pIndex;
      glyph.srcX = (int)rect.x;
      glyph.srcY = (int)rect.y;

      data.setGlyph(c, glyph);
      pixmap.dispose();
    }

    // generate kerning
    for (int i = 0; i < parameter.characters.length(); i++) {
      for (int j = 0; j < parameter.characters.length(); j++) {
        char firstChar = parameter.characters.charAt(i);
        Glyph first = data.getGlyph(firstChar);
        if (first == null) continue;
        char secondChar = parameter.characters.charAt(j);
        Glyph second = data.getGlyph(secondChar);
        if (second == null) continue;
        int kerning = FreeType.getKerning(face, FreeType.getCharIndex(face, firstChar),
          FreeType.getCharIndex(face, secondChar), 0);
        if (kerning == 0) continue;
        first.setKerning(secondChar, FreeType.toInt(kerning));
      }
    }

    if (ownsAtlas) {
      Array<Page> pages = packer.getPages();
      data.regions = new TextureRegion[pages.size];

      for (int i = 0; i < pages.size; i++) {
        Page p = pages.get(i);

View Full Code Here


     * @param fileName
     * @param parameter
     */
    @Override
    public SpritePack loadSync(AssetManager manager, String fileName, SpritePackParameter parameter) {
        PixmapPacker pixmapPacker = new PixmapPacker(512, 512, Pixmap.Format.RGBA8888, 1, true);
        for(FileHandle file : files) {
            Pixmap pixmap = manager.get(file.path(), Pixmap.class);
            pixmapPacker.pack(file.nameWithoutExtension(), pixmap);
        }
        return new SpritePack(pixmapPacker.generateTextureAtlas(Texture.TextureFilter.Nearest,
                                                                Texture.TextureFilter.Nearest,
                                                                false));
    }
View Full Code Here

       
      if (maxTextureSize > 0)
        pageWidth = Math.min(pageWidth, maxTextureSize);

      ownsAtlas = true;
      packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, false);
    }

    //to minimize collisions we'll use this format : pathWithoutExtension_size[_flip]_glyph
    String packPrefix = ownsAtlas ? "" : (filePath + '_' + size + (flip ? "_flip_" : '_') );
   
View Full Code Here

      data.down = -data.down;
    }

    boolean ownsAtlas = false;

    PixmapPacker packer = parameter.packer;

    if (packer == null) {
      // generate the glyphs
      int maxGlyphHeight = (int)Math.ceil(data.lineHeight);
      int pageWidth = MathUtils
        .nextPowerOfTwo((int)Math.sqrt(maxGlyphHeight * maxGlyphHeight * parameter.characters.length()));

      if (maxTextureSize > 0) pageWidth = Math.min(pageWidth, maxTextureSize);

      ownsAtlas = true;
      packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, false);
    }

    // to minimize collisions we'll use this format : pathWithoutExtension_size[_flip]_glyph
    String packPrefix = ownsAtlas ? "" : (filePath + '_' + parameter.size + (parameter.flip ? "_flip_" : '_'));

    for (int i = 0; i < parameter.characters.length(); i++) {
      char c = parameter.characters.charAt(i);
      if (!FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't load char '" + c + "'");
        continue;
      }
      if (!FreeType.renderGlyph(face.getGlyph(), FreeType.FT_RENDER_MODE_NORMAL)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't render char '" + c + "'");
        continue;
      }
      GlyphSlot slot = face.getGlyph();
      GlyphMetrics metrics = slot.getMetrics();
      Bitmap bitmap = slot.getBitmap();
      Pixmap pixmap = bitmap.getPixmap(Format.RGBA8888);
      Glyph glyph = new Glyph();
      glyph.id = (int)c;
      glyph.width = pixmap.getWidth();
      glyph.height = pixmap.getHeight();
      glyph.xoffset = slot.getBitmapLeft();
      glyph.yoffset = parameter.flip ? -slot.getBitmapTop() + (int)baseLine : -(glyph.height - slot.getBitmapTop())
        - (int)baseLine;
      glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance());

      if (bitmapped) {
        pixmap.setColor(Color.CLEAR);
        pixmap.fill();
        ByteBuffer buf = bitmap.getBuffer();
        for (int h = 0; h < glyph.height; h++) {
          int idx = h * bitmap.getPitch();
          for (int w = 0; w < (glyph.width + glyph.xoffset); w++) {
            int bit = (buf.get(idx + (w / 8)) >>> (7 - (w % 8))) & 1;
            pixmap.drawPixel(w, h, ((bit == 1) ? Color.WHITE.toIntBits() : Color.CLEAR.toIntBits()));
          }
        }

      }

      String name = packPrefix + c;
      Rectangle rect = packer.pack(name, pixmap);

      // determine which page it was packed into
      int pIndex = packer.getPageIndex(name);
      if (pIndex == -1) // we should not get here
        throw new IllegalStateException("packer was not able to insert '" + name + "' into a page");

      glyph.page = pIndex;
      glyph.srcX = (int)rect.x;
      glyph.srcY = (int)rect.y;

      data.setGlyph(c, glyph);
      pixmap.dispose();
    }

    // generate kerning
    for (int i = 0; i < parameter.characters.length(); i++) {
      for (int j = 0; j < parameter.characters.length(); j++) {
        char firstChar = parameter.characters.charAt(i);
        Glyph first = data.getGlyph(firstChar);
        if (first == null) continue;
        char secondChar = parameter.characters.charAt(j);
        Glyph second = data.getGlyph(secondChar);
        if (second == null) continue;
        int kerning = FreeType.getKerning(face, FreeType.getCharIndex(face, firstChar),
          FreeType.getCharIndex(face, secondChar), 0);
        if (kerning == 0) continue;
        first.setKerning(secondChar, FreeType.toInt(kerning));
      }
    }

    if (ownsAtlas) {
      Array<Page> pages = packer.getPages();
      data.regions = new TextureRegion[pages.size];

      for (int i = 0; i < pages.size; i++) {
        Page p = pages.get(i);

View Full Code Here

      data.down = -data.down;
    }

    boolean ownsAtlas = false;

    PixmapPacker packer = parameter.packer;

    if (packer == null) {
      // generate the glyphs
      int maxGlyphHeight = (int)Math.ceil(data.lineHeight);
      int pageWidth = MathUtils
        .nextPowerOfTwo((int)Math.sqrt(maxGlyphHeight * maxGlyphHeight * parameter.characters.length()));

      if (maxTextureSize > 0) pageWidth = Math.min(pageWidth, maxTextureSize);

      ownsAtlas = true;
      packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, false);
    }

    // to minimize collisions we'll use this format : pathWithoutExtension_size[_flip]_glyph
    String packPrefix = ownsAtlas ? "" : (filePath + '_' + parameter.size + (parameter.flip ? "_flip_" : '_'));

    for (int i = 0; i < parameter.characters.length(); i++) {
      char c = parameter.characters.charAt(i);
      if (!FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't load char '" + c + "'");
        continue;
      }
      if (!FreeType.renderGlyph(face.getGlyph(), FreeType.FT_RENDER_MODE_NORMAL)) {
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't render char '" + c + "'");
        continue;
      }
      GlyphSlot slot = face.getGlyph();
      GlyphMetrics metrics = slot.getMetrics();
      Bitmap bitmap = slot.getBitmap();
      Pixmap pixmap = bitmap.getPixmap(Format.RGBA8888);
      Glyph glyph = new Glyph();
      glyph.id = (int)c;
      glyph.width = pixmap.getWidth();
      glyph.height = pixmap.getHeight();
      glyph.xoffset = slot.getBitmapLeft();
      glyph.yoffset = parameter.flip ? -slot.getBitmapTop() + (int)baseLine : -(glyph.height - slot.getBitmapTop())
        - (int)baseLine;
      glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance());

      if (bitmapped) {
        pixmap.setColor(Color.CLEAR);
        pixmap.fill();
        ByteBuffer buf = bitmap.getBuffer();
        for (int h = 0; h < glyph.height; h++) {
          int idx = h * bitmap.getPitch();
          for (int w = 0; w < (glyph.width + glyph.xoffset); w++) {
            int bit = (buf.get(idx + (w / 8)) >>> (7 - (w % 8))) & 1;
            pixmap.drawPixel(w, h, ((bit == 1) ? Color.WHITE.toIntBits() : Color.CLEAR.toIntBits()));
          }
        }

      }

      String name = packPrefix + c;
      Rectangle rect = packer.pack(name, pixmap);

      // determine which page it was packed into
      int pIndex = packer.getPageIndex(name);
      if (pIndex == -1) // we should not get here
        throw new IllegalStateException("packer was not able to insert '" + name + "' into a page");

      glyph.page = pIndex;
      glyph.srcX = (int)rect.x;
      glyph.srcY = (int)rect.y;

      data.setGlyph(c, glyph);
      pixmap.dispose();
    }

    // generate kerning
    if (parameter.kerning) {
      for (int i = 0; i < parameter.characters.length(); i++) {
        for (int j = 0; j < parameter.characters.length(); j++) {
          char firstChar = parameter.characters.charAt(i);
          Glyph first = data.getGlyph(firstChar);
          if (first == null) continue;
          char secondChar = parameter.characters.charAt(j);
          Glyph second = data.getGlyph(secondChar);
          if (second == null) continue;
          int kerning = FreeType.getKerning(face, FreeType.getCharIndex(face, firstChar),
            FreeType.getCharIndex(face, secondChar), 0);
          if (kerning == 0) continue;
          first.setKerning(secondChar, FreeType.toInt(kerning));
        }
      }
    }
    if (ownsAtlas) {
      Array<Page> pages = packer.getPages();
      data.regions = new TextureRegion[pages.size];

      for (int i = 0; i < pages.size; i++) {
        Page p = pages.get(i);

View Full Code Here

        placeRect(bestNode);
        rects.removeIndex(bestRectIndex);
      }

      Page result = getResult();
      result.remainingRects = rects;
      return result;
    }
View Full Code Here

      for (int i = 0; i < usedRectangles.size; i++) {
        Rect rect = usedRectangles.get(i);
        w = Math.max(w, rect.x + rect.width);
        h = Math.max(h, rect.y + rect.height);
      }
      Page result = new Page();
      result.outputRects = new Array(usedRectangles);
      result.occupancy = getOccupancy();
      result.width = w;
      result.height = h;
      return result;
View Full Code Here

      }
    }

    Array<Page> pages = new Array();
    while (inputRects.size > 0) {
      Page result = packPage(inputRects);
      pages.add(result);
      inputRects = result.remainingRects;
    }
    return pages;
  }
View Full Code Here

    // Find the minimal page size that fits all rects.
    BinarySearch widthSearch = new BinarySearch(minWidth, settings.maxWidth, settings.fast ? 25 : 15, settings.pot);
    BinarySearch heightSearch = new BinarySearch(minHeight, settings.maxHeight, settings.fast ? 25 : 15, settings.pot);
    int width = widthSearch.reset(), height = heightSearch.reset(), i = 0;
    Page bestResult = null;
    while (true) {
      Page bestWidthResult = null;
      while (width != -1) {
        Page result = packAtSize(true, width - edgePaddingX, height - edgePaddingY, inputRects);
        if (++i % 70 == 0) System.out.println();
        System.out.print(".");
        bestWidthResult = getBest(bestWidthResult, result);
        width = widthSearch.next(result == null);
      }
View Full Code Here

  }

  /** @param fully If true, the only results that pack all rects will be considered. If false, all results are considered, not all
   *           rects may be packed. */
  private Page packAtSize (boolean fully, int width, int height, Array<Rect> inputRects) {
    Page bestResult = null;
    for (int i = 0, n = methods.length; i < n; i++) {
      maxRects.init(width, height);
      Page result;
      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++) {
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.graphics.g2d.PixmapPacker$Page

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.