Example #1
0
 private static double decodeWord(byte[] plane, int index, int pixelType, boolean little) {
   final double value;
   switch (pixelType) {
     case FormatTools.UINT8:
       value = plane[index] & 0xff;
       break;
     case FormatTools.INT8:
       value = plane[index];
       break;
     case FormatTools.UINT16:
       value = DataTools.bytesToShort(plane, 2 * index, 2, little) & 0xffff;
       break;
     case FormatTools.INT16:
       value = DataTools.bytesToShort(plane, 2 * index, 2, little);
       break;
     case FormatTools.UINT32:
       value = DataTools.bytesToInt(plane, 4 * index, 4, little) & 0xffffffffL;
       break;
     case FormatTools.INT32:
       value = DataTools.bytesToInt(plane, 4 * index, 4, little);
       break;
     case FormatTools.FLOAT:
       value = DataTools.bytesToFloat(plane, 4 * index, 4, little);
       break;
     case FormatTools.DOUBLE:
       value = DataTools.bytesToDouble(plane, 8 * index, 8, little);
       break;
     default:
       value = Double.NaN;
   }
   return value;
 }
Example #2
0
  /* @see IFormatHandler#setId(String) */
  public void setId(String id) throws FormatException, IOException {
    try {
      super.setId(id);
    } catch (CMMException e) {
      // strip out all but the first application marker
      // ImageIO isn't too keen on supporting multiple application markers
      // in the same stream, as evidenced by:
      //
      // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6488904

      in = new RandomAccessInputStream(id);
      ByteArrayOutputStream v = new ByteArrayOutputStream();

      byte[] tag = new byte[2];
      in.read(tag);
      v.write(tag);

      in.read(tag);
      int tagValue = DataTools.bytesToShort(tag, false) & 0xffff;
      boolean appNoteFound = false;
      while (tagValue != 0xffdb) {
        if (!appNoteFound || (tagValue < 0xffe0 && tagValue >= 0xfff0)) {
          v.write(tag);

          in.read(tag);
          int len = DataTools.bytesToShort(tag, false) & 0xffff;
          byte[] tagContents = new byte[len - 2];
          in.read(tagContents);
          v.write(tag);
          v.write(tagContents);
        } else {
          in.read(tag);
          int len = DataTools.bytesToShort(tag, false) & 0xffff;
          in.skipBytes(len - 2);
        }

        if (tagValue >= 0xffe0 && tagValue < 0xfff0 && !appNoteFound) {
          appNoteFound = true;
        }
        in.read(tag);
        tagValue = DataTools.bytesToShort(tag, false) & 0xffff;
      }
      v.write(tag);
      byte[] remainder = new byte[(int) (in.length() - in.getFilePointer())];
      in.read(remainder);
      v.write(remainder);

      ByteArrayHandle bytes = new ByteArrayHandle(v.toByteArray());

      Location.mapFile(currentId + ".fixed", bytes);
      super.setId(currentId + ".fixed");
    }
    if (getSizeX() > MAX_SIZE && getSizeY() > MAX_SIZE && !legacyReaderInitialized) {
      close();
      useLegacy = true;
      super.setId(id);
    }
    currentId = id;
  }