Skip to main content

[JAI] ColorConvert to self ColorModel is lossy?

3 replies [Last post]
Anonymous

Yesterday I post a problem dealing with ColorConvert... Tracing the
problem I've found it must be within my 'convertirColorModel'
implementation. It takes two arguments: the PlanarImage to convert,
and the new ColorModel. The problem is that even if I pass
myPlanarImage.getColorModel() ColorModel as argument pixel values
change. This is the calling code:

PlanarImage bb00 = Generador.tomarBanda(imagen, 0);
int[] pp00 = bb00.getData().getPixels(0, 0, ancho, alto, (int[]) null);
PlanarImage bb11 = Generador.tomarBanda(imagen, 1);
int[] pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
System.out.println("\n"+imagen.getColorModel()+"\n");

imagen = Conversor.convertirColorModel(imagen, cmOriginal);
bb00 = Generador.tomarBanda(imagen, 0);
pp00 = bb00.getData().getPixels(0, 0,
ancho, alto, (int[]) null);
bb11 = Generador.tomarBanda(imagen, 1);
pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
System.out.println("\n"+imagen.getColorModel()+"\n");

(The only important line is the calling, the others are there just for
debugging...). 'tomarBanda' just returns a band of a PlanarImage. This
is the code:

public static PlanarImage tomarBanda(PlanarImage imagen, int banda) {
int[] bandas = new int[1];
bandas[0] = banda;
ParameterBlock pb = new ParameterBlock();
pb.addSource(imagen);
pb.add(bandas);
return JAI.create("bandSelect", pb);
}

I've tried with two implementations of the main method.
The first one:

public static PlanarImage convertirColorModel(PlanarImage pi, ColorModel cm) {
ParameterBlock pb = new ParameterBlock();
pb.addSource(pi).add(cm);
pi = JAI.create("ColorConvert", pb, null);
return pi;
}

And the second one:

public static PlanarImage convertingColorModel(PlanarImage pi, ColorModel cm) {
ParameterBlock pb = new ParameterBlock();
ImageLayout il = new ImageLayout();
il.setSampleModel(cm.createCompatibleSampleModel(pi.getWidth(),pi.getHeight()));
RenderingHints hints = new
RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, il);
pb.addSource(pi).add(cm);
pi = JAI.create("ColorConvert", pb, hints);
return pi;
}

The results are the same:

initial pp00: 255, 0, 255, 255, 255, 0, 255, 0...
initial pp11: 255, 0, 255, 0, 255, 255, 255, 0...

final pp00: 252, 0, 252, 253, 252, 22, 252, 0
final pp11: 253, 0, 253, 0, 253, 253, 253, 19

Obviously initial and final should be the same...

Any ideas?
--
Juan Ignacio Sánchez Lara
Ingeniero Técnico en Informática de Sistemas

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Aastha Bhardwaj

Hi Juan,

We have been able to reproduce the behavior that you describe. For a
majority of the image types, the JAI "ColorConvert" operation is
actually implemented to use the java.awt.image.ColorConvertOp class for
the color conversion and it was verified that this problem exists in
that class. I have forwarded this problem on to the relevant team.

Thanks for bringing this to our attention,

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

> Yesterday I post a problem dealing with ColorConvert... Tracing the
> problem I've found it must be within my 'convertirColorModel'
> implementation. It takes two arguments: the PlanarImage to convert,
> and the new ColorModel. The problem is that even if I pass
> myPlanarImage.getColorModel() ColorModel as argument pixel values
> change. This is the calling code:
>
> PlanarImage bb00 = Generador.tomarBanda(imagen, 0);
> int[] pp00 = bb00.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> PlanarImage bb11 = Generador.tomarBanda(imagen, 1);
> int[] pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> System.out.println("\n"+imagen.getColorModel()+"\n");
>
> imagen = Conversor.convertirColorModel(imagen, cmOriginal);
> bb00 = Generador.tomarBanda(imagen, 0);
> pp00 = bb00.getData().getPixels(0, 0,
> ancho, alto, (int[]) null);
> bb11 = Generador.tomarBanda(imagen, 1);
> pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> System.out.println("\n"+imagen.getColorModel()+"\n");
>
>
> (The only important line is the calling, the others are there just for
> debugging...). 'tomarBanda' just returns a band of a PlanarImage. This
> is the code:
>
> public static PlanarImage tomarBanda(PlanarImage imagen, int banda) {
> int[] bandas = new int[1];
> bandas[0] = banda;
> ParameterBlock pb = new ParameterBlock();
> pb.addSource(imagen);
> pb.add(bandas);
> return JAI.create("bandSelect", pb);
> }
>
>
>
> I've tried with two implementations of the main method.
> The first one:
>
> public static PlanarImage convertirColorModel(PlanarImage pi, ColorModel cm) {
> ParameterBlock pb = new ParameterBlock();
> pb.addSource(pi).add(cm);
> pi = JAI.create("ColorConvert", pb, null);
> return pi;
> }
>
>
>
> And the second one:
>
> public static PlanarImage convertingColorModel(PlanarImage pi, ColorModel cm) {
> ParameterBlock pb = new ParameterBlock();
> ImageLayout il = new ImageLayout();
> il.setSampleModel(cm.createCompatibleSampleModel(pi.getWidth(),pi.getHeight()));
> RenderingHints hints = new
> RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, il);
> pb.addSource(pi).add(cm);
> pi = JAI.create("ColorConvert", pb, hints);
> return pi;
> }
>
>
> The results are the same:
>
> initial pp00: 255, 0, 255, 255, 255, 0, 255, 0...
> initial pp11: 255, 0, 255, 0, 255, 255, 255, 0...
>
> final pp00: 252, 0, 252, 253, 252, 22, 252, 0
> final pp11: 253, 0, 253, 0, 253, 253, 253, 19
>
> Obviously initial and final should be the same...
>
> Any ideas?

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Juan Ignacio Sánchez Lara

Thank you very very much for that information.

Knowing that it's a bug is really important for me and my current job.
I hope it can be fixed soon :-)

Thanks once more

On 6/2/05, Aastha Bhardwaj wrote:
> Hi Juan,
>
> We have been able to reproduce the behavior that you describe. For a
> majority of the image types, the JAI "ColorConvert" operation is
> actually implemented to use the java.awt.image.ColorConvertOp class for
> the color conversion and it was verified that this problem exists in
> that class. I have forwarded this problem on to the relevant team.
>
> Thanks for bringing this to our attention,
>
> Aastha
>
> ---------------------
> Aastha Bhardwaj
> Java Advanced Imaging
> Sun Microsystems
>
>
> > Yesterday I post a problem dealing with ColorConvert... Tracing the
> > problem I've found it must be within my 'convertirColorModel'
> > implementation. It takes two arguments: the PlanarImage to convert,
> > and the new ColorModel. The problem is that even if I pass
> > myPlanarImage.getColorModel() ColorModel as argument pixel values
> > change. This is the calling code:
> >
> > PlanarImage bb00 = Generador.tomarBanda(imagen, 0);
> > int[] pp00 = bb00.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> > PlanarImage bb11 = Generador.tomarBanda(imagen, 1);
> > int[] pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> > System.out.println("\n"+imagen.getColorModel()+"\n");
> >
> > imagen = Conversor.convertirColorModel(imagen, cmOriginal);
> > bb00 = Generador.tomarBanda(imagen, 0);
> > pp00 = bb00.getData().getPixels(0, 0,
> > ancho, alto, (int[]) null);
> > bb11 = Generador.tomarBanda(imagen, 1);
> > pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
> > System.out.println("\n"+imagen.getColorModel()+"\n");
> >
> >
> > (The only important line is the calling, the others are there just for
> > debugging...). 'tomarBanda' just returns a band of a PlanarImage. This
> > is the code:
> >
> > public static PlanarImage tomarBanda(PlanarImage imagen, int banda) {
> > int[] bandas = new int[1];
> > bandas[0] = banda;
> > ParameterBlock pb = new ParameterBlock();
> > pb.addSource(imagen);
> > pb.add(bandas);
> > return JAI.create("bandSelect", pb);
> > }
> >
> >
> >
> > I've tried with two implementations of the main method.
> > The first one:
> >
> > public static PlanarImage convertirColorModel(PlanarImage pi, ColorModel cm) {
> > ParameterBlock pb = new ParameterBlock();
> > pb.addSource(pi).add(cm);
> > pi = JAI.create("ColorConvert", pb, null);
> > return pi;
> > }
> >
> >
> >
> > And the second one:
> >
> > public static PlanarImage convertingColorModel(PlanarImage pi, ColorModel cm) {
> > ParameterBlock pb = new ParameterBlock();
> > ImageLayout il = new ImageLayout();
> > il.setSampleModel(cm.createCompatibleSampleModel(pi.getWidth(),pi.getHeight()));
> > RenderingHints hints = new
> > RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, il);
> > pb.addSource(pi).add(cm);
> > pi = JAI.create("ColorConvert", pb, hints);
> > return pi;
> > }
> >
> >
> > The results are the same:
> >
> > initial pp00: 255, 0, 255, 255, 255, 0, 255, 0...
> > initial pp11: 255, 0, 255, 0, 255, 255, 255, 0...
> >
> > final pp00: 252, 0, 252, 253, 252, 22, 252, 0
> > final pp11: 253, 0, 253, 0, 253, 253, 253, 19
> >
> > Obviously initial and final should be the same...
> >
> > Any ideas?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

--
Juan Ignacio Sánchez Lara
Ingeniero Técnico en Informática de Sistemas

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Aastha Bhardwaj

Hi Juan,

The bug has been filed. The bug ID is 6279846, and the bug report should
be visible in a day or two at

http://bugs.sun.com/bugdatabase/index.jsp

You can always vote for the bug once it is visible on the above site, to
increase its chances of being fixed soon.

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

> Thank you very very much for that information.
>
> Knowing that it's a bug is really important for me and my current job.
> I hope it can be fixed soon :-)
>
> Thanks once more
>
> On 6/2/05, Aastha Bhardwaj wrote:
>
>>Hi Juan,
>>
>>We have been able to reproduce the behavior that you describe. For a
>>majority of the image types, the JAI "ColorConvert" operation is
>>actually implemented to use the java.awt.image.ColorConvertOp class for
>>the color conversion and it was verified that this problem exists in
>>that class. I have forwarded this problem on to the relevant team.
>>
>>Thanks for bringing this to our attention,
>>
>>Aastha
>>
>>---------------------
>>Aastha Bhardwaj
>>Java Advanced Imaging
>>Sun Microsystems
>>
>>
>>
>>>Yesterday I post a problem dealing with ColorConvert... Tracing the
>>>problem I've found it must be within my 'convertirColorModel'
>>>implementation. It takes two arguments: the PlanarImage to convert,
>>>and the new ColorModel. The problem is that even if I pass
>>>myPlanarImage.getColorModel() ColorModel as argument pixel values
>>>change. This is the calling code:
>>>
>>>PlanarImage bb00 = Generador.tomarBanda(imagen, 0);
>>>int[] pp00 = bb00.getData().getPixels(0, 0, ancho, alto, (int[]) null);
>>>PlanarImage bb11 = Generador.tomarBanda(imagen, 1);
>>>int[] pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
>>>System.out.println("\n"+imagen.getColorModel()+"\n");
>>>
>>>imagen = Conversor.convertirColorModel(imagen, cmOriginal);
>>>bb00 = Generador.tomarBanda(imagen, 0);
>>>pp00 = bb00.getData().getPixels(0, 0,
>>>ancho, alto, (int[]) null);
>>>bb11 = Generador.tomarBanda(imagen, 1);
>>>pp11 = bb11.getData().getPixels(0, 0, ancho, alto, (int[]) null);
>>>System.out.println("\n"+imagen.getColorModel()+"\n");
>>>
>>>
>>>(The only important line is the calling, the others are there just for
>>>debugging...). 'tomarBanda' just returns a band of a PlanarImage. This
>>>is the code:
>>>
>>>public static PlanarImage tomarBanda(PlanarImage imagen, int banda) {
>>> int[] bandas = new int[1];
>>> bandas[0] = banda;
>>> ParameterBlock pb = new ParameterBlock();
>>> pb.addSource(imagen);
>>> pb.add(bandas);
>>> return JAI.create("bandSelect", pb);
>>> }
>>>
>>>
>>>
>>>I've tried with two implementations of the main method.
>>>The first one:
>>>
>>>public static PlanarImage convertirColorModel(PlanarImage pi, ColorModel cm) {
>>> ParameterBlock pb = new ParameterBlock();
>>> pb.addSource(pi).add(cm);
>>> pi = JAI.create("ColorConvert", pb, null);
>>> return pi;
>>> }
>>>
>>>
>>>
>>>And the second one:
>>>
>>>public static PlanarImage convertingColorModel(PlanarImage pi, ColorModel cm) {
>>> ParameterBlock pb = new ParameterBlock();
>>> ImageLayout il = new ImageLayout();
>>> il.setSampleModel(cm.createCompatibleSampleModel(pi.getWidth(),pi.getHeight()));
>>> RenderingHints hints = new
>>>RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, il);
>>> pb.addSource(pi).add(cm);
>>> pi = JAI.create("ColorConvert", pb, hints);
>>> return pi;
>>> }
>>>
>>>
>>>The results are the same:
>>>
>>>initial pp00: 255, 0, 255, 255, 255, 0, 255, 0...
>>>initial pp11: 255, 0, 255, 0, 255, 255, 255, 0...
>>>
>>>final pp00: 252, 0, 252, 253, 252, 22, 252, 0
>>>final pp11: 253, 0, 253, 0, 253, 253, 253, 19
>>>
>>>Obviously initial and final should be the same...
>>>
>>>Any ideas?
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>>For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net