Very simple right now. This will probably use Perlin noise and parameters in the future.
| 20 | // Very simple right now. |
| 21 | // This will probably use Perlin noise and parameters in the future. |
| 22 | ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) |
| 23 | { |
| 24 | ILuint i, j, c, Factor, Factor2, NumPix; |
| 25 | ILint Val; |
| 26 | ILushort *ShortPtr; |
| 27 | ILuint *IntPtr; |
| 28 | ILubyte *RegionMask; |
| 29 | |
| 30 | iluCurImage = ilGetCurImage(); |
| 31 | if (iluCurImage == NULL) { |
| 32 | ilSetError(ILU_ILLEGAL_OPERATION); |
| 33 | return IL_FALSE; |
| 34 | } |
| 35 | |
| 36 | RegionMask = iScanFill(); |
| 37 | |
| 38 | // @TODO: Change this to work correctly without time()! |
| 39 | //srand(time(NULL)); |
| 40 | NumPix = iluCurImage->SizeOfData / iluCurImage->Bpc; |
| 41 | |
| 42 | switch (iluCurImage->Bpc) |
| 43 | { |
| 44 | case 1: |
| 45 | Factor = (ILubyte)(Tolerance * (UCHAR_MAX / 2)); |
| 46 | if (Factor == 0) |
| 47 | return IL_TRUE; |
| 48 | Factor2 = Factor + Factor; |
| 49 | for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { |
| 50 | if (RegionMask) { |
| 51 | if (!RegionMask[j]) |
| 52 | continue; |
| 53 | } |
| 54 | Val = (ILint)((ILint)(rand() % Factor2) - Factor); |
| 55 | for (c = 0; c < iluCurImage->Bpp; c++) { |
| 56 | if ((ILint)iluCurImage->Data[i + c] + Val > UCHAR_MAX) |
| 57 | iluCurImage->Data[i + c] = UCHAR_MAX; |
| 58 | else if ((ILint)iluCurImage->Data[i + c] + Val < 0) |
| 59 | iluCurImage->Data[i + c] = 0; |
| 60 | else |
| 61 | iluCurImage->Data[i + c] += Val; |
| 62 | } |
| 63 | } |
| 64 | break; |
| 65 | case 2: |
| 66 | Factor = (ILushort)(Tolerance * (USHRT_MAX / 2)); |
| 67 | if (Factor == 0) |
| 68 | return IL_TRUE; |
| 69 | Factor2 = Factor + Factor; |
| 70 | ShortPtr = (ILushort*)iluCurImage->Data; |
| 71 | for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { |
| 72 | if (RegionMask) { |
| 73 | if (!RegionMask[j]) |
| 74 | continue; |
| 75 | } |
| 76 | Val = (ILint)((ILint)(rand() % Factor2) - Factor); |
| 77 | for (c = 0; c < iluCurImage->Bpp; c++) { |
| 78 | if ((ILint)ShortPtr[i + c] + Val > USHRT_MAX) |
| 79 | ShortPtr[i + c] = USHRT_MAX; |
nothing calls this directly
no test coverage detected