Menu

#328 PNGs from openstreetmap tiles always load as grayscale

None
wont-fix
None
5
2021-01-23
2021-01-21
dima
No

Hi. Openstreetmap tiles are distributed as color .png files. Loading one in freeimage always loads them as grayscale 8bpp images. I'm attaching an arbitrary image that shows the issue. I'm running freeimage on Debian:

dima@shorty:~$ dpkg -l 'libfreeimage' 'libpng' | grep '^ii'
ii libfreeimage-dev 3.18.0+ds2-6 amd64 Support library for graphics image formats (development files)
ii libfreeimage3:amd64 3.18.0+ds2-6 amd64 Support library for graphics image formats (library)
ii libpng-dev:amd64 1.6.37-3 amd64 PNG library - development (version 1.6)
ii libpng16-16:amd64 1.6.37-3 amd64 PNG library - runtime (version 1.6)

Thanks

1 Attachments

Discussion

  • dima

    dima - 2021-01-21

    I'm attaching a demo program that demos the problem. It does this:

    $ gcc -o tstimage tstimage.c -lfreeimage && ./tstimage /tmp/tst.png
    width = 256
    height = 256
    pitch = 256
    bpp = 8

     
  • dima

    dima - 2021-01-21

    Hi. I figured out the problem. This image uses a palette, so it really is 8 bits per pixel. So this isn't a bug, but I have a feature request:

    FreeImage_Load() should be able to take a flag to automatically convert all palettized images to 24bpp. This is a special case, but an extremely common one.

    Thanks.

     
  • Hervé Drolon

    Hervé Drolon - 2021-01-23
    • status: open --> wont-fix
    • assigned_to: Hervé Drolon
    • Group: -->
     
  • Hervé Drolon

    Hervé Drolon - 2021-01-23

    Hi,

    About the "take a flag to automatically convert all palettized images to 24bpp" feature, you can do it yourself using functions such as
    FreeImage_GetImageType
    FreeImage_GetBPP
    FreeImage_GetColorType
    FreeImage_GetColorsUsed
    => and then FreeImage_ConvertTo24Bits if you really need 24-bit images
    It is up to you to decide how to post-convert loaded images, according to your specific use case.
    This cannot be a flag added to the loading functions. You have to check yourself what you are loading and adapt the loaded formats to your specific needs.

    NB: note also that the FreeImage_ColorQuantize / FIQ_LFPQUANT algorithm was designed for GIS professional people in order to convert 24-bit images to 8-bit paletized images.
    It's no coincidence if you see 8-bit palettized images in GIS systems !

    Hervé

     
  • dima

    dima - 2021-01-23

    Hi. Thanks for the response.

    Once I figured out what the issue was, I found the FreeImage_ConvertTo24Bits() function to do what I wanted. A load-time flag would be useful to make the life of the user easier by handling this common use case instead of asking the user to do it. This would be similar to the JPEG_GREYSCALE flag. The user CAN make that conversion themselves if they want to, but the flag makes it nicer. Something like FIF_EXPAND_PALETTE or something.

    A very related issue is how to make it clear to the user that the image is palettized without making them ask the question they don't know to ask. It took me a while to figure out that this was the issue, and until I figured it out, it REALLY looked like a bug. Should there be a note in the docs for FreeImage_Load() mentioning that a palette could be used? I don't love that solution. Any better ideas?

    Thanks!

     

Log in to post a comment.