Custom RGB ColorModel

I have a program that displays RGB images (internally represented as int [] s) on the screen. I want to be able to configure the parameters that are used to map a value in memory (for example, a red intensity of 128) to a screen value. For example, I want to say that "the maximum intensity (1.0) for red corresponds to a pixel value of 50, the minimum intensity (0.0) corresponds to 4". And, of course, adjust both green and blue components.

From what I can say, this requires creating a custom ColorModel, perhaps subclass PackedColorModel. I am currently using DirectColorModelone that does not look customizable (it always displays 0 for the component at 0 on the display and 255 at 1.0 on the display). Worse, for some reason, his methods are final, so I cannot create my own version DirectColorModelwith different rules.

Unfortunately, it PackedColorModeldoes not seem remotely trivial for the subclass. In addition to leaving a huge number of abstract methods, its constructor accepts ColorSpace, the only implementation of which is ICC_ColorSpace, which, in turn, requires ICC_Profile. If I were trying to do some work on photography, then perhaps I would be interested in this level of detail, but my needs are not so complex; I just want to be able to scale the intensity of the R / G / B components in my image data.

Is there any simple enough way to achieve what I'm trying to do, or do I really need to jump down the rabbit hole and build a complex system to make some basic color adjustment to a reasonable extent?

In the past, I did similar things using OpenGL calls, but unfortunately this is not an option, because ultimately the visualization code is out of my control; I can customize the color model used by the call Graphics.drawImage().

Thank you for your time!

+4
source share

Source: https://habr.com/ru/post/1610990/


All Articles