Menu ▾ ▴

#57 FreeImage_GetOriginalBPP

open
nobody
None
5
2012-10-31
2010-08-08
Lucian Sabo
No

In some situations FreeImage imports the image in a more suitable bit depth - different to the original.
For example in the ICO plugin, to import transparency you need to pass ICO_MAKEALPHA which returns a 32 bit image containing an alpha channel.
The conversion is made regardless of the original bit depth, which can be 1, 2, 4 or 24. The ICO format has a stranger transparency storage ( XOR and AND masks ) and it can't be done otherwise.
The original bit depth is lost in this case, and there is not method to retrieve it as the conversion takes place in the loader. So you need to choose either to have transparent files or a correct bit depth information.

The RAW plugin may load the image data either as 24 bit RGB either as 48 bit RGB16. In fact the original RAW bit depth can be 12 or 14 on new camera sensors. The original data usually does not contain color information, it contains just light, then the data is overlaid with a color filter array, usually a Bayer filter in post-processing. Few sensors, such as the Foveon X3 sensor, capture information directly in RGB form, having three pixel sensors in each location. But RAW image bit depth is commonly known as 12 or 14 bit not 36 or 42...

The need to have the original bit depth emerged.

Attached is a file describing how I implemented it

FreeImage_GetOriginalBPP() returns the value from FreeImage_GetBPP if no originial BPP was set.

Discussion

  • Lucian Sabo

    Lucian Sabo - 2010-08-08
     
  • Mihail Naydenov

    Mihail Naydenov - 2010-08-09

    I see your reason. But BPP is by no means an exception - Compression, Color Space, Channel Count and other are commonly present and inaccurate after conversion to FIBITMAP.

    The solution for the problem is to use metadata. Currently however only TIFF and JPEG have full metadata.
    I was thinking of creating FREE_IMAGE_COMMON metadata model which will accommodate the needed info, describing the original file properties if no native MD model is present.

    So, this quick fix is not the way to do it in general - FIBITMAP holds "fields", used to access pixel data, and thats it. Any file info should be metadata, not to mention this way we can reuse such MD from other MD formats like tiff.

     
  • Hervé Drolon

    Hervé Drolon - 2010-08-09

    I agree with Mihail : metadata is the way to solve this. However I don't think a new metadata model is needed, as Exif already provides many features : BitsPerSample, Compression, SamplesPerPixel, etc.

     
  • Mihail Naydenov

    Mihail Naydenov - 2010-08-09

    Yes, I was thinking of reusing Tiff flags , but surely there will be places where we have to invent our own.
    For instance Compression in Tiff defines a lot of compressions, many of which RLE, however none the type TGA or BMP use (AFAICS).
    Sooner or later we will have to add our own "tags" and things will get messy...
    Still, considering the overlap is greater than the differences, a "common" MD most certainly will be based on an existing one.

     
  • Lucian Sabo

    Lucian Sabo - 2010-08-10

    I was thinking on implementing in metadata also, but I needed only the original bit depth and this implementation was easier. I need to call only GetOriginalBPP to get this information.
    Alternatively, I need to create a function in my code to check for that EXIF tag and if-present to use it or use the GetBPP return value instead.

    I can implement this functionality by EXIF metadata like you suggested

    FreeImage_GetOriginalBPP would still be useful integrated into FreeImage rather than in my code.
    Shall I change the implementation to use metadata and remove GetOriginalBPP or should I keep it ?

     

Anonymous
Anonymous

Add attachments
Cancel