From: chaoskagami Date: Sun, 19 Oct 2014 05:37:42 +0000 (-0400) Subject: Added crop of BMP when scale occurs. I'll start making an encoder soon. But, to note... X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;p=console%2FRCOMage.git Added crop of BMP when scale occurs. I'll start making an encoder soon. But, to note - for the sake of all our sanity - MAKE YOUR TEXTURES A MULTIPLE OF 16 WIDTH, and a MULTIPLE of 8 height. God help you otherwise, because insertion and extraction isn't standardized with PSP tools. Some seem to reflow, some seem to insert padding. I'm incapable of figuring this out without some sort of flag. --- diff --git a/src/gimtool.c b/src/gimtool.c index b5068fa..a541bac 100644 --- a/src/gimtool.c +++ b/src/gimtool.c @@ -17,19 +17,20 @@ #include "gimtool.h" -uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp) { +uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp, int fix) { width = (width * bpp) >> 3; uint8_t* dest = (uint8_t*)calloc(sizeof(uint8_t), width*height); int rowblocks = (width / 16); - int dstoff = 0; + int dst_y = 0, dst_x = 0; int x, y; for (y = 0; y < height; y++) { + dst_x = 0; for (x = 0; x < width; x++) { int blockX = x / 16; @@ -38,9 +39,12 @@ uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp) { int blockIndex = blockX + ((blockY) * rowblocks); int blockAddress = blockIndex * 16 * 8; - dest[dstoff] = data[blockAddress + ((x - blockX * 16)) + ((y - blockY * 8) * 16)]; - dstoff++; + int dstoff = dst_x + ( dst_y * width ); + + dest[dstoff] = data[blockAddress + (x - blockX * 16) + ((y - blockY * 8) * 16)]; + dst_x++; } + dst_y++; } return dest; @@ -49,7 +53,7 @@ uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp) { void dump_bitmap(char* fname, uint8_t* data32bpp, int width, int height) { // Bitmaps are bottom-up for rows - so first thing's first. - uint8_t* data_new = (char*)calloc(sizeof(char), width*height*4); + uint8_t* data_new = (uint8_t*)calloc(sizeof(uint8_t*), width*height*4); // FLIP IT. int i; for(i=0; iBMP ("); fflush(stdout); - // FIXME - Swizzle code is apparently incorrect. Blocks end up shifted wrong. + // FIXME - Swizzle code is apparently incorrect. Blocks end up shifted wrong with >8bpp. + + int original_width = width; + int original_height = height; if (width % 16 != 0) width += 16 - (width % 16); if (height % 8 != 0) height += 8 - (height % 8); + //printf("Fix +[%d, %d], ", width - original_width, height - original_height); + if(swizzled) { printf("SWIZ, "); fflush(stdout); + //int fix = original_width % 16; + switch (datFmt) { case Rgb565: case Argb1555: case Argb4444: - texture_data = unswizzle(texture_data, width, height, 16); + texture_data = unswizzle(texture_data, width, height, 16, 0); break; case Argb8888: - texture_data = unswizzle(texture_data, width, height, 32); + texture_data = unswizzle(texture_data, width, height, 32, 0); break; case Index4: - texture_data = unswizzle(texture_data, width, height, 4); + texture_data = unswizzle(texture_data, width, height, 4, 0); break; case Index8: - texture_data = unswizzle(texture_data, width, height, 8); + texture_data = unswizzle(texture_data, width, height, 8, 0); break; } } @@ -414,7 +442,7 @@ OutData* ReadData(uint8_t* data, int length) { break; case Argb8888: printf("4bpp, ARGB8888)"); - palData = unswizzle(decode_Argb8888(&data[palleteOffset], 16, 1), 16, 1, 32); + palData = decode_Argb8888(&data[palleteOffset], 16, 1); break; } newData = decode_Index4(texture_data, palData, width, height); @@ -450,9 +478,9 @@ OutData* ReadData(uint8_t* data, int length) { OutData* out = (OutData*)calloc(sizeof(OutData), 1); - out->data = newData; - out->width = width+widthOff; - out->height = height+heightOff; + out->data = crop(newData, width, height, original_width, original_height); + out->width = original_width; + out->height = original_height; return out; } diff --git a/src/gimtool.h b/src/gimtool.h index 78bc07e..3578d98 100644 --- a/src/gimtool.h +++ b/src/gimtool.h @@ -54,7 +54,7 @@ typedef struct { uint8_t* data; } OutData; -uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp); +uint8_t* unswizzle(uint8_t* data, int width, int height, int bpp, int fix); void dump_bitmap(char* fname, uint8_t* data32bpp, int width, int height); uint8_t* decode_Rgb565(uint8_t* data, int width, int height);