Menu ▾ ▴

#287 Monochrome PNG load as 256 color image

None
wont-fix
None
5
2019-04-07
2019-02-20
No

Our CAD libraries apply special logic for monochrome images (use object colors instead of original). This logic frequently used in AutoCAD-like products. But current version of FreeImage silently loads monochrome PNG's (in case if them contains transparent color index) as 256 indexed color images, so we can't process this type of rasters correctly. Problem caused by following piece of code in PruginPNG.cpp:

ConfigureDecoder
...
  case PNG_COLOR_TYPE_PALETTE:
  ...
        // if a tRNS chunk is provided, we must also expand the palletized data to 8-bits,
        // this allows us to make use of the transparency table with existing FreeImage methods
        if (bIsTransparent && (pixel_depth < 8)) {
            png_set_packing(png_ptr);

I understand that transparency table will be invoked in this case, but what is a reason to extend it up to 256 color indexes instead of keeping it as 2 color indexes? As I can see transparency table array has it's own value containing number of entries, so physically length of transparency array can differ from number of color indexes. I also understand that transparency array length change can influence onto exist code, based onto current implementation of FreeImage, but probably you can add new option to correctly process number of color entries in PNG's even if them contains transparency? This is seriously confusing that FreeImage silently change image type, as result we can't handle this type of rasters somehow by alternative way.

1 Attachments

Discussion

  • Johnny Petersen

    Johnny Petersen - 2019-02-25

    The original file, per attachment above, is a 1-BPP PNG (BitDepth 1 and ColorType 3), having only two colors: one is White and the other Green. Because it is ColorType 3, it has a PLTE chunk. The original PLTE entries are shown on the left side of the screenshot appended below (1st entry of PLTE is White and 2nd Green). The corresponding tRNS entries on the right side are: 1st 0 (fully transparent) and 2nd 255 (fully opaque). This means the White part of the image is to be transparent and the Green part of the image is to be opaque.

     

    Last edit: Johnny Petersen 2019-02-26
  • Hervé Drolon

    Hervé Drolon - 2019-04-07
    • status: open --> wont-fix
    • assigned_to: Hervé Drolon
    • Group: -->
     
  • Hervé Drolon

    Hervé Drolon - 2019-04-07

    Hi,

    This is a design decision and this will not change.
    The main goal is to be able to load an image and to display it directly on a screen.
    There's no graphic API that can understand a 2-bit palettized image with trns, so FreeImage transparently convert image files to displayable images.

    Hervé

     

Log in to post a comment.