When saving a .exr file using FreeImage with a FIBITMAP of type FIT_RGBF and the EXR_FLOAT flag, the resulting file is saved with a
16-bit depth per channel instead of the expected 32-bit float depth. This
behavior persists even though the EXR_FLOAT flag is explicitly passed to
the FreeImage_Save function.
My code:
Click to expand code
#include <FreeImage.h>#include <iostream>#include <string>FIBITMAP*CreateTestImage(unsignedwidth,unsignedheight){FIBITMAP*bitmap=FreeImage_AllocateT(FIT_RGBF,width,height);if(!bitmap){std::cerr<<"Failed to allocate image."<<std::endl;returnnullptr;}//Filltheimagewithagradientfloat*bits=reinterpret_cast<float*>(FreeImage_GetBits(bitmap));for(unsignedy=0;y<height;++y){for(unsignedx=0;x<width;++x){unsignedindex=(y*width+x)*3;bits[index+0]=static_cast<float>(x)/width;bits[index+1]=static_cast<float>(y)/height;bits[index+2]=0.5f;}}returnbitmap;}voidSaveTestImage(conststd::string&filename,FIBITMAP*bitmap,intflags){if(!bitmap){std::cerr<<"Invalid bitmap, cannot save."<<std::endl;return;}unsignedwidth=FreeImage_GetWidth(bitmap);unsignedheight=FreeImage_GetHeight(bitmap);unsignedbpp=FreeImage_GetBPP(bitmap);FREE_IMAGE_TYPEtype=FreeImage_GetImageType(bitmap);std::cout<<"Image properties:"<<std::endl;std::cout<<" Width: "<<width<<std::endl;std::cout<<" Height: "<<height<<std::endl;std::cout<<" Bits per pixel: "<<bpp<<std::endl;std::cout<<" Image type: "<<type<<std::endl;std::cout<<"Saving image to "<<filename<<"..."<<std::endl;if(FreeImage_Save(FIF_EXR,bitmap,filename.c_str(),flags)){std::cout<<"Image saved successfully: "<<filename<<std::endl;}else{std::cerr<<"Failed to save image: "<<filename<<std::endl;}}intmain(){FreeImage_Initialise();constunsignedwidth=512;constunsignedheight=512;conststd::stringfilename="test_image.exr";FIBITMAP*bitmap=CreateTestImage(width,height);if(!bitmap){FreeImage_DeInitialise();return1;}intflags=EXR_FLOAT;SaveTestImage(filename,bitmap,flags);FreeImage_Unload(bitmap);FreeImage_DeInitialise();return0;}
Description
When saving a
.exrfile using FreeImage with aFIBITMAPof typeFIT_RGBFand theEXR_FLOATflag, the resulting file is saved with a16-bit depth per channel instead of the expected 32-bit float depth. This
behavior persists even though the
EXR_FLOATflag is explicitly passed tothe
FreeImage_Savefunction.My code:
Click to expand code
magick output:
Click to expand loge
Expected Behaviour
The
.exrfile should be saved with 32-bit float depth per channel.