EXR to HDR conversion

  • The First Door

    The First Door - 2012-07-31

    Hi all,

    I've been trying to use FreeImage to create a program which will convert EXR
    files to HDR files, but I've run into a problem.
    I've managed to convert between different low-dynamic range image formats
    (such as BMP to PNG) without issue, but when I try to save as an HDR file, the
    save fails. What is confusing me most, is that it isn't calling the error
    handler I've provided, so I have no idea why it is failing, the save call is
    just returning false.

    Anyway, I'm sure I'm doing something silly, so any help would be appreciated!
    I'll included the appropriate code below.

    int main(int argc, char *argv[])
        char* filePath = "exrFile.exr";
        FIBITMAP *bitmap;
        printf("FreeImage %s \n", FreeImage_GetVersion());
        printf("%s\n\n", FreeImage_GetCopyrightMessage());
        //Init the file format type for the load command
        fif = FreeImage_GetFileType(filePath, 0);
        //Set the error handler for when something goes wrong!
        if(fif == FIF_UNKNOWN)
            printf("Cannot get filetype from signature, trying extension\n");
            // If we can't get the signature, try to guess the file format from the file extension
            fif = FreeImage_GetFIFFromFilename(filePath);
        // Check we CAN load that file type
        if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif))
            if(bitmap = FreeImage_Load(fif, filePath, 0))
                printf("Image loaded successfully\n");
                printf("\n***IMAGE NOT LOADED***\n");
        if (FreeImage_Save(FIF_HDR, bitmap, "hdrFile.hdr", 0))
            printf("Image saved successfully\n\n");
            printf("\n***IMAGE NOT SAVED***\n\n");
        return EXIT_SUCCESS;

    N.B. I've not included the error handler as it just checks the file format and
    prints the message like the provided examples. I do, however, know it works as
    it is called when I try to load a non-existent file.

    Thanks in advance for any help!

  • The First Door

    The First Door - 2012-07-31

    P.s. Just in case this is important, I should say that I'm programming on
    Windows 7 64-bit using Dev C++. Also, according to the version number I'm
    compiling against the 3.15.3 DLL. In fact, the full command-line output is as

    FreeImage 3.15.3
    This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See [url]http://freeimage.sourceforge.net[/url] for details
    Image loaded successfully
    Press any key to continue . . .
  • Raissel

    Raissel - 2012-08-08

    Hi, It's maybe to late to answer your question, if it's still not solved, try
    specifying the flag in the saving function, it must solve your problem
    FreeImage_Save(FIF_HDR, bitmap, "hdrFile.hdr", HDR_DEFAULT)

  • The First Door

    The First Door - 2012-08-08

    Hi there, thanks very much for the reply! It's not too late, as I'm still
    trying to sort this problem. I've just tried your suggestion and it doesn't
    fix my problem, sadly.

    It seems that for some reason saving any data to an HDR file is silently
    failing. Whenever the code is run it creates a 0 KB file before returning in a
    failed state.This applies to bitmap data loaded in, or created via the
    FreeImage_Allocate or FreeImage_AllocateT functions. Saving to an EXR file,
    however, seems to be working correctly, so I'm really not sure what I'm doing

    Thanks again for any help you can give!

  • Raissel

    Raissel - 2012-08-08

    Check that your bitmap has pixels before saving, also check that your image is
    RGBF and the BPP are 96, otherwise use FreeImage_ConvertToRGBF().

  • The First Door

    The First Door - 2012-08-08

    Ah! Thank you, I think that has solved it! The files seem to be saving
    correctly now.

    The EXR files I was importing were full 32 bits per colour channel with alpha
    (FIT_RGBAF/128 bit format) it seems. I guess that the HDR format or the
    FreeImage exporter doesn't support alpha images then?

    Thanks again for all your help!

  • Hervé Drolon

    Hervé Drolon - 2012-09-23


    I've added an error message inside the HDR plugin, so that it is thrown when
    you try to save a format that cannot be handled by this plugin.
    Changes are available in the CVS.

    Note that you can check for saving capabilities using a code like this:

    // Check that the dib can be saved in this format
    BOOL bCanSave;

    FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib);
    if(image_type == FIT_BITMAP) {
    // standard bitmap type
    WORD bpp = FreeImage_GetBPP(_dib);
    bCanSave = (FreeImage_FIFSupportsWriting(fif) &&
    FreeImage_FIFSupportsExportBPP(fif, bpp));
    } else {
    // special bitmap type
    bCanSave = FreeImage_FIFSupportsExportType(fif, image_type);

    if(bCanSave) {
    bSuccess = FreeImage_Save(fif, _dib, lpszPathName, flag);
    return bSuccess;

    Hope this help,


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks