Examples of WritableRaster


Examples of java.awt.image.WritableRaster

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

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

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

Examples of java.awt.image.WritableRaster

            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

Examples of java.awt.image.WritableRaster

    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

Examples of java.awt.image.WritableRaster

        int eltsPerRow = (bitDepth == 16) ? bytesPerRow/2 : bytesPerRow;
        byte[] curr = new byte[bytesPerRow];
        byte[] prior = new byte[bytesPerRow];

        // Create a 1-row tall Raster to hold the data
        WritableRaster passRow =
            createRaster(passWidth, 1, inputBands,
                         eltsPerRow,
                         bitDepth);
        DataBuffer dataBuffer = passRow.getDataBuffer();
        int type = dataBuffer.getDataType();
        byte[] byteData = null;
        short[] shortData = null;
        if (type == DataBuffer.TYPE_BYTE) {
            byteData = ((DataBufferByte)dataBuffer).getData();
View Full Code Here

Examples of java.awt.image.WritableRaster

    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

Examples of java.awt.image.WritableRaster

                // Create an interleaved raster for copying for 8-bit case.
                // This ensures that for RGB data the band offsets are {0,1,2}.
                // If the JPEG encoder encounters data with BGR offsets as
                // {2,1,0} then it will make yet another copy of the data
                // which might as well be averted here.
                WritableRaster target = sampleModel.getSampleSize(0) == 8 ?
                    Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                                   im.getWidth(),
                                                   im.getHeight(),
                                                   sampleModel.getNumBands(),
                                                   new Point(im.getMinX(),
                                                             im.getMinY())) :
                    null;

                // Copy the data.
                ras = im.copyData(target);
            }

            // Convert the Raster to a WritableRaster.
            WritableRaster wRas;
            if (ras instanceof WritableRaster) {
                wRas = (WritableRaster)ras;
            } else {
                wRas = Raster.createWritableRaster(ras.getSampleModel(),
                                                   ras.getDataBuffer(),
                                                   new Point(ras.getSampleModelTranslateX(),
                                                             ras.getSampleModelTranslateY()));
            }

            // Ensure that the WritableRaster has origin (0,0) and the
            // same dimensions as the image (if derived from a single
            // image tile, the tile dimensions might differ from the
            // image dimensions.
            if (wRas.getMinX() != 0 || wRas.getMinY() != 0 ||
                wRas.getWidth() != im.getWidth() ||
                wRas.getHeight() != im.getHeight())
                wRas = wRas.createWritableChild(wRas.getMinX(),
                                                wRas.getMinY(),
                                                im.getWidth(),
                                                im.getHeight(),
                                                0, 0,
                                                null);

            bi = new BufferedImage(colorModel, wRas, false, null);
        }

        if (colorModel instanceof IndexColorModel) {
            //
            // Need to expand the indexed data to components.
            // The convertToIntDiscrete method is used to perform this.
            //
            IndexColorModel icm = (IndexColorModel)colorModel;
            bi = icm.convertToIntDiscrete(bi.getRaster(), false);

            if(bi.getSampleModel().getNumBands() == 4) {
                //
                // Without copying data create a BufferedImage which has
                // only the RGB bands, not the alpha band.
                //
                WritableRaster rgbaRas = bi.getRaster();
                WritableRaster rgbRas =
                    rgbaRas.createWritableChild(0, 0,
                                                bi.getWidth(), bi.getHeight(),
                                                0, 0,
                                                new int[] {0, 1, 2});
                //
View Full Code Here

Examples of java.awt.image.WritableRaster

    }

    private Raster computeTile(int tileX, int tileY) {
        // Create a new tile.
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));
        WritableRaster tile = Raster.createWritableRaster(sampleModel, org);
        Rectangle tileRect = tile.getBounds();

        // There should only be one tile.
        try {
            switch (variant) {
            case PBM_ASCII:
            case PBM_RAW:
                // SampleModel for these cases should be MultiPixelPacked.

                DataBuffer dataBuffer = tile.getDataBuffer();
                if (isRaw(variant)) {
                    // Read the entire image.
                    byte[] buf = ((DataBufferByte)dataBuffer).getData();
                    input.readFully(buf, 0, buf.length);
                } else {
                    // Read 8 rows at a time
                    byte[] pixels = new byte[8*width];
                    int offset = 0;
                    for (int row = 0; row < tileHeight; row += 8) {
                        int rows = Math.min(8, tileHeight - row);
                        int len = (rows*width + 7)/8;

                        for (int i = 0; i < rows*width; i++) {
                            pixels[i] = (byte)readInteger(input);
                        }
                        sampleModel.setDataElements(tileRect.x,
                                                    row,
                                                    tileRect.width,
                                                    rows,
                                                    pixels,
                                                    dataBuffer);
                    }
                }
                break;

            case PGM_ASCII:
            case PGM_RAW:
            case PPM_ASCII:
            case PPM_RAW:
                // SampleModel for these cases should be PixelInterleaved.
                int size = width*height*numBands;

                switch (dataType) {
                case DataBuffer.TYPE_BYTE:
                    DataBufferByte bbuf =
                        (DataBufferByte)tile.getDataBuffer();
                    byte[] byteArray = bbuf.getData();
                    if (isRaw(variant)) {
                        input.readFully(byteArray);
                    } else {
                        for (int i = 0; i < size; i++) {
                            byteArray[i] = (byte)readInteger(input);
                        }
                    }
                    break;

                case DataBuffer.TYPE_USHORT:
                    DataBufferUShort sbuf =
                        (DataBufferUShort)tile.getDataBuffer();
                    short[] shortArray = sbuf.getData();
                    for (int i = 0; i < size; i++) {
                        shortArray[i] = (short)readInteger(input);
                    }
                    break;

                case DataBuffer.TYPE_INT:
                    DataBufferInt ibuf =
                        (DataBufferInt)tile.getDataBuffer();
                    int[] intArray = ibuf.getData();
                    for (int i = 0; i < size; i++) {
                        intArray[i] = readInteger(input);
                    }
                    break;
View Full Code Here

Examples of java.awt.image.WritableRaster

           ((MultiPixelPackedSampleModel)sm).getDataBitOffset() != 0) {
            MultiPixelPackedSampleModel mppsm =
                new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                width, height, 1,
                                                (width + 7)/8, 0);
            WritableRaster raster =
                Raster.createWritableRaster(mppsm,
                                            new Point(im.getMinX(),
                                                      im.getMinY()));
            raster.setRect(im.getData());
            tile = raster;
        } else if(im.getNumXTiles() == 1 &&
                  im.getNumYTiles() == 1) {
            tile = im.getTile(im.getMinTileX(), im.getMinTileY());
        } else {
View Full Code Here

Examples of java.awt.image.WritableRaster

        BufferedImage bi = new BufferedImage(width,
                                             height,
                                             BufferedImage.TYPE_BYTE_BINARY);

        // Get the image tile.
        WritableRaster tile = bi.getWritableTile(0, 0);

        // Get the SampleModel.
        MultiPixelPackedSampleModel sm =
            (MultiPixelPackedSampleModel)bi.getSampleModel();

        // Read the data.
        input.readFully(((DataBufferByte)tile.getDataBuffer()).getData(),
                   0, height*sm.getScanlineStride());

        return bi;
    }
View Full Code Here

Examples of java.awt.image.WritableRaster

    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 destRect = new Rectangle(org.x, org.y,
                  tileWidth, tileHeight).intersection(computableBounds);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.