mirror of
https://github.com/codestation/mhtools
synced 2025-03-04 06:47:16 +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++) {
|
for(int i = 0; i < header_gim_count; i++) {
|
||||||
Gim gim = new Gim();
|
Gim gim = new Gim();
|
||||||
gim.load(file);
|
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 fileformat;
|
||||||
String format;
|
String format;
|
||||||
|
String fileout;
|
||||||
if(gim.getDataType() == Gim.GIM_TYPE_PALETTE)
|
if(gim.getDataType() == Gim.GIM_TYPE_PALETTE)
|
||||||
format = "palette";
|
format = "palette";
|
||||||
else if(gim.getDataType() == Gim.GIM_TYPE_PIXELS)
|
else if(gim.getDataType() == Gim.GIM_TYPE_PIXELS)
|
||||||
format = "pixels";
|
format = "pixels";
|
||||||
|
else if(gim.getDataType() == Gim.GIM_TYPE_NOPALETTE)
|
||||||
|
format = "none";
|
||||||
else
|
else
|
||||||
format = "image";
|
format = "image";
|
||||||
String palette;
|
String palette = null;
|
||||||
if(gim.getPaletteType() == Gim.RGBA8888) {
|
if(gim.getDataType() != Gim.GIM_TYPE_NOPALETTE) {
|
||||||
palette = "RGBA8888";
|
if(gim.getPaletteType() == Gim.RGBA8888) {
|
||||||
} else {
|
palette = "RGBA8888";
|
||||||
palette = "RGBA5551";
|
} else {
|
||||||
|
palette = "RGBA5551";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(gim.isSupported()) {
|
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";
|
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);
|
System.out.println("Extracting " + fileout);
|
||||||
File out = new File(fileout);
|
File out = new File(fileout);
|
||||||
out.delete();
|
out.delete();
|
||||||
ImageIO.write(bi,fileformat, out);
|
ImageIO.write(bi,fileformat, out);
|
||||||
} else {
|
} else {
|
||||||
fileformat = "gim";
|
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);
|
FileOutputStream out = new FileOutputStream(fileout);
|
||||||
gim.write(out);
|
gim.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
|
@ -50,8 +50,10 @@ public class ExtractPluginE extends EndianFixer implements Decoder {
|
||||||
int file_offset = readInt(file);
|
int file_offset = readInt(file);
|
||||||
int file_size = readInt(file);
|
int file_size = readInt(file);
|
||||||
current = file.getFilePointer();
|
current = file.getFilePointer();
|
||||||
if(file_offset == 0)
|
if(file_offset == 0) {
|
||||||
continue;
|
new File(String.format("%s/%03d_empty.bin", directory, i)).createNewFile();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
file.seek(file_offset);
|
file.seek(file_offset);
|
||||||
byte buffer[] = new byte[file_size];
|
byte buffer[] = new byte[file_size];
|
||||||
file.read(buffer);
|
file.read(buffer);
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class Gim extends EndianFixer {
|
||||||
public static final int RGBA8888 = 3;
|
public static final int RGBA8888 = 3;
|
||||||
public static final int RGBA5551 = 1;
|
public static final int RGBA5551 = 1;
|
||||||
public static final int GIM_TYPE_PIXELS = 4;
|
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 GIM_TYPE_PALETTE = 5;
|
||||||
public static final int HEADER_SIZE = 16;
|
public static final int HEADER_SIZE = 16;
|
||||||
public static final int BPP32_BYTE = 4;
|
public static final int BPP32_BYTE = 4;
|
||||||
|
@ -47,13 +48,15 @@ public class Gim extends EndianFixer {
|
||||||
height = readShort(in);
|
height = readShort(in);
|
||||||
imagedata = new byte[data_size - 16];
|
imagedata = new byte[data_size - 16];
|
||||||
in.read(imagedata);
|
in.read(imagedata);
|
||||||
palette_size = readInt(in);
|
if(data_type != GIM_TYPE_NOPALETTE) {
|
||||||
palette_flags = readInt(in);
|
palette_size = readInt(in);
|
||||||
palette_type = readInt(in);
|
palette_flags = readInt(in);
|
||||||
palette_count = readInt(in);
|
palette_type = readInt(in);
|
||||||
int palette_datasize = palette_count * (palette_type == RGBA8888 ? 4 : 2);
|
palette_count = readInt(in);
|
||||||
palettedata = new byte[palette_datasize];
|
int palette_datasize = palette_count * (palette_type == RGBA8888 ? 4 : 2);
|
||||||
in.read(palettedata);
|
palettedata = new byte[palette_datasize];
|
||||||
|
in.read(palettedata);
|
||||||
|
}
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,11 +154,13 @@ public class Gim extends EndianFixer {
|
||||||
writeShort(out, width);
|
writeShort(out, width);
|
||||||
writeShort(out, height);
|
writeShort(out, height);
|
||||||
out.write(imagedata);
|
out.write(imagedata);
|
||||||
writeInt(out, palette_size);
|
if(data_type != GIM_TYPE_NOPALETTE) {
|
||||||
writeInt(out, palette_flags);
|
writeInt(out, palette_size);
|
||||||
writeInt(out, palette_type);
|
writeInt(out, palette_flags);
|
||||||
writeInt(out, palette_count);
|
writeInt(out, palette_type);
|
||||||
out.write(palettedata);
|
writeInt(out, palette_count);
|
||||||
|
out.write(palettedata);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +283,7 @@ public class Gim extends EndianFixer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSupported() {
|
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);
|
(data_type == GIM_TYPE_PALETTE && palette_count <= 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue