Changeset 3369


Ignore:
Timestamp:
11/14/07 13:55:36 (12 years ago)
Author:
melissa
Message:

Lossless JPEG is now supported, if JAI (with native code) is installed. This will not work with the version of jai_imageio.jar in SVN, as jai_imageio.jar doesn't include the native JPEG reader.

Location:
trunk/loci/formats
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/codec/JPEGCodec.java

    r3279 r3369  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
     29import java.util.Iterator; 
    2930import javax.imageio.ImageIO; 
     31import javax.imageio.spi.*; 
     32import javax.imageio.stream.ImageInputStream; 
    3033import loci.formats.*; 
     34 
     35import com.sun.media.imageioimpl.plugins.clib.CLibImageReader; 
    3136 
    3237/** 
     
    7075  { 
    7176    BufferedImage b; 
     77    long fp = in.getFilePointer(); 
    7278    try { 
    7379      while (in.read() != (byte) 0xff || in.read() != (byte) 0xd8); 
     
    7682    } 
    7783    catch (IOException exc) { 
    78       LogTools.println( 
    79         "An I/O error occurred decompressing image. Stack dump follows:"); 
    80       LogTools.trace(exc); 
    81       return null; 
     84      //LogTools.println( 
     85      //  "An I/O error occurred decompressing image. Stack dump follows:"); 
     86      //LogTools.trace(exc); 
     87      //return null; 
     88 
     89      System.setProperty("com.sun.media.imageio.disableCodecLib", "false"); 
     90      try { 
     91        Class jpegSpi = Class.forName( 
     92          "com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi"); 
     93        IIORegistry registry = IIORegistry.getDefaultInstance(); 
     94        Object jpeg = registry.getServiceProviderByClass(jpegSpi); 
     95 
     96        javax.imageio.ImageReader r = 
     97          ((ImageReaderSpi) jpeg).createReaderInstance(); 
     98 
     99        in.seek(fp); 
     100        while (in.read() != (byte) 0xff || in.read() != (byte) 0xd8); 
     101        in.seek(in.getFilePointer() - 2); 
     102 
     103        ImageInputStream ii = ImageIO.createImageInputStream(in); 
     104        r.setInput(ii); 
     105        b = r.read(0); 
     106      } 
     107      catch (IOException e) { 
     108        LogTools.println("An I/O error occurred while decompressing image. " + 
     109          "Stack dump follows:"); 
     110        LogTools.trace(e); 
     111        return null; 
     112      } 
     113      catch (ClassNotFoundException e) { 
     114        LogTools.println("An I/O error occurred while decompressing image. " + 
     115          "Stack dump follows:"); 
     116        LogTools.trace(e); 
     117        return null; 
     118      } 
    82119    } 
    83  
    84     byte[][] buf = ImageTools.getBytes(b); 
     120    byte[][] buf = ImageTools.getPixelBytes(b, 
     121      ((Boolean) options).booleanValue()); 
     122    /* debug */ System.out.println("bytes per channel : " + buf[0].length); 
    85123    byte[] rtn = new byte[buf.length * buf[0].length]; 
    86124    if (buf.length == 1) rtn = buf[0]; 
  • trunk/loci/formats/codec/MJPBCodec.java

    r3201 r3369  
    294294 
    295295        JPEGCodec jpeg = new JPEGCodec(); 
    296         byte[] top = jpeg.decompress(v.toByteArray()); 
    297         byte[] bottom = jpeg.decompress(v2.toByteArray()); 
     296        byte[] top = jpeg.decompress(v.toByteArray(), Boolean.FALSE); 
     297        byte[] bottom = jpeg.decompress(v2.toByteArray(), Boolean.FALSE); 
    298298 
    299299        int bpp = bits < 40 ? bits / 8 : (bits - 32) / 8; 
     
    320320        v.add((byte) 0xff); 
    321321        v.add((byte) 0xd9); 
    322         return new JPEGCodec().decompress(v.toByteArray()); 
     322        return new JPEGCodec().decompress(v.toByteArray(), Boolean.FALSE); 
    323323      } 
    324324    } 
  • trunk/loci/formats/in/DicomReader.java

    r3354 r3369  
    160160    if (isJPEG) { 
    161161      JPEGCodec codec = new JPEGCodec(); 
    162       buf = codec.decompress(buf); 
     162      buf = codec.decompress(buf, new Boolean(core.littleEndian[0])); 
    163163    } 
    164164 
     
    353353        else { 
    354354          in.seek(offsets[i - 1]); 
    355           new JPEGCodec().decompress(in, null); 
     355          new JPEGCodec().decompress(in, new Boolean(core.littleEndian[0])); 
    356356          offsets[i] = in.getFilePointer(); 
    357357        } 
  • trunk/loci/formats/in/QTReader.java

    r3354 r3369  
    722722    } 
    723723    else if (code.equals("jpeg")) { 
    724       return new JPEGCodec().decompress(pixs); 
     724      return new JPEGCodec().decompress(pixs, 
     725        new Boolean(core.littleEndian[0])); 
    725726    } 
    726727    else throw new FormatException("Unsupported codec : " + code); 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r3368 r3369  
    199199        if (isJPEG) { 
    200200          JPEGCodec codec = new JPEGCodec(); 
    201           buf = codec.decompress(buf); 
     201          buf = codec.decompress(buf, new Boolean(core.littleEndian[0])); 
    202202        } 
    203203      } 
Note: See TracChangeset for help on using the changeset viewer.