Skip to main content

[JAI-IMAGEIO] Problems Merging JPG to TIFF and backward

3 replies [Last post]
Anonymous

Hi,

I want to merge two JPG to a TIFF image. Something
fails there. The TIFF image is created and the first
page is OK. However the second page is not okay in
IfranView. I use daily builds.

If I do the way back extracting the second page of
the created image fails reading with:

javax.imageio.IIOException: Missing required strip or tile offsets field.
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getTileOrStripOffset(TIFFImageReader.java:454)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1127)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1417)

The code classes are appended as files. Any JPG file can be
used maybe twice as input for merge.

Kind regards,
--
Marco Jacob
Prisma GmbH, Germany
[ImageIOTools.java]
[Imaging.java]
[ImagingException.java]
---------------------------------------------------------------------
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.
mjacob@union06.de

Today I got it:

If your write a sequence of images into tiff you don't
need only to flush the ImageOutputStream but also
call close!
If only flush() is called the last image is not written.
The call to close() will write the last image.

I would like a change to the behaviour this way:

* imageOutputStream.flush() should write all
* imageOutputStream.close() should only close the stream
not write anything
* writer.dispose() should flush and close the underlying
stream (if not done) so I don't need a reference to
ImageOutputStream

Is there a reason why close() writes the last bytes of the tiff?

Kind regards,
--
Marco Jacob
Prisma GmbH, Germany

>I found out that always the last page is not okay.
>As I write 3 times the same JPG into the tiff file
>the first two pages are OK.
>
>What am I doing wrong?
>The code sequence for writing:
>
> writer = ImageIOTools.getImageWriterByMime(outMime, out);
> writer.prepareWriteSequence(null);
> IIOImage image;
> for (int i=0; i > reader = ImageIOTools.getImageReaderByMime(inMime[i], in[i]);
> if (reader==null) {
> throw new ImagingException("Format "+inMime[i]+" not supported for
>input");
> }
> image = reader.readAll(0, reader.getDefaultReadParam());
> param = writer.getDefaultWriteParam();
> writer.writeToSequence(image, param);
> }
> writer.endWriteSequence();
> ((ImageOutputStream) writer.getOutput()).flush();
>
>
>Kind regards,
>--
>Marco Jacob
>Prisma GmbH, Germany
>
>
>>I want to merge two JPG to a TIFF image. Something
>>fails there. The TIFF image is created and the first
>>page is OK. However the second page is not okay in
>>IfranView. I use daily builds.
>>
>>If I do the way back extracting the second page of
>>the created image fails reading with:
>>
>>javax.imageio.IIOException: Missing required strip or tile offsets field.
>> at
>>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getTileOrStripOffset(TI
>F
>>FImageReader.java:454)
>> at
>>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageRea
>d
>>er.java:1127)
>> at
>>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.ja
>v
>>a:1417)

---------------------------------------------------------------------
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 Tue, 3 Apr 2007, mjacob@union06.de wrote:

> Today I got it:
>
> If your write a sequence of images into tiff you don't
> need only to flush the ImageOutputStream but also
> call close!
> If only flush() is called the last image is not written.
> The call to close() will write the last image.

I think this probably has to do with the nature of the streams used as opposed
to the TIFF writer. As you appear to be passing in an OutputStream for example
instead of a file, the ImageOutputStream eventually used merely wraps the
OutputStream. I think if you know you are going to a File eventually then it
would be preferable to use a File or RandomAccessFile to create the
ImageOutputStream.

> I would like a change to the behaviour this way:
>
> * imageOutputStream.flush() should write all
> * imageOutputStream.close() should only close the stream
> not write anything
> * writer.dispose() should flush and close the underlying
> stream (if not done) so I don't need a reference to
> ImageOutputStream

These are javax.imageio specification issues which would best be filed at
bugs.sun.com under category "JDK" and subcategory "imageio".

> Is there a reason why close() writes the last bytes of the tiff?

I don't know. I suppose the logic would be that it ensures no data loss.

Brian

> Kind regards,
> --
> Marco Jacob
> Prisma GmbH, Germany
>
>
>> I found out that always the last page is not okay.
>> As I write 3 times the same JPG into the tiff file
>> the first two pages are OK.
>>
>> What am I doing wrong?
>> The code sequence for writing:
>>
>> writer = ImageIOTools.getImageWriterByMime(outMime, out);
>> writer.prepareWriteSequence(null);
>> IIOImage image;
>> for (int i=0; i >> reader = ImageIOTools.getImageReaderByMime(inMime[i], in[i]);
>> if (reader==null) {
>> throw new ImagingException("Format "+inMime[i]+" not supported for
>> input");
>> }
>> image = reader.readAll(0, reader.getDefaultReadParam());
>> param = writer.getDefaultWriteParam();
>> writer.writeToSequence(image, param);
>> }
>> writer.endWriteSequence();
>> ((ImageOutputStream) writer.getOutput()).flush();
>>
>>
>> Kind regards,
>> --
>> Marco Jacob
>> Prisma GmbH, Germany
>>
>>
>>> I want to merge two JPG to a TIFF image. Something
>>> fails there. The TIFF image is created and the first
>>> page is OK. However the second page is not okay in
>>> IfranView. I use daily builds.
>>>
>>> If I do the way back extracting the second page of
>>> the created image fails reading with:
>>>
>>> javax.imageio.IIOException: Missing required strip or tile offsets field.
>>> at
>>> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getTileOrStripOffset(TI
>> F
>>> FImageReader.java:454)
>>> at
>>> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageRea
>> d
>>> er.java:1127)
>>> at
>>> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.ja
>> v
>>> a:1417)
>
> ---------------------------------------------------------------------
> 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

mjacob@union06.de

I found out that always the last page is not okay.
As I write 3 times the same JPG into the tiff file
the first two pages are OK.

What am I doing wrong?
The code sequence for writing:

writer = ImageIOTools.getImageWriterByMime(outMime, out);
writer.prepareWriteSequence(null);
IIOImage image;
for (int i=0; i reader = ImageIOTools.getImageReaderByMime(inMime[i], in[i]);
if (reader==null) {
throw new ImagingException("Format "+inMime[i]+" not supported for input");
}
image = reader.readAll(0, reader.getDefaultReadParam());
param = writer.getDefaultWriteParam();
writer.writeToSequence(image, param);
}
writer.endWriteSequence();
((ImageOutputStream) writer.getOutput()).flush();

Kind regards,
--
Marco Jacob
Prisma GmbH, Germany

>I want to merge two JPG to a TIFF image. Something
>fails there. The TIFF image is created and the first
>page is OK. However the second page is not okay in
>IfranView. I use daily builds.
>
>If I do the way back extracting the second page of
>the created image fails reading with:
>
>javax.imageio.IIOException: Missing required strip or tile offsets field.
> at
>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getTileOrStripOffset(TIF
>FImageReader.java:454)
> at
>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageRead
>er.java:1127)
> at
>com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.jav
>a:1417)

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