As I understood your question, you want to do the following:
Load RGB image -> process YCbCr image -> Use RGB image again
And you want us to help you, to make this process as seamless as possible. First and foremost you want us to give you a simple way to avoid the ->
(converting) parts.
Well I looked into the BufferedImage
documentation. It seems, as if there doesn't exist a way to change the ColorSpace
of an once created BufferedImage
.
You could create a new BufferedImage
with an YCbCr color space for that you can use the predefined ICC_ColorSpace
. Then you copy the data from your old image possibly via ColorSpace.fromRGB
to the YCbCr color space, do the image processing and then convert again via ColorSpace.toRGB
. This method requires you to fully convert the image before and after processing via existing methods. Furthermore you have to know, how ICC_ColorSpace
converts your image to YCbCr color space. Otherwise you can't know, which array indices corresponds to the same pixel.
If you just want to create a wrapper around the RGB-BufferedImage
that lets you manipulate this image, as if it was an YCbCr image, that isn't possible with BufferedImage
.
EDIT:
To convert the color space of a BufferedImage
use ColorConvertOp
. The code would look something like this:
ColorConvertOp cco = new ColorConvertOp(new YCbCrColorSpace(), null);
BufferedImage ycbcrImage = cco.filter( oldRGBImage, null );
This requires you to either write your own ColorSpace
class or you could download and use the classes mentioned here. If you just want to load a JPEG image you should use the predefined classes.