Skip to main content

Jpeg2000 compressing in Linux using imageIO

5 replies [Last post]
shrieky
Offline
Joined: 2007-11-26

Hi ,

I have developed a utility to convert from any format to jp2 using JAI and ImageIO.
I am able to convert any format to jp2 and read the output file jp2 on Windows platform. The same is not true for Linux as I am able to write to Jp2.
I am using the same version of the libraries(Jai and ImageIO) for both Windows and Linux.

The code and error trace while while reading the output of linux written jp2 is below.

P.S : File written (jp2) is readable in Linux.

Any help in this regard is appreciated.

Regards
Shrieky

Code :
/***************************************************************************************************/

public class TestApp {

public TestApp() {
RenderedImage rimg = (RenderedImage) JAI.create("fileload", "/home/isduser/Data/RasterData/Leena/lena512.bmp", null);
ImageOutputStream ios = null;
try {
ios = ImageIO.createImageOutputStream(new File("/home/isduser/geo.jp2"));
ios.setByteOrder(ByteOrder.LITTLE_ENDIAN);
} catch (IOException ex) {
ex.printStackTrace();
}

Iterator writers = null;
ImageWriter writer = null;

writers = ImageIO.getImageWritersBySuffix("jp2");

writer = (ImageWriter) writers.next();

ImageWriteDescriptor.create(rimg, ios, "jp2", true, true, false, false, null, null, null, null, null, null, null, writer, null);
}

public static void main(String[] arg) {

TestApp t = new TestApp();

}
}

/****************************************************************************************************/

java.lang.RuntimeException: File is neither valid JP2 file nor valid JPEG 2000 codestream
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:696)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.(J2KReadState.java:189)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImage.(J2KRenderedImage.java:67)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.readAsRenderedImage(J2KImageReader.java:477)
at ImageFileRead.GenericImageReader.(GenericImageReader.java:141)

Caused by: java.lang.Error: File is neither valid JP2 file nor valid JPEG 2000 codestream
at jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormatReader.java:182)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:418)
... 38 more
java.lang.RuntimeException: File is neither valid JP2 file nor valid JPEG 2000 codestream
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:696)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.(J2KReadState.java:189)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImage.(J2KRenderedImage.java:67)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.readAsRenderedImage(J2KImageReader.java:477)
at I
Caused by: java.lang.Error: File is neither valid JP2 file nor valid JPEG 2000 codestream
at jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormatReader.java:182)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:418)
... 14 more

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nidel, Mike

Yes, you're right, I meant to say 'getImageWritersByFormatName()' not Readers.
Sorry for the confusion.

It appears that there is a bug in the J2KImageWriter (java-only version) that
causes your problem. Unfortunately the chances are very small that it will be
fixed.

Look for the libclib_jiio.so file -- if you installed JAI ImageIO Tools into
your JRE, this should be in the JRE somewhere. If it's not there, that's probably
the issue. You can try to force Java to find this native library in some other
path (e.g. your application classpath) by adding the following option to the
java command line, assuming that the file is in /some/dir/libclib_jiio.so:

-Djava.library.path=/some/dir

and you also need to make sure that the LD_LIBRARY_PATH environment variable
is set (this isn't ALWAYS needed but it is safest to just set it):

export LD_LIBRARY_PATH=/some/dir

There is another system property that can be used to manually disable the codec
lib (native code in libclib_jiio.so). An interesting test would be to disable
the codec lib on Windows, either by renaming clib_jiio.dll, or by using the
system property to disable it:

-Dcom.sun.media.imageio.disableCodecLib=true

If you disable this codec lib on Windows and write your JP2 file, you should
see exactly the same behavior with this file that you did writing from linux.
If not... then the problem is more complex.

cheers,

Mike

> -----Original Message-----
> From: jai-interest@javadesktop.org [mailto:jai-
> interest@javadesktop.org]
> Sent: Friday, September 18, 2009 3:05 AM
> To: interest@jai.dev.java.net
> Subject: Re: RE: [JAI] Jpeg2000 compressing in Linux using imageIO
>
> Dear Mike ,
>
> Thanks for the reply.
> Below are the answers for the the questions you have asked.
>
> 1. you can write a JPEG2000 file on Windows and read it OK on both
> Windows
> and Linux (?)
>
> -----> Yes
>
> 2. you can write a JPEG2000 file on Linux but you cannot read this file
> on
> Windows (?)
>
> -----> No. The output jp2 written on Linux neither works on Windows or
> Linux.
> In other words I am not able write Jp2 properly on Linux.
>
> 3. the error messages you included are received when trying to read the
> jp2 file you wrote on Linux (?)
>
> -----> Yes.
>
> Mike , I believe the problem is towards the writer class rather the
> reader class.
>
> The output for the code which you have given :
>
> On Windows :
> -------------------------
> Reader:
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib
> Reader: com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader
>
> On Linux :
> -------------------------
> Reader: com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader
>
>
> And for the code :
>
> Iterator iter = ImageIO.getImage[b]Writers[/b]ByFormatName("jpeg2000");
> while(iter.hasNext())
> {
> System.out.println("Writer : "+iter.next().getClass().getName());
> }
>
>
> On Windows :
> -------------------------
> Writer :
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterCodecLib
> Writer : com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter
>
> On Linux :
> -------------------------
> Writer : com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter
>
>
> How can make J2KImageWriterCodecLib work on linux ?
> [Message sent by forum member 'shrieky' (srikanth1947@gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=364550
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net

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

shrieky
Offline
Joined: 2007-11-26

Hi Mike ,

I have downloaded all the imageio libraries from sun's website (and has to do some R&D to install the bin file like change "tail +235" to "tail -n+235"). I have installed that into java installed directory and it worked like Magic.

Thanks for the help Mike.

Regards,
Srikanth

Nidel, Mike

Your description is a little bit confusing. Let me see if I understand
correctly:

1. you can write a JPEG2000 file on Windows and read it OK on both Windows
and Linux (?)
2. you can write a JPEG2000 file on Linux but you cannot read this file on
Windows (?)
3. the error messages you included are received when trying to read the
jp2 file you wrote on Linux (?)

If this is true, I suspect that you are using two different JPEG2000
ImageWriter plugins. One of them uses a native library to write the file,
while the other is pure java. Can you run the following code on windows and
linux and see what is output? (Note I haven't tried this code so you may
get syntax errors.)

Iterator iter = ImageIO.getImageReadersByFormatName("jpeg2000");
while(iter.hasNext())
{
System.out.println("Reader: "+iter.next().getClass().getName());
}

//////////////////////////////////////////

If you look inside jai_imageio.jar, you'll see there are classes
J2KImageWriter and J2KImageWriterCodecLib. The output of the code
above will have either one or two lines, depending on whether the
native CodecLib binaries are available.

Let us know if this helps you.

> -----Original Message-----
> From: jai-interest@javadesktop.org [mailto:jai-
> interest@javadesktop.org]
> Sent: Thursday, September 17, 2009 6:55 AM
> To: interest@jai.dev.java.net
> Subject: [JAI] Jpeg2000 compressing in Linux using imageIO
>
> Hi ,
>
> I have developed a utility to convert from any format to jp2 using JAI
> and ImageIO.
> I am able to convert any format to jp2 and read the output file jp2 on
> Windows platform. The same is not true for Linux as I am able to write
> to Jp2.
> I am using the same version of the libraries(Jai and ImageIO) for both
> Windows and Linux.
>
> The code and error trace while while reading the output of linux
> written jp2 is below.
>
> P.S : File written (jp2) is readable in Linux.
>
> Any help in this regard is appreciated.
>
> Regards
> Shrieky
>
> Code :
> /**********************************************************************
> *****************************/
>
> public class TestApp {
>
> public TestApp() {
> RenderedImage rimg = (RenderedImage) JAI.create("fileload",
> "/home/isduser/Data/RasterData/Leena/lena512.bmp", null);
> ImageOutputStream ios = null;
> try {
> ios = ImageIO.createImageOutputStream(new
> File("/home/isduser/geo.jp2"));
> ios.setByteOrder(ByteOrder.LITTLE_ENDIAN);
> } catch (IOException ex) {
> ex.printStackTrace();
> }
>
> Iterator writers = null;
> ImageWriter writer = null;
>
> writers = ImageIO.getImageWritersBySuffix("jp2");
>
> writer = (ImageWriter) writers.next();
>
>
>
> ImageWriteDescriptor.create(rimg, ios, "jp2", true, true,
> false, false, null, null, null, null, null, null, null, writer, null);
> }
>
> public static void main(String[] arg) {
>
> TestApp t = new TestApp();
>
> }
> }
>
> /**********************************************************************
> ******************************/
>
>
>
>
> java.lang.RuntimeException: File is neither valid JP2 file nor valid
> JPEG 2000 codestream
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(
> J2KReadState.java:696)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.(J2KReadS
> tate.java:189)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImage.(J2KR
> enderedImage.java:67)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.readAsRendere
> dImage(J2KImageReader.java:477)
> at
> ImageFileRead.GenericImageReader.(GenericImageReader.java:141)
>
> Caused by: java.lang.Error: File is neither valid JP2 file nor valid
> JPEG 2000 codestream
> at
> jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormat
> Reader.java:182)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(
> J2KReadState.java:418)
> ... 38 more
> java.lang.RuntimeException: File is neither valid JP2 file nor valid
> JPEG 2000 codestream
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(
> J2KReadState.java:696)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.(J2KReadS
> tate.java:189)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImage.(J2KR
> enderedImage.java:67)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.readAsRendere
> dImage(J2KImageReader.java:477)
> at I
> Caused by: java.lang.Error: File is neither valid JP2 file nor valid
> JPEG 2000 codestream
> at
> jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormat
> Reader.java:182)
> at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(
> J2KReadState.java:418)
> ... 14 more
> [Message sent by forum member 'shrieky' (srikanth1947@gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=364396
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net

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

shrieky
Offline
Joined: 2007-11-26

Dear Mike ,

Thanks for the reply.
Below are the answers for the the questions you have asked.

1. you can write a JPEG2000 file on Windows and read it OK on both Windows
and Linux (?)

-----> Yes

2. you can write a JPEG2000 file on Linux but you cannot read this file on
Windows (?)

-----> No. The output jp2 written on Linux neither works on Windows or Linux.
In other words I am not able write Jp2 properly on Linux.

3. the error messages you included are received when trying to read the
jp2 file you wrote on Linux (?)

-----> Yes.

Mike , I believe the problem is towards the writer class rather the reader class.

The output for the code which you have given :

On Windows :
-------------------------
Reader: com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib
Reader: com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader

On Linux :
-------------------------
Reader: com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader

And for the code :

Iterator iter = ImageIO.getImage[b]Writers[/b]ByFormatName("jpeg2000");
while(iter.hasNext())
{
System.out.println("Writer : "+iter.next().getClass().getName());
}

On Windows :
-------------------------
Writer : com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterCodecLib
Writer : com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter

On Linux :
-------------------------
Writer : com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter

How can make J2KImageWriterCodecLib work on linux ?

shrieky
Offline
Joined: 2007-11-26

I forgot to mention , both J2KImageWriterCodecLib and J2KImageWriter are available with ImageIO plugins on Linux.