Ive got some in memory images in various simple formats, which I need to quickly convert to another format. In cases where the target format contains an alpha channel but the source does not, alpha should be taken as its full value (eg 0xFF for an 8bit target alpha channel).
I need to be able to deal with various formats, such as A8R8G8B8, R8G8B8A8, A1R4G4B4, R5G6B5, etc.
Conversion of pixels between any of these formats is simple, however I don't want to have to manually code every single combination, I also don't want to have a 2 pass solution of converting to a common format (eg A8R8G8B8) before converting again to the final format both for performance reasons, and that if I want to use a higher definition format, say A16B16G16R16 or a floating point I'd either loose some data converting to the intermediate format, or have to rewrite everything to use a different higher definition format...
Ideally id like some sort of enum with values for each format, and then a single method to convert, eg say
enum ImageFormat
{
FMT_A8R8G8B8,//32bit
FMT_A1R4G4B4,//16bit
FMT_R5G6B5,//16bit
FMT_A32R32G32B32F,//128bit floating point format
...
};
struct Image
{
ImageFormat Format;
size_t Width, Height;
size_t Pitch;
void *Data;
};
Image *ConvertImage(ImageFormat *targetFormat, const Image *sourceImage);