Code: Select all
IImage* getARGBImage(stringc filename)
{
IImage* srcImage = System::Driver->createImageFromFile(filename);
IImage* bmpImage = NULL;
if(srcImage->getColorFormat() != ECF_A8R8G8B8) {
printf("Image color format doesn't match, converting!\n");
dimension2du dim = srcImage->getDimension();
void* load_pixels = malloc((dim.Width * dim.Height) << 2);
switch(srcImage->getColorFormat())
{
case ECF_A1R5G5B5:
convert_A1R5G5B5toA8R8G8B8(srcImage->lock(), (dim.Width * dim.Height), load_pixels);
break;
case ECF_R5G6B5:
convert_R5G6B5toA8R8G8B8(srcImage->lock(), (dim.Width * dim.Height), load_pixels);
break;
case ECF_R8G8B8:
convert_R8G8B8toA8R8G8B8(srcImage->lock(), (dim.Width * dim.Height), load_pixels);
break;
}
bmpImage = System::Driver->createImageFromData(ECF_A8R8G8B8, dim, load_pixels, false, true);
free(load_pixels);
srcImage->drop();
return bmpImage;
} else {
return srcImage;
}
}
Code: Select all
IImage* newImage = getARGBImage(filename);
ITexture* newTexture = IVideoDriver::addTexture(filename, newImage);
PS: convert_A1R5G5B5toA8R8G8B8, convert_A1R5G5B5toA8R8G8B8, convert_R8G8B8toA8R8G8B8 are found in CColorConverter.cpp (in the irrlicht sources).