mirror of
https://github.com/codestation/mhtools
synced 2024-12-12 12:52:30 +00:00
Handle special case of gim files without palette.
Force creation of empty file for null table pointer in .pak extraction.
This commit is contained in:
parent
0706c9de14
commit
e8eabbca35
3 changed files with 41 additions and 25 deletions
|
@ -64,33 +64,42 @@ public class ExtractPluginD extends EndianFixer implements Decoder {
|
|||
for(int i = 0; i < header_gim_count; i++) {
|
||||
Gim gim = new Gim();
|
||||
gim.load(file);
|
||||
int buffered_type = BufferedImage.TYPE_INT_ARGB;
|
||||
BufferedImage bi = new BufferedImage(gim.getWidth(), gim.getHeight(), buffered_type);
|
||||
bi.setRGB(0, 0, gim.getWidth(), gim.getHeight(), gim.getRGBarray(), 0, gim.getWidth());
|
||||
String fileformat;
|
||||
String format;
|
||||
String fileout;
|
||||
if(gim.getDataType() == Gim.GIM_TYPE_PALETTE)
|
||||
format = "palette";
|
||||
else if(gim.getDataType() == Gim.GIM_TYPE_PIXELS)
|
||||
format = "pixels";
|
||||
else if(gim.getDataType() == Gim.GIM_TYPE_NOPALETTE)
|
||||
format = "none";
|
||||
else
|
||||
format = "image";
|
||||
String palette;
|
||||
if(gim.getPaletteType() == Gim.RGBA8888) {
|
||||
palette = "RGBA8888";
|
||||
} else {
|
||||
palette = "RGBA5551";
|
||||
String palette = null;
|
||||
if(gim.getDataType() != Gim.GIM_TYPE_NOPALETTE) {
|
||||
if(gim.getPaletteType() == Gim.RGBA8888) {
|
||||
palette = "RGBA8888";
|
||||
} else {
|
||||
palette = "RGBA5551";
|
||||
}
|
||||
}
|
||||
if(gim.isSupported()) {
|
||||
int buffered_type = BufferedImage.TYPE_INT_ARGB;
|
||||
BufferedImage bi = new BufferedImage(gim.getWidth(), gim.getHeight(), buffered_type);
|
||||
bi.setRGB(0, 0, gim.getWidth(), gim.getHeight(), gim.getRGBarray(), 0, gim.getWidth());
|
||||
fileformat = "png";
|
||||
String fileout = String.format(directory + "/%03d", i) + "_" + format + "_" + palette + "." + fileformat;
|
||||
fileout = String.format(directory + "/%03d", i) + "_" + format + "_" + palette + "." + fileformat;
|
||||
System.out.println("Extracting " + fileout);
|
||||
File out = new File(fileout);
|
||||
out.delete();
|
||||
ImageIO.write(bi,fileformat, out);
|
||||
} else {
|
||||
fileformat = "gim";
|
||||
String fileout = String.format(directory + "/%03d", i) + "_" + format + "_" + palette + "." + fileformat;
|
||||
if(palette != null)
|
||||
fileout = String.format(directory + "/%03d", i) + "_" + format + "_" + palette + "." + fileformat;
|
||||
else
|
||||
fileout = String.format(directory + "/%03d", i) + "_" + format + "." + fileformat;
|
||||
System.out.println("Extracting " + fileout);
|
||||
FileOutputStream out = new FileOutputStream(fileout);
|
||||
gim.write(out);
|
||||
out.close();
|
||||
|
|
|
@ -50,8 +50,10 @@ public class ExtractPluginE extends EndianFixer implements Decoder {
|
|||
int file_offset = readInt(file);
|
||||
int file_size = readInt(file);
|
||||
current = file.getFilePointer();
|
||||
if(file_offset == 0)
|
||||
continue;
|
||||
if(file_offset == 0) {
|
||||
new File(String.format("%s/%03d_empty.bin", directory, i)).createNewFile();
|
||||
continue;
|
||||
}
|
||||
file.seek(file_offset);
|
||||
byte buffer[] = new byte[file_size];
|
||||
file.read(buffer);
|
||||
|
|
|
@ -12,6 +12,7 @@ public class Gim extends EndianFixer {
|
|||
public static final int RGBA8888 = 3;
|
||||
public static final int RGBA5551 = 1;
|
||||
public static final int GIM_TYPE_PIXELS = 4;
|
||||
public static final int GIM_TYPE_NOPALETTE = 8;
|
||||
public static final int GIM_TYPE_PALETTE = 5;
|
||||
public static final int HEADER_SIZE = 16;
|
||||
public static final int BPP32_BYTE = 4;
|
||||
|
@ -47,13 +48,15 @@ public class Gim extends EndianFixer {
|
|||
height = readShort(in);
|
||||
imagedata = new byte[data_size - 16];
|
||||
in.read(imagedata);
|
||||
palette_size = readInt(in);
|
||||
palette_flags = readInt(in);
|
||||
palette_type = readInt(in);
|
||||
palette_count = readInt(in);
|
||||
int palette_datasize = palette_count * (palette_type == RGBA8888 ? 4 : 2);
|
||||
palettedata = new byte[palette_datasize];
|
||||
in.read(palettedata);
|
||||
if(data_type != GIM_TYPE_NOPALETTE) {
|
||||
palette_size = readInt(in);
|
||||
palette_flags = readInt(in);
|
||||
palette_type = readInt(in);
|
||||
palette_count = readInt(in);
|
||||
int palette_datasize = palette_count * (palette_type == RGBA8888 ? 4 : 2);
|
||||
palettedata = new byte[palette_datasize];
|
||||
in.read(palettedata);
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
|
@ -151,11 +154,13 @@ public class Gim extends EndianFixer {
|
|||
writeShort(out, width);
|
||||
writeShort(out, height);
|
||||
out.write(imagedata);
|
||||
writeInt(out, palette_size);
|
||||
writeInt(out, palette_flags);
|
||||
writeInt(out, palette_type);
|
||||
writeInt(out, palette_count);
|
||||
out.write(palettedata);
|
||||
if(data_type != GIM_TYPE_NOPALETTE) {
|
||||
writeInt(out, palette_size);
|
||||
writeInt(out, palette_flags);
|
||||
writeInt(out, palette_type);
|
||||
writeInt(out, palette_count);
|
||||
out.write(palettedata);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -278,7 +283,7 @@ public class Gim extends EndianFixer {
|
|||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return (data_type == GIM_TYPE_PIXELS && palette_count <=16) ||
|
||||
return (data_type != GIM_TYPE_NOPALETTE) || (data_type == GIM_TYPE_PIXELS && palette_count <=16) ||
|
||||
(data_type == GIM_TYPE_PALETTE && palette_count <= 256);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue