Beispiel #1
0
 byte[] uncompress(byte[] input) {
   if (fi.compression == FileInfo.PACK_BITS)
     return packBitsUncompress(input, fi.rowsPerStrip * fi.width * fi.getBytesPerPixel());
   else if (fi.compression == FileInfo.LZW || fi.compression == FileInfo.LZW_WITH_DIFFERENCING)
     return lzwUncompress(input);
   else if (fi.compression == FileInfo.ZIP) return zipUncompress(input);
   else return input;
 }
Beispiel #2
0
 static void error(String msg, FileInfo fi, long offset, long length) {
   IJ.error(
       "FileOpener",
       "FileInfo parameter error. \n"
           + msg
           + "\n \n"
           + "  Width: "
           + fi.width
           + "\n"
           + "  Height: "
           + fi.height
           + "\n"
           + "  Offset: "
           + offset
           + "\n"
           + "  Bytes/pixel: "
           + fi.getBytesPerPixel()
           + "\n"
           + (length > 0 ? "  File length: " + length + "\n" : ""));
 }
Beispiel #3
0
 static boolean validateFileInfo(File f, FileInfo fi) {
   long offset = fi.getOffset();
   long length = 0;
   if (fi.width <= 0 || fi.height < 0) {
     error("Width or height <= 0.", fi, offset, length);
     return false;
   }
   if (offset >= 0 && offset < 1000L) return true;
   if (offset < 0L) {
     error("Offset is negative.", fi, offset, length);
     return false;
   }
   if (fi.fileType == FileInfo.BITMAP || fi.compression != FileInfo.COMPRESSION_NONE) return true;
   length = f.length();
   long size = fi.width * fi.height * fi.getBytesPerPixel();
   size = fi.nImages > 1 ? size : size / 4;
   if (fi.height == 1) size = 0; // allows plugins to read info of unknown length at end of file
   if (offset + size > length) {
     error("Offset + image size > file length.", fi, offset, length);
     return false;
   }
   return true;
 }
Beispiel #4
0
 /**
  * Reads the image from the InputStream and returns the pixel array (byte, short, int or float).
  * Returns null if there was an IO exception. Does not close the InputStream.
  */
 public Object readPixels(InputStream in) {
   Object pixels;
   startTime = System.currentTimeMillis();
   try {
     switch (fi.fileType) {
       case FileInfo.GRAY8:
       case FileInfo.COLOR8:
         bytesPerPixel = 1;
         skip(in);
         pixels = (Object) read8bitImage(in);
         break;
       case FileInfo.GRAY16_SIGNED:
       case FileInfo.GRAY16_UNSIGNED:
         bytesPerPixel = 2;
         skip(in);
         pixels = (Object) read16bitImage(in);
         break;
       case FileInfo.GRAY32_INT:
       case FileInfo.GRAY32_UNSIGNED:
       case FileInfo.GRAY32_FLOAT:
         bytesPerPixel = 4;
         skip(in);
         pixels = (Object) read32bitImage(in);
         break;
       case FileInfo.GRAY64_FLOAT:
         bytesPerPixel = 8;
         skip(in);
         pixels = (Object) read64bitImage(in);
         break;
       case FileInfo.RGB:
       case FileInfo.BGR:
       case FileInfo.ARGB:
       case FileInfo.ABGR:
       case FileInfo.BARG:
       case FileInfo.CMYK:
         bytesPerPixel = fi.getBytesPerPixel();
         skip(in);
         pixels = (Object) readChunkyRGB(in);
         break;
       case FileInfo.RGB_PLANAR:
         bytesPerPixel = 3;
         skip(in);
         pixels = (Object) readPlanarRGB(in);
         break;
       case FileInfo.BITMAP:
         bytesPerPixel = 1;
         skip(in);
         pixels = (Object) read1bitImage(in);
         break;
       case FileInfo.RGB48:
         bytesPerPixel = 6;
         skip(in);
         pixels = (Object) readRGB48(in);
         break;
       case FileInfo.RGB48_PLANAR:
         bytesPerPixel = 2;
         skip(in);
         pixels = (Object) readRGB48Planar(in);
         break;
       case FileInfo.GRAY12_UNSIGNED:
         skip(in);
         short[] data = read12bitImage(in);
         pixels = (Object) data;
         break;
       case FileInfo.GRAY24_UNSIGNED:
         skip(in);
         pixels = (Object) read24bitImage(in);
         break;
       default:
         pixels = null;
     }
     showProgress(1, 1);
     return pixels;
   } catch (IOException e) {
     IJ.log("" + e);
     return null;
   }
 }