MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY ilConvertBuffer

Function ILAPIENTRY ilConvertBuffer

DevIL/src-IL/src/il_convbuff.cpp:35–1961  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 }
34
35ILAPI void* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, ILpal *SrcPal, void *Buffer)
36{
37 //static const ILfloat LumFactor[3] = { 0.299f, 0.587f, 0.114f }; // Used for conversion to luminance
38 //static const ILfloat LumFactor[3] = { 0.3086f, 0.6094f, 0.0820f }; // http://www.sgi.com/grafica/matrix/index.html
39 static const ILfloat LumFactor[3] = { 0.212671f, 0.715160f, 0.072169f }; // http://www.inforamp.net/~poynton/ and libpng's libpng.txt
40
41 ILubyte *NewData = NULL;
42 ILuint i, j, c, Size;
43 ILfloat Resultf;
44 ILdouble Resultd;
45 ILuint NumPix; // Really number of pixels * bpp.
46 ILuint BpcDest;
47 void *Data = NULL;
48 ILimage *PalImage = NULL, *TempImage = NULL;
49
50 if (SizeOfData == 0 || Buffer == NULL) {
51 ilSetError(IL_INVALID_PARAM);
52 return NULL;
53 }
54
55 Data = iSwitchTypes(SizeOfData, SrcType, DestType, Buffer);
56 if (Data == NULL)
57 return NULL;
58
59 BpcDest = ilGetBpcType(DestType);
60 NumPix = SizeOfData / ilGetBpcType(SrcType);
61
62 if (DestFormat == SrcFormat) {
63 NewData = (ILubyte*)ialloc(NumPix * BpcDest);
64 if (NewData == NULL) {
65 return IL_FALSE;
66 }
67 memcpy(NewData, Data, NumPix * BpcDest);
68 if (Data != Buffer)
69 ifree(Data);
70
71 return NewData;
72 }
73
74 // Colour-indexed images are special here
75 if (SrcFormat == IL_COLOUR_INDEX) {
76 // We create a temporary palette image so that we can send it to iConvertPalette.
77 PalImage = (ILimage*)icalloc(1, sizeof(ILimage)); // Much better to have it all set to 0.
78 if (PalImage == NULL)
79 return NULL;
80 // Populate the temporary palette image.
81 PalImage->Pal.Palette = SrcPal->Palette;
82 PalImage->Pal.PalSize = SrcPal->PalSize;
83 PalImage->Pal.PalType = SrcPal->PalType;
84 PalImage->Width = NumPix;
85 PalImage->Height = 1;
86 PalImage->Depth = 1;
87 PalImage->Format = IL_COLOUR_INDEX;
88 PalImage->Type = IL_UNSIGNED_BYTE;
89 PalImage->Data = (ILubyte*)Buffer;
90 PalImage->Bpp = 1;
91 PalImage->SizeOfData = SizeOfData;
92

Callers

nothing calls this directly

Calls 12

ilSetErrorFunction · 0.85
ilGetBpcTypeFunction · 0.85
iConvertPaletteFunction · 0.85
ilCloseImageFunction · 0.85
abc2cba_byteFunction · 0.85
abc2cba_shortFunction · 0.85
abc2cba_intFunction · 0.85
abc2cba_doubleFunction · 0.85
abcd2cbad_byteFunction · 0.85
abcd2cbad_shortFunction · 0.85
abcd2cbad_intFunction · 0.85
abcd2cbad_doubleFunction · 0.85

Tested by

no test coverage detected