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

Function ILAPIENTRY iluNegative

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

Inverts the colours in the image

Source from the content-addressed store, hash-verified

333
334//! Inverts the colours in the image
335ILboolean ILAPIENTRY iluNegative()
336{
337 ILuint i, j, c, *IntPtr, NumPix, Bpp;
338 ILubyte *Data;
339 ILushort *ShortPtr;
340 ILubyte *RegionMask;
341
342 iluCurImage = ilGetCurImage();
343 if (iluCurImage == NULL) {
344 ilSetError(ILU_ILLEGAL_OPERATION);
345 return IL_FALSE;
346 }
347
348 if (iluCurImage->Format == IL_COLOUR_INDEX) {
349 if (!iluCurImage->Pal.Palette || !iluCurImage->Pal.PalSize || iluCurImage->Pal.PalType == IL_PAL_NONE) {
350 ilSetError(ILU_ILLEGAL_OPERATION);
351 return IL_FALSE;
352 }
353 Data = iluCurImage->Pal.Palette;
354 i = iluCurImage->Pal.PalSize;
355 }
356 else {
357 Data = iluCurImage->Data;
358 i = iluCurImage->SizeOfData;
359 }
360
361 RegionMask = iScanFill();
362
363 // @TODO: Optimize this some.
364
365 NumPix = i / iluCurImage->Bpc;
366 Bpp = iluCurImage->Bpp;
367
368 if (RegionMask) {
369 switch (iluCurImage->Bpc)
370 {
371 case 1:
372 for (j = 0, i = 0; j < NumPix; j += Bpp, i++, Data += Bpp) {
373 for (c = 0; c < Bpp; c++) {
374 if (RegionMask[i])
375 *(Data+c) = ~*(Data+c);
376 }
377 }
378 break;
379
380 case 2:
381 ShortPtr = (ILushort*)Data;
382 for (j = 0, i = 0; j < NumPix; j += Bpp, i++, ShortPtr += Bpp) {
383 for (c = 0; c < Bpp; c++) {
384 if (RegionMask[i])
385 *(ShortPtr+c) = ~*(ShortPtr+c);
386 }
387 }
388 break;
389
390 case 4:
391 IntPtr = (ILuint*)Data;
392 for (j = 0, i = 0; j < NumPix; j += Bpp, i++, IntPtr += Bpp) {

Callers

nothing calls this directly

Calls 2

ilSetErrorFunction · 0.85
iScanFillFunction · 0.85

Tested by

no test coverage detected