ofImage from GIF displays with blue tint

Loading frames of a GIF image and drawing them to an ofFbo.
Each frame of the GIF is an ofImage.
I’m using this addon to save and load the gif: https://github.com/Geistyp/ofxGif

The frames display, but with a blue tint:

When opening the gif file in a different program (browser/xcode) the colors display correctly.

Alpha blending is disabled with ofDisableAlphaBlending(); before drawing.

Drawing GIF frames with the following:

void GifManager::draw() {
    ofBackground(0);
    ofSetColor(255, 255, 255, 255);
    ofImage currentFrame = gifloader.pages[index];
    currentFrame.draw(0, 0, ofGetWidth(), ofGetHeight());
}

My gut thinks it might be something to do with this in the ofxGif source (https://github.com/Geistyp/ofxGif/blob/master/src/ofxGif.cpp#L135):

#ifdef TARGET_LITTLE_ENDIAN
		if (swapForLittleEndian && sizeof(unsigned char) == 1) {
			pix.swapRgb();
		}
#endif

…but forcing that to always or never happen seems to make no difference…

Any ideas how to display the colors properly?

Thanks!

It is probably loading a BGR into RGB, so yes, your guts seem to be right, but I cant say where this is happening

Thanks for the reply!

I was looking at this similar thread: [SOLVED] ofVideoGrabber with BAYER8 pixelformat

And I tried manually calling .swapRgb() - it had no effect.

Right now I’m trying to manually flip around the channels with code similar to the below (taken from the above thread):

ofPixelsRef pixels = cam.getPixelsRef();
ofPixels rpix = pixels.getChannel(0);
ofPixels gpix = pixels.getChannel(1);
ofPixels bpix = pixels.getChannel(2);

pixels.setChannel(0, gpix);
pixels.setChannel(1, rpix);
pixels.setChannel(2, bpix);

image.setFromPixels( pixels );

This is puzzling!

The code below ended up solving this issue! I didn’t think this would do anything (first I tried swapping them to bgr - same blue tint, so then I tried this):

void GifManager::draw() {
    ofSetColor(255, 255, 255, 255);
    
    ofImage img = gifloader.pages[index];
    ofPixels pix = img.getPixels();
    
    ofPixels rpix = pix.getChannel(0);
    ofPixels gpix = pix.getChannel(1);
    ofPixels bpix = pix.getChannel(2);
    
    pix.setChannel(0, rpix);
    pix.setChannel(1, gpix);
    pix.setChannel(2, bpix);
    
    img.setFromPixels(pix);
    
    img.draw(0, 0, ofGetWidth(), ofGetHeight());
}

It looks like I’m just reassigning the same channels to themselves? But sure enough, the GIF frames display with proper colors!!


Further exploration - this code also fixes the issue (something in getPixels/setFromPixels?):

void GifManager::draw() {
    ofSetColor(255, 255, 255, 255);
    
    ofImage img = gifloader.pages[index];
    ofPixels pix = img.getPixels();
    img.setFromPixels(pix);
    
    img.draw(0, 0, ofGetWidth(), ofGetHeight());
}

Hi,

I’m home now, I’ve been able to test changing from BGR to RGB (with an external software), and this is the result… seems correct to me.

Are you sure you are inverting the channels correctly?

The code I posted above solves the issue, with no (explicit) channel swapping… it’s very strange!

Thanks for your help!

1 Like

had the same issue, your code solves the problem.