From: chaoskagami Date: Sat, 18 Oct 2014 22:10:00 +0000 (-0400) Subject: Still not functional - at least everything is right-side up now X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=dfcc498082d964cb7573901b8c8fb41f1f5176b9;p=console%2FRCOMage.git Still not functional - at least everything is right-side up now --- diff --git a/src/gimtool.c b/src/gimtool.c index 11611e1..7f08439 100644 --- a/src/gimtool.c +++ b/src/gimtool.c @@ -18,7 +18,7 @@ #include "gimtool.h" char* unswizzle(char* data, int width, int height, int bpp) { - width = (width * bpp) >> 3; + width = (width * bpp) / 8; char* dest = (char*)calloc(sizeof(char), width*height); @@ -48,6 +48,14 @@ char* unswizzle(char* data, int width, int height, int bpp) { void dump_bitmap(char* fname, char* data32bpp, int width, int height) { + // Bitmaps are bottom-up for rows - so first thing's first. + char* data_new = (char*)calloc(sizeof(char), width*height*4); + // FLIP IT. + int i; + for(i=0; iBMP ("); + if(swizzled) { + printf("SWIZ, "); switch (datFmt) { case Rgb565: case Argb1555: case Argb4444: - texture_data = unswizzle(texture_data, width, height, 16); + texture_data = unswizzle(texture_data, width+widthOff, height+heightOff, 16); break; case Argb8888: - texture_data = unswizzle(texture_data, width, height, 32); + texture_data = unswizzle(texture_data, width+widthOff, height+heightOff, 32); break; case Index4: - texture_data = unswizzle(texture_data, width, height, 4); + texture_data = unswizzle(texture_data, width+widthOff, height+heightOff, 4); break; case Index8: - texture_data = unswizzle(texture_data, width, height, 8); + texture_data = unswizzle(texture_data, width+widthOff, height+heightOff, 8); break; } } @@ -361,60 +373,67 @@ OutData* ReadData(char* data, int length) { char* palData = NULL; - if(datFmt == Index8) { - // Extract pallete - switch (palFmt) { - case Rgb565: - palData = decode_Rgb565( &data[palleteOffset], 256, 1); - break; - case Argb1555: - palData = decode_Argb1555(&data[palleteOffset], 256, 1); - break; - case Argb4444: - palData = decode_Argb4444(&data[palleteOffset], 256, 1); - break; - case Argb8888: - palData = decode_Argb8888(&data[palleteOffset], 256, 1); - break; - } - } - - if(datFmt == Index4) { - // Extract pallete - switch (palFmt) { - case Rgb565: - palData = decode_Rgb565(&data[palleteOffset], 16, 1); - break; - case Argb1555: - palData = decode_Argb1555(&data[palleteOffset], 16, 1); - break; - case Argb4444: - palData = decode_Argb4444(&data[palleteOffset], 16, 1); - break; - case Argb8888: - palData = decode_Argb8888(&data[palleteOffset], 16, 1); - break; - } - } - switch (datFmt) { case Rgb565: - newData = decode_Rgb565(texture_data, width, height); + printf("RGB565)"); + newData = decode_Rgb565(texture_data, width+widthOff, height+heightOff); break; case Argb1555: - newData = decode_Argb1555(texture_data, width, height); + printf("ARGB1555)"); + newData = decode_Argb1555(texture_data, width+widthOff, height+heightOff); break; case Argb4444: - newData = decode_Argb4444(texture_data, width, height); + printf("ARGB4444)"); + newData = decode_Argb4444(texture_data, width+widthOff, height+heightOff); break; case Argb8888: - newData = decode_Argb8888(texture_data, width, height); + printf("ARGB8888)"); + newData = decode_Argb8888(texture_data, width+widthOff, height+heightOff); break; case Index4: - newData = decode_Index4(texture_data, palData, width, height); + // Extract pallete + switch (palFmt) { + case Rgb565: + printf("4bpp, RGB565)"); + palData = decode_Rgb565( &data[palleteOffset], 16, 1); + break; + case Argb1555: + printf("4bpp, ARGB1555)"); + palData = decode_Argb1555(&data[palleteOffset], 16, 1); + break; + case Argb4444: + printf("4bpp, ARGB4444)"); + palData = decode_Argb4444(&data[palleteOffset], 16, 1); + break; + case Argb8888: + printf("4bpp, ARGB8888)"); + palData = decode_Argb8888(&data[palleteOffset], 16, 1); + break; + } + + newData = decode_Index4(texture_data, palData, width+widthOff, height+heightOff); break; case Index8: - newData = decode_Index8(texture_data, palData, width, height); + // Extract pallete + switch (palFmt) { + case Rgb565: + printf("8bpp, RGB565)"); + palData = decode_Rgb565( &data[palleteOffset], 256, 1); + break; + case Argb1555: + printf("8bpp, ARGB1555)"); + palData = decode_Argb1555(&data[palleteOffset], 256, 1); + break; + case Argb4444: + printf("8bpp, ARGB4444)"); + palData = decode_Argb4444(&data[palleteOffset], 256, 1); + break; + case Argb8888: + printf("8bpp, ARGB8888)"); + palData = decode_Argb8888(&data[palleteOffset], 256, 1); + break; + } + newData = decode_Index8(texture_data, palData, width+widthOff, height+heightOff); break; case Unknown: // Invalid format. @@ -424,8 +443,8 @@ OutData* ReadData(char* data, int length) { OutData* out = (OutData*)calloc(sizeof(OutData), 1); out->data = newData; - out->width = width; - out->height = height; + out->width = width+widthOff; + out->height = height+heightOff; return out; } @@ -435,13 +454,15 @@ uint8_t GIMExport(char* data, size_t len, char* file_out) { OutData* data_converted = ReadData(data, len); if(data_converted == NULL) { - //fprintf(stderr, "GIM data has issues - dying.\n"); + printf(" - Failed.\n"); return -1; } // Export to bitmap. dump_bitmap(file_out, data_converted->data, data_converted->width, data_converted->height); + printf(" - OK.\n"); + return 0; } @@ -457,6 +478,8 @@ uint8_t GIMToBMP(char* file_in, char* file_out) { // Read in RAW data. char* input_data = (char*)calloc(sizeof(char), size); fread(input_data, 1, size, input); + + printf("gimtool-exp: %s, ", file_out); return GIMExport(input_data, size, file_out); }