Package java.awt.image

Examples of java.awt.image.WritableRaster


        byte[] array = getPDStream().getByteArray();

//      Get the ColorModel right
        PDColorSpace colorspace = getColorSpace();
        ColorModel cm = colorspace.createColorModel( bpc );
        WritableRaster raster = cm.createCompatibleWritableRaster( width, height );
        //DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        byte[] bufferData = buffer.getData();
        //System.arraycopy( array, 0, bufferData, 0, array.length );
        int predictor = getPredictor();

        PredictorAlgorithm filter = PredictorAlgorithm.getFilter(predictor);
View Full Code Here


                    // raster in "BGRA" order like OpenCV.. alpha needs to be last
                    offsets = new int[] {2, 1, 0, 3};
                }

                ColorModel cm = null;
                WritableRaster wr = null;
                if (depth() == IPL_DEPTH_8U || depth() == IPL_DEPTH_8S) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_BYTE, width(), height(), nChannels(), widthStep(),
View Full Code Here

            return super.computeTile(tileX, tileY);
        }

        /* Create a new WritableRaster to represent this tile. */
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));
        WritableRaster dest = createWritableRaster(sampleModel, org);

        /* Clip output rectangle to image bounds. */
        Rectangle rect = new Rectangle(org.x, org.y,
                                       sampleModel.getWidth(),
                                       sampleModel.getHeight());
View Full Code Here

     * @param tileY The Y index of the tile.
     */
    public Raster computeTile(int tileX, int tileY) {
        /* Create a new WritableRaster to represent this tile. */
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));
        WritableRaster dest = createWritableRaster(sampleModel, org);

        /* Clip output rectangle to image bounds. */
        Rectangle rect = new Rectangle(org.x, org.y,
                                       sampleModel.getWidth(),
                                       sampleModel.getHeight());
View Full Code Here

    public Raster computeTile(int tileX, int tileY) {
        /* The origin of the tile. */
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));

        /* Create a new WritableRaster to represent this tile. */
        WritableRaster dest = createWritableRaster(sampleModel, org);

        /* Find the intersection between this tile and the writable bounds. */
        Rectangle rect = new Rectangle(org.x, org.y, tileWidth, tileHeight);
        Rectangle destRect = rect.intersection(computableBounds);
        Rectangle destRect1 = rect.intersection(getBounds());
View Full Code Here

                if(sm.getWidth() != region.width ||
                   sm.getHeight() != region.height) {
                    sm = sm.createCompatibleSampleModel(region.width,
                                                        region.height);
                }
                WritableRaster destinationRaster =
                    createWritableRaster(sm, region.getLocation());
                Raster sourceRaster =
                    tile.getBounds().equals(region) ?
                    tile : tile.createChild(region.x, region.y,
                                            region.width, region.height,
                                            region.x, region.y,
                                            null);
                JDKWorkarounds.setRect(destinationRaster, sourceRaster);
                return destinationRaster;
            } else {
                // Image is immutable so returning the tile or a child
                // thereof is acceptable.
                return tile.getBounds().equals(region) ?
                    tile : tile.createChild(region.x, region.y,
                                            region.width, region.height,
                                            region.x, region.y,
                                            null);
            }
        } else {
            // Extract a region crossing tiles into a new WritableRaster
            WritableRaster dstRaster;
            SampleModel srcSM = getSampleModel();
            int dataType = srcSM.getDataType();
            int nbands = srcSM.getNumBands();
            boolean isBandChild = false;

            ComponentSampleModel csm = null;
            int[] bandOffs = null;

            boolean fastCobblePossible = false;
            if (srcSM instanceof ComponentSampleModel) {
                csm = (ComponentSampleModel)srcSM;
                int ps = csm.getPixelStride();
                boolean isBandInt = (ps == 1 && nbands > 1);
                isBandChild = (ps > 1 && nbands != ps);
                if ( (!isBandChild) && (!isBandInt)) {
                    bandOffs = csm.getBandOffsets();
                    int i;
                    for (i=0; i<nbands; i++) {
                        if (bandOffs[i] >= nbands) {
                            break;
                        }
                    }
                    if (i == nbands) {
                        fastCobblePossible = true;
                    }
                }
            }

            if (fastCobblePossible) {
                // For acceptable cases of ComponentSampleModel,
                // use an optimized cobbler which directly accesses the
                // tile DataBuffers, using arraycopy whenever possible.
                try {
                    SampleModel interleavedSM =
                        RasterFactory.createPixelInterleavedSampleModel(
                            dataType,
                            region.width,
                            region.height,
                            nbands,
                            region.width*nbands,
                            bandOffs);
                    dstRaster = createWritableRaster(interleavedSM,
                                                     region.getLocation());
                } catch (IllegalArgumentException e) {
                    throw new IllegalArgumentException(
                        JaiI18N.getString("PlanarImage2"));
                }

                switch (dataType) {
                  case DataBuffer.TYPE_BYTE:
                    cobbleByte(region, dstRaster);
                    break;
                  case DataBuffer.TYPE_SHORT:
                    cobbleShort(region, dstRaster);
                    break;
                  case DataBuffer.TYPE_USHORT:
                    cobbleUShort(region, dstRaster);
                    break;
                  case DataBuffer.TYPE_INT:
                    cobbleInt(region, dstRaster);
                    break;
                  case DataBuffer.TYPE_FLOAT:
                    cobbleFloat(region, dstRaster);
                    break;
                  case DataBuffer.TYPE_DOUBLE:
                    cobbleDouble(region, dstRaster);
                    break;
                  default:
                    break;
                }
            } else {
                SampleModel sm = sampleModel;
                if(sm.getWidth() != region.width ||
                   sm.getHeight() != region.height) {
                    sm = sm.createCompatibleSampleModel(region.width,
                                                        region.height);
                }

                try {
                    dstRaster = createWritableRaster(sm,
                                                     region.getLocation());
                } catch (IllegalArgumentException e) {
                    throw new IllegalArgumentException(
                        JaiI18N.getString("PlanarImage2"));
                }

                for (int j = startTileY; j <= endTileY; j++) {
                    for (int i = startTileX; i <= endTileX; i++) {
                        Raster tile = getTile(i, j);

                        Rectangle subRegion = region.intersection(
                                              tile.getBounds());
                        Raster subRaster =
                            tile.createChild(subRegion.x,
                                             subRegion.y,
                                             subRegion.width,
                                             subRegion.height,
                                             subRegion.x,
                                             subRegion.y,
                                             null);

      if (sm instanceof ComponentSampleModel &&
                            isBandChild) {
                            // Need to handle this case specially, since
                            // setDataElements will not copy band child images
                            switch (sm.getDataType()) {
                              case DataBuffer.TYPE_FLOAT:
                                dstRaster.setPixels(
                                  subRegion.x,
                                  subRegion.y,
                                  subRegion.width,
                                  subRegion.height,
                                  subRaster.getPixels(
                                    subRegion.x,
                                    subRegion.y,
                                    subRegion.width,
                                    subRegion.height,
                                    new float[nbands*subRegion.width*subRegion.height]));
                                break;
                              case DataBuffer.TYPE_DOUBLE:
                                dstRaster.setPixels(
                                  subRegion.x,
                                  subRegion.y,
                                  subRegion.width,
                                  subRegion.height,
                                  subRaster.getPixels(
                                    subRegion.x,
                                    subRegion.y,
                                    subRegion.width,
                                    subRegion.height,
                                    new double[nbands*subRegion.width*subRegion.height]));
                                break;
                              default:
                                dstRaster.setPixels(
                                  subRegion.x,
                                  subRegion.y,
                                  subRegion.width,
                                  subRegion.height,
                                  subRaster.getPixels(
View Full Code Here

        // Get the intersection of the Raster and image bounds.
        Rectangle isect = imageBounds.intersection(destBounds);

        if(!isect.isEmpty()) {
            // Copy image data into the dest Raster.
            WritableRaster isectRaster = dest.createWritableChild(
                                             isect.x, isect.y,
                                             isect.width, isect.height,
                                             isect.x, isect.y,
                                             null);
            copyData(isectRaster);
View Full Code Here

            destSM = destSM.createCompatibleSampleModel(region.width,
                                                        region.height);
        }

        // Translate it
        WritableRaster dest = createWritableRaster(destSM,
                                                   region.getLocation());

        copyExtendedData(dest, extender);
        return dest;
    }
View Full Code Here

            return theTile;
        }

  // Create a new tile
  Point org = new Point(tileXToX(tileX), tileYToY(tileY));
  WritableRaster tile =
      RasterFactory.createWritableRaster(sampleModel, org);
  byte bdata[] = null; // buffer for byte data
  short sdata[] = null; // buffer for short data
  int idata[] = null; // buffer for int data

  if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
      bdata = (byte[])((DataBufferByte)tile.getDataBuffer()).getData();
  else if (sampleModel.getDataType() == DataBuffer.TYPE_USHORT)
      sdata = (short[])((DataBufferUShort)tile.getDataBuffer()).getData();
  else if (sampleModel.getDataType() == DataBuffer.TYPE_INT)
      idata = (int[])((DataBufferInt)tile.getDataBuffer()).getData();

  // There should only be one tile.
  switch(imageType) {

  case VERSION_2_1_BIT:
      // no compression
      read1Bit(bdata, 3);
      break;

  case VERSION_2_4_BIT:
      // no compression
      read4Bit(bdata, 3);
      break;

  case VERSION_2_8_BIT:
      // no compression
      read8Bit(bdata, 3);
      break;

  case VERSION_2_24_BIT:
      // no compression
      read24Bit(bdata);
      break;

  case VERSION_3_1_BIT:
      // 1-bit images cannot be compressed.
      read1Bit(bdata, 4);
      break;

  case VERSION_3_4_BIT:
      switch((int)compression) {
      case BI_RGB:
    read4Bit(bdata, 4);
    break;

      case BI_RLE4:
    int pixels[] = readRLE4();
    tile.setPixels(0, 0, width, height, pixels);
    break;

      default:
    throw new
        RuntimeException(JaiI18N.getString("BMPImageDecoder3"));
      }
      break;

  case VERSION_3_8_BIT:
      switch((int)compression) {
      case BI_RGB:
    read8Bit(bdata, 4);
        break;

      case BI_RLE8:
    readRLE8(bdata);
    break;

      default:
    throw new
        RuntimeException(JaiI18N.getString("BMPImageDecoder3"));
      }

      break;

  case VERSION_3_24_BIT:
      // 24-bit images are not compressed
      read24Bit(bdata);
      break;

  case VERSION_3_NT_16_BIT:
      read16Bit(sdata);
      break;

  case VERSION_3_NT_32_BIT:
      read32Bit(idata);
      break;

  case VERSION_4_1_BIT:
      read1Bit(bdata, 4);
      break;

  case VERSION_4_4_BIT:
      switch((int)compression) {

      case BI_RGB:
    read4Bit(bdata, 4);
    break;

      case BI_RLE4:
    int pixels[] = readRLE4();
    tile.setPixels(0, 0, width, height, pixels);
    break;

      default:
    throw new
        RuntimeException(JaiI18N.getString("BMPImageDecoder3"));
View Full Code Here

    private WritableRaster createRaster(int width, int height, int bands,
                                        int scanlineStride,
                                        int bitDepth) {

        DataBuffer dataBuffer;
        WritableRaster ras = null;
        Point origin = new Point(0, 0);
        if ((bitDepth < 8) && (bands == 1)) {
            dataBuffer = new DataBufferByte(height*scanlineStride);
            ras = Raster.createPackedRaster(dataBuffer,
                                            width, height,
View Full Code Here

TOP

Related Classes of java.awt.image.WritableRaster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.