How to extend BufferedImage class to support

  • Thread starter Czterysta Czwarty
  • Start date
C

Czterysta Czwarty

Hi!

I need your help to finish my image compression project.

How to build a BufferedImage class to support YCbCr color scheme
(luminance channel and two chrominance)?
Can you give me some tips, what I should to change?

I was thinking about adding getYCbCr() method, which would be used
getRGB() and calculate new values for each pixel, but I would like to
build a class, which fully served by this model, only getting lost in
class ColorModel, Raster, etc.

Have anybody ever changed it and can help me?
 
J

Jeff Higgins

Hi!

I need your help to finish my image compression project.

How to build a BufferedImage class to support YCbCr color scheme
(luminance channel and two chrominance)?
Can you give me some tips, what I should to change?

I was thinking about adding getYCbCr() method, which would be used
getRGB() and calculate new values for each pixel, but I would like to
build a class, which fully served by this model, only getting lost in
class ColorModel, Raster, etc.

Have anybody ever changed it and can help me?

This is way outside of what I've done with images, but:
what happens if you construct a BufferedImage with a ColorModel
that has been constructed with a ColorSpace.getInstance(TYPE_YCbCr)
and appropriate values for all the other construction parameters?
Does a call to your BufferedImage's .getRGB() return an appropriate value?
 
C

Czterysta Czwarty

This is way outside of what I've done with images, but:
what happens if you construct a BufferedImage with a ColorModel
that has been constructed with a ColorSpace.getInstance(TYPE_YCbCr)
and appropriate values for all the other construction parameters?

I wrote this:

ColorSpace cs = ColorSpace.getInstance(ColorSpace.TYPE_YCbCr);
int[] bits = { 8, 8, 8 };
ColorModel cm = new ComponentColorModel(cs, bits, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

but I still don't know how to convert pixel colors there and back. I
need getLuminance() method etc.
 
J

Jeff Higgins

This is way outside of what I've done with images, but:
what happens if you construct a BufferedImage with a ColorModel
that has been constructed with a ColorSpace.getInstance(TYPE_YCbCr)
and appropriate values for all the other construction parameters?

I wrote this:

ColorSpace cs = ColorSpace.getInstance(ColorSpace.TYPE_YCbCr);
int[] bits = { 8, 8, 8 };
ColorModel cm = new ComponentColorModel(cs, bits, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

I'm hoping to learn with you. I'll rephrase my question.
Have you been able to construct(or load, or convert to) a valid
BufferedImage that uses a ColorSpace of type ColorSpace.TYPE_YCbCr?

If you have, does theBufferedImage's getRGB()methods return an
appropriate conversion, and will you post a short compilable demo?
If you haven't maybe you should, so as to have something to work with.
but I still don't know how to convert pixel colors there and back. I
need getLuminance() method etc.

I don't think you will find a YCbCr API in the JDK or JAI, I may be
wrong. If not you'll need to write your own. Lew pointed to one link,
there seems to be much info available on the web.

Wikipedia's article on YCbCr seems to me to imply that a YCbCr color
space is mainly useful as a storage or transmission format and that
leads me to wonder why you want a YCbCr API, especially pasted onto
BufferedImage?
 
J

John B. Matthews

Czterysta Czwarty said:
Do you have one minute?  Because if you have one minute, you'll find
that the first hit on
<http://www.google.com/search?hl=en&q=ycbcr+Java>
is
<http://www.f4.fhtw-berlin.de/~barthel/ImageJ/ColorInspector/HTMLHelp/farbraumJava.htm>
[...]
I found this, but I want to do this with ColorModel and ColorSpace and
I don't know how?

I though you would use the the formula mentioned above to implement
the getRed(), getGreen() and getBlue() method in your extension of
ColorModel.

Also, you might like this example suggested by Jeff Higgins:

<http://helpdesk.objects.com.au/java/changing-the-colormodel-of-a-bufferedimage>

in this discussion:

<http://groups.google.com/group/comp.lang.java.help/browse_frm/thread/63c6c2114e6ddc06>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top