Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017 Longri
* Copyright 2017 devemux86
*
* Based on PixmapPacker from LibGdx converted to use VTM Bitmaps without any LibGdx dependencies:
* https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/PixmapPacker.java
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see .
*/
package org.oscim.utils;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Canvas;
import org.oscim.backend.canvas.Color;
import org.oscim.renderer.atlas.TextureAtlas;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BitmapPacker {
private final int atlasWidth, atlasHeight;
private final int padding;
private final PackStrategy packStrategy;
private final boolean flipY;
private final List packerAtlasItems = new ArrayList<>();
public BitmapPacker(int atlasWidth, int atlasHeight, int padding, boolean flipY) {
this(atlasWidth, atlasHeight, padding, new GuillotineStrategy(), flipY);
}
public BitmapPacker(int atlasWidth, int atlasHeight, int padding, PackStrategy packStrategy,
boolean flipY) {
this.atlasWidth = atlasWidth;
this.atlasHeight = atlasHeight;
this.padding = padding;
this.packStrategy = packStrategy;
this.flipY = flipY;
}
public synchronized Rect add(Object key, Bitmap image) {
Rect rect = new Rect(0, 0, image.getWidth(), image.getHeight());
if (rect.width > atlasWidth || rect.height > atlasHeight) {
if (key == null)
throw new RuntimeException("PackerAtlasItem size too small for Bitmap.");
throw new RuntimeException("PackerAtlasItem size too small for Bitmap: " + key);
}
PackerAtlasItem packerAtlasItem = packStrategy.pack(this, key, rect);
if (key != null) {
packerAtlasItem.rects.put(key, rect);
packerAtlasItem.addedRects.add(key);
}
int rectX = rect.x, rectY = rect.y, rectWidth = rect.width, rectHeight = rect.height;
packerAtlasItem.drawBitmap(image, rectX,
flipY ? packerAtlasItem.image.getHeight() - rectY - rectHeight : rectY);
return rect;
}
public synchronized PackerAtlasItem getAtlasItem(int index) {
return packerAtlasItems.get(index);
}
public int getAtlasCount() {
return packerAtlasItems.size();
}
public static class PackerAtlasItem {
HashMap