Skip to main content

Getting filename to codec?

2 replies [Last post]
joelsk
Offline
Joined: 2005-11-18
Points: 0

I'm implementing an ImageIO codec which is based on
an image library that, unfortunately, requires a file
name in order to open the image as opposed to supporting
using already opened files or streams.

I see that in writing the codec I can specify different
sorts of input objects (ImageInputStream, for example)
so it seems the codec can support opening the image
based on a string filename. What I don't see is how
to get JAI to send a filename across.

When I do a JAI.create( "ImageRead", filename ) it
seems that the ImageRead operation has already opened
the file and turned it into an ImageInputStream by the
time it gets to my codec. Is there a trick to getting
the data across? Or do I need to write my own JAI
operation?

joel

Reply viewing options

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

On Jun 1, 2006, at 6:28 AM, jai-imageio@javadesktop.org wrote:

> I'm implementing an ImageIO codec which is based on
> an image library that, unfortunately, requires a file
> name in order to open the image as opposed to supporting
> using already opened files or streams.
>
> I see that in writing the codec I can specify different
> sorts of input objects (ImageInputStream, for example)
> so it seems the codec can support opening the image
> based on a string filename. What I don't see is how
> to get JAI to send a filename across.
>
> When I do a JAI.create( "ImageRead", filename ) it
> seems that the ImageRead operation has already opened
> the file and turned it into an ImageInputStream by the
> time it gets to my codec. Is there a trick to getting
> the data across? Or do I need to write my own JAI
> operation?

I had a similar problem with a codec I wrote for the Canon .CRW format,
where unfortunately a single image is split into two files with two
different
extensions, and matching should be done by file name.

I registered a custom ImageInputStreamSpi, which is a factory that
can control the
way an ImageInputStream are created. In this way I instantiate a
custom ImageInputStream
which "remembers" the original file:

public class FileImageInputStream2 extends FileImageInputStream
{
private File file;

public FileImageInputStream2 (File file) throws
FileNotFoundException, IOException
{
super(file);
this.file = file;
}

public File getFile ()
{
return file;
}
}

In this way, an instance of FileImageInputStream2 is passed to your
codec and you can invoke
the getFile() method. There's something to improve, but it's actually
working.

The complete code is available for download at jrawio.dev.java.net,
look at the package
it.tidalwave.imageio.io.

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36

---------------------------------------------------------------------
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 Jun 1, 2006, at 6:28 AM, jai-imageio@javadesktop.org wrote:
>
>> I'm implementing an ImageIO codec which is based on
>> an image library that, unfortunately, requires a file
>> name in order to open the image as opposed to supporting
>> using already opened files or streams.

Unexpected side effects are certainly interesting ...

> I had a similar problem with a codec I wrote for the Canon .CRW format,
> where unfortunately a single image is split into two files with two different
> extensions, and matching should be done by file name.
>
> I registered a custom ImageInputStreamSpi, which is a factory that can
> control the
> way an ImageInputStream are created. In this way I instantiate a custom
> ImageInputStream
> which "remembers" the original file:

This is a good solution. Another one would be to register your own
RenderedImageFactory for "ImageRead".

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