I am using libjpeg to decode a jpeg image from disk to a memory buffer allocated on the heap. I use jpeg_read_scanlines
to read and decode each scanline from the file. This is working perfectly, decoding each pixel as a 24-bit RGB value.
The problem is that I am using an additional third-party library which requires a buffer in BGR format (rather than RGB). When using this library I get odd results as the channels are in the wrong order.
Therefore, I would like to find a way to make libjpeg decode to BGR format rather than RGB. I have trawled the web and cannot find how to configure libjpeg to do this? I know I could do an additional pass over the memory buffer and re-order the colour channels manually, however the application I am working on is extremely time critical and must be as fast and as efficient as possible.