question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DiscreteAlphaIndexColorModel.getNumComponents is giving the wrong information

See original GitHub issue

Describe the bug According to my understanding, the ColorModel.getNumComponents should return the number of components/channels in the final image, not in the sample buffer. DiscreteAlphaIndexColorModel.getNumComponents’ implementation is giving sample size.

Version information

  1. 3.8.2

  2. More details:

If you look at the documentation for getNumComponents you can see that this is the number of channels in the final image. E.g. RGB would be 3. RGB with Alpha would be 4. This can be verified by looking at the implementation for an IndexColorModel (which defaults to ColorModels implementation). Usually, with an IndexColorModel, the sample buffer would contain an single array of 1 byte per pixel. That means the “number of samples” per pixel is 1. However, if I have an RGB image with an IndexColorModel, the .getNumComponents is 3.

DiscreteAlphaIndexColorModel is basically a 2 “sample” per pixel model (one sample is an RGB image with an IndexColorModel and the other is the Alpha channel). Therefore, under almost all circumstances, the getNumComponents should return 4 (unless it somehow got constructed for an image without an alpha channel, in which case it should return 3 since it should act just like an IndexColorModel without an alpha channel).

Instead, it always returns 2 (potentially 1 if it doesn’t have an alpha channel).

It’s possible there’s a misunderstanding on my part. If so, please let me know.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jimfcarrollcommented, Aug 12, 2022

I have a project with a conversion from a BufferedImage to an OpenCV mat. In the test for the conversion I compare the pixel values from the original BufferedImage to the resulting Mat pixel-by-pixel. That compare fails because of the number of channels. Here is my workaround in the test code:

https://github.com/KognitionAI/pilecv4j/blob/master/lib-image/src/test/java/ai/kognition/pilecv4j/image/UtilsForTesting.java#L108

If I’m misinterpreting what that method means on the color model, then I can just use: colorModel.getNumColorComponents() + (hasAlpha ? 1 : 0) but I thought I’d just add the issue here as an FYI in case I’m not misinterpreting it.

0reactions
jimfcarrollcommented, Aug 22, 2022

Thanks. Sounds great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JPEGImageReader.java example - Javatips.net
This class describes the usage of JPEGImageReader.java.
Read more >
Add a notice to warn users that the company has reached the ...
DiscreteAlphaIndexColorModel.getNumComponents is giving the wrong information, 4, 2022-07-29, 2022-08-05. ui-router core v6.0.7 does not work with IE ...
Read more >
TwelveMonkeys - bytemeta
DiscreteAlphaIndexColorModel.getNumComponents is giving the wrong information. gjrjf. gjrjf CLOSED · Updated 1 month ago ...
Read more >
Haraldk TwelveMonkeys Issues - IssueHint
DiscreteAlphaIndexColorModel.getNumComponents is giving the wrong information, closed, 7 ; WebP: Reading from InputStream with unknown length does not decode ( ...
Read more >
TwelveMonkeys - githubmemory
DiscreteAlphaIndexColorModel.getNumComponents is giving the wrong information. gjrjf. gjrjf CLOSED · Updated 1 month ago ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found