MCPcopy Create free account
hub / github.com/DentonW/DevIL / ReadIndexed

Function ReadIndexed

DevIL/src-IL/src/il_psd.cpp:285–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283
284
285ILboolean ReadIndexed(PSDHEAD *Head)
286{
287 ILuint ColorMode, ResourceSize, MiscInfo, i, j, NumEnt;
288 ILushort Compressed;
289 ILubyte *Palette = NULL, *Resources = NULL;
290
291 ColorMode = GetBigUInt(); // Skip over the 'color mode data section'
292 if (ColorMode % 3 != 0) {
293 ilSetError(IL_INVALID_FILE_HEADER);
294 return IL_FALSE;
295 }
296 Palette = (ILubyte*)ialloc(ColorMode);
297 if (Palette == NULL)
298 return IL_FALSE;
299 if (iread(Palette, 1, ColorMode) != ColorMode)
300 goto cleanup_error;
301
302 ResourceSize = GetBigUInt(); // Read the 'image resources section'
303 Resources = (ILubyte*)ialloc(ResourceSize);
304 if (Resources == NULL) {
305 return IL_FALSE;
306 }
307 if (iread(Resources, 1, ResourceSize) != ResourceSize)
308 goto cleanup_error;
309
310 MiscInfo = GetBigUInt();
311 if (ieof())
312 goto cleanup_error;
313 iseek(MiscInfo, IL_SEEK_CUR);
314
315 Compressed = GetBigUShort();
316 if (ieof())
317 goto cleanup_error;
318
319 if (Head->Channels != 1 || Head->Depth != 8) {
320 ilSetError(IL_FORMAT_NOT_SUPPORTED);
321 goto cleanup_error;
322 }
323 ChannelNum = Head->Channels;
324
325 if (!ilTexImage(Head->Width, Head->Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL))
326 goto cleanup_error;
327
328 iCurImage->Pal.Palette = (ILubyte*)ialloc(ColorMode);
329 if (iCurImage->Pal.Palette == NULL) {
330 goto cleanup_error;
331 }
332 iCurImage->Pal.PalSize = ColorMode;
333 iCurImage->Pal.PalType = IL_PAL_RGB24;
334
335 NumEnt = iCurImage->Pal.PalSize / 3;
336 for (i = 0, j = 0; i < iCurImage->Pal.PalSize; i += 3, j++) {
337 iCurImage->Pal.Palette[i ] = Palette[j];
338 iCurImage->Pal.Palette[i+1] = Palette[j+NumEnt];
339 iCurImage->Pal.Palette[i+2] = Palette[j+NumEnt*2];
340 }
341 ifree(Palette);
342 Palette = NULL;

Callers 1

ReadPsdFunction · 0.85

Calls 5

GetBigUIntFunction · 0.85
ilSetErrorFunction · 0.85
GetBigUShortFunction · 0.85
PsdGetDataFunction · 0.85
ParseResourcesFunction · 0.85

Tested by

no test coverage detected