Skip to main content

[JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor band indices

17 replies [Last post]
Anonymous

I'm playing around with writing a 3-band JPEG from a 4-band image. I've
never had any problem with this before.

Among a few other operators, I'm doing a band select with bands 2,1,0 to
produce an RGB image from BGR bands in the 4-band file. When I write the
resulting image to a JPEG file, I get different results using the J2SE
writer than what I see from the CLib writer. (I discovered this
originally because I didn't have the native clib library available at
some point.)

It looks like the CLib writer is ignoring the band indices in the
SampleModel that were modified by the band select operator. As I said,
I've never had this problem before.

Has anyone seen this before? I could come up with a test case but I'm
working toward a deadline right now.

The operator chain is:

bandselect -> scale -> LUT -> format -> border

Mike

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

Reply viewing options

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

On Mon, 5 Feb 2007, Nidel, Mike wrote:

> yeah I suspected there was an additional API for Raster but I hadn't
> looked at it yet.
> Is it easier for you to produce the fix than for me to patch it?
> Otherwise I will do it
> later today or tomorrow.

What happens if you just add this line

mediaLibFormat = getMediaLibFormat(sampleModel, image.getColorModel());

after line 713 of CLibImageWriter.java? The modified block of code would look
like this:

} else { // !reformatData
// No reformatting needed.
raster = getContiguousData(image, sourceRegion).createTranslatedChild(0, 0);
sampleModel = raster.getSampleModel();
mediaLibFormat = getMediaLibFormat(sampleModel, image.getColorModel());
}

Thanks,

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

that appears to have done the trick.
now what?

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Monday, February 05, 2007 6:10 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> On Mon, 5 Feb 2007, Nidel, Mike wrote:
>
> > yeah I suspected there was an additional API for Raster but
> I hadn't
> > looked at it yet.
> > Is it easier for you to produce the fix than for me to patch it?
> > Otherwise I will do it
> > later today or tomorrow.
>
> What happens if you just add this line
>
> mediaLibFormat = getMediaLibFormat(sampleModel,
> image.getColorModel());
>
> after line 713 of CLibImageWriter.java? The modified block of
> code would look like this:
>
> } else { // !reformatData
> // No reformatting needed.
> raster = getContiguousData(image,
> sourceRegion).createTranslatedChild(0, 0);
> sampleModel = raster.getSampleModel();
> mediaLibFormat = getMediaLibFormat(sampleModel,
> image.getColorModel()); }
>
> Thanks,
>
> Brian
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

Either add a patch to the issue report or I'll just fix it directly which
would likely be easier.

Thanks,

Brian

On Tue, 6 Feb 2007, Nidel, Mike wrote:

> that appears to have done the trick.
> now what?
>
>> -----Original Message-----
>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>> Sent: Monday, February 05, 2007 6:10 PM
>> To: interest@jai-imageio.dev.java.net
>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
>> honor band indices
>>
>> On Mon, 5 Feb 2007, Nidel, Mike wrote:
>>
>>> yeah I suspected there was an additional API for Raster but
>> I hadn't
>>> looked at it yet.
>>> Is it easier for you to produce the fix than for me to patch it?
>>> Otherwise I will do it
>>> later today or tomorrow.
>>
>> What happens if you just add this line
>>
>> mediaLibFormat = getMediaLibFormat(sampleModel,
>> image.getColorModel());
>>
>> after line 713 of CLibImageWriter.java? The modified block of
>> code would look like this:
>>
>> } else { // !reformatData
>> // No reformatting needed.
>> raster = getContiguousData(image,
>> sourceRegion).createTranslatedChild(0, 0);
>> sampleModel = raster.getSampleModel();
>> mediaLibFormat = getMediaLibFormat(sampleModel,
>> image.getColorModel()); }
>>
>> Thanks,
>>
>> Brian
>>
>> ----------------
>> Brian Burkhalter
>> Java Media, Imaging, and Graphics
>> Sun Microsystems, Inc.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> This email message is for the sole use of the intended
>> recipient(s) and may contain confidential and privileged
>> information. Any unauthorized review, use, disclosure or
>> distribution is prohibited.
>> If you are not the intended recipient, please contact the
>> sender by reply email and destroy all copies of the original message.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail:
>> interest-help@jai-imageio.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

I've filed issue 114 for this bug.
Hopefully my description is adequate.

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 6:17 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Sorry about that. I guess an issue needs to be filed. As you
> spent so much time on it already I can do that if you like.
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > It appears the problem lies in the getContiguousData() method. line
> > 261 of my copy of CLibImageWriter.java.
> >
> > see the else clause that says in a comment "Image is tiled"?
> >
> > If I get into there (my image is tiled before writing) then
> it writes
> > the image wrong. If instead I forcibly untile the image beforehand
> > (format op with tile width/height == image width/height) then all
> > appears to work well. The problem I guess is with the way
> the raster
> > is created and populated for a tiled input.
> >
> > too bad it took me 9+ hours to figure that out...
> >
> >
> >
> > private static final Raster getContiguousData(RenderedImage im,
> > Rectangle region) {
> > if(im == null) {
> > throw new IllegalArgumentException("im == null");
> > } else if(region == null) {
> > throw new IllegalArgumentException("region == null");
> > }
> >
> > Raster raster;
> > if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
> > // Image is not tiled so just get a reference to
> the tile.
> > raster = im.getTile(im.getMinTileX(), im.getMinTileY());
> >
> > // Ensure result has requested coverage.
> > Rectangle bounds = raster.getBounds();
> > if (!bounds.equals(region)) {
> > raster = raster.createChild(region.x, region.y,
> > region.width,
> region.height,
> > region.x, region.y,
> > null);
> > }
> > } else {
> > // Image is tiled.
> >
> > // Create an interleaved raster for copying for
> 8-bit case.
> > // This ensures that for RGB data the band offsets are
> > {0,1,2}.
> > SampleModel sampleModel = im.getSampleModel();
> > WritableRaster target =
> sampleModel.getSampleSize(0) == 8 ?
> > Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
> > im.getWidth(),
> > im.getHeight(),
> >
> > sampleModel.getNumBands(),
> > new
> Point(im.getMinX(),
> >
> im.getMinY()))
> > :
> > null;
> >
> > // Copy the data.
> > raster = im.copyData(target);
> > }
> >
> > return raster;
> > }
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 1:40 PM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Actually I am surprised that getContiguousData() is even being
> >> called. I would think that the "scale" operation would create a
> >> SampleModel which is not a subset SampleModel but had band offsets
> >> {2,1,0}. This order should be able to be handled by the CLib JPEG
> >> writer without reformatting.
> >>
> >> Does anything different happen if you create a TYPE_3BYTE_BGR
> >> BufferedImage just after BandSelect and write the 3-band
> data into it?
> >>
> >> Are you using 8-bit data?
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> OK the problem appears to be here. The following code is in
> >> Raster at
> >>> line 186:
> >>>
> >>>
> >>> public static WritableRaster createInterleavedRaster(int
> >> dataType,
> >>> int
> >> w, int h,
> >>> int bands,
> >>> Point
> >>> location) {
> >>> int[] bandOffsets = new int[bands];
> >>> for (int i = 0; i < bands; i++) {
> >>> bandOffsets[i] = i;
> >>> }
> >>> return createInterleavedRaster(dataType, w, h,
> >> w*bands, bands,
> >>> bandOffsets, location);
> >>> }
> >>>
> >>>
> >>> This is called from CLibImageWriter.getContiguousData():288.
> >>> The band offsets are automatically set to [0,1,2].
> >>>
> >>> The result appears to be that the sample model of the
> >> produced tile is
> >>> not the same as the sample model of the input image (which
> >> in my case
> >>> has band offsets [2,1,0]. This corresponds to the problem
> >> I'm seeing,
> >>> which is that the resulting image has the bands in the
> wrong order.
> >>>
> >>> So... how can I work around this? I really want to be able
> >> to write my
> >>> code so that it will work either with the core JPEG writer
> >> or the CLib
> >>> one.
> >>>
> >>> Mike
> >>>
> >>>> -----Original Message-----
> >>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >>>> Sent: Friday, February 02, 2007 11:50 AM
> >>>> To: interest@jai-imageio.dev.java.net
> >>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
> to honor
> >>>> band indices
> >>>>
> >>>> Mike,
> >>>>
> >>>> So I assume that the Java implementation delivers what you
> >> expect but
> >>>> the CLib one does not?
> >>>>
> >>>> Brian
> >>>>
> >>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>>>
> >>>>> I'm playing around with writing a 3-band JPEG from a
> 4-band image.
> >>>>> I've never had any problem with this before.
> >>>>>
> >>>>> Among a few other operators, I'm doing a band select with
> >>>> bands 2,1,0
> >>>>> to produce an RGB image from BGR bands in the 4-band
> file. When I
> >>>>> write the resulting image to a JPEG file, I get
> different results
> >>>>> using the J2SE writer than what I see from the CLib writer. (I
> >>>>> discovered this originally because I didn't have the
> native clib
> >>>>> library available at some point.)
> >>>>>
> >>>>> It looks like the CLib writer is ignoring the band
> indices in the
> >>>>> SampleModel that were modified by the band select operator.
> >>>> As I said,
> >>>>> I've never had this problem before.
> >>>>>
> >>>>> Has anyone seen this before? I could come up with a test
> >>>> case but I'm
> >>>>> working toward a deadline right now.
> >>>>>
> >>>>> The operator chain is:
> >>>>>
> >>>>> bandselect -> scale -> LUT -> format -> border
> >>>>>
> >>>>>
> >>>>>
> >>>>> Mike
> >>>>>
> >>>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail:
> >>>> interest-unsubscribe@jai-imageio.dev.java.net
> >>>>> For additional commands, e-mail:
> >>>>> interest-help@jai-imageio.dev.java.net
> >>>>>
> >>>>>
> >>>>
> >>>> ----------------
> >>>> Brian Burkhalter
> >>>> Java Media, Imaging, and Graphics
> >>>> Sun Microsystems, Inc.
> >>>>
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>> This email message is for the sole use of the intended
> >>>> recipient(s) and may contain confidential and privileged
> >> information.
> >>>> Any unauthorized review, use, disclosure or distribution is
> >>>> prohibited.
> >>>> If you are not the intended recipient, please contact the
> >> sender by
> >>>> reply email and destroy all copies of the original message.
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>>> For additional commands, e-mail:
> >>>> interest-help@jai-imageio.dev.java.net
> >>>>
> >>>>
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> information.
> >> Any unauthorized review, use, disclosure or distribution is
> >> prohibited.
> >> If you are not the intended recipient, please contact the
> sender by
> >> reply email and destroy all copies of the original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

It looks fine - thanks.

Sorry this cost you so much time.

Brian

On Mon, 5 Feb 2007, Nidel, Mike wrote:

> I've filed issue 114 for this bug.
> Hopefully my description is adequate.
>
>> -----Original Message-----
>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>> Sent: Friday, February 02, 2007 6:17 PM
>> To: interest@jai-imageio.dev.java.net
>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
>> honor band indices
>>
>> Sorry about that. I guess an issue needs to be filed. As you
>> spent so much time on it already I can do that if you like.
>>
>> Brian
>>
>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>
>>> It appears the problem lies in the getContiguousData() method. line
>>> 261 of my copy of CLibImageWriter.java.
>>>
>>> see the else clause that says in a comment "Image is tiled"?
>>>
>>> If I get into there (my image is tiled before writing) then
>> it writes
>>> the image wrong. If instead I forcibly untile the image beforehand
>>> (format op with tile width/height == image width/height) then all
>>> appears to work well. The problem I guess is with the way
>> the raster
>>> is created and populated for a tiled input.
>>>
>>> too bad it took me 9+ hours to figure that out...
>>>
>>>
>>>
>>> private static final Raster getContiguousData(RenderedImage im,
>>> Rectangle region) {
>>> if(im == null) {
>>> throw new IllegalArgumentException("im == null");
>>> } else if(region == null) {
>>> throw new IllegalArgumentException("region == null");
>>> }
>>>
>>> Raster raster;
>>> if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
>>> // Image is not tiled so just get a reference to
>> the tile.
>>> raster = im.getTile(im.getMinTileX(), im.getMinTileY());
>>>
>>> // Ensure result has requested coverage.
>>> Rectangle bounds = raster.getBounds();
>>> if (!bounds.equals(region)) {
>>> raster = raster.createChild(region.x, region.y,
>>> region.width,
>> region.height,
>>> region.x, region.y,
>>> null);
>>> }
>>> } else {
>>> // Image is tiled.
>>>
>>> // Create an interleaved raster for copying for
>> 8-bit case.
>>> // This ensures that for RGB data the band offsets are
>>> {0,1,2}.
>>> SampleModel sampleModel = im.getSampleModel();
>>> WritableRaster target =
>> sampleModel.getSampleSize(0) == 8 ?
>>> Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
>>> im.getWidth(),
>>> im.getHeight(),
>>>
>>> sampleModel.getNumBands(),
>>> new
>> Point(im.getMinX(),
>>>
>> im.getMinY()))
>>> :
>>> null;
>>>
>>> // Copy the data.
>>> raster = im.copyData(target);
>>> }
>>>
>>> return raster;
>>> }
>>>
>>>> -----Original Message-----
>>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>>>> Sent: Friday, February 02, 2007 1:40 PM
>>>> To: interest@jai-imageio.dev.java.net
>>>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
>>>> band indices
>>>>
>>>> Actually I am surprised that getContiguousData() is even being
>>>> called. I would think that the "scale" operation would create a
>>>> SampleModel which is not a subset SampleModel but had band offsets
>>>> {2,1,0}. This order should be able to be handled by the CLib JPEG
>>>> writer without reformatting.
>>>>
>>>> Does anything different happen if you create a TYPE_3BYTE_BGR
>>>> BufferedImage just after BandSelect and write the 3-band
>> data into it?
>>>>
>>>> Are you using 8-bit data?
>>>>
>>>> Brian
>>>>
>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>>>
>>>>> OK the problem appears to be here. The following code is in
>>>> Raster at
>>>>> line 186:
>>>>>
>>>>>
>>>>> public static WritableRaster createInterleavedRaster(int
>>>> dataType,
>>>>> int
>>>> w, int h,
>>>>> int bands,
>>>>> Point
>>>>> location) {
>>>>> int[] bandOffsets = new int[bands];
>>>>> for (int i = 0; i < bands; i++) {
>>>>> bandOffsets[i] = i;
>>>>> }
>>>>> return createInterleavedRaster(dataType, w, h,
>>>> w*bands, bands,
>>>>> bandOffsets, location);
>>>>> }
>>>>>
>>>>>
>>>>> This is called from CLibImageWriter.getContiguousData():288.
>>>>> The band offsets are automatically set to [0,1,2].
>>>>>
>>>>> The result appears to be that the sample model of the
>>>> produced tile is
>>>>> not the same as the sample model of the input image (which
>>>> in my case
>>>>> has band offsets [2,1,0]. This corresponds to the problem
>>>> I'm seeing,
>>>>> which is that the resulting image has the bands in the
>> wrong order.
>>>>>
>>>>> So... how can I work around this? I really want to be able
>>>> to write my
>>>>> code so that it will work either with the core JPEG writer
>>>> or the CLib
>>>>> one.
>>>>>
>>>>> Mike
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>>>>>> Sent: Friday, February 02, 2007 11:50 AM
>>>>>> To: interest@jai-imageio.dev.java.net
>>>>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
>> to honor
>>>>>> band indices
>>>>>>
>>>>>> Mike,
>>>>>>
>>>>>> So I assume that the Java implementation delivers what you
>>>> expect but
>>>>>> the CLib one does not?
>>>>>>
>>>>>> Brian
>>>>>>
>>>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>>>>>
>>>>>>> I'm playing around with writing a 3-band JPEG from a
>> 4-band image.
>>>>>>> I've never had any problem with this before.
>>>>>>>
>>>>>>> Among a few other operators, I'm doing a band select with
>>>>>> bands 2,1,0
>>>>>>> to produce an RGB image from BGR bands in the 4-band
>> file. When I
>>>>>>> write the resulting image to a JPEG file, I get
>> different results
>>>>>>> using the J2SE writer than what I see from the CLib writer. (I
>>>>>>> discovered this originally because I didn't have the
>> native clib
>>>>>>> library available at some point.)
>>>>>>>
>>>>>>> It looks like the CLib writer is ignoring the band
>> indices in the
>>>>>>> SampleModel that were modified by the band select operator.
>>>>>> As I said,
>>>>>>> I've never had this problem before.
>>>>>>>
>>>>>>> Has anyone seen this before? I could come up with a test
>>>>>> case but I'm
>>>>>>> working toward a deadline right now.
>>>>>>>
>>>>>>> The operator chain is:
>>>>>>>
>>>>>>> bandselect -> scale -> LUT -> format -> border
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Mike
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail:
>>>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>>>> For additional commands, e-mail:
>>>>>>> interest-help@jai-imageio.dev.java.net
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ----------------
>>>>>> Brian Burkhalter
>>>>>> Java Media, Imaging, and Graphics
>>>>>> Sun Microsystems, Inc.
>>>>>>
>>>>>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>> This email message is for the sole use of the intended
>>>>>> recipient(s) and may contain confidential and privileged
>>>> information.
>>>>>> Any unauthorized review, use, disclosure or distribution is
>>>>>> prohibited.
>>>>>> If you are not the intended recipient, please contact the
>>>> sender by
>>>>>> reply email and destroy all copies of the original message.
>>>>>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail:
>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>>> For additional commands, e-mail:
>>>>>> interest-help@jai-imageio.dev.java.net
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>> For additional commands, e-mail:
>>>>> interest-help@jai-imageio.dev.java.net
>>>>>
>>>>>
>>>>
>>>> ----------------
>>>> Brian Burkhalter
>>>> Java Media, Imaging, and Graphics
>>>> Sun Microsystems, Inc.
>>>>
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> This email message is for the sole use of the intended
>>>> recipient(s) and may contain confidential and privileged
>> information.
>>>> Any unauthorized review, use, disclosure or distribution is
>>>> prohibited.
>>>> If you are not the intended recipient, please contact the
>> sender by
>>>> reply email and destroy all copies of the original message.
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>>
>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>>> For additional commands, e-mail:
>>>> interest-help@jai-imageio.dev.java.net
>>>>
>>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>> For additional commands, e-mail:
>>> interest-help@jai-imageio.dev.java.net
>>>
>>>
>>
>> ----------------
>> Brian Burkhalter
>> Java Media, Imaging, and Graphics
>> Sun Microsystems, Inc.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> This email message is for the sole use of the intended
>> recipient(s) and may contain confidential and privileged
>> information. Any unauthorized review, use, disclosure or
>> distribution is prohibited.
>> If you are not the intended recipient, please contact the
>> sender by reply email and destroy all copies of the original message.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail:
>> interest-help@jai-imageio.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

It appears the problem lies in the getContiguousData() method. line 261
of my copy of CLibImageWriter.java.

see the else clause that says in a comment "Image is tiled"?

If I get into there (my image is tiled before writing) then it writes
the image wrong. If instead I forcibly untile the image beforehand
(format op with tile width/height == image width/height) then all
appears to work well. The problem I guess is with the way the raster is
created and populated for a tiled input.

too bad it took me 9+ hours to figure that out...

private static final Raster getContiguousData(RenderedImage im,
Rectangle region) {
if(im == null) {
throw new IllegalArgumentException("im == null");
} else if(region == null) {
throw new IllegalArgumentException("region == null");
}

Raster raster;
if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
// Image is not tiled so just get a reference to the tile.
raster = im.getTile(im.getMinTileX(), im.getMinTileY());

// Ensure result has requested coverage.
Rectangle bounds = raster.getBounds();
if (!bounds.equals(region)) {
raster = raster.createChild(region.x, region.y,
region.width, region.height,
region.x, region.y,
null);
}
} else {
// Image is tiled.

// Create an interleaved raster for copying for 8-bit case.
// This ensures that for RGB data the band offsets are
{0,1,2}.
SampleModel sampleModel = im.getSampleModel();
WritableRaster target = sampleModel.getSampleSize(0) == 8 ?
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
im.getWidth(),
im.getHeight(),

sampleModel.getNumBands(),
new Point(im.getMinX(),
im.getMinY()))
:
null;

// Copy the data.
raster = im.copyData(target);
}

return raster;
}

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 1:40 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Actually I am surprised that getContiguousData() is even
> being called. I would think that the "scale" operation would
> create a SampleModel which is not a subset SampleModel but
> had band offsets {2,1,0}. This order should be able to be
> handled by the CLib JPEG writer without reformatting.
>
> Does anything different happen if you create a TYPE_3BYTE_BGR
> BufferedImage just after BandSelect and write the 3-band data into it?
>
> Are you using 8-bit data?
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > OK the problem appears to be here. The following code is in
> Raster at
> > line 186:
> >
> >
> > public static WritableRaster createInterleavedRaster(int
> dataType,
> > int
> w, int h,
> > int bands,
> > Point
> > location) {
> > int[] bandOffsets = new int[bands];
> > for (int i = 0; i < bands; i++) {
> > bandOffsets[i] = i;
> > }
> > return createInterleavedRaster(dataType, w, h,
> w*bands, bands,
> > bandOffsets, location);
> > }
> >
> >
> > This is called from CLibImageWriter.getContiguousData():288.
> > The band offsets are automatically set to [0,1,2].
> >
> > The result appears to be that the sample model of the
> produced tile is
> > not the same as the sample model of the input image (which
> in my case
> > has band offsets [2,1,0]. This corresponds to the problem
> I'm seeing,
> > which is that the resulting image has the bands in the wrong order.
> >
> > So... how can I work around this? I really want to be able
> to write my
> > code so that it will work either with the core JPEG writer
> or the CLib
> > one.
> >
> > Mike
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 11:50 AM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Mike,
> >>
> >> So I assume that the Java implementation delivers what you
> expect but
> >> the CLib one does not?
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> I'm playing around with writing a 3-band JPEG from a 4-band image.
> >>> I've never had any problem with this before.
> >>>
> >>> Among a few other operators, I'm doing a band select with
> >> bands 2,1,0
> >>> to produce an RGB image from BGR bands in the 4-band file. When I
> >>> write the resulting image to a JPEG file, I get different results
> >>> using the J2SE writer than what I see from the CLib writer. (I
> >>> discovered this originally because I didn't have the native clib
> >>> library available at some point.)
> >>>
> >>> It looks like the CLib writer is ignoring the band indices in the
> >>> SampleModel that were modified by the band select operator.
> >> As I said,
> >>> I've never had this problem before.
> >>>
> >>> Has anyone seen this before? I could come up with a test
> >> case but I'm
> >>> working toward a deadline right now.
> >>>
> >>> The operator chain is:
> >>>
> >>> bandselect -> scale -> LUT -> format -> border
> >>>
> >>>
> >>>
> >>> Mike
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> information.
> >> Any unauthorized review, use, disclosure or distribution is
> >> prohibited.
> >> If you are not the intended recipient, please contact the
> sender by
> >> reply email and destroy all copies of the original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

Sorry about that. I guess an issue needs to be filed. As you spent so much
time on it already I can do that if you like.

Brian

On Fri, 2 Feb 2007, Nidel, Mike wrote:

> It appears the problem lies in the getContiguousData() method. line 261
> of my copy of CLibImageWriter.java.
>
> see the else clause that says in a comment "Image is tiled"?
>
> If I get into there (my image is tiled before writing) then it writes
> the image wrong. If instead I forcibly untile the image beforehand
> (format op with tile width/height == image width/height) then all
> appears to work well. The problem I guess is with the way the raster is
> created and populated for a tiled input.
>
> too bad it took me 9+ hours to figure that out...
>
>
>
> private static final Raster getContiguousData(RenderedImage im,
> Rectangle region) {
> if(im == null) {
> throw new IllegalArgumentException("im == null");
> } else if(region == null) {
> throw new IllegalArgumentException("region == null");
> }
>
> Raster raster;
> if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
> // Image is not tiled so just get a reference to the tile.
> raster = im.getTile(im.getMinTileX(), im.getMinTileY());
>
> // Ensure result has requested coverage.
> Rectangle bounds = raster.getBounds();
> if (!bounds.equals(region)) {
> raster = raster.createChild(region.x, region.y,
> region.width, region.height,
> region.x, region.y,
> null);
> }
> } else {
> // Image is tiled.
>
> // Create an interleaved raster for copying for 8-bit case.
> // This ensures that for RGB data the band offsets are
> {0,1,2}.
> SampleModel sampleModel = im.getSampleModel();
> WritableRaster target = sampleModel.getSampleSize(0) == 8 ?
> Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
> im.getWidth(),
> im.getHeight(),
>
> sampleModel.getNumBands(),
> new Point(im.getMinX(),
> im.getMinY()))
> :
> null;
>
> // Copy the data.
> raster = im.copyData(target);
> }
>
> return raster;
> }
>
>> -----Original Message-----
>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>> Sent: Friday, February 02, 2007 1:40 PM
>> To: interest@jai-imageio.dev.java.net
>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
>> honor band indices
>>
>> Actually I am surprised that getContiguousData() is even
>> being called. I would think that the "scale" operation would
>> create a SampleModel which is not a subset SampleModel but
>> had band offsets {2,1,0}. This order should be able to be
>> handled by the CLib JPEG writer without reformatting.
>>
>> Does anything different happen if you create a TYPE_3BYTE_BGR
>> BufferedImage just after BandSelect and write the 3-band data into it?
>>
>> Are you using 8-bit data?
>>
>> Brian
>>
>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>
>>> OK the problem appears to be here. The following code is in
>> Raster at
>>> line 186:
>>>
>>>
>>> public static WritableRaster createInterleavedRaster(int
>> dataType,
>>> int
>> w, int h,
>>> int bands,
>>> Point
>>> location) {
>>> int[] bandOffsets = new int[bands];
>>> for (int i = 0; i < bands; i++) {
>>> bandOffsets[i] = i;
>>> }
>>> return createInterleavedRaster(dataType, w, h,
>> w*bands, bands,
>>> bandOffsets, location);
>>> }
>>>
>>>
>>> This is called from CLibImageWriter.getContiguousData():288.
>>> The band offsets are automatically set to [0,1,2].
>>>
>>> The result appears to be that the sample model of the
>> produced tile is
>>> not the same as the sample model of the input image (which
>> in my case
>>> has band offsets [2,1,0]. This corresponds to the problem
>> I'm seeing,
>>> which is that the resulting image has the bands in the wrong order.
>>>
>>> So... how can I work around this? I really want to be able
>> to write my
>>> code so that it will work either with the core JPEG writer
>> or the CLib
>>> one.
>>>
>>> Mike
>>>
>>>> -----Original Message-----
>>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>>>> Sent: Friday, February 02, 2007 11:50 AM
>>>> To: interest@jai-imageio.dev.java.net
>>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
>>>> band indices
>>>>
>>>> Mike,
>>>>
>>>> So I assume that the Java implementation delivers what you
>> expect but
>>>> the CLib one does not?
>>>>
>>>> Brian
>>>>
>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>>>
>>>>> I'm playing around with writing a 3-band JPEG from a 4-band image.
>>>>> I've never had any problem with this before.
>>>>>
>>>>> Among a few other operators, I'm doing a band select with
>>>> bands 2,1,0
>>>>> to produce an RGB image from BGR bands in the 4-band file. When I
>>>>> write the resulting image to a JPEG file, I get different results
>>>>> using the J2SE writer than what I see from the CLib writer. (I
>>>>> discovered this originally because I didn't have the native clib
>>>>> library available at some point.)
>>>>>
>>>>> It looks like the CLib writer is ignoring the band indices in the
>>>>> SampleModel that were modified by the band select operator.
>>>> As I said,
>>>>> I've never had this problem before.
>>>>>
>>>>> Has anyone seen this before? I could come up with a test
>>>> case but I'm
>>>>> working toward a deadline right now.
>>>>>
>>>>> The operator chain is:
>>>>>
>>>>> bandselect -> scale -> LUT -> format -> border
>>>>>
>>>>>
>>>>>
>>>>> Mike
>>>>>
>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>> For additional commands, e-mail:
>>>>> interest-help@jai-imageio.dev.java.net
>>>>>
>>>>>
>>>>
>>>> ----------------
>>>> Brian Burkhalter
>>>> Java Media, Imaging, and Graphics
>>>> Sun Microsystems, Inc.
>>>>
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> This email message is for the sole use of the intended
>>>> recipient(s) and may contain confidential and privileged
>> information.
>>>> Any unauthorized review, use, disclosure or distribution is
>>>> prohibited.
>>>> If you are not the intended recipient, please contact the
>> sender by
>>>> reply email and destroy all copies of the original message.
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>>
>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>>> For additional commands, e-mail:
>>>> interest-help@jai-imageio.dev.java.net
>>>>
>>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>> For additional commands, e-mail:
>>> interest-help@jai-imageio.dev.java.net
>>>
>>>
>>
>> ----------------
>> Brian Burkhalter
>> Java Media, Imaging, and Graphics
>> Sun Microsystems, Inc.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> This email message is for the sole use of the intended
>> recipient(s) and may contain confidential and privileged
>> information. Any unauthorized review, use, disclosure or
>> distribution is prohibited.
>> If you are not the intended recipient, please contact the
>> sender by reply email and destroy all copies of the original message.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail:
>> interest-help@jai-imageio.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

Oh, don't mind my complaining. It's not like I've never had a bug in my
own code.

Did I explain the problem clearly? Did anyone have a chance to look at
the code
and see if my hunch was correct? For now, a workaround is to insert the
retiling
operator at the end of my chain, so at least that option is there. After
I discovered
that, I didn't investigate any further as to the actual cause of the
bug.

I'll file the issue. It makes me feel important. ;-)
Heck, I might even fix it sometime if I'm feeling industrious.

Mike

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 6:17 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Sorry about that. I guess an issue needs to be filed. As you
> spent so much time on it already I can do that if you like.
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > It appears the problem lies in the getContiguousData() method. line
> > 261 of my copy of CLibImageWriter.java.
> >
> > see the else clause that says in a comment "Image is tiled"?
> >
> > If I get into there (my image is tiled before writing) then
> it writes
> > the image wrong. If instead I forcibly untile the image beforehand
> > (format op with tile width/height == image width/height) then all
> > appears to work well. The problem I guess is with the way
> the raster
> > is created and populated for a tiled input.
> >
> > too bad it took me 9+ hours to figure that out...
> >
> >
> >
> > private static final Raster getContiguousData(RenderedImage im,
> > Rectangle region) {
> > if(im == null) {
> > throw new IllegalArgumentException("im == null");
> > } else if(region == null) {
> > throw new IllegalArgumentException("region == null");
> > }
> >
> > Raster raster;
> > if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
> > // Image is not tiled so just get a reference to
> the tile.
> > raster = im.getTile(im.getMinTileX(), im.getMinTileY());
> >
> > // Ensure result has requested coverage.
> > Rectangle bounds = raster.getBounds();
> > if (!bounds.equals(region)) {
> > raster = raster.createChild(region.x, region.y,
> > region.width,
> region.height,
> > region.x, region.y,
> > null);
> > }
> > } else {
> > // Image is tiled.
> >
> > // Create an interleaved raster for copying for
> 8-bit case.
> > // This ensures that for RGB data the band offsets are
> > {0,1,2}.
> > SampleModel sampleModel = im.getSampleModel();
> > WritableRaster target =
> sampleModel.getSampleSize(0) == 8 ?
> > Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
> > im.getWidth(),
> > im.getHeight(),
> >
> > sampleModel.getNumBands(),
> > new
> Point(im.getMinX(),
> >
> im.getMinY()))
> > :
> > null;
> >
> > // Copy the data.
> > raster = im.copyData(target);
> > }
> >
> > return raster;
> > }
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 1:40 PM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Actually I am surprised that getContiguousData() is even being
> >> called. I would think that the "scale" operation would create a
> >> SampleModel which is not a subset SampleModel but had band offsets
> >> {2,1,0}. This order should be able to be handled by the CLib JPEG
> >> writer without reformatting.
> >>
> >> Does anything different happen if you create a TYPE_3BYTE_BGR
> >> BufferedImage just after BandSelect and write the 3-band
> data into it?
> >>
> >> Are you using 8-bit data?
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> OK the problem appears to be here. The following code is in
> >> Raster at
> >>> line 186:
> >>>
> >>>
> >>> public static WritableRaster createInterleavedRaster(int
> >> dataType,
> >>> int
> >> w, int h,
> >>> int bands,
> >>> Point
> >>> location) {
> >>> int[] bandOffsets = new int[bands];
> >>> for (int i = 0; i < bands; i++) {
> >>> bandOffsets[i] = i;
> >>> }
> >>> return createInterleavedRaster(dataType, w, h,
> >> w*bands, bands,
> >>> bandOffsets, location);
> >>> }
> >>>
> >>>
> >>> This is called from CLibImageWriter.getContiguousData():288.
> >>> The band offsets are automatically set to [0,1,2].
> >>>
> >>> The result appears to be that the sample model of the
> >> produced tile is
> >>> not the same as the sample model of the input image (which
> >> in my case
> >>> has band offsets [2,1,0]. This corresponds to the problem
> >> I'm seeing,
> >>> which is that the resulting image has the bands in the
> wrong order.
> >>>
> >>> So... how can I work around this? I really want to be able
> >> to write my
> >>> code so that it will work either with the core JPEG writer
> >> or the CLib
> >>> one.
> >>>
> >>> Mike
> >>>
> >>>> -----Original Message-----
> >>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >>>> Sent: Friday, February 02, 2007 11:50 AM
> >>>> To: interest@jai-imageio.dev.java.net
> >>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
> to honor
> >>>> band indices
> >>>>
> >>>> Mike,
> >>>>
> >>>> So I assume that the Java implementation delivers what you
> >> expect but
> >>>> the CLib one does not?
> >>>>
> >>>> Brian
> >>>>
> >>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>>>
> >>>>> I'm playing around with writing a 3-band JPEG from a
> 4-band image.
> >>>>> I've never had any problem with this before.
> >>>>>
> >>>>> Among a few other operators, I'm doing a band select with
> >>>> bands 2,1,0
> >>>>> to produce an RGB image from BGR bands in the 4-band
> file. When I
> >>>>> write the resulting image to a JPEG file, I get
> different results
> >>>>> using the J2SE writer than what I see from the CLib writer. (I
> >>>>> discovered this originally because I didn't have the
> native clib
> >>>>> library available at some point.)
> >>>>>
> >>>>> It looks like the CLib writer is ignoring the band
> indices in the
> >>>>> SampleModel that were modified by the band select operator.
> >>>> As I said,
> >>>>> I've never had this problem before.
> >>>>>
> >>>>> Has anyone seen this before? I could come up with a test
> >>>> case but I'm
> >>>>> working toward a deadline right now.
> >>>>>
> >>>>> The operator chain is:
> >>>>>
> >>>>> bandselect -> scale -> LUT -> format -> border
> >>>>>
> >>>>>
> >>>>>
> >>>>> Mike
> >>>>>
> >>>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail:
> >>>> interest-unsubscribe@jai-imageio.dev.java.net
> >>>>> For additional commands, e-mail:
> >>>>> interest-help@jai-imageio.dev.java.net
> >>>>>
> >>>>>
> >>>>
> >>>> ----------------
> >>>> Brian Burkhalter
> >>>> Java Media, Imaging, and Graphics
> >>>> Sun Microsystems, Inc.
> >>>>
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>> This email message is for the sole use of the intended
> >>>> recipient(s) and may contain confidential and privileged
> >> information.
> >>>> Any unauthorized review, use, disclosure or distribution is
> >>>> prohibited.
> >>>> If you are not the intended recipient, please contact the
> >> sender by
> >>>> reply email and destroy all copies of the original message.
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>>> For additional commands, e-mail:
> >>>> interest-help@jai-imageio.dev.java.net
> >>>>
> >>>>
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> information.
> >> Any unauthorized review, use, disclosure or distribution is
> >> prohibited.
> >> If you are not the intended recipient, please contact the
> sender by
> >> reply email and destroy all copies of the original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

The explanation is clear and I think the fix is probably simple: at line 289
of CLibImageWriter.java I think the creatInterleavedRaster() version used
needs to be changed to this one:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/Raster.html#createInterleavedRaster(int,%20int,%20int,%20int,%20int,%20int[],%20java.awt.Point)

with scanlineStride = width*numBands, pixelStride = numBands, and bandOffsets
set to match those of the source.

On Mon, 5 Feb 2007, Nidel, Mike wrote:

> Oh, don't mind my complaining. It's not like I've never had a bug in my
> own code.
>
> Did I explain the problem clearly? Did anyone have a chance to look at
> the code
> and see if my hunch was correct? For now, a workaround is to insert the
> retiling
> operator at the end of my chain, so at least that option is there. After
> I discovered
> that, I didn't investigate any further as to the actual cause of the
> bug.
>
> I'll file the issue. It makes me feel important. ;-)
> Heck, I might even fix it sometime if I'm feeling industrious.
>
> Mike
>
>> -----Original Message-----
>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>> Sent: Friday, February 02, 2007 6:17 PM
>> To: interest@jai-imageio.dev.java.net
>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
>> honor band indices
>>
>> Sorry about that. I guess an issue needs to be filed. As you
>> spent so much time on it already I can do that if you like.
>>
>> Brian
>>
>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>
>>> It appears the problem lies in the getContiguousData() method. line
>>> 261 of my copy of CLibImageWriter.java.
>>>
>>> see the else clause that says in a comment "Image is tiled"?
>>>
>>> If I get into there (my image is tiled before writing) then
>> it writes
>>> the image wrong. If instead I forcibly untile the image beforehand
>>> (format op with tile width/height == image width/height) then all
>>> appears to work well. The problem I guess is with the way
>> the raster
>>> is created and populated for a tiled input.
>>>
>>> too bad it took me 9+ hours to figure that out...
>>>
>>>
>>>
>>> private static final Raster getContiguousData(RenderedImage im,
>>> Rectangle region) {
>>> if(im == null) {
>>> throw new IllegalArgumentException("im == null");
>>> } else if(region == null) {
>>> throw new IllegalArgumentException("region == null");
>>> }
>>>
>>> Raster raster;
>>> if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
>>> // Image is not tiled so just get a reference to
>> the tile.
>>> raster = im.getTile(im.getMinTileX(), im.getMinTileY());
>>>
>>> // Ensure result has requested coverage.
>>> Rectangle bounds = raster.getBounds();
>>> if (!bounds.equals(region)) {
>>> raster = raster.createChild(region.x, region.y,
>>> region.width,
>> region.height,
>>> region.x, region.y,
>>> null);
>>> }
>>> } else {
>>> // Image is tiled.
>>>
>>> // Create an interleaved raster for copying for
>> 8-bit case.
>>> // This ensures that for RGB data the band offsets are
>>> {0,1,2}.
>>> SampleModel sampleModel = im.getSampleModel();
>>> WritableRaster target =
>> sampleModel.getSampleSize(0) == 8 ?
>>> Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
>>> im.getWidth(),
>>> im.getHeight(),
>>>
>>> sampleModel.getNumBands(),
>>> new
>> Point(im.getMinX(),
>>>
>> im.getMinY()))
>>> :
>>> null;
>>>
>>> // Copy the data.
>>> raster = im.copyData(target);
>>> }
>>>
>>> return raster;
>>> }
>>>
>>>> -----Original Message-----
>>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>>>> Sent: Friday, February 02, 2007 1:40 PM
>>>> To: interest@jai-imageio.dev.java.net
>>>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
>>>> band indices
>>>>
>>>> Actually I am surprised that getContiguousData() is even being
>>>> called. I would think that the "scale" operation would create a
>>>> SampleModel which is not a subset SampleModel but had band offsets
>>>> {2,1,0}. This order should be able to be handled by the CLib JPEG
>>>> writer without reformatting.
>>>>
>>>> Does anything different happen if you create a TYPE_3BYTE_BGR
>>>> BufferedImage just after BandSelect and write the 3-band
>> data into it?
>>>>
>>>> Are you using 8-bit data?
>>>>
>>>> Brian
>>>>
>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>>>
>>>>> OK the problem appears to be here. The following code is in
>>>> Raster at
>>>>> line 186:
>>>>>
>>>>>
>>>>> public static WritableRaster createInterleavedRaster(int
>>>> dataType,
>>>>> int
>>>> w, int h,
>>>>> int bands,
>>>>> Point
>>>>> location) {
>>>>> int[] bandOffsets = new int[bands];
>>>>> for (int i = 0; i < bands; i++) {
>>>>> bandOffsets[i] = i;
>>>>> }
>>>>> return createInterleavedRaster(dataType, w, h,
>>>> w*bands, bands,
>>>>> bandOffsets, location);
>>>>> }
>>>>>
>>>>>
>>>>> This is called from CLibImageWriter.getContiguousData():288.
>>>>> The band offsets are automatically set to [0,1,2].
>>>>>
>>>>> The result appears to be that the sample model of the
>>>> produced tile is
>>>>> not the same as the sample model of the input image (which
>>>> in my case
>>>>> has band offsets [2,1,0]. This corresponds to the problem
>>>> I'm seeing,
>>>>> which is that the resulting image has the bands in the
>> wrong order.
>>>>>
>>>>> So... how can I work around this? I really want to be able
>>>> to write my
>>>>> code so that it will work either with the core JPEG writer
>>>> or the CLib
>>>>> one.
>>>>>
>>>>> Mike
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>>>>>> Sent: Friday, February 02, 2007 11:50 AM
>>>>>> To: interest@jai-imageio.dev.java.net
>>>>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
>> to honor
>>>>>> band indices
>>>>>>
>>>>>> Mike,
>>>>>>
>>>>>> So I assume that the Java implementation delivers what you
>>>> expect but
>>>>>> the CLib one does not?
>>>>>>
>>>>>> Brian
>>>>>>
>>>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>>>>>
>>>>>>> I'm playing around with writing a 3-band JPEG from a
>> 4-band image.
>>>>>>> I've never had any problem with this before.
>>>>>>>
>>>>>>> Among a few other operators, I'm doing a band select with
>>>>>> bands 2,1,0
>>>>>>> to produce an RGB image from BGR bands in the 4-band
>> file. When I
>>>>>>> write the resulting image to a JPEG file, I get
>> different results
>>>>>>> using the J2SE writer than what I see from the CLib writer. (I
>>>>>>> discovered this originally because I didn't have the
>> native clib
>>>>>>> library available at some point.)
>>>>>>>
>>>>>>> It looks like the CLib writer is ignoring the band
>> indices in the
>>>>>>> SampleModel that were modified by the band select operator.
>>>>>> As I said,
>>>>>>> I've never had this problem before.
>>>>>>>
>>>>>>> Has anyone seen this before? I could come up with a test
>>>>>> case but I'm
>>>>>>> working toward a deadline right now.
>>>>>>>
>>>>>>> The operator chain is:
>>>>>>>
>>>>>>> bandselect -> scale -> LUT -> format -> border
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Mike
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail:
>>>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>>>> For additional commands, e-mail:
>>>>>>> interest-help@jai-imageio.dev.java.net
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ----------------
>>>>>> Brian Burkhalter
>>>>>> Java Media, Imaging, and Graphics
>>>>>> Sun Microsystems, Inc.
>>>>>>
>>>>>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>> This email message is for the sole use of the intended
>>>>>> recipient(s) and may contain confidential and privileged
>>>> information.
>>>>>> Any unauthorized review, use, disclosure or distribution is
>>>>>> prohibited.
>>>>>> If you are not the intended recipient, please contact the
>>>> sender by
>>>>>> reply email and destroy all copies of the original message.
>>>>>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
>>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail:
>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>>> For additional commands, e-mail:
>>>>>> interest-help@jai-imageio.dev.java.net
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
>>>> interest-unsubscribe@jai-imageio.dev.java.net
>>>>> For additional commands, e-mail:
>>>>> interest-help@jai-imageio.dev.java.net
>>>>>
>>>>>
>>>>
>>>> ----------------
>>>> Brian Burkhalter
>>>> Java Media, Imaging, and Graphics
>>>> Sun Microsystems, Inc.
>>>>
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> This email message is for the sole use of the intended
>>>> recipient(s) and may contain confidential and privileged
>> information.
>>>> Any unauthorized review, use, disclosure or distribution is
>>>> prohibited.
>>>> If you are not the intended recipient, please contact the
>> sender by
>>>> reply email and destroy all copies of the original message.
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>>
>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>>> For additional commands, e-mail:
>>>> interest-help@jai-imageio.dev.java.net
>>>>
>>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>> For additional commands, e-mail:
>>> interest-help@jai-imageio.dev.java.net
>>>
>>>
>>
>> ----------------
>> Brian Burkhalter
>> Java Media, Imaging, and Graphics
>> Sun Microsystems, Inc.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> This email message is for the sole use of the intended
>> recipient(s) and may contain confidential and privileged
>> information. Any unauthorized review, use, disclosure or
>> distribution is prohibited.
>> If you are not the intended recipient, please contact the
>> sender by reply email and destroy all copies of the original message.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail:
>> interest-help@jai-imageio.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

yeah I suspected there was an additional API for Raster but I hadn't
looked at it yet.
Is it easier for you to produce the fix than for me to patch it?
Otherwise I will do it
later today or tomorrow.

Adding a retile (or untile) op at the end of the chain before writing
the JPEG added
perhaps 10-15% onto the time to write the image. Not too bad, since the
total time in
most cases is ~2 seconds, but I'm curious why it would really impact at
all since the
JPEG writer would have had to cobble the tiles together anyway. If you
have any thoughts,
I'd be curious to know, but it's not important really.

Mike

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Monday, February 05, 2007 12:47 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> The explanation is clear and I think the fix is probably
> simple: at line 289 of CLibImageWriter.java I think the
> creatInterleavedRaster() version used needs to be changed to this one:
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/Raster.
> html#createInterleavedRaster(int,%20int,%20int,%20int,%20int,%
> 20int[],%20java.awt.Point)
>
> with scanlineStride = width*numBands, pixelStride = numBands,
> and bandOffsets set to match those of the source.
>
> On Mon, 5 Feb 2007, Nidel, Mike wrote:
>
> > Oh, don't mind my complaining. It's not like I've never had
> a bug in
> > my own code.
> >
> > Did I explain the problem clearly? Did anyone have a chance
> to look at
> > the code and see if my hunch was correct? For now, a
> workaround is to
> > insert the retiling operator at the end of my chain, so at
> least that
> > option is there. After I discovered that, I didn't investigate any
> > further as to the actual cause of the bug.
> >
> > I'll file the issue. It makes me feel important. ;-) Heck, I might
> > even fix it sometime if I'm feeling industrious.
> >
> > Mike
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 6:17 PM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Sorry about that. I guess an issue needs to be filed. As
> you spent so
> >> much time on it already I can do that if you like.
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> It appears the problem lies in the getContiguousData()
> method. line
> >>> 261 of my copy of CLibImageWriter.java.
> >>>
> >>> see the else clause that says in a comment "Image is tiled"?
> >>>
> >>> If I get into there (my image is tiled before writing) then
> >> it writes
> >>> the image wrong. If instead I forcibly untile the image
> beforehand
> >>> (format op with tile width/height == image width/height) then all
> >>> appears to work well. The problem I guess is with the way
> >> the raster
> >>> is created and populated for a tiled input.
> >>>
> >>> too bad it took me 9+ hours to figure that out...
> >>>
> >>>
> >>>
> >>> private static final Raster getContiguousData(RenderedImage im,
> >>>
> Rectangle region) {
> >>> if(im == null) {
> >>> throw new IllegalArgumentException("im == null");
> >>> } else if(region == null) {
> >>> throw new IllegalArgumentException("region == null");
> >>> }
> >>>
> >>> Raster raster;
> >>> if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
> >>> // Image is not tiled so just get a reference to
> >> the tile.
> >>> raster = im.getTile(im.getMinTileX(),
> im.getMinTileY());
> >>>
> >>> // Ensure result has requested coverage.
> >>> Rectangle bounds = raster.getBounds();
> >>> if (!bounds.equals(region)) {
> >>> raster = raster.createChild(region.x, region.y,
> >>> region.width,
> >> region.height,
> >>> region.x, region.y,
> >>> null);
> >>> }
> >>> } else {
> >>> // Image is tiled.
> >>>
> >>> // Create an interleaved raster for copying for
> >> 8-bit case.
> >>> // This ensures that for RGB data the band offsets are
> >>> {0,1,2}.
> >>> SampleModel sampleModel = im.getSampleModel();
> >>> WritableRaster target =
> >> sampleModel.getSampleSize(0) == 8 ?
> >>>
> Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
> >>> im.getWidth(),
> >>> im.getHeight(),
> >>>
> >>> sampleModel.getNumBands(),
> >>> new
> >> Point(im.getMinX(),
> >>>
> >> im.getMinY()))
> >>> :
> >>> null;
> >>>
> >>> // Copy the data.
> >>> raster = im.copyData(target);
> >>> }
> >>>
> >>> return raster;
> >>> }
> >>>
> >>>> -----Original Message-----
> >>>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >>>> Sent: Friday, February 02, 2007 1:40 PM
> >>>> To: interest@jai-imageio.dev.java.net
> >>>> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
> to honor
> >>>> band indices
> >>>>
> >>>> Actually I am surprised that getContiguousData() is even being
> >>>> called. I would think that the "scale" operation would create a
> >>>> SampleModel which is not a subset SampleModel but had
> band offsets
> >>>> {2,1,0}. This order should be able to be handled by the
> CLib JPEG
> >>>> writer without reformatting.
> >>>>
> >>>> Does anything different happen if you create a TYPE_3BYTE_BGR
> >>>> BufferedImage just after BandSelect and write the 3-band
> >> data into it?
> >>>>
> >>>> Are you using 8-bit data?
> >>>>
> >>>> Brian
> >>>>
> >>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>>>
> >>>>> OK the problem appears to be here. The following code is in
> >>>> Raster at
> >>>>> line 186:
> >>>>>
> >>>>>
> >>>>> public static WritableRaster createInterleavedRaster(int
> >>>> dataType,
> >>>>> int
> >>>> w, int h,
> >>>>>
> int bands,
> >>>>> Point
> >>>>> location) {
> >>>>> int[] bandOffsets = new int[bands];
> >>>>> for (int i = 0; i < bands; i++) {
> >>>>> bandOffsets[i] = i;
> >>>>> }
> >>>>> return createInterleavedRaster(dataType, w, h,
> >>>> w*bands, bands,
> >>>>> bandOffsets, location);
> >>>>> }
> >>>>>
> >>>>>
> >>>>> This is called from CLibImageWriter.getContiguousData():288.
> >>>>> The band offsets are automatically set to [0,1,2].
> >>>>>
> >>>>> The result appears to be that the sample model of the
> >>>> produced tile is
> >>>>> not the same as the sample model of the input image (which
> >>>> in my case
> >>>>> has band offsets [2,1,0]. This corresponds to the problem
> >>>> I'm seeing,
> >>>>> which is that the resulting image has the bands in the
> >> wrong order.
> >>>>>
> >>>>> So... how can I work around this? I really want to be able
> >>>> to write my
> >>>>> code so that it will work either with the core JPEG writer
> >>>> or the CLib
> >>>>> one.
> >>>>>
> >>>>> Mike
> >>>>>
> >>>>>> -----Original Message-----
> >>>>>> From: Brian.Burkhalter@Sun.COM
> [mailto:Brian.Burkhalter@Sun.COM]
> >>>>>> Sent: Friday, February 02, 2007 11:50 AM
> >>>>>> To: interest@jai-imageio.dev.java.net
> >>>>>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem
> >> to honor
> >>>>>> band indices
> >>>>>>
> >>>>>> Mike,
> >>>>>>
> >>>>>> So I assume that the Java implementation delivers what you
> >>>> expect but
> >>>>>> the CLib one does not?
> >>>>>>
> >>>>>> Brian
> >>>>>>
> >>>>>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>>>>>
> >>>>>>> I'm playing around with writing a 3-band JPEG from a
> >> 4-band image.
> >>>>>>> I've never had any problem with this before.
> >>>>>>>
> >>>>>>> Among a few other operators, I'm doing a band select with
> >>>>>> bands 2,1,0
> >>>>>>> to produce an RGB image from BGR bands in the 4-band
> >> file. When I
> >>>>>>> write the resulting image to a JPEG file, I get
> >> different results
> >>>>>>> using the J2SE writer than what I see from the CLib
> writer. (I
> >>>>>>> discovered this originally because I didn't have the
> >> native clib
> >>>>>>> library available at some point.)
> >>>>>>>
> >>>>>>> It looks like the CLib writer is ignoring the band
> >> indices in the
> >>>>>>> SampleModel that were modified by the band select operator.
> >>>>>> As I said,
> >>>>>>> I've never had this problem before.
> >>>>>>>
> >>>>>>> Has anyone seen this before? I could come up with a test
> >>>>>> case but I'm
> >>>>>>> working toward a deadline right now.
> >>>>>>>
> >>>>>>> The operator chain is:
> >>>>>>>
> >>>>>>> bandselect -> scale -> LUT -> format -> border
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> Mike
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail:
> >>>>>> interest-unsubscribe@jai-imageio.dev.java.net
> >>>>>>> For additional commands, e-mail:
> >>>>>>> interest-help@jai-imageio.dev.java.net
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>> ----------------
> >>>>>> Brian Burkhalter
> >>>>>> Java Media, Imaging, and Graphics Sun Microsystems, Inc.
> >>>>>>
> >>>>>>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>>>> This email message is for the sole use of the intended
> >>>>>> recipient(s) and may contain confidential and privileged
> >>>> information.
> >>>>>> Any unauthorized review, use, disclosure or distribution is
> >>>>>> prohibited.
> >>>>>> If you are not the intended recipient, please contact the
> >>>> sender by
> >>>>>> reply email and destroy all copies of the original message.
> >>>>>>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>>>>
> >>>>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail:
> >>>> interest-unsubscribe@jai-imageio.dev.java.net
> >>>>>> For additional commands, e-mail:
> >>>>>> interest-help@jai-imageio.dev.java.net
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail:
> >>>> interest-unsubscribe@jai-imageio.dev.java.net
> >>>>> For additional commands, e-mail:
> >>>>> interest-help@jai-imageio.dev.java.net
> >>>>>
> >>>>>
> >>>>
> >>>> ----------------
> >>>> Brian Burkhalter
> >>>> Java Media, Imaging, and Graphics
> >>>> Sun Microsystems, Inc.
> >>>>
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>> This email message is for the sole use of the intended
> >>>> recipient(s) and may contain confidential and privileged
> >> information.
> >>>> Any unauthorized review, use, disclosure or distribution is
> >>>> prohibited.
> >>>> If you are not the intended recipient, please contact the
> >> sender by
> >>>> reply email and destroy all copies of the original message.
> >>>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>>>
> >>>>
> >>
> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>>> For additional commands, e-mail:
> >>>> interest-help@jai-imageio.dev.java.net
> >>>>
> >>>>
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> >> information. Any unauthorized review, use, disclosure or
> >> distribution is prohibited.
> >> If you are not the intended recipient, please contact the
> >> sender by reply email and destroy all copies of the
> original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

On Mon, 5 Feb 2007, Nidel, Mike wrote:

> yeah I suspected there was an additional API for Raster but I hadn't
> looked at it yet.
> Is it easier for you to produce the fix than for me to patch it?
> Otherwise I will do it
> later today or tomorrow.

I don't know about producing it but testing it would be easier for you as you
already have the test case in hand. Let me look at it again ...

> Adding a retile (or untile) op at the end of the chain before writing
> the JPEG added
> perhaps 10-15% onto the time to write the image. Not too bad, since the
> total time in
> most cases is ~2 seconds, but I'm curious why it would really impact at
> all since the
> JPEG writer would have had to cobble the tiles together anyway. If you
> have any thoughts,
> I'd be curious to know, but it's not important really.

That sounds strange. It's not readily apparent why it would add time other
than if there were something associated with having an additional op. Perhaps
this caused so cache issues or recomputation or something?

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

No luck so far on the buffered image approach.

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 1:40 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Actually I am surprised that getContiguousData() is even
> being called. I would think that the "scale" operation would
> create a SampleModel which is not a subset SampleModel but
> had band offsets {2,1,0}. This order should be able to be
> handled by the CLib JPEG writer without reformatting.
>
> Does anything different happen if you create a TYPE_3BYTE_BGR
> BufferedImage just after BandSelect and write the 3-band data into it?
>
> Are you using 8-bit data?
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > OK the problem appears to be here. The following code is in
> Raster at
> > line 186:
> >
> >
> > public static WritableRaster createInterleavedRaster(int
> dataType,
> > int
> w, int h,
> > int bands,
> > Point
> > location) {
> > int[] bandOffsets = new int[bands];
> > for (int i = 0; i < bands; i++) {
> > bandOffsets[i] = i;
> > }
> > return createInterleavedRaster(dataType, w, h,
> w*bands, bands,
> > bandOffsets, location);
> > }
> >
> >
> > This is called from CLibImageWriter.getContiguousData():288.
> > The band offsets are automatically set to [0,1,2].
> >
> > The result appears to be that the sample model of the
> produced tile is
> > not the same as the sample model of the input image (which
> in my case
> > has band offsets [2,1,0]. This corresponds to the problem
> I'm seeing,
> > which is that the resulting image has the bands in the wrong order.
> >
> > So... how can I work around this? I really want to be able
> to write my
> > code so that it will work either with the core JPEG writer
> or the CLib
> > one.
> >
> > Mike
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 11:50 AM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Mike,
> >>
> >> So I assume that the Java implementation delivers what you
> expect but
> >> the CLib one does not?
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> I'm playing around with writing a 3-band JPEG from a 4-band image.
> >>> I've never had any problem with this before.
> >>>
> >>> Among a few other operators, I'm doing a band select with
> >> bands 2,1,0
> >>> to produce an RGB image from BGR bands in the 4-band file. When I
> >>> write the resulting image to a JPEG file, I get different results
> >>> using the J2SE writer than what I see from the CLib writer. (I
> >>> discovered this originally because I didn't have the native clib
> >>> library available at some point.)
> >>>
> >>> It looks like the CLib writer is ignoring the band indices in the
> >>> SampleModel that were modified by the band select operator.
> >> As I said,
> >>> I've never had this problem before.
> >>>
> >>> Has anyone seen this before? I could come up with a test
> >> case but I'm
> >>> working toward a deadline right now.
> >>>
> >>> The operator chain is:
> >>>
> >>> bandselect -> scale -> LUT -> format -> border
> >>>
> >>>
> >>>
> >>> Mike
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> information.
> >> Any unauthorized review, use, disclosure or distribution is
> >> prohibited.
> >> If you are not the intended recipient, please contact the
> sender by
> >> reply email and destroy all copies of the original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Nidel, Mike

OK the problem appears to be here. The following code is in Raster at
line 186:

public static WritableRaster createInterleavedRaster(int dataType,
int w, int h,
int bands,
Point location)
{
int[] bandOffsets = new int[bands];
for (int i = 0; i < bands; i++) {
bandOffsets[i] = i;
}
return createInterleavedRaster(dataType, w, h, w*bands, bands,
bandOffsets, location);
}

This is called from CLibImageWriter.getContiguousData():288.
The band offsets are automatically set to [0,1,2].

The result appears to be that the sample model of the produced tile
is not the same as the sample model of the input image (which in my
case has band offsets [2,1,0]. This corresponds to the problem I'm
seeing, which is that the resulting image has the bands in the wrong
order.

So... how can I work around this? I really want to be able to write my
code so that it will work either with the core JPEG writer or the CLib
one.

Mike

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 11:50 AM
> To: interest@jai-imageio.dev.java.net
> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Mike,
>
> So I assume that the Java implementation delivers what you
> expect but the CLib one does not?
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > I'm playing around with writing a 3-band JPEG from a 4-band image.
> > I've never had any problem with this before.
> >
> > Among a few other operators, I'm doing a band select with
> bands 2,1,0
> > to produce an RGB image from BGR bands in the 4-band file. When I
> > write the resulting image to a JPEG file, I get different results
> > using the J2SE writer than what I see from the CLib writer. (I
> > discovered this originally because I didn't have the native clib
> > library available at some point.)
> >
> > It looks like the CLib writer is ignoring the band indices in the
> > SampleModel that were modified by the band select operator.
> As I said,
> > I've never had this problem before.
> >
> > Has anyone seen this before? I could come up with a test
> case but I'm
> > working toward a deadline right now.
> >
> > The operator chain is:
> >
> > bandselect -> scale -> LUT -> format -> border
> >
> >
> >
> > Mike
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

Actually I am surprised that getContiguousData() is even being called. I would
think that the "scale" operation would create a SampleModel which is not a
subset SampleModel but had band offsets {2,1,0}. This order should be able to
be handled by the CLib JPEG writer without reformatting.

Does anything different happen if you create a TYPE_3BYTE_BGR BufferedImage
just after BandSelect and write the 3-band data into it?

Are you using 8-bit data?

Brian

On Fri, 2 Feb 2007, Nidel, Mike wrote:

> OK the problem appears to be here. The following code is in Raster at
> line 186:
>
>
> public static WritableRaster createInterleavedRaster(int dataType,
> int w, int h,
> int bands,
> Point location)
> {
> int[] bandOffsets = new int[bands];
> for (int i = 0; i < bands; i++) {
> bandOffsets[i] = i;
> }
> return createInterleavedRaster(dataType, w, h, w*bands, bands,
> bandOffsets, location);
> }
>
>
> This is called from CLibImageWriter.getContiguousData():288.
> The band offsets are automatically set to [0,1,2].
>
> The result appears to be that the sample model of the produced tile
> is not the same as the sample model of the input image (which in my
> case has band offsets [2,1,0]. This corresponds to the problem I'm
> seeing, which is that the resulting image has the bands in the wrong
> order.
>
> So... how can I work around this? I really want to be able to write my
> code so that it will work either with the core JPEG writer or the CLib
> one.
>
> Mike
>
>> -----Original Message-----
>> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
>> Sent: Friday, February 02, 2007 11:50 AM
>> To: interest@jai-imageio.dev.java.net
>> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
>> honor band indices
>>
>> Mike,
>>
>> So I assume that the Java implementation delivers what you
>> expect but the CLib one does not?
>>
>> Brian
>>
>> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>>
>>> I'm playing around with writing a 3-band JPEG from a 4-band image.
>>> I've never had any problem with this before.
>>>
>>> Among a few other operators, I'm doing a band select with
>> bands 2,1,0
>>> to produce an RGB image from BGR bands in the 4-band file. When I
>>> write the resulting image to a JPEG file, I get different results
>>> using the J2SE writer than what I see from the CLib writer. (I
>>> discovered this originally because I didn't have the native clib
>>> library available at some point.)
>>>
>>> It looks like the CLib writer is ignoring the band indices in the
>>> SampleModel that were modified by the band select operator.
>> As I said,
>>> I've never had this problem before.
>>>
>>> Has anyone seen this before? I could come up with a test
>> case but I'm
>>> working toward a deadline right now.
>>>
>>> The operator chain is:
>>>
>>> bandselect -> scale -> LUT -> format -> border
>>>
>>>
>>>
>>> Mike
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> interest-unsubscribe@jai-imageio.dev.java.net
>>> For additional commands, e-mail:
>>> interest-help@jai-imageio.dev.java.net
>>>
>>>
>>
>> ----------------
>> Brian Burkhalter
>> Java Media, Imaging, and Graphics
>> Sun Microsystems, Inc.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> This email message is for the sole use of the intended
>> recipient(s) and may contain confidential and privileged
>> information. Any unauthorized review, use, disclosure or
>> distribution is prohibited.
>> If you are not the intended recipient, please contact the
>> sender by reply email and destroy all copies of the original message.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail:
>> interest-help@jai-imageio.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

your first paragraph seems full of true assertions; about the
scale operator, about the band offsets, and about the CLib handling
it without reformatting. but the non-reformatting path still calls
getContiguousData() apparently.

It's definitely detecting that the image is BGR correctly though.
that happens in CLibImageWriter.getMediaLibDataType().

Yes, it's 8-bit data, at least after the LUT is performed. the
LUT is a dynamic range adjustment mapping. the result is an 8-bit image.
i wonder if something is wrong with the color model...? i don't know.

i'll try the BufferedImage thing.

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 1:40 PM
> To: interest@jai-imageio.dev.java.net
> Subject: RE: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Actually I am surprised that getContiguousData() is even
> being called. I would think that the "scale" operation would
> create a SampleModel which is not a subset SampleModel but
> had band offsets {2,1,0}. This order should be able to be
> handled by the CLib JPEG writer without reformatting.
>
> Does anything different happen if you create a TYPE_3BYTE_BGR
> BufferedImage just after BandSelect and write the 3-band data into it?
>
> Are you using 8-bit data?
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > OK the problem appears to be here. The following code is in
> Raster at
> > line 186:
> >
> >
> > public static WritableRaster createInterleavedRaster(int
> dataType,
> > int
> w, int h,
> > int bands,
> > Point
> > location) {
> > int[] bandOffsets = new int[bands];
> > for (int i = 0; i < bands; i++) {
> > bandOffsets[i] = i;
> > }
> > return createInterleavedRaster(dataType, w, h,
> w*bands, bands,
> > bandOffsets, location);
> > }
> >
> >
> > This is called from CLibImageWriter.getContiguousData():288.
> > The band offsets are automatically set to [0,1,2].
> >
> > The result appears to be that the sample model of the
> produced tile is
> > not the same as the sample model of the input image (which
> in my case
> > has band offsets [2,1,0]. This corresponds to the problem
> I'm seeing,
> > which is that the resulting image has the bands in the wrong order.
> >
> > So... how can I work around this? I really want to be able
> to write my
> > code so that it will work either with the core JPEG writer
> or the CLib
> > one.
> >
> > Mike
> >
> >> -----Original Message-----
> >> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> >> Sent: Friday, February 02, 2007 11:50 AM
> >> To: interest@jai-imageio.dev.java.net
> >> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to honor
> >> band indices
> >>
> >> Mike,
> >>
> >> So I assume that the Java implementation delivers what you
> expect but
> >> the CLib one does not?
> >>
> >> Brian
> >>
> >> On Fri, 2 Feb 2007, Nidel, Mike wrote:
> >>
> >>> I'm playing around with writing a 3-band JPEG from a 4-band image.
> >>> I've never had any problem with this before.
> >>>
> >>> Among a few other operators, I'm doing a band select with
> >> bands 2,1,0
> >>> to produce an RGB image from BGR bands in the 4-band file. When I
> >>> write the resulting image to a JPEG file, I get different results
> >>> using the J2SE writer than what I see from the CLib writer. (I
> >>> discovered this originally because I didn't have the native clib
> >>> library available at some point.)
> >>>
> >>> It looks like the CLib writer is ignoring the band indices in the
> >>> SampleModel that were modified by the band select operator.
> >> As I said,
> >>> I've never had this problem before.
> >>>
> >>> Has anyone seen this before? I could come up with a test
> >> case but I'm
> >>> working toward a deadline right now.
> >>>
> >>> The operator chain is:
> >>>
> >>> bandselect -> scale -> LUT -> format -> border
> >>>
> >>>
> >>>
> >>> Mike
> >>>
> >>>
> >>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> interest-unsubscribe@jai-imageio.dev.java.net
> >>> For additional commands, e-mail:
> >>> interest-help@jai-imageio.dev.java.net
> >>>
> >>>
> >>
> >> ----------------
> >> Brian Burkhalter
> >> Java Media, Imaging, and Graphics
> >> Sun Microsystems, Inc.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged
> information.
> >> Any unauthorized review, use, disclosure or distribution is
> >> prohibited.
> >> If you are not the intended recipient, please contact the
> sender by
> >> reply email and destroy all copies of the original message.
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> >> For additional commands, e-mail:
> >> interest-help@jai-imageio.dev.java.net
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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

Brian Burkhalter

Mike,

So I assume that the Java implementation delivers what you expect but the CLib
one does not?

Brian

On Fri, 2 Feb 2007, Nidel, Mike wrote:

> I'm playing around with writing a 3-band JPEG from a 4-band image. I've
> never had any problem with this before.
>
> Among a few other operators, I'm doing a band select with bands 2,1,0 to
> produce an RGB image from BGR bands in the 4-band file. When I write the
> resulting image to a JPEG file, I get different results using the J2SE
> writer than what I see from the CLib writer. (I discovered this
> originally because I didn't have the native clib library available at
> some point.)
>
> It looks like the CLib writer is ignoring the band indices in the
> SampleModel that were modified by the band select operator. As I said,
> I've never had this problem before.
>
> Has anyone seen this before? I could come up with a test case but I'm
> working toward a deadline right now.
>
> The operator chain is:
>
> bandselect -> scale -> LUT -> format -> border
>
>
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Nidel, Mike

that's exactly right. i'm playing with it as we speak (write).

> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Friday, February 02, 2007 11:50 AM
> To: interest@jai-imageio.dev.java.net
> Subject: Re: [JAI-IMAGEIO] CLib JPEG writer doesn't seem to
> honor band indices
>
> Mike,
>
> So I assume that the Java implementation delivers what you
> expect but the CLib one does not?
>
> Brian
>
> On Fri, 2 Feb 2007, Nidel, Mike wrote:
>
> > I'm playing around with writing a 3-band JPEG from a 4-band image.
> > I've never had any problem with this before.
> >
> > Among a few other operators, I'm doing a band select with
> bands 2,1,0
> > to produce an RGB image from BGR bands in the 4-band file. When I
> > write the resulting image to a JPEG file, I get different results
> > using the J2SE writer than what I see from the CLib writer. (I
> > discovered this originally because I didn't have the native clib
> > library available at some point.)
> >
> > It looks like the CLib writer is ignoring the band indices in the
> > SampleModel that were modified by the band select operator.
> As I said,
> > I've never had this problem before.
> >
> > Has anyone seen this before? I could come up with a test
> case but I'm
> > working toward a deadline right now.
> >
> > The operator chain is:
> >
> > bandselect -> scale -> LUT -> format -> border
> >
> >
> >
> > Mike
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Java Media, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended
> recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, disclosure or
> distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

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