ofImage::getPixels() produces something inverted here ?!

Hi folks,

I just retook my code of a prototype initiated one month ago about a little iOS app which produce some strange fx on picture taken with the cam.

I’d like to process an array of pixels, so I’m doing that:

            unsigned char *pixels = photo.getPixels();  
            int w = photo.width;  
            int h = photo.height;  
            int skip = 10;  
            for(int j = 0; j < h; j+=skip){  
                for(int i = 0; i < w; i+=skip){  
                    int index = j*w*4 + i*4;  
                    int valueR = pixels[index];  
                    int valueG = pixels[index+1];  
                    int valueB = pixels[index+2];  
                    ofRect(i, j, skip, skip);  

This is a very basic code producing a pixelization
But the result is inverted.

Second question, I’d like to put the result into another ofImage in order to convert it as an UIImage in a further routine.

Any one would help with that ?

What do you mean by inverted. Does it look like the green channel and the red channel are switched or is black white and versa?

Does the behavior also apply if you load a jpeg instead of using the image from the cam?

I meant the picture is flipped vertically. (I fix the subject of the topic … sorry)

ah ok. no problem :smiley:

But strange your code is not working. It looks ok.

I guess you are using all standard of classes? ofImage etc? Or did you mix in some Obj-C of your own to get to the image? If so, sometimes some image types store pixels in a different order. If they do, it’s totally ok to just add something like.

ofRect(i, h-j, skip, skip);

I’m using ObjC for cam & shoot handling but especially because I’m using ShareKit which works very fine btw.
But the objC part gives me some problems and I could probably invoke ShareKit from OF.

I have also some pb of autorotation etc. Maybe in another thread (it is my first app which would handle all the orientations possible AND which would have to display a pix correctly in all of these)