esilverberg/ios-image-filters — Issue #5: Zero dividing issue
Author: Lithiums
Created: 2012-02-02 13:30:05+00:00
State: open

There may be some zero dividing issues, for example:

void filterPosterize(UInt8 *pixelBuf, UInt32 offset, void *context)
{
int levels = *((int*)context);
int step = 255 / levels;

int r = offset;
int g = offset+1;
int b = offset+2;

int red = pixelBuf[r];
int green = pixelBuf[g];
int blue = pixelBuf[b];

pixelBuf[r] = SAFECOLOR((red / step) * step);
pixelBuf[g] = SAFECOLOR((green / step) * step);
pixelBuf[b] = SAFECOLOR((blue / step) * step);
}

I once crashed on int step = 255 / levels;