Friday 15 April 2011

image - Is there a equivalent of Android's BitmapFactory.Options isDecodeBounds for TIFF in Java/JAI? -


I am trying to improve the performance of my system (a Java app running in Tomcat) and now a barrier In operation, we need the dimensions of TIFF images to read and read, so we use the JSD ImageDecoder and ImageDecoder decoder = ImageCodec.createImageDecoder ("TIFF", input, The ultimate); RenderedImage r = decoder.decodeAsRenderedImage (); Int width = r.getWidth (); Int height = r.getHeight ();

By sampling data, much time is spent in createImageDecoder. My assumption (without going to ImageCodec's source code) is it possibly trying to decode input stream

Coming from Android land, I'm hoping that BitmapFactory.Options Similar to the installation of .inJustDecodeBounds = true , there is a solution similar to the direct explanation, but there is no luck finding any other library so far. (I know that hard support on Android is missing in AOP, but it is a matter of another day.)

Anybody knows this library which does this? Or is there any way to achieve the same goal of using Jai / IdiIio?

It seems that the groups of this information together in a title, so that you Can read:

  Private static dimensions getTiffDimensions (InputStream tiffFile) throws IOException {readableByteChannel channel = Channels.newChannel (tiffFile); Bytebuff buffer = Bytebuffer.Olock (12); Balrade (channel, buffer, 8); Byte endian = buffer.get (); If (endian! = Buffer.get () || (endian! = 'I' and endian! = 'M')) (new iOxation ("not a quarrel file.");} Buffer.scer (endian == ' I '? Byteorder. LittelIne: Byteorder. BigADIN; if (buffer.Tet!) = 42) {New IOXation ("No Tiff File."); } // Go to the first image directory. Note that we have already read 8 bytes. TiffFile.skip (buffer.getInt () - 8); Int width = -1; Intensity height = -1; // The first two byte fields of IFD are the number of bytes. Balrade (channel, buffer, 2); (At field count = buffer.Tet (); field count & gt; 0 & amp; amp; amp; amp; amp; amp; amp; amp; amp; & amp; (width & lt; 0 height & lt; 0); -fieldcode) {forceRead (Channel, buffer, 12); Switch (buffer.at ()) {case 0x0100: // image width width = refill (buffer); break; Case 0x0101: // image "length", height of height = reading field (buffer); break; }} Return new dimensions (width, height); } Private stationary zero force reads (readable channel channel, byte buffer buffer, int n) throws IOException {buffer. (0); Buffer.limit (n); While (buffer HSrmaning ()) {channel.read (buffer); } Buffer. Flip (); } Private Static Integrated Field (byte buffer buffer) {int type = buffer.getShort (); Int count = buffer.getInt (); If (calculation! = 1) {new runtime expedition ("expected to count 1 for given field."); } Switch (type) {case 3: // word reffer buffer.tat (); Case 4: // Int Refer Buffer.GetInt (); Default: // char (not used here) Return buffer. Gate () & amp; 0xFF; }}   

I tested it with some different quarrel files (black and white color with transit, encoded length) and it works fine. Depending on the layout of your TIFF file, it needs to read a lot of streams before getting the size (one of the previously tested files, saved from Apple's preview, at the end of the file was this) Could.

No comments:

Post a Comment