Skip to content

Image's Pixel method fails with 16 bit images #698

@luca-della-vedova

Description

@luca-della-vedova

Environment

  • OS Version: Ubuntu 24.04
  • Source or binary build? Either

Description

  • Expected behavior: Images with 16 bit channels can be accessed
  • Actual behavior: The Pixel function fails

Steps to reproduce

  1. Get a glTF with a 16 bit metallic roughness map
  2. Try to load it

Output

You will get this error printed out once for each image pixel (so 1 million times for a 1024x1024 map)

What is happening?

An RGB image with 16 bits per channel has a total of 48 bits per pixel (BPP in FreeImage terms). However, the implementation of FreeImage_GetPixelColor can only handle 8, 16 or 24 BPP, so it falls through the default case and fails.

I believe there are a few possible solutions to this:

Custom parsing for 48 BPP images

We could do custom parsing for 48 BPP (and I suppose 64 BPP, for RGBA 16 bit images) where we scan the image manually and get the pixel value.

Downsample to 8 bits

We could just downsample all images to 8 bits and accept that perhaps 16 bit maps are a bit overkill

Change library

We could change to a different library that can actually handle 16 bit images well, Freeimage seems to be pretty unmaintained (I thought there were some experiments in this direction?)

Do nothing and just fix the error message

At the very least we should print a warning for unsupported BPPs and exit early, rather than having a very puzzling pixel access error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions