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

Function ReadGrey

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

Source from the content-addressed store, hash-verified

225
226
227ILboolean ReadGrey(PSDHEAD *Head)
228{
229 ILuint ColorMode, ResourceSize, MiscInfo;
230 ILushort Compressed;
231 ILenum Type;
232 ILubyte *Resources = NULL;
233
234 ColorMode = GetBigUInt(); // Skip over the 'color mode data section'
235 iseek(ColorMode, IL_SEEK_CUR);
236
237 ResourceSize = GetBigUInt(); // Read the 'image resources section'
238 Resources = (ILubyte*)ialloc(ResourceSize);
239 if (Resources == NULL) {
240 return IL_FALSE;
241 }
242 if (iread(Resources, 1, ResourceSize) != ResourceSize)
243 goto cleanup_error;
244
245 MiscInfo = GetBigUInt();
246 iseek(MiscInfo, IL_SEEK_CUR);
247
248 Compressed = GetBigUShort();
249
250 ChannelNum = Head->Channels;
251 Head->Channels = 1; // Temporary to read only one channel...some greyscale .psd files have 2.
252 if (Head->Channels != 1) {
253 ilSetError(IL_FORMAT_NOT_SUPPORTED);
254 return IL_FALSE;
255 }
256 switch (Head->Depth)
257 {
258 case 8:
259 Type = IL_UNSIGNED_BYTE;
260 break;
261 case 16:
262 Type = IL_UNSIGNED_SHORT;
263 break;
264 default:
265 ilSetError(IL_FORMAT_NOT_SUPPORTED);
266 return IL_FALSE;
267 }
268
269 if (!ilTexImage(Head->Width, Head->Height, 1, 1, IL_LUMINANCE, Type, NULL))
270 goto cleanup_error;
271 if (!PsdGetData(Head, iCurImage->Data, (ILboolean)Compressed))
272 goto cleanup_error;
273 if (!ParseResources(ResourceSize, Resources))
274 goto cleanup_error;
275 ifree(Resources);
276
277 return IL_TRUE;
278
279cleanup_error:
280 ifree(Resources);
281 return IL_FALSE;
282}
283
284

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