I am working on an application, which has to use pixel manipulation in the following way: around a point(x,y) I have to condense or expand the pixels in a circle of radius R, but I want to keep the rectangular frame of the UIImage. I get the raw data n the following way (I found this on the web):
CGImageRef imageRef = image.CGImage;
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CFDataRef dataref = CopyImagePixels(imageRef);
unsigned char *rawData = CFDataGetBytePtr(dataref);
So, I have in rawData the pixel data.
int byteIndex = 0;
for (int ii = 0 ; ii < width * height ; ++ii)
{
//now rawData[baseIndex] stands for red
//rawData[baseIndex + 1] stands for green
//rawData[baseIndex + 2] stands for blue
byteIndex += 4;
}
Now, how do I know if the current pixel is within the circle of origin(x,y) and of radius R? And how do I condense/expand these pixels?
Thanks
Use pythagorus' theorem - a2 + b2 = c2
c2 is easy:
For each pixel, given its position (xp, yp) - which you can maintain in your loop - get the square of the distance from the origin and compare to maxDistance:
I don't know what you mean be condensing the pixels, but I'm sure that you can work out what you need to do now...