예제 #1
0
  public SampleModel getSampleModel() {
    if (sampleModel != null) return sampleModel;

    int realWidth = (int) Math.min(tileWidth, width);
    int realHeight = (int) Math.min(tileHeight, height);

    if (nComp == 1 && (maxDepth == 1 || maxDepth == 2 || maxDepth == 4))
      sampleModel =
          new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, realWidth, realHeight, maxDepth);
    else if (maxDepth <= 8)
      sampleModel =
          new PixelInterleavedSampleModel(
              DataBuffer.TYPE_BYTE, realWidth, realHeight, nComp, realWidth * nComp, bandOffsets);
    else if (maxDepth <= 16)
      sampleModel =
          new PixelInterleavedSampleModel(
              isSigned ? DataBuffer.TYPE_SHORT : DataBuffer.TYPE_USHORT,
              realWidth,
              realHeight,
              nComp,
              realWidth * nComp,
              bandOffsets);
    else if (maxDepth <= 32)
      sampleModel =
          new PixelInterleavedSampleModel(
              DataBuffer.TYPE_INT, realWidth, realHeight, nComp, realWidth * nComp, bandOffsets);
    else throw new IllegalArgumentException(I18N.getString("J2KReadState11") + " " + +maxDepth);
    return sampleModel;
  }
예제 #2
0
  public Raster getTile(int tileX, int tileY, WritableRaster raster) throws IOException {
    Point nT = ictransf.getNumTiles(null);

    if (noTransform) {
      if (tileX >= nT.x || tileY >= nT.y)
        throw new IllegalArgumentException(I18N.getString("J2KImageReader0"));

      ictransf.setTile(tileX * tileStepX, tileY * tileStepY);

      // The offset of the active tiles is the same for all components,
      // since we don't support different component dimensions.
      int tOffx;
      int tOffy;
      int cTileWidth;
      int cTileHeight;
      if (raster != null && (this.resolution < hd.getDecoderSpecs().dls.getMin())
          || stepX != 1
          || stepY != 1) {
        tOffx = raster.getMinX();
        tOffy = raster.getMinY();
        cTileWidth = Math.min(raster.getWidth(), ictransf.getTileWidth());
        cTileHeight = Math.min(raster.getHeight(), ictransf.getTileHeight());
      } else {
        tOffx =
            ictransf.getCompULX(0)
                - (ictransf.getImgULX() + ictransf.getCompSubsX(0) - 1) / ictransf.getCompSubsX(0)
                + destinationRegion.x;
        tOffy =
            ictransf.getCompULY(0)
                - (ictransf.getImgULY() + ictransf.getCompSubsY(0) - 1) / ictransf.getCompSubsY(0)
                + destinationRegion.y;
        cTileWidth = ictransf.getTileWidth();
        cTileHeight = ictransf.getTileHeight();
      }

      if (raster == null)
        raster = Raster.createWritableRaster(sampleModel, new Point(tOffx, tOffy));

      int numBands = sampleModel.getNumBands();

      if (tOffx + cTileWidth >= destinationRegion.width + destinationRegion.x)
        cTileWidth = destinationRegion.width + destinationRegion.x - tOffx;

      if (tOffy + cTileHeight >= destinationRegion.height + destinationRegion.y)
        cTileHeight = destinationRegion.height + destinationRegion.y - tOffy;

      // create the line buffer for pixel data if it is not large enough
      // or null
      if (pixbuf == null || pixbuf.length < cTileWidth * numBands)
        pixbuf = new int[cTileWidth * numBands];
      boolean prog = false;

      // Deliver in lines to reduce memory usage
      for (int l = 0; l < cTileHeight; l++) {
        if (reader.getAbortRequest()) break;

        // Request line data
        for (int i = 0; i < numBands; i++) {
          if (reader.getAbortRequest()) break;
          DataBlkInt db = dataBlocks[i];
          db.ulx = 0;
          db.uly = l;
          db.w = cTileWidth;
          db.h = 1;
          ictransf.getInternCompData(db, channelMap[sourceBands[i]]);
          prog = prog || db.progressive;

          int[] data = db.data;
          int k1 = db.offset + cTileWidth - 1;

          int fracBit = fracBits[i];
          int lS = levelShift[i];
          int min = minValues[i];
          int max = maxValues[i];

          if (ImageUtil.isBinary(sampleModel)) {
            // Force min max to 0 and 1.
            min = 0;
            max = 1;
            if (bytebuf == null || bytebuf.length < cTileWidth * numBands)
              bytebuf = new byte[cTileWidth * numBands];
            for (int j = cTileWidth - 1; j >= 0; j--) {
              int tmp = (data[k1--] >> fracBit) + lS;
              bytebuf[j] = (byte) ((tmp < min) ? min : ((tmp > max) ? max : tmp));
            }

            ImageUtil.setUnpackedBinaryData(
                bytebuf, raster, new Rectangle(tOffx, tOffy + l, cTileWidth, 1));
          } else {

            for (int j = cTileWidth - 1; j >= 0; j--) {
              int tmp = (data[k1--] >> fracBit) + lS;
              pixbuf[j] = (tmp < min) ? min : ((tmp > max) ? max : tmp);
            }

            raster.setSamples(tOffx, tOffy + l, cTileWidth, 1, destinationBands[i], pixbuf);
          }
        }
      }
    } else {
      readSubsampledRaster(raster);
    }

    return raster;
  }