Allocating ofImage with GL_RGB doesn't give any warnings

Hi,

By accident I used GL_RGB to allocate an ofPixels and then spent a long time debugging why the width was 0 (assuming it was related to vectors and std::move), until I realized I should have used OF_IMAGE_COLOR instead.

// wrong
ofPixels p;
p.allocate(w, h, GL_RGB);

Functions like ofPixelFormatFromImageType and channelsFromPixelFormat give warnings when trying to use an unrecognized image type. Couldn’t this check also be done when using GL_RGB?

I don’t know of an easy solution. Current API is:

allocate(size_t w, size_t h, size_t _channels)
allocate(size_t w, size_t h, ofPixelFormat format)
allocate(size_t w, size_t h, ofImageType type)

So if you pass a macro that resolves to an int, you will be using the first call. So in other words, the only way to prevent this is error is to remove the first API. Which I don’t think is good for anyone. Otherwise creating a new type channel, but that would make things overcomplicated and also would break everyone’s code. That’s all I know. Maybe somebody else can find a good solution?

Since GL_RGB is defined as 0x1907, I understand I would be allocating 6407 channels.

What about something like

if(_channels > 4) {
  ofLog("Note: allocating ofImage with _channels > 4");
}

?

sounds good to me :slight_smile: