* Loads the sprites. * * @param index The index of the list of sprite files to load. * @param sprites The array where to store CSIP for each loaded sprite. */
| 81 | * @param sprites The array where to store CSIP for each loaded sprite. |
| 82 | */ |
| 83 | static void Sprites_Load(const char *filename) |
| 84 | { |
| 85 | uint8 *buffer; |
| 86 | uint16 count; |
| 87 | uint16 i; |
| 88 | uint16 size; |
| 89 | |
| 90 | buffer = File_ReadWholeFile(filename); |
| 91 | |
| 92 | count = READ_LE_UINT16(buffer); |
| 93 | |
| 94 | s_spritesCount += count; |
| 95 | g_sprites = (uint8 **)realloc(g_sprites, s_spritesCount * sizeof(uint8 *)); |
| 96 | |
| 97 | for (i = 0; i < count; i++) { |
| 98 | const uint8 *src = Sprites_GetSprite(buffer, i); |
| 99 | uint8 *dst = NULL; |
| 100 | |
| 101 | Debug("Sprites %-12s %3d : 0x%04x %2dx%2d %2d %5d %5d\n", filename, i, |
| 102 | READ_LE_UINT16(src)/*Flags*/, READ_LE_UINT16(src+3)/*Width*/, src[2], /* height */ |
| 103 | src[5] /* height */, READ_LE_UINT16(src+6) /* packed size */, READ_LE_UINT16(src+8) /* decoded size */); |
| 104 | if (src != NULL) { |
| 105 | if (g_unpackSHPonLoad && (src[0] & 0x2) == 0) { |
| 106 | size = READ_LE_UINT16(src+8) + 10; |
| 107 | if (READ_LE_UINT16(src) & 0x1) { |
| 108 | size += 16; /* 16 bytes more for the palette */ |
| 109 | } |
| 110 | dst = (uint8 *)malloc(size); |
| 111 | if (dst == NULL) { |
| 112 | Error("Sprites_Load(%s) failed to allocate %u bytes\n", filename, size); |
| 113 | } else { |
| 114 | const uint8 *encoded_data = src; |
| 115 | uint8 *decoded_data = dst; |
| 116 | *decoded_data++ = *encoded_data++ | 0x2; /* the sprite is not Format80 encoded any more */ |
| 117 | memcpy(decoded_data, encoded_data, 5); |
| 118 | decoded_data += 5; |
| 119 | WRITE_LE_UINT16(decoded_data, size); /* new packed size */ |
| 120 | decoded_data += 2; |
| 121 | encoded_data += 7; |
| 122 | *decoded_data++ = *encoded_data++; /* copy pixel size */ |
| 123 | *decoded_data++ = *encoded_data++; |
| 124 | if (READ_LE_UINT16(src) & 0x1) { |
| 125 | memcpy(decoded_data, encoded_data, 16); /* copy palette */ |
| 126 | decoded_data += 16; |
| 127 | encoded_data += 16; |
| 128 | } |
| 129 | Format80_Decode(decoded_data, encoded_data, READ_LE_UINT16(src+8)); |
| 130 | } |
| 131 | } else { |
| 132 | size = READ_LE_UINT16(src + 6); /* "packed" size */ |
| 133 | dst = (uint8 *)malloc(size); |
| 134 | if (dst == NULL) { |
| 135 | Error("Sprites_Load(%s) failed to allocate %u bytes\n", filename, size); |
| 136 | } else { |
| 137 | memcpy(dst, src, size); |
| 138 | } |
| 139 | } |
| 140 | } |
no test coverage detected