MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Sprites_LoadCPSFile

Function Sprites_LoadCPSFile

src/sprites.c:294–333  ·  view source on GitHub ↗

* Loads a CPS file. * * @param filename The name of the file to load. * @param screenID The index of a memory block where to store loaded data. * @param palette Where to store the palette, if any. * @return The size of the loaded image. */

Source from the content-addressed store, hash-verified

292 * @return The size of the loaded image.
293 */
294static uint32 Sprites_LoadCPSFile(const char *filename, Screen screenID, uint8 *palette)
295{
296 uint8 index;
297 uint16 size;
298 uint8 *buffer;
299 uint8 *buffer2;
300 uint16 paletteSize;
301
302 buffer = GFX_Screen_Get_ByIndex(screenID);
303
304 index = File_Open(filename, FILE_MODE_READ);
305
306 size = File_Read_LE16(index);
307
308 File_Read(index, buffer, 8);
309
310 size -= 8;
311
312 paletteSize = READ_LE_UINT16(buffer + 6);
313
314 if (palette != NULL && paletteSize != 0) {
315 File_Read(index, palette, paletteSize);
316 } else {
317 File_Seek(index, paletteSize, 1);
318 }
319
320 buffer[6] = 0; /* dont read palette next time */
321 buffer[7] = 0;
322 size -= paletteSize;
323
324 buffer2 = GFX_Screen_Get_ByIndex(screenID);
325 buffer2 += GFX_Screen_GetSize_ByIndex(screenID) - size - 8;
326
327 memmove(buffer2, buffer, 8);
328 File_Read(index, buffer2 + 8, size);
329
330 File_Close(index);
331
332 return Sprites_Decode(buffer2, buffer);
333}
334
335/**
336 * Loads an image.

Callers 2

Sprites_LoadImageFunction · 0.85

Calls 7

GFX_Screen_Get_ByIndexFunction · 0.85
File_Read_LE16Function · 0.85
File_ReadFunction · 0.85
File_SeekFunction · 0.85
File_CloseFunction · 0.85
Sprites_DecodeFunction · 0.85

Tested by

no test coverage detected