"flip" ofImage?

working with ofImages, I’m running into some trouble with them being flipped. At the moment, I have some pixels loaded into an FBO, and am using setFromPixels() to put those pixels into an ofImage. The problem is, the ofImage is coming out upside-down- flipped across the x-axis. The actual code looks something like:

myImage.setFromPixels((unsigned char*) myFBO.getPixels(),myFBO.width(),myFBO.height(),OF_IMAGE_COLOR_ALPHA);  

Is there either A) a way that I can flip the image after loading it (i.e. modifying the pixels, not just changing how it looks on the screen) or B) stop this from happening all together?

I also experienced this … somewhere on the forum I read a article about this - but can’t find it anymore. … to flip a image just use the extension from here: http://forum.openframeworks.cc/t/ofximage/4100/0


Took a look at the code that you linked. It would appear that the methods are expecting an ofPixels pix&. But, my pixels are in the context of an unsigned char*[]. How would I go about converting from unsigned char* to ofPixels?

I am going to hazard a quick guess. In ofxFBOTexture, your image is flipped because openGL coords are from bottom left instead of top left. see lines 113 and 114 of ofxFBOTexture:

glScalef(1, -1, 1); // Invert Y axis so increasing Y goes down  
glTranslatef(0, -h, 0); // shift origin up to upper left corner  

I haven’t tried any code yet, this is just a guess, but you may have to un-translate when grabbing pixels again.

Also, if you don’t mind messing with another plug-in, ofxCVImage has a mirror method that is really simple to use.

I am too are wondering how to convert unsigned char* to ofPixels.

I my case I want to rotate a pixel array inside a threaded class. this means i can’t use ofximage rotate because it gives me a opengl error, even with setUseTexture = false.


I’m using this code to flip things

	if (flipVertical&&!flipHorizontal) {		// Flip Vertical Only  
		glTranslated(0, ofGetHeight(), 0);  
		glScalef(1, -1, 0);  
	}else if (!flipVertical&&flipHorizontal) {	// Flip Horizontal Only  
		glTranslated(ofGetWidth(), 0, 0);  
		glScalef(-1, 1, 0);  
	}else if(flipVertical&&flipHorizontal){		// Flip Vertical & Horizontal  
		glTranslated(ofGetWidth(), ofGetHeight(), 0);  
		glScalef(-1, -1, 0);  
	}else if (!flipVertical&&!flipHorizontal) {     // No flip  
		glScalef(1, 1, 0);  
	// Image to be flipped  
        // image.draw(((ofGetWidth()/2)-(image.getWidth()/2)), ((ofGetHeight()/2)-(image.getHeight()/2)));  

Hope it helps you

this is good to know.

unfortunately it is not possible, or very difficult to use opengl in a thread other than the main thread.

thanks anyway.