Jump to content
  • Advertisement
Sign in to follow this  
ElganSayer

OpenGL ARGB to RGBA

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have a buffer in ARGB format. for display in the library im using i need it to be, RGBA


bitmap_in = sourceBuffer
ARGB buffer with width/height of sourceBufferRect



if (!Image.LoadFromPixels(bitmap_rect.width(),bitmap_rect.height(), bitmap_in))
{
// Error...
}



LoadFromPixels(w, h, PointerToPixelsInMemory);
Please note that when you load an image from memory, pixels must have a specific format, which is 32-bits RGBA.


I think I can bind them to opengl textures, but im using a library which doesnt give me much power to manipulate that.


So to do this, i guess i need to convert the buffer...i have no idea where to start.

atm im trying to break it down into single chars, and swap a and put it at the end of every . forth? but im breaking the images and am a bit lost.

Share this post


Link to post
Share on other sites
Advertisement
Assuming its just raw ARGB bytes with no encoding, etc, something like this might work

const int numPix = width * height;
for(int i = 0; i < numPix; ++i)
{
unsigned char argb[4]; // get em out of buffer
int off = (i * 4); // current a byte of pixel i
argb[0] = buffer_in[off + 0]; //a
argb[1] = buffer_in[off + 1]; //r
argb[2] = buffer_in[off + 2]; //g
argb[3] = buffer_in[off + 3]; //b

buffer_in[off + 0] = argb[1]; //r
buffer_in[off + 1] = argb[2]; //g
buffer_in[off + 2] = argb[3]; //b
buffer_in[off + 3] = argb[0]; ///a
}

might need more to go on, pixel data type, format, etc

Share this post


Link to post
Share on other sites
Or:


unsigned int* data = (unsigned int*)image;
for ( for idx = 0; idx < numPixels; ++idx ) {
data[idx] = (data[idx] << 8) | (data[idx] >> 24);
}


Though, we need a bit more detail... What library are you using and where is this image data coming from?

Share this post


Link to post
Share on other sites
Thanx :) Very interesting! I just want to get back from being here over christmas to my office at home! grr


Further information:


THe buffer is coming from here: Berkelium

virtual void Berkelium::WindowDelegate::onPaint ( Window * win,

const unsigned char * sourceBuffer,

const Rect & sourceBufferRect,

size_t numCopyRects,

const Rect * copyRects,

int dx,

int dy,

const Rect & scrollRect
)

[inline, virtual] The window is being painted.

You need to synchronously copy the buffer into application (video) memory before returning.

Parameters:
win Window instance that fired this event.
sourceBuffer ARGB buffer with width/height of sourceBufferRect.
sourceBufferRect Rect containing the buffer.
numCopyRects Length of copyRects.
copyRects Array of valid+changed rectangles of sourceBuffer. Anything not in copyRects is usually garbage data. While these must lie within sourceBufferRect to make sense, they are not relative to sourceBufferRect.
dx If non-zero, the area of the page specified by scrollRect has been scrolled horizontally.
dy If non-zero, the area of the page specified by scrollRect has been scrolled vertically.
scrollRect Area of the page to scroll. Only valid if dx&&dy.



and being applied to SFML


LoadFromPixels(w, h, PointerToPixelsInMemory);
Please note that when you load an image from memory, pixels must have a specific format, which is 32-bits RGBA.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!