コード例 #1
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
  int[] readPlanarRGB(InputStream in) throws IOException {
    if (fi.compression > FileInfo.COMPRESSION_NONE) return readCompressedPlanarRGBImage(in);
    DataInputStream dis = new DataInputStream(in);
    int planeSize = nPixels; // 1/3 image size
    byte[] buffer = new byte[planeSize];
    int[] pixels = new int[nPixels];
    int r, g, b;

    startTime = 0L;
    showProgress(10, 100);
    dis.readFully(buffer);
    for (int i = 0; i < planeSize; i++) {
      r = buffer[i] & 0xff;
      pixels[i] = 0xff000000 | (r << 16);
    }

    showProgress(40, 100);
    dis.readFully(buffer);
    for (int i = 0; i < planeSize; i++) {
      g = buffer[i] & 0xff;
      pixels[i] |= g << 8;
    }

    showProgress(70, 100);
    dis.readFully(buffer);
    for (int i = 0; i < planeSize; i++) {
      b = buffer[i] & 0xff;
      pixels[i] |= b;
    }

    showProgress(90, 100);
    return pixels;
  }
コード例 #2
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 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;
 }
コード例 #3
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 float[] read24bitImage(InputStream in) throws IOException {
   byte[] buffer = new byte[width * 3];
   float[] pixels = new float[nPixels];
   int b1, b2, b3;
   DataInputStream dis = new DataInputStream(in);
   for (int y = 0; y < height; y++) {
     // IJ.log("read24bitImage: ");
     dis.readFully(buffer);
     int b = 0;
     for (int x = 0; x < width; x++) {
       b1 = buffer[b++] & 0xff;
       b2 = buffer[b++] & 0xff;
       b3 = buffer[b++] & 0xff;
       pixels[x + y * width] = (b3 << 16) | (b2 << 8) | b1;
     }
   }
   return pixels;
 }
コード例 #4
0
 byte[] download(File f) {
   if (!f.exists()) {
     IJ.error("Plugin Installer", "File not found: " + f);
     return null;
   }
   byte[] data = null;
   try {
     int len = (int) f.length();
     InputStream in = new BufferedInputStream(new FileInputStream(f));
     DataInputStream dis = new DataInputStream(in);
     data = new byte[len];
     dis.readFully(data);
     dis.close();
   } catch (Exception e) {
     IJ.error("Plugin Installer", "" + e);
     data = null;
   }
   return data;
 }
コード例 #5
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 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;
 }
コード例 #6
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 byte[] read1bitImage(InputStream in) throws IOException {
   if (fi.compression == FileInfo.LZW)
     throw new IOException("ImageJ cannot open 1-bit LZW compressed TIFFs");
   int scan = (int) Math.ceil(width / 8.0);
   int len = scan * height;
   byte[] buffer = new byte[len];
   byte[] pixels = new byte[nPixels];
   DataInputStream dis = new DataInputStream(in);
   dis.readFully(buffer);
   int value1, value2, offset, index;
   for (int y = 0; y < height; y++) {
     offset = y * scan;
     index = y * width;
     for (int x = 0; x < scan; x++) {
       value1 = buffer[offset + x] & 0xff;
       for (int i = 7; i >= 0; i--) {
         value2 = (value1 & (1 << i)) != 0 ? 255 : 0;
         if (index < pixels.length) pixels[index++] = (byte) value2;
       }
     }
   }
   return pixels;
 }
コード例 #7
0
ファイル: ImageReader.java プロジェクト: Bio7/imagej1
 short[] read12bitImage(InputStream in) throws IOException {
   int bytesPerLine = (int) (width * 1.5);
   if ((width & 1) == 1) bytesPerLine++; // add 1 if odd
   byte[] buffer = new byte[bytesPerLine * height];
   short[] pixels = new short[nPixels];
   DataInputStream dis = new DataInputStream(in);
   dis.readFully(buffer);
   for (int y = 0; y < height; y++) {
     int index1 = y * bytesPerLine;
     int index2 = y * width;
     int count = 0;
     while (count < width) {
       pixels[index2 + count] =
           (short) (((buffer[index1] & 0xff) * 16) + ((buffer[index1 + 1] >> 4) & 0xf));
       count++;
       if (count == width) break;
       pixels[index2 + count] =
           (short) (((buffer[index1 + 1] & 0xf) * 256) + (buffer[index1 + 2] & 0xff));
       count++;
       index1 += 3;
     }
   }
   return pixels;
 }