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

Function ILAPIENTRY iluInvertAlpha

DevIL/src-ILU/src/ilu_manip.cpp:269–331  ·  view source on GitHub ↗

Inverts the alpha in the image

Source from the content-addressed store, hash-verified

267
268//! Inverts the alpha in the image
269ILboolean ILAPIENTRY iluInvertAlpha() {
270 ILuint i, *IntPtr, NumPix;
271 ILubyte *Data;
272 ILushort *ShortPtr;
273 ILfloat *FltPtr;
274 ILdouble *DblPtr;
275 ILubyte Bpp;
276
277 iluCurImage = ilGetCurImage();
278 if (iluCurImage == NULL) {
279 ilSetError(ILU_ILLEGAL_OPERATION);
280 return IL_FALSE;
281 }
282
283 if (iluCurImage->Format != IL_RGBA &&
284 iluCurImage->Format != IL_BGRA &&
285 iluCurImage->Format != IL_LUMINANCE_ALPHA) {
286 ilSetError(ILU_ILLEGAL_OPERATION);
287 return IL_FALSE;
288 }
289
290 Data = iluCurImage->Data;
291 Bpp = iluCurImage->Bpp;
292 NumPix = iluCurImage->Width * iluCurImage->Height * iluCurImage->Depth;
293
294 switch (iluCurImage->Type)
295 {
296 case IL_BYTE:
297 case IL_UNSIGNED_BYTE:
298 Data += (Bpp - 1);
299 for( i = Bpp - 1; i < NumPix; i++, Data += Bpp )
300 *(Data) = ~*(Data);
301 break;
302
303 case IL_SHORT:
304 case IL_UNSIGNED_SHORT:
305 ShortPtr = ((ILushort*)Data) + Bpp-1;
306 for (i = Bpp - 1; i < NumPix; i++, ShortPtr += Bpp)
307 *(ShortPtr) = ~*(ShortPtr);
308 break;
309
310 case IL_INT:
311 case IL_UNSIGNED_INT:
312 IntPtr = ((ILuint*)Data) + Bpp-1;
313 for (i = Bpp - 1; i < NumPix; i++, IntPtr += Bpp)
314 *(IntPtr) = ~*(IntPtr);
315 break;
316
317 case IL_FLOAT:
318 FltPtr = ((ILfloat*)Data) + Bpp - 1;
319 for (i = Bpp - 1; i < NumPix; i++, FltPtr += Bpp)
320 *(FltPtr) = 1.0f - *(FltPtr);
321 break;
322
323 case IL_DOUBLE:
324 DblPtr = ((ILdouble*)Data) + Bpp - 1;
325 for (i = Bpp - 1; i < NumPix; i++, DblPtr += Bpp)
326 *(DblPtr) = 1.0f - *(DblPtr);

Callers

nothing calls this directly

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected