@@ -27,14 +27,12 @@ public Resource execute(String[] fields) throws IllegalArgumentException, IOExce
System.out.println("Wrong TILESET definition");
System.out.println("TILESET name \"file\" [compression [opt]]");
System.out.println(" name Tileset variable name");
System.out.println(
" file the image to convert to TileSet structure (should be a 8bpp .bmp or .png)");
System.out.println(" file the image to convert to TileSet structure (indexed colors BMP or PNG image)");
System.out.println(" compression compression type, accepted values:");
System.out.println(" -1 / BEST / AUTO = use best compression");
System.out.println(" 0 / NONE = no compression (default)");
System.out.println(" 1 / APLIB = aplib library (good compression ratio but slow)");
System.out.println(
" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)");
System.out.println(" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)");
System.out.println(" opt define the optimisation level, accepted values:");
System.out.println(" 0 / NONE = no optimisation, each tile is unique");
System.out.println(" 1 / ALL = ignore duplicated and flipped tile (default)");
@@ -52,14 +52,16 @@ public Image(String id, String imgFile, Compression compression, TileOptimizatio
data = ImageUtil.convertTo8bpp(data, imgInfo.bpp);

// b0-b3 = pixel data; b4-b5 = palette index; b7 = priority bit
// check if image try to use bit 6 (probably mean that we have too much colors in our image)
for (byte d : data)
{
// bit 6 used ?
if ((d & 0x40) != 0)
throw new IllegalArgumentException("'" + imgFile
+ "' has color index in [64..127] range, IMAGE resource requires image with a maximum of 64 colors");
}

// just ignore it..
// // check if image try to use bit 6 (probably mean that we have too much colors in our image)
// for (byte d : data)
// {
// // bit 6 used ?
// if ((d & 0x40) != 0)
// throw new IllegalArgumentException("'" + imgFile
// + "' has color index in [64..127] range, IMAGE resource requires image with a maximum of 64 colors");
// }

// build TILESET with wanted compression
tileset = (Tileset) addInternalResource(new Tileset(id + "_tileset", data, w, h, 0, 0, wt, ht, tileOpt,
@@ -9,6 +9,8 @@
import sgdk.rescomp.type.Basics.TileEquality;
import sgdk.rescomp.type.Basics.TileOptimization;
import sgdk.rescomp.type.Tile;
import sgdk.tool.ImageUtil;
import sgdk.tool.ImageUtil.BasicImageInfo;

public class Tilemap extends Resource
{
@@ -82,6 +84,41 @@ public static Tilemap getTilemap(String id, Tileset tileset, int mapBase, byte[]
opt, compression);
}

public static Tilemap getTilemap(String id, Tileset tileset, int mapBase, String imgFile, TileOptimization tileOpt,
Compression compression) throws IOException
{
// retrieve basic infos about the image
final BasicImageInfo imgInfo = ImageUtil.getBasicInfo(imgFile);

// check BPP is correct
if (imgInfo.bpp > 8)
throw new IllegalArgumentException("'" + imgFile + "' is in " + imgInfo.bpp
+ " bpp format, only indexed images (8,4,2,1 bpp) are supported.");

// set width and height
final int w = imgInfo.w;
final int h = imgInfo.h;

// check size is correct
if ((w & 7) != 0)
throw new IllegalArgumentException("'" + imgFile + "' width is '" + w + ", should be a multiple of 8.");
if ((h & 7) != 0)
throw new IllegalArgumentException("'" + imgFile + "' height is '" + h + ", should be a multiple of 8.");

// get size in tile
final int wt = w / 8;
final int ht = h / 8;

// get image data
byte[] data = ImageUtil.getIndexedPixels(imgFile);
// convert to 8 bpp
data = ImageUtil.convertTo8bpp(data, imgInfo.bpp);

// b0-b3 = pixel data; b4-b5 = palette index; b7 = priority bit
// build TILEMAP with wanted compression
return Tilemap.getTilemap(id, tileset, mapBase, data, wt, ht, tileOpt, compression);
}

public final int w;
public final int h;
final int hc;