예제 #1
0
 Object readRGB48(InputStream in) throws IOException {
   if (fi.compression > FileInfo.COMPRESSION_NONE) return readCompressedRGB48(in);
   int channels = fi.samplesPerPixel;
   short[][] stack = new short[channels][nPixels];
   DataInputStream dis = new DataInputStream(in);
   int pixel = 0;
   int min = 65535, max = 0;
   if (fi.stripLengths == null) {
     fi.stripLengths = new int[fi.stripOffsets.length];
     fi.stripLengths[0] = width * height * bytesPerPixel;
   }
   for (int i = 0; i < fi.stripOffsets.length; i++) {
     if (i > 0) {
       long skip =
           (fi.stripOffsets[i] & 0xffffffffL)
               - (fi.stripOffsets[i - 1] & 0xffffffffL)
               - fi.stripLengths[i - 1];
       if (skip > 0L) dis.skip(skip);
     }
     int len = fi.stripLengths[i];
     int bytesToGo = (nPixels - pixel) * channels * 2;
     if (len > bytesToGo) len = bytesToGo;
     byte[] buffer = new byte[len];
     dis.readFully(buffer);
     int value;
     int channel = 0;
     boolean intel = fi.intelByteOrder;
     for (int base = 0; base < len; base += 2) {
       if (intel) value = ((buffer[base + 1] & 0xff) << 8) | (buffer[base] & 0xff);
       else value = ((buffer[base] & 0xff) << 8) | (buffer[base + 1] & 0xff);
       if (value < min) min = value;
       if (value > max) max = value;
       stack[channel][pixel] = (short) (value);
       channel++;
       if (channel == channels) {
         channel = 0;
         pixel++;
       }
     }
     showProgress(i + 1, fi.stripOffsets.length);
   }
   this.min = min;
   this.max = max;
   return stack;
 }
예제 #2
0
 Object readCompressedRGB48(InputStream in) throws IOException {
   if (fi.compression == FileInfo.LZW_WITH_DIFFERENCING)
     throw new IOException("ImageJ cannot open 48-bit LZW compressed TIFFs with predictor");
   int channels = 3;
   short[][] stack = new short[channels][nPixels];
   DataInputStream dis = new DataInputStream(in);
   int pixel = 0;
   int min = 65535, max = 0;
   for (int i = 0; i < fi.stripOffsets.length; i++) {
     if (i > 0) {
       long skip =
           (fi.stripOffsets[i] & 0xffffffffL)
               - (fi.stripOffsets[i - 1] & 0xffffffffL)
               - fi.stripLengths[i - 1];
       if (skip > 0L) dis.skip(skip);
     }
     int len = fi.stripLengths[i];
     byte[] buffer = new byte[len];
     dis.readFully(buffer);
     buffer = uncompress(buffer);
     len = buffer.length;
     if (len % 2 != 0) len--;
     int value;
     int channel = 0;
     boolean intel = fi.intelByteOrder;
     for (int base = 0; base < len && pixel < nPixels; base += 2) {
       if (intel) value = ((buffer[base + 1] & 0xff) << 8) | (buffer[base] & 0xff);
       else value = ((buffer[base] & 0xff) << 8) | (buffer[base + 1] & 0xff);
       if (value < min) min = value;
       if (value > max) max = value;
       stack[channel][pixel] = (short) (value);
       channel++;
       if (channel == channels) {
         channel = 0;
         pixel++;
       }
     }
     showProgress(i + 1, fi.stripOffsets.length);
   }
   this.min = min;
   this.max = max;
   return stack;
 }