コード例 #1
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 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;
 }
コード例 #2
0
ファイル: FileOpener.java プロジェクト: earrouvi/PAPPL
 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" : ""));
 }
コード例 #3
0
ファイル: FileOpener.java プロジェクト: earrouvi/PAPPL
 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;
 }
コード例 #4
0
ファイル: ImageWriter.java プロジェクト: dannyZhou/imagej
 /**
  * Writes the image to the specified OutputStream. The OutputStream is not closed. The fi.pixels
  * field must contain the image data. If fi.nImages>1 then fi.pixels must be a 2D array, for
  * example an array of images returned by ImageStack.getImageArray()). The fi.offset field is
  * ignored.
  */
 public void write(OutputStream out) throws IOException {
   if (fi.pixels == null && fi.virtualStack == null)
     throw new IOException("ImageWriter: fi.pixels==null");
   if (fi.nImages > 1 && fi.virtualStack == null && !(fi.pixels instanceof Object[]))
     throw new IOException("ImageWriter: fi.pixels not a stack");
   if (fi.width * fi.height * fi.getBytesPerPixel() < 26214400)
     showProgressBar = false; // don't show progress bar if image<25MB
   switch (fi.fileType) {
     case FileInfo.GRAY8:
     case FileInfo.COLOR8:
       if (fi.nImages > 1 && fi.virtualStack != null) write8BitVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) write8BitStack(out, (Object[]) fi.pixels);
       else write8BitImage(out, (byte[]) fi.pixels);
       break;
     case FileInfo.GRAY16_SIGNED:
     case FileInfo.GRAY16_UNSIGNED:
       if (fi.nImages > 1 && fi.virtualStack != null) write16BitVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) write16BitStack(out, (Object[]) fi.pixels);
       else write16BitImage(out, (short[]) fi.pixels);
       break;
     case FileInfo.RGB48:
       writeRGB48Image(out, (Object[]) fi.pixels);
       break;
     case FileInfo.GRAY32_FLOAT:
       if (fi.nImages > 1 && fi.virtualStack != null) writeFloatVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) writeFloatStack(out, (Object[]) fi.pixels);
       else writeFloatImage(out, (float[]) fi.pixels);
       break;
     case FileInfo.RGB:
       if (fi.nImages > 1 && fi.virtualStack != null) writeRGBVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) writeRGBStack(out, (Object[]) fi.pixels);
       else writeRGBImage(out, (int[]) fi.pixels);
       break;
     default:
   }
 }
コード例 #5
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 /**
  * 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;
   }
 }