Package javax.media.jai

Examples of javax.media.jai.RasterAccessor


        // Retrieve format tags.
        RasterFormatTag[] formatTags = getFormatTags();

        Rectangle srcRect = mapDestRect(destRect, 0);

        RasterAccessor src = new RasterAccessor(sources[0], srcRect,
                                                formatTags[0],
                                                getSource(0).getColorModel());
        RasterAccessor dst = new RasterAccessor(dest, destRect,
                                                formatTags[1], getColorModel());

        int srcPixelStride = src.getPixelStride();
        int srcLineStride = src.getScanlineStride();
        int[] srcBandOffsets = src.getBandOffsets();

        int dstPixelStride = dst.getPixelStride();
        int dstLineStride = dst.getScanlineStride();
        int[] dstBandOffsets = dst.getBandOffsets();

        int width = dst.getWidth() * dstPixelStride;
        int height = dst.getHeight() * dstLineStride;
        int bands = dst.getNumBands();

        switch (dst.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            byteLoop(width, height, bands,
                     srcPixelStride, srcLineStride, srcBandOffsets,
                     src.getByteDataArrays(),
                     dstPixelStride, dstLineStride, dstBandOffsets,
                     dst.getByteDataArrays());
            break;

        case DataBuffer.TYPE_SHORT:
            shortLoop(width, height, bands,
                      srcPixelStride, srcLineStride, srcBandOffsets,
                      src.getShortDataArrays(),
                      dstPixelStride, dstLineStride, dstBandOffsets,
                      dst.getShortDataArrays());
            break;

        case DataBuffer.TYPE_USHORT:
            ushortLoop(width, height, bands,
                       srcPixelStride, srcLineStride, srcBandOffsets,
                       src.getShortDataArrays(),
                       dstPixelStride, dstLineStride, dstBandOffsets,
                       dst.getShortDataArrays());
            break;

        case DataBuffer.TYPE_INT:
            intLoop(width, height, bands,
                    srcPixelStride, srcLineStride, srcBandOffsets,
                    src.getIntDataArrays(),
                    dstPixelStride, dstLineStride, dstBandOffsets,
                    dst.getIntDataArrays());
            break;

        case DataBuffer.TYPE_FLOAT:
            floatLoop(width, height, bands,
                      srcPixelStride, srcLineStride, srcBandOffsets,
                      src.getFloatDataArrays(),
                      dstPixelStride, dstLineStride, dstBandOffsets,
                      dst.getFloatDataArrays());
            break;

        case DataBuffer.TYPE_DOUBLE:
            doubleLoop(width, height, bands,
                       srcPixelStride, srcLineStride, srcBandOffsets,
                       src.getDoubleDataArrays(),
                       dstPixelStride, dstLineStride, dstBandOffsets,
                       dst.getDoubleDataArrays());
            break;
        }

        if (dst.isDataCopy()) {
            dst.clampDataArrays();
            dst.copyDataToRaster();
        }
    }
View Full Code Here


     */
    protected void computeRect(Raster[] sources,
                               WritableRaster dest,
                               Rectangle destRect) {
        /* For PointOpImage, srcRect = destRect. */
        RasterAccessor s1 = new RasterAccessor(
            sources[0], destRect, tags[0], getSourceImage(0).getColorModel());

        RasterAccessor s2 = new RasterAccessor(
            sources[1], destRect, tags[1], getSourceImage(1).getColorModel());

        RasterAccessor a1 = new RasterAccessor(
            alpha1.getData(destRect), destRect,
            tags[2], alpha1.getColorModel());

        RasterAccessor a2 = null, d;
        if (alpha2 == null) {
            d = new RasterAccessor(dest, destRect,
                                   tags[3], getColorModel());
        } else {
            a2 = new RasterAccessor(alpha2.getData(destRect), destRect,
                                    tags[3], alpha2.getColorModel());
            d = new RasterAccessor(dest, destRect,
                                   tags[4], getColorModel());
        }

        switch (d.getDataType()) {
        case DataBuffer.TYPE_BYTE:
View Full Code Here

                               Rectangle destRect) {
        // Retrieve format tags.
        RasterFormatTag[] formatTags = getFormatTags();

        /* For PointOpImage, srcRect = destRect. */
        RasterAccessor s1 = new RasterAccessor(sources[0], destRect, 
                                               formatTags[0],
                                               getSourceImage(0).getColorModel());
        RasterAccessor s2 = new RasterAccessor(sources[1], destRect, 
                                               formatTags[1],
                                               getSourceImage(1).getColorModel());
        RasterAccessor d = new RasterAccessor(dest, destRect, 
                                              formatTags[2], getColorModel());

        switch (d.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            computeRectByte(s1, s2, d);
            break;
        case DataBuffer.TYPE_USHORT:
            computeRectUShort(s1, s2, d);
            break;
        case DataBuffer.TYPE_SHORT:
            computeRectShort(s1, s2, d);
            break;
        case DataBuffer.TYPE_INT:
            computeRectInt(s1, s2, d);
            break;
        case DataBuffer.TYPE_FLOAT:
            computeRectFloat(s1, s2, d);
            break;
        case DataBuffer.TYPE_DOUBLE:
            computeRectDouble(s1, s2, d);
            break;
        }

        if (d.isDataCopy()) {
            d.clampDataArrays();
            d.copyDataToRaster();
        }
    }
View Full Code Here

        Raster source = sources[0];
        Rectangle srcRect = mapDestRect(destRect, 0);
        RasterAccessor srcAccessor =
            new RasterAccessor(source, srcRect, formatTags[0],
                               getSource(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, formatTags[1],
                               this.getColorModel());
        switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            byteLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_SHORT:
            shortLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_USHORT:
            ushortLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_FLOAT:
            floatLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_DOUBLE:
            doubleLoop(srcAccessor, dstAccessor);
            break;
        default:
        }
        // If the RasterAccessor object set up a temporary buffer for the
        // op to write to, tell the RasterAccessor to write that data
        // to the raster no that we're done with it.
        if (dstAccessor.isDataCopy()) {
            dstAccessor.clampDataArrays();
            dstAccessor.copyDataToRaster();
        }
    }
View Full Code Here

        // In the first version source Rectangle is the whole source
        // image always.
        //
        // See if we can cache the source to avoid multiple rasteraccesors
        //
        RasterAccessor srcAccessor =
            new RasterAccessor(source,
                               srcRect,
                               formatTags[0],
                               getSourceImage(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest,
                               destRect,
                               formatTags[1],
                               getColorModel());

        switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            byteLoop(srcAccessor,
                     destRect,
                     srcRectX,
                     srcRectY,
                     dstAccessor);
            break;

        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor,
                    destRect,
                    srcRectX,
                    srcRectY,
                    dstAccessor);
            break;

        case DataBuffer.TYPE_SHORT:
            shortLoop(srcAccessor,
                      destRect,
                      srcRectX,
                      srcRectY,
                      dstAccessor);
            break;

        case DataBuffer.TYPE_USHORT:
            ushortLoop(srcAccessor,
                       destRect,
                       srcRectX,
                       srcRectY,
                       dstAccessor);
      break;

        case DataBuffer.TYPE_FLOAT:
            floatLoop(srcAccessor,
                      destRect,
                      srcRectX,
                      srcRectY,
                      dstAccessor);
      break;

        case DataBuffer.TYPE_DOUBLE:
            doubleLoop(srcAccessor,
                       destRect,
                       srcRectX,
                       srcRectY,
                       dstAccessor);
      break;
  }

        // If the RasterAccessor object set up a temporary buffer for the
        // op to write to, tell the RasterAccessor to write that data
        // to the raster, that we're done with it.
        if (dstAccessor.isDataCopy()) {
            dstAccessor.clampDataArrays();
            dstAccessor.copyDataToRaster();
        }
    }
View Full Code Here

                               Rectangle destRect) {
        // Retrieve format tags.
        RasterFormatTag[] formatTags = getFormatTags();

        // Construct RasterAccessors.
        RasterAccessor srcAccessor =
            new RasterAccessor(sources[0], destRect,
                               formatTags[0],
                               getSourceImage(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, formatTags[1], getColorModel());

        // Branch to the method appropriate to the accessor data type.
        switch(dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            computeRectByte(srcAccessor, dstAccessor,
                            destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_SHORT:
            computeRectShort(srcAccessor, dstAccessor,
                             destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_USHORT:
            computeRectUShort(srcAccessor, dstAccessor,
                              destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_INT:
            computeRectInt(srcAccessor, dstAccessor,
                           destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_FLOAT:
            computeRectFloat(srcAccessor, dstAccessor,
                             destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_DOUBLE:
            computeRectDouble(srcAccessor, dstAccessor,
                              destRect.height, destRect.width);
            break;
        default:
            // NB: This statement should be unreachable.
            throw new RuntimeException(JaiI18N.getString("MagnitudePhaseOpImage0"));
        }

        if (dstAccessor.needsClamping()) {
            dstAccessor.clampDataArrays();
        }

        // Make sure that the output data is copied to the destination.
        dstAccessor.copyDataToRaster();
    }
View Full Code Here

        WritableRaster filterRst = Raster.createWritableRaster(filterSM, filterRect.getLocation());

        BufferedImage dest = new BufferedImage(srcCM, destRst, src.isAlphaPremultiplied(), null);

        RasterFormatTag[] formatTags = RasterAccessor.findCompatibleTags(new RenderedImage[] { src }, dest);
        RasterAccessor srcRA = new RasterAccessor(srcRst, srcRst.getBounds(), formatTags[0], src.getColorModel());
        RasterAccessor filterRA = new RasterAccessor(filterRst, filterRect, formatTags[1], src.getColorModel());
        RasterAccessor dstRA = new RasterAccessor(destRst, destRect, formatTags[1], dest.getColorModel());

        switch (dstRA.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                computeRectByte(srcRA, filterRA, dstRA);
                break;
            case DataBuffer.TYPE_USHORT:
                computeRectUShort(srcRA, filterRA, dstRA);
View Full Code Here

  }
 
  protected void computeRect(Raster[] sources, WritableRaster dest,
      Rectangle destRect) {
    RasterFormatTag[] formatTags = getFormatTags();
    RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1],
        getColorModel());

    Rectangle mapRect = backwardMapRect(destRect, 0);
    Rectangle tmpRect = null;
    if (scaleFactor > WORK_LOAD_FACTOR) {
      tmpRect = mapHorizontalComputeRect(mapRect, destRect).intersection(
          filterRect);
    } else {
      tmpRect = mapVerticalComputeRect(mapRect, destRect).intersection(filterRect);
    }

    SampleModel nsm = dest.getSampleModel().createCompatibleSampleModel(
        tmpRect.width, tmpRect.height);
    WritableRaster filterRaster = Raster.createWritableRaster(nsm,
        tmpRect.getLocation());
    RasterAccessor f = new RasterAccessor(filterRaster, tmpRect,
        formatTags[1], getColorModel());

    RasterAccessor src = new RasterAccessor(sources[0],
        mapRect.intersection(sources[0].getBounds()), formatTags[0],
        getSourceImage(0).getColorModel());

    switch (dst.getDataType()) {
    case DataBuffer.TYPE_BYTE:
View Full Code Here

        int srcY = source.getMinY();

        // Retrieve format tags.
        RasterFormatTag[] formatTags = getFormatTags();

        RasterAccessor srcAccessor =
            new RasterAccessor(source,
                               new Rectangle(srcX, srcY,
                                             srcWidth, srcHeight),
                               formatTags[0],
                               getSourceImage(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, 
                               formatTags[1], getColorModel());

        // Set data type flags.
        int srcDataType = srcAccessor.getDataType();
        int dstDataType = dstAccessor.getDataType();

        // Set pixel and line strides.
        int srcPixelStride = srcAccessor.getPixelStride();
        int srcScanlineStride = srcAccessor.getScanlineStride();
        int dstPixelStride = dstAccessor.getPixelStride();
        int dstScanlineStride = dstAccessor.getScanlineStride();

        // Loop over the bands.
        int numBands = sampleModel.getNumBands();
        for(int band = 0; band < numBands; band++) {
            // Get the source and destination arrays for this band.
            Object srcData = srcAccessor.getDataArray(band);
            Object dstData = dstAccessor.getDataArray(band);

            if(destRect.width > 1) {
                // Set the FCT length.
                fct.setLength(getWidth());

                // Initialize the data offsets for this band.
                int srcOffset = srcAccessor.getBandOffset(band);
                int dstOffset = dstAccessor.getBandOffset(band);

                // Perform the row transforms.
                for(int row = 0; row < srcHeight; row++) {
                    // Set the input data of the FCT.
                    fct.setData(srcDataType, srcData,
                                srcOffset, srcPixelStride,
                                srcWidth);

                    // Calculate the DFT of the row.
                    fct.transform();

                    // Get the output data of the FCT.
                    fct.getData(dstDataType, dstData,
                                dstOffset, dstPixelStride);

                    // Increment the data offsets.
                    srcOffset += srcScanlineStride;
                    dstOffset += dstScanlineStride;
                }
            }

            if(destRect.width == 1) { // destRect.height > 1
                // Initialize the data offsets for this band.
                int srcOffset = srcAccessor.getBandOffset(band);
                int dstOffset = dstAccessor.getBandOffset(band);

                // Set the input data of the FCT.
                fct.setData(srcDataType, srcData,
                            srcOffset, srcScanlineStride,
                            srcHeight);

                // Calculate the DFT of the row.
                fct.transform();

                // Get the output data of the FCT.
                fct.getData(dstDataType, dstData,
                            dstOffset, dstScanlineStride);
            } else if(destRect.height > 1) { // destRect.width > 1
                // Reset the FCT length.
                fct.setLength(getHeight());

                // Initialize destination offset.
                int dstOffset = dstAccessor.getBandOffset(band);

                // Perform the column transforms.
                for(int col = 0; col < destRect.width; col++) {
                    // Set the input data of the FCT.
                    fct.setData(dstDataType, dstData,
                                dstOffset, dstScanlineStride,
                                destRect.height);

                    // Calculate the DFT of the column.
                    fct.transform();

                    // Get the output data of the FCT.
                    fct.getData(dstDataType, dstData,
                                dstOffset, dstScanlineStride);

                    // Increment the data offset.
                    dstOffset += dstPixelStride;
                }
            }
        }

        if (dstAccessor.needsClamping()) {
            dstAccessor.clampDataArrays();
        }

        // Make sure that the output data is copied to the destination.
        dstAccessor.copyDataToRaster();
    }
View Full Code Here

        Raster source = sources[0];
        Rectangle srcRect = mapDestRect(destRect, 0);
        RasterAccessor srcAccessor =
            new RasterAccessor(source, srcRect,
                               formatTags[0], getSourceImage(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect,
                               formatTags[1], getColorModel());
        switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            byteLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_SHORT:
            shortLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_USHORT:
            ushortLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_FLOAT:
            floatLoop(srcAccessor, dstAccessor);
            break;
        case DataBuffer.TYPE_DOUBLE:
            doubleLoop(srcAccessor, dstAccessor);
            break;

        default:
        }
        // If the RasterAccessor object set up a temporary buffer for the
        // op to write to, tell the RasterAccessor to write that data
        // to the raster no that we're done with it.
        if (dstAccessor.isDataCopy()) {
            dstAccessor.clampDataArrays();
            dstAccessor.copyDataToRaster();
        }
    }
View Full Code Here

TOP

Related Classes of javax.media.jai.RasterAccessor

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.