Ticket #8998: dataLoader.diff
File dataLoader.diff, 6.1 KB (added by , 16 years ago) |
---|
-
dataLoader.cpp
37 37 38 38 int loadSingleFile; 39 39 40 // TODO: Unify decodeGfxFormat1, decodeGfxFormat4 and decodeGfxFormat5 41 42 void decodeGfxFormat1(dataFileEntry *pCurrentFileEntry) { 43 uint8 *buffer; 40 // First attempt to unify decodeGfx - Jaime Abraham Corrales Gonzalez 41 void decodeGfxUnified(dataFileEntry *pCurrentFileEntry, int16 format) { 44 42 uint8 *dataPtr = pCurrentFileEntry->subData.ptr; 43 int spriteSize; 45 44 46 int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->width; 47 int x = 0; 48 49 buffer = (uint8 *) malloc(spriteSize); 50 51 while (x < spriteSize) { 52 uint8 c; 53 uint16 p0; 54 55 p0 = (dataPtr[0] << 8) | dataPtr[1]; 56 57 /* decode planes */ 58 for (c = 0; c < 16; c++) { 59 buffer[x + c] = ((p0 >> 15) & 1); 60 61 p0 <<= 1; 62 } 63 64 x += 16; 65 66 dataPtr += 2; 45 // Unified how to get spriteSize 46 switch (format) { 47 case 1: 48 case 4: 49 spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->width; 50 break; 51 case 5: 52 spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn; 53 break; 67 54 } 68 55 69 pCurrentFileEntry->subData.ptr = buffer; 70 } 56 uint8 *buffer = (uint8 *) malloc(spriteSize); 71 57 72 void decodeGfxFormat4(dataFileEntry *pCurrentFileEntry) { 73 uint8 *buffer; 74 uint8 *dataPtr = pCurrentFileEntry->subData.ptr; 75 76 int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->width; 58 // Formats 1 and 4 77 59 int x = 0; 60 // Format 5 61 uint8 *destP = buffer; 62 int range = pCurrentFileEntry->height * pCurrentFileEntry->width; 78 63 79 buffer = (uint8 *) malloc(spriteSize); 64 // Unified how to operate with Gfx 65 switch (format) { 66 case 1: 67 case 4: 68 while (x < spriteSize) { 69 uint8 c; 70 uint16 p0; 71 // Format 4 72 uint16 p1; 73 uint16 p2; 74 uint16 p3; 80 75 81 while (x < spriteSize) { 82 uint8 c; 83 uint16 p0; 84 uint16 p1; 85 uint16 p2; 86 uint16 p3; 76 p0 = (dataPtr[0] << 8) | dataPtr[1]; 77 // Format 4 78 if (format == 4) { 79 p1 = (dataPtr[2] << 8) | dataPtr[3]; 80 p2 = (dataPtr[4] << 8) | dataPtr[5]; 81 p3 = (dataPtr[6] << 8) | dataPtr[7]; 82 } 87 83 88 p0 = (dataPtr[0] << 8) | dataPtr[1]; 89 p1 = (dataPtr[2] << 8) | dataPtr[3]; 90 p2 = (dataPtr[4] << 8) | dataPtr[5]; 91 p3 = (dataPtr[6] << 8) | dataPtr[7]; 84 /* decode planes */ 85 for (c = 0; c < 16; c++) { 86 // Format 4 87 if (format == 4) { 88 buffer[x + c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8); 89 } else { 90 buffer[x + c] = ((p0 >> 15) & 1); 91 } 92 92 93 /* decode planes */ 94 for (c = 0; c < 16; c++) { 95 buffer[x + c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8); 93 p0 <<= 1; 94 // Format 4 95 if (format == 4) { 96 p1 <<= 1; 97 p2 <<= 1; 98 p3 <<= 1; 99 } 100 } 96 101 97 p0 <<= 1; 98 p1 <<= 1; 99 p2 <<= 1; 100 p3 <<= 1; 102 x += 16; 103 104 dataPtr += (2 * format); 101 105 } 102 106 103 x += 16;107 break; 104 108 105 dataPtr += 8; 106 } 109 case 5: 110 for (int line = 0; line < pCurrentFileEntry->height; line++) { 111 uint8 p0, p1, p2, p3, p4; 107 112 108 pCurrentFileEntry->subData.ptr = buffer; 109 } 113 for (int x = 0; x < pCurrentFileEntry->widthInColumn; x++) { 114 int bit = 7 - (x % 8); 115 int col = x / 8; 110 116 111 void decodeGfxFormat5(dataFileEntry *pCurrentFileEntry) { 112 uint8 *dataPtr = pCurrentFileEntry->subData.ptr; 113 int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn; 114 int range = pCurrentFileEntry->height * pCurrentFileEntry->width; 117 p0 = (dataPtr[line*pCurrentFileEntry->width + col + range * 0] >> bit) & 1; 118 p1 = (dataPtr[line*pCurrentFileEntry->width + col + range * 1] >> bit) & 1; 119 p2 = (dataPtr[line*pCurrentFileEntry->width + col + range * 2] >> bit) & 1; 120 p3 = (dataPtr[line*pCurrentFileEntry->width + col + range * 3] >> bit) & 1; 121 p4 = (dataPtr[line*pCurrentFileEntry->width + col + range * 4] >> bit) & 1; 115 122 116 uint8 *buffer = (uint8 *)malloc(spriteSize); 117 uint8 *destP = buffer; 118 119 for (int line = 0; line < pCurrentFileEntry->height; line++) { 120 uint8 p0, p1, p2, p3, p4; 121 122 for (int x = 0; x < pCurrentFileEntry->widthInColumn; x++) { 123 int bit = 7 - (x % 8); 124 int col = x / 8; 125 126 p0 = (dataPtr[line*pCurrentFileEntry->width + col + range * 0] >> bit) & 1; 127 p1 = (dataPtr[line*pCurrentFileEntry->width + col + range * 1] >> bit) & 1; 128 p2 = (dataPtr[line*pCurrentFileEntry->width + col + range * 2] >> bit) & 1; 129 p3 = (dataPtr[line*pCurrentFileEntry->width + col + range * 3] >> bit) & 1; 130 p4 = (dataPtr[line*pCurrentFileEntry->width + col + range * 4] >> bit) & 1; 131 132 *destP++ = p0 | (p1 << 1) | (p2 << 2) | (p3 << 3) | (p4 << 4); 123 *destP++ = p0 | (p1 << 1) | (p2 << 2) | (p3 << 3) | (p4 << 4); 124 } 133 125 } 126 127 break; 134 128 } 135 129 136 130 pCurrentFileEntry->subData.ptr = buffer; … … 470 464 case 1: { 471 465 filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn * 8; 472 466 filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_BGMASK; 473 decodeGfx Format1(&filesDatabase[fileIndex]);467 decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); 474 468 filesDatabase[fileIndex].subData.index = currentEntryIdx; 475 469 filesDatabase[fileIndex].subData.transparency = 0; 476 470 break; … … 478 472 case 4: { 479 473 filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn * 2; 480 474 filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_SPRITE; 481 decodeGfx Format4(&filesDatabase[fileIndex]);475 decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); 482 476 filesDatabase[fileIndex].subData.index = currentEntryIdx; 483 477 filesDatabase[fileIndex].subData.transparency = localBuffer.transparency % 0x10; 484 478 break; 485 479 } 486 480 case 5: { 487 481 filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_SPRITE; 488 decodeGfx Format5(&filesDatabase[fileIndex]);482 decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); 489 483 filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn; 490 484 filesDatabase[fileIndex].subData.index = currentEntryIdx; 491 485 filesDatabase[fileIndex].subData.transparency = localBuffer.transparency;