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

Function ReadRGB

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

Source from the content-addressed store, hash-verified

359
360
361ILboolean ReadRGB(PSDHEAD *Head)
362{
363 ILuint ColorMode, ResourceSize, MiscInfo;
364 ILushort Compressed;
365 ILenum Format, Type;
366 ILubyte *Resources = NULL;
367
368 ColorMode = GetBigUInt(); // Skip over the 'color mode data section'
369 iseek(ColorMode, IL_SEEK_CUR);
370
371 ResourceSize = GetBigUInt(); // Read the 'image resources section'
372 Resources = (ILubyte*)ialloc(ResourceSize);
373 if (Resources == NULL)
374 return IL_FALSE;
375 if (iread(Resources, 1, ResourceSize) != ResourceSize)
376 goto cleanup_error;
377
378 MiscInfo = GetBigUInt();
379 iseek(MiscInfo, IL_SEEK_CUR);
380
381 Compressed = GetBigUShort();
382
383 ChannelNum = Head->Channels;
384 if (Head->Channels == 3)
385 {
386 Format = IL_RGB;
387 }
388 else if (Head->Channels == 4)
389 {
390 Format = IL_RGBA;
391 }
392 else if (Head->Channels >= 5)
393 {
394 // Additional channels are accumulated as a single alpha channel, since
395 // if an image does not have a layer set as the "background", but also
396 // has a real alpha channel, there will be 5 channels (or more).
397 Format = IL_RGBA;
398 }
399 else
400 {
401 ilSetError(IL_FORMAT_NOT_SUPPORTED);
402 return IL_FALSE;
403 }
404
405 switch (Head->Depth)
406 {
407 case 8:
408 Type = IL_UNSIGNED_BYTE;
409 break;
410 case 16:
411 Type = IL_UNSIGNED_SHORT;
412 break;
413 default:
414 ilSetError(IL_FORMAT_NOT_SUPPORTED);
415 return IL_FALSE;
416 }
417 if (!ilTexImage(Head->Width, Head->Height, 1, (Format==IL_RGB) ? 3 : 4, Format, Type, NULL))
418 goto cleanup_error;

Callers 1

ReadPsdFunction · 0.85

Calls 5

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

Tested by

no test coverage detected