Menu

#263 Failure writing GIF

None
closed
None
5
2018-07-31
2015-08-25
No

Performing back-to-back write/read tests through the library, writing a FIF_GIF creates a corrupt file. Upon attempted readback, the error "EOF reading Logical Screen Descriptor" is thrown.

format = FIT_BITMAP
BPP = 24;
(all local code checked out by reading/writing to other formats).

1 Attachments

Discussion

  • Hervé Drolon

    Hervé Drolon - 2015-08-25
    • status: open --> pending
    • assigned_to: Hervé Drolon
    • Group: -->
     
  • Hervé Drolon

    Hervé Drolon - 2015-08-25

    Hi,

    First, note that the GIF format does not support 24-bit formats.
    You should see an error message when using FreeImage_SetOutputMessage and FreeImage_Save should return NULL.

    Now I don't understand how you managed to save a 24-bit dib as GIF using FreeImage (note: your sample file is not a GIF file, just edit it with a text editor to see this).

    Can you show me a sample code ?

    Hervé

     
  • Mathew Maher

    Mathew Maher - 2015-08-26

    Hi Herve,
    Thanks for the fast response on this!

    Apologies for the muck-up: I made the assumption 8bits meant 8bits per channel (x3 = 24bit)!

    To get to the point of saving, I did:

    a). FreeImage_AllocateT(FIF_BITMAP, x, y, 24);
    b). used FreeImage_GetBits() to populate bitmap ([FI_RGBA_RED], etc)
    c). performed the following write function:

    bool ImageWriter(FIBITMAP bmp, const char lpszPathName, FIF_GIF,GIF_DEFAULT)
    {
    FREE_IMAGE_TYPE itype = FreeImage_GetImageType(bmp);

    if (!bmp)
        return false;
    
    //if no output type specified, try to guess it from the filename extension
    if (fif == FIF_UNKNOWN)
    {
        fif = FreeImage_GetFIFFromFilename(lpszPathName);
    }
    
    // check that the plugin has sufficient writing and export capabilities ... 
    if ((FreeImage_FIFSupportsWriting(fif)) && (FreeImage_FIFSupportsExportType(fif, itype)))
    {
        //everything good, save it! 
        if (FreeImage_Save(fif, bmp, lpszPathName, flag) == TRUE)
            return true;
    }
    
    return false;
    

    }

    The writer returns true.

    Let me know if you need any more detail.

    cheers, and thanks for your hard work!

    Mat

     
  • Hervé Drolon

    Hervé Drolon - 2015-08-28

    Hi,

    The correct test should be someting like this

    BOOL fipImage::save(const char* lpszPathName, int flag) const {
        FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
        BOOL bSuccess = FALSE;
    
        // Try to guess the file format from the file extension
        fif = FreeImage_GetFIFFromFilename(lpszPathName);
        if(fif != FIF_UNKNOWN ) {
            // 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;
            }
        }
        return bSuccess;
    }
    

    See also FreeImage_FIFSupportsWriting in the PDF doc.

    Hervé

     

    Last edit: Hervé Drolon 2015-08-28
  • Hervé Drolon

    Hervé Drolon - 2018-07-31
    • status: pending --> closed
     
  • Hervé Drolon

    Hervé Drolon - 2018-07-31

    Closed in release 3.18.0
    Please open a new bug if your problem persist.

     

Log in to post a comment.

Auth0 Logo