Embedded thumbnail cannot be modified

Developers
2012-01-29
2014-02-27
  • gianni brembati

    gianni brembati - 2012-01-29

    I can get the thumbnail (FreeImage_GetThumbnail).
    I can modify thumbnail (FreeImage_SetThumbnail) and retrieve the modified
    thumbnail.
    But when I save the image the thumbnail is the original one.

    Is the memory location of the original thumbnail different from the memory
    location for Get/Set ?

    Jacopo

     
  • Hervé Drolon

    Hervé Drolon - 2012-02-05

    Hi,

    I don't see why this cannot work for you : can you post a sample code ?

    Hervé

     
  • gianni brembati

    gianni brembati - 2012-02-07

    VB code. I suppose you can follow it.

    If (FreeImage_GetThumbnail(dibIn)) Then
    dibThumb = FreeImage_GetThumbnail(dibIn)
    ' Get thumbnail width and height
    ThumbW = FreeImage_GetWidth(dibThumb)
    ThumbH = FreeImage_GetHeight(dibThumb)
    ... code to show thumbnail .... ==> thumbnail is correct
    dibNewThumb = FreeImage_Clone(dibThumb)
    BitsPtrNewThumb = FreeImage_GetBits(dibNewThumb)
    .... code to modify NewThumb (for example from color to grayscale)
    .... code to show thumbnail .... ==> thumbnail is correct(=grayscale)

    bOK = FreeImage_SetThumbnail(ByVal dibIn, ByVal dibNewThumb)
    bOK = FreeImage_Save(FIF_JPEG, dibIn, App.path + "\test.jpg", 90)
    End If

    After SetThumbnail, if I invoke GetThumbnail the returned thumbnail is correct
    (grayscale).

    If I load the saved file (test.jpg), I get the original thumbnail (color not
    grayscale)

    The same is true if I delete the thumbnail ...bOK =
    FreeImage_SetThumbnail(ByVal dibIn, ByVal 0&)

    After deleting, GetThumbnail does not return a thumbnail, but saving the image
    and loading it I get the original thumbnail.

    Jacopo

     
  • Hervé Drolon

    Hervé Drolon - 2012-02-07

    Hi,

    I think I've found the explanation for the problem you encountered ...

    Inside JPEG images, thumbnails can be located
    - in the JFIF "JFXX" extension APP0 marker
    - in the Exif segment
    A single image can thus contain two thumbnails (one in each location).

    So if your image contains an Exif segment with an embedded thumbnail, the
    following occurs on loading:
    - the JFXX segment is loaded and the possibly present thumbnail is attached to the dib
    - the Exif segment is loaded and the possibly present thumbnail is attached to the dib (thus replacing the previous one)

    That's why you always see a 24-bit thumbnail (the one coming from the Exif
    segment).
    You can check this by erasing the Exif segment before writing :

    FreeImage_SetMetadata(FIMD_EXIF_RAW, dibIn, NULL, NULL)
    bOK = FreeImage_Save(FIF_JPEG, dibIn, App.path + "\test.jpg", 90)

    Then when loading the image, you will recover your 8-bit greyscale thumbnail.

    One possible way to correct this in FreeImage would be, on loading, to invert
    the order metadata is loaded (i.e. first load Exif, then load JFXX).
    This would be more consistent with the expected behavior of the FI API.
    However, other softwares may choose to ignore the JFXX segment and only load
    the Exif segment, so that I don't know if its a good fix.

    Suggestions and comments on this possible fix are welcome ...

    Hervé

     
  • gianni brembati

    gianni brembati - 2012-02-08

    Hervè,
    thanks for you time.

    I suppose your solution doesn't work, unfortunally.

    If exif thumbnail is attached to dib, I can modify this thumbnail.
    If I erase the exif segment the modified thumbnail is erased too.

    In any case I tried, but it doesn't work.

    May be I am wrong, the TIFF specification doesn't have a thumbnail tag.
    After loading a tif image, GetThumbnail returns a thumbnail.
    I suppose it is exif thumbnail and it is the only thumbnail.
    When I save the dib, after modifying the thumbnail, the embedded thumbnail is
    the original, not the modified one.

    I don't see any difference from jpg image behaviour.

    Jacopo

     
  • Hervé Drolon

    Hervé Drolon - 2012-02-09

    "If I erase the exif segment the modified thumbnail is erased too."
    => no, the modified thumbnail is keeped intact and on saving, it is stored in
    the JFXX segment.

     
  • Mihail Naydenov

    Mihail Naydenov - 2014-02-27

    The right thing to do is to edit the exif. This is trivially done using libexif, editing the EXIF_RAW tag.

    May be we can incorporate libexif into FreeImage? Can a LGPL lib be incorporated?

     

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