Package java.awt.image

Examples of java.awt.image.WritableRaster


    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 destRect =
View Full Code Here


                clampFloat(uid.data, uid.type);
                break;
            }
        }

        WritableRaster raster = (WritableRaster)uid.raster;
        Rectangle rect = uid.rect;
        int type = uid.type;

        switch (type) {
        case DataBuffer.TYPE_BYTE:
            byte[] bd = uid.getByteData(0);

            if (isMultiPixelPackedSM &&
                transferType == DataBuffer.TYPE_BYTE) {
                raster.setDataElements(rect.x, rect.y,
                                       rect.width, rect.height, bd);
            } else {
                int size = bd.length;
                int[] d = new int[size];
                for (int i = 0; i < size; i++) {
                    d[i] = bd[i] & 0xff;
                }
                raster.setPixels(rect.x, rect.y, rect.width, rect.height, d);
            }
            break;

        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_SHORT:
            short[] sd = uid.getShortData(0);

            if (isComponentSM) {
                // The only time this needs to set to is a byte buffer.
                UnpackedImageData buid = getPixelsCSM(raster, rect,
                                                      DataBuffer.TYPE_BYTE,
                                                      true);
                byte[][] bdata = buid.getByteData();

                for (int b = 0; b < numBands; b++) {
                    byte[] d = bdata[b];
                    int lo = buid.getOffset(b);

                    for (int i = b, h = 0; h < rect.height; h++) {
                        int po = lo;
                        lo += buid.lineStride;

                        for (int w = 0; w < rect.width; w++) {
                            d[po] = (byte)sd[i];

                            po += buid.pixelStride;
                            i += numBands;
                        }
                    }
                }
            } else if (isMultiPixelPackedSM &&
                       transferType == DataBuffer.TYPE_USHORT) {
                raster.setDataElements(rect.x, rect.y,
                                       rect.width, rect.height, sd);
            } else {
                int size = sd.length;
                int[] d = new int[size];
                if (type == DataBuffer.TYPE_USHORT) {
                    for (int i = 0; i < size; i++) {
                        d[i] = sd[i] & 0xffff;
                    }
                } else {
                    for (int i = 0; i < size; i++) {
                        d[i] = sd[i];
                    }
                }
                raster.setPixels(rect.x, rect.y, rect.width, rect.height, d);
            }
            break;

        case DataBuffer.TYPE_INT:
            raster.setPixels(rect.x, rect.y, rect.width, rect.height,
                             uid.getIntData(0));
            break;

        case DataBuffer.TYPE_FLOAT:
            raster.setPixels(rect.x, rect.y, rect.width, rect.height,
                             uid.getFloatData(0));
            break;

        case DataBuffer.TYPE_DOUBLE:
            raster.setPixels(rect.x, rect.y, rect.width, rect.height,
                             uid.getDoubleData(0));
            break;
        }
    }
View Full Code Here

            /*
             * The getPackedData() method should set "set" to false if
             * the Raster is not writable.
             * Copy one line at a time to avoid using too much memory.
             */
            WritableRaster wr = (WritableRaster)raster;
            int size = pid.lineStride * 8;
            int[] p = new int[size];

            for (int i = 0, h = 0; h < rect.height; h++) {
                for (int w = 0; w < size; w += 8) {
                    p[w] = (data[i] >>> 7) & 0x1;
                    p[w+1] = (data[i] >>> 6) & 0x1;
                    p[w+2] = (data[i] >>> 5) & 0x1;
                    p[w+3] = (data[i] >>> 4) & 0x1;
                    p[w+4] = (data[i] >>> 3) & 0x1;
                    p[w+5] = (data[i] >>> 2) & 0x1;
                    p[w+6] = (data[i] >>> 1) & 0x1;
                    p[w+7] = data[i] & 0x1;
                    i++;
                }
                wr.setPixels(rect.x, rect.y + h, rect.width, 1, p);
            }
        }
    }
View Full Code Here

        if (!uid.convertToDest) {
            return;
        }

        WritableRaster raster = (WritableRaster)uid.raster;
        Rectangle rect = uid.rect;
        int type = uid.type;

        int size = rect.width * rect.height * numComponents;
        int[] ic = null;

        switch (type) {
        case DataBuffer.TYPE_BYTE:
            byte[] bc = uid.getByteData(0);
            ic = new int[size];
            for (int i = 0; i < size; i++) {
                ic[i] = bc[i] & 0xff;
            }
            break;

        case DataBuffer.TYPE_USHORT:
            short[] usc = uid.getShortData(0);
            ic = new int[size];
            for (int i = 0; i < size; i++) {
                ic[i] = usc[i] & 0xffff;
            }
            break;

        case DataBuffer.TYPE_SHORT:
            short[] sc = uid.getShortData(0);
            ic = new int[size];
            for (int i = 0; i < size; i++) {
                ic[i] = sc[i];
            }
            break;

        case DataBuffer.TYPE_INT:
            ic = uid.getIntData(0);
            break;

        case DataBuffer.TYPE_FLOAT:
            float[] fc = uid.getFloatData(0);
            ic = new int[size];
            for (int i = 0; i < size; i++) {
                ic[i] = (int)fc[i];;
            }
            break;

        case DataBuffer.TYPE_DOUBLE:
            double[] dc = uid.getDoubleData(0);
            ic = new int[size];
            for (int i = 0; i < size; i++) {
                ic[i] = (int)dc[i];
            }
            break;
        }

        int width = rect.x + rect.width;
        int height = rect.y + rect.height;

        for (int i = 0, y = rect.y; y < height; y++) {
            for (int x = rect.x; x < width; x++) {
                Object p = colorModel.getDataElements(ic, i, null);
                raster.setDataElements(x, y, p);
                i += numComponents;
            }
        }
    }
View Full Code Here

        byte[] r = data[0]// red
        byte[] g = data[1]// green
        byte[] b = data[2]// blue
        byte[] a = data[3]// alpha

        WritableRaster raster = (WritableRaster)uid.raster;
        Rectangle rect = uid.rect;

        int maxX = rect.x + rect.width;
        int maxY = rect.y + rect.height;

        for (int i = 0, y = rect.y; y < maxY; y++) {
            for (int x = rect.x; x < maxX; x++) {
                int rgb = (a[i] << 24) | (b[i] << 16) |
                          (g[i] << 8) | r[i];

                Object p = colorModel.getDataElements(rgb, null);
                raster.setDataElements(x, y, p);
                i++;
            }
        }
    }
View Full Code Here

        // Make sure the fields are initialized.
  initializeFields();

        // Get a WritableRaster to represent this tile.
        WritableRaster dest = null;
        if (isInPlaceEnabled) {
            if (source0IsWritableRenderedImage) {
                // Check one out from the WritableRenderedImage source.
                dest = source0AsWritableRenderedImage.getWritableTile(tileX,
                                                                      tileY);
            } else { // source0 is OpImage
                // Re-use one from the OpImage source.
                // First check whether the source raster is cached.
                Raster raster =
                    source0AsOpImage.getTileFromCache(tileX, tileY);

                if (raster == null) {
                    // Compute the tile.
                    try {
                        raster = source0AsOpImage.computeTile(tileX, tileY);
                        if (raster instanceof WritableRaster) {
                            dest = (WritableRaster)raster;
                        }
                    } catch(Exception e) {
                        // Do nothing: this catch is simply in case the
                        // OpImage in question does not itself implement
                        // computeTile() in which case it may be resolved
                        // to OpImage.computeTile() which will throw an
                        // Exception.
                    }
                }
            }
        }

        // Set tile recycling flag.
        boolean recyclingSource0Tile = dest != null;

        if (!recyclingSource0Tile) {
            // Create a new WritableRaster.
            Point org = new Point(tileXToX(tileX), tileYToY(tileY));
            dest = createWritableRaster(sampleModel, org);
        }

        // Colormap operation: return the source Raster if operating
        // in place or a copy thereof otherwise.
        if(isColormapOperation()) {
            if(!recyclingSource0Tile) {
                PlanarImage src = getSource(0);
                Raster srcTile = null;
                Rectangle srcRect = null;
                Rectangle dstRect = dest.getBounds();

                // Confirm that the tile grids of the source and destination
                // are the same
                if (sameTileGrid) {
                    // Tile grids are aligned so the tile indices correspond
                    // to pixels at the same locations in source and destination
                    srcTile = getSource(0).getTile(tileX, tileY);
                }
                else if (dstRect.intersects(src.getBounds())) {
                    // Tile grids are not aligned but the destination rectangle
                    // intersects the source bounds so get the data using
                    // the destination rectangle
                    srcTile = src.getData(dstRect);
                }
                else {
                    // The destination rectangle does not interest the source
                    // bounds so just return the destination.
                    return dest;
                }

                srcRect = srcTile.getBounds();

                // Ensure that the source tile doesn't lie outside the
                // destination tile.
                if(!dstRect.contains(srcRect)) {
                    srcRect = dstRect.intersection(srcRect);
                    srcTile =
                        srcTile.createChild(srcTile.getMinX(),
                                            srcTile.getMinY(),
                                            srcRect.width,
                                            srcRect.height,
                                            srcRect.x,
                                            srcRect.y,
                                            null);
                }

                JDKWorkarounds.setRect(dest, srcTile, 0, 0);
            }
            return dest;
        }

        // Output bounds are initially equal to the tile bounds.
        int destMinX = dest.getMinX();
        int destMinY = dest.getMinY();
        int destMaxX = destMinX + dest.getWidth();
        int destMaxY = destMinY + dest.getHeight();

        // Clip output bounds to the dest image bounds.
        Rectangle bounds = getBounds();
        if (destMinX < bounds.x) {
            destMinX = bounds.x;
View Full Code Here

    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,
View Full Code Here

                return;
            }

            // Writeback should only be necessary on destRasters which
            // should be writable so this cast should succeed.
            WritableRaster wr = (WritableRaster)raster;

            if (wr.getSampleModel() instanceof ComponentSampleModel) {
                ComponentSampleModel csm =
                   (ComponentSampleModel)wr.getSampleModel();
                int rasScanlineStride = csm.getScanlineStride();
                int rasPixelStride = csm.getPixelStride();

                int subRasterOffset =
                 (rect.y-raster.getSampleModelTranslateY())*rasScanlineStride+
                 (rect.x-raster.getSampleModelTranslateX())*rasPixelStride;

                int rasBankIndices[] = csm.getBankIndices();
                int rasBandOffsets[] = csm.getBandOffsets();
                int rasDataOffsets[] = raster.getDataBuffer().getOffsets();

                if (rasDataOffsets.length == 1) {
                    for (int i = 0; i < numBands; i++) {
                        rasBandOffsets[i] += rasDataOffsets[0] +
                           subRasterOffset;
                    }
                } else if (rasDataOffsets.length == rasBandOffsets.length) {
                    for (int i = 0; i < numBands; i++) {
                        rasBandOffsets[i] += rasDataOffsets[i] +
                            subRasterOffset;
                    }
                }

                Object mlibDataArray = null;
                switch (getDataType()) {
                case DataBuffer.TYPE_BYTE:
                    byte bArray[][] = new byte[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        bArray[i] = mlimages[0].getByteData();
                    }
                    mlibDataArray = bArray;
                    break;
                case DataBuffer.TYPE_USHORT:
                    short usArray[][] = new short[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        usArray[i] = mlimages[0].getUShortData();
                    }
                    mlibDataArray = usArray;
                    break;
                case DataBuffer.TYPE_SHORT:
                    short sArray[][] = new short[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        sArray[i] = mlimages[0].getShortData();
                    }
                    mlibDataArray = sArray;
                    break;
                case DataBuffer.TYPE_INT:
                    int iArray[][] = new int[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        iArray[i] = mlimages[0].getIntData();
                    }
                    mlibDataArray = iArray;
                    break;
                case DataBuffer.TYPE_FLOAT:
                    float fArray[][] = new float[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        fArray[i] = mlimages[0].getFloatData();
                    }
                    mlibDataArray = fArray;
                    break;
                case DataBuffer.TYPE_DOUBLE:
                    double dArray[][] = new double[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        dArray[i] = mlimages[0].getDoubleData();
                    }
                    mlibDataArray = dArray;
                    break;
                }


    byte tmpDataArray[] = null;
                Object rasDataArray = null;
                switch (csm.getDataType()) {
                    case DataBuffer.TYPE_BYTE: {
                        DataBufferByte dbb =
                            (DataBufferByte)raster.getDataBuffer();
                        byte rasByteDataArray[][] = new byte[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasByteDataArray[i] =
                                dbb.getData(rasBankIndices[i]);
                        }
      tmpDataArray =  rasByteDataArray[0];
                        rasDataArray = rasByteDataArray;
                        }
                        break;
                    case DataBuffer.TYPE_USHORT: {
                        DataBufferUShort dbus =
                            (DataBufferUShort)raster.getDataBuffer();
                        short rasUShortDataArray[][] = new short[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasUShortDataArray[i] =
                                dbus.getData(rasBankIndices[i]);
                        }
                        rasDataArray = rasUShortDataArray;
                        }
                        break;
                    case DataBuffer.TYPE_SHORT: {
                        DataBufferShort dbs =
                            (DataBufferShort)raster.getDataBuffer();
                        short rasShortDataArray[][] = new short[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasShortDataArray[i] =
                                dbs.getData(rasBankIndices[i]);
                        }
                        rasDataArray = rasShortDataArray;
                        }
                        break;
                    case DataBuffer.TYPE_INT: {
                        DataBufferInt dbi =
                            (DataBufferInt)raster.getDataBuffer();
                        int rasIntDataArray[][] = new int[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasIntDataArray[i] =
                                dbi.getData(rasBankIndices[i]);
                        }
                        rasDataArray = rasIntDataArray;
                        }
                        break;
                    case DataBuffer.TYPE_FLOAT: {
                        DataBuffer dbf =
                            raster.getDataBuffer();
                        float rasFloatDataArray[][] = new float[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasFloatDataArray[i] =
                                DataBufferUtils.getDataFloat(dbf, rasBankIndices[i]);
                        }
                        rasDataArray = rasFloatDataArray;
                        }
                        break;
                    case DataBuffer.TYPE_DOUBLE: {
                        DataBuffer dbd =
                            raster.getDataBuffer();
                        double rasDoubleDataArray[][] = new double[numBands][];
                        for (int i = 0; i < numBands; i++) {
                            rasDoubleDataArray[i] =
                                DataBufferUtils.getDataDouble(dbd, rasBankIndices[i]);
                        }
                        rasDataArray = rasDoubleDataArray;
                        }
                        break;
                }


                // src = mlib && dst = ras
                Image.Reformat(
                        rasDataArray,
                        mlibDataArray,
                        numBands,
                        rect.width,rect.height,
                        getMediaLibDataType(csm.getDataType()),
                        rasBandOffsets,
                        rasScanlineStride,
                        rasPixelStride,
                        getMediaLibDataType(this.getDataType()),
                        bandOffsets,
                        rect.width*numBands,
                        numBands);
            } else {
                // If COPIED and the raster doesn't have ComponentSampleModel
                // data is moved with getPixel/setPixel (even byte/short)
                switch (getDataType()) {
                case DataBuffer.TYPE_INT:
                    wr.setPixels(rect.x,rect.y,
                                 rect.width,rect.height,
                                 mlimages[0].getIntData());
                    break;
                case DataBuffer.TYPE_FLOAT:
                    wr.setPixels(rect.x,rect.y,
                                 rect.width,rect.height,
                                 mlimages[0].getFloatData());
                    break;
                case DataBuffer.TYPE_DOUBLE:
                    wr.setPixels(rect.x,rect.y,
                                 rect.width,rect.height,
                                 mlimages[0].getDoubleData());
                    break;
                }
            }
View Full Code Here

     */
    public WritableRaster fromCIEXYZ(Raster src,
                                     int[] srcComponentSize,
                                     WritableRaster dest,
                                     int[] destComponentSize) {
  WritableRaster tempRas =
      CIEXYZToRGB(src, srcComponentSize, null, null) ;
  return fromRGB(tempRas, tempRas.getSampleModel().getSampleSize(),
      dest, destComponentSize) ;
    }
View Full Code Here

     */
    public WritableRaster toCIEXYZ(Raster src,
                                   int[] srcComponentSize,
                                   WritableRaster dest,
                                   int[] destComponentSize) {
        WritableRaster tempRas = toRGB(src, srcComponentSize, null, null) ;
        return RGBToCIEXYZ(tempRas, tempRas.getSampleModel().getSampleSize(),
      dest, destComponentSize) ;
    }
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.