Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.RasterAccessor


        RasterFormatTag[] formatTags = getFormatTags();

        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_SHORT:
            shortLoop(srcAccessor,dstAccessor);
            break;
        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor,dstAccessor);
            break;
        default:
            String className = this.getClass().getName();
            throw new RuntimeException(JaiI18N.getString("Convolve3x3OpImage1"));
        }
        // 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


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

        /* No need to mapSourceRect for PointOps. */
        RasterAccessor s = new RasterAccessor(sources[0],
                                              destRect,
                                              formatTags[0],
                                              getSourceImage(0).getColorModel());
        RasterAccessor d = new RasterAccessor(dest,
                                              destRect,
                                              formatTags[1],
                                              getColorModel());

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

        if (d.needsClamping()) {
            d.clampDataArrays();
        }
        d.copyDataToRaster();
    }
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],
                                               getSource(0).getColorModel());
        RasterAccessor s2 = new RasterAccessor(sources[1], destRect,
                                               formatTags[1],
                                               getSource(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

        RasterFormatTag[] formatTags = getFormatTags();

        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());

        if(dstAccessor.isBinary()) {
            byte[] srcBits = srcAccessor.getBinaryDataArray();
            byte[] dstBits = dstAccessor.getBinaryDataArray();

            System.arraycopy(srcBits, 0, dstBits, 0, dstBits.length);

            dstAccessor.copyBinaryDataToRaster();
        } else {
            switch (dstAccessor.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                byteLoop(srcAccessor,dstAccessor);
                break;
            case DataBuffer.TYPE_SHORT:
            case DataBuffer.TYPE_USHORT:
                shortLoop(srcAccessor,dstAccessor);
                break;
            case DataBuffer.TYPE_INT:
                intLoop(srcAccessor,dstAccessor);
                break;
            case DataBuffer.TYPE_FLOAT:
                floatLoop(srcAccessor,dstAccessor);
                break;
            case DataBuffer.TYPE_DOUBLE:
                doubleLoop(srcAccessor,dstAccessor);
                break;
            default:
                String className = this.getClass().getName();
                throw new RuntimeException(JaiI18N.getString("Convolve3x3OpImage1"));
            }

            // 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

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

        RasterAccessor s1 = new RasterAccessor(sources[0], destRect, 
                                               formatTags[0],
                                               getSource(0).getColorModel());
        RasterAccessor s2 = new RasterAccessor(sources[1], destRect, 
                                               formatTags[1],
                                               getSource(1).getColorModel());
        RasterAccessor d = new RasterAccessor(dest, destRect, 
                                              formatTags[2], getColorModel());
        if(d.isBinary()) {
            byte[] src1Bits = s1.getBinaryDataArray();
            byte[] src2Bits = s2.getBinaryDataArray();
            byte[] dstBits = d.getBinaryDataArray();

            int length = dstBits.length;
            for(int i = 0; i < length; i++) {
                // "Subtract" is equivalent to the following
                // when -1 is clamped to 0.
                dstBits[i] = (byte)(src1Bits[i] & (byte)(~(src2Bits[i])));
            }

            d.copyBinaryDataToRaster();

      return;
        }

        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.needsClamping()) {
            d.clampDataArrays();
        }

        d.copyDataToRaster();
    }
View Full Code Here

        // 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

  Raster source = sources[0];
  // Get the source rectangle
        Rectangle srcRect = source.getBounds();

        RasterAccessor srcAccessor =
            new RasterAccessor(source, srcRect,
                               formatTags[0], getSource(0).getColorModel());

        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, formatTags[1], getColorModel());

  int dwidth = destRect.width;
  int dheight = destRect.height;
        int srcPixelStride = srcAccessor.getPixelStride();
  int srcScanlineStride = srcAccessor.getScanlineStride();

  int[] ypos = new int[dheight];
  int[] xpos = new int[dwidth];

  int   xfracvalues[] = null, yfracvalues[] = null;
  float xfracvaluesFloat[] = null, yfracvaluesFloat[] = null;

        switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_INT:
       yfracvalues = new int[dheight];
       xfracvalues = new int[dwidth];
       preComputePositionsInt(destRect, srcRect.x, srcRect.y,
      srcPixelStride, srcScanlineStride,
      xpos, ypos, xfracvalues, yfracvalues);
       break;

  case DataBuffer.TYPE_FLOAT:
  case DataBuffer.TYPE_DOUBLE:
       yfracvaluesFloat = new float[dheight];
       xfracvaluesFloat = new float[dwidth];
       preComputePositionsFloat(destRect, srcRect.x, srcRect.y,
      srcPixelStride, srcScanlineStride,
      xpos, ypos, xfracvaluesFloat, yfracvaluesFloat);
             break;

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

        switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            byteLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvalues, yfracvalues);
            break;

        case DataBuffer.TYPE_SHORT:
            shortLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvalues, yfracvalues);
            break;

        case DataBuffer.TYPE_USHORT:
            ushortLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvalues, yfracvalues);
            break;

        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvalues, yfracvalues);
            break;

  case DataBuffer.TYPE_FLOAT:
      floatLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvaluesFloat, yfracvaluesFloat);
            break;

  case DataBuffer.TYPE_DOUBLE:
      doubleLoop(srcAccessor, destRect, dstAccessor,
      xpos, ypos, xfracvaluesFloat, yfracvaluesFloat);
            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 no that we're done with it.
        if (dstAccessor.isDataCopy()) {
            dstAccessor.clampDataArrays();
            dstAccessor.copyDataToRaster();
        }
    }
View Full Code Here

        for(int i = 0; i < numSources; i++) {
            if(sources[i] != null) {
                RasterFormatTag formatTag =
                    new RasterFormatTag(sources[i].getSampleModel(),
                                        formatTagID);
                s[i] = new RasterAccessor(sources[i], destRect, formatTag,
                                          null);
            }
        }

        // Create dest accessor.
        RasterAccessor d =
            new RasterAccessor(dest, destRect,
                               new RasterFormatTag(dest.getSampleModel(),
                                                   formatTagID),
                               null);

        // Create the alpha accessors.
        RasterAccessor[] a = new RasterAccessor[numSources];
        if(alphaRaster != null) {
            for(int i = 0; i < numSources; i++) {
                if(alphaRaster[i] != null) {
                    SampleModel alphaSM = alphaRaster[i].getSampleModel();
                    int alphaFormatTagID =
                        RasterAccessor.findCompatibleTag(null, alphaSM);
                    RasterFormatTag alphaFormatTag =
                        new RasterFormatTag(alphaSM, alphaFormatTagID);
                    a[i] = new RasterAccessor(alphaRaster[i], destRect, 
                                              alphaFormatTag,
                                              sourceAlpha[i].getColorModel());
                }
            }
        }

        // Branch to data type-specific method.
        switch (d.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            computeRectByte(s, d, a, roiRaster);
            break;
        case DataBuffer.TYPE_USHORT:
            computeRectUShort(s, d, a, roiRaster);
            break;
        case DataBuffer.TYPE_SHORT:
            computeRectShort(s, d, a, roiRaster);
            break;
        case DataBuffer.TYPE_INT:
            computeRectInt(s, d, a, roiRaster);
            break;
        case DataBuffer.TYPE_FLOAT:
            computeRectFloat(s, d, a, roiRaster);
            break;
        case DataBuffer.TYPE_DOUBLE:
            computeRectDouble(s, d, a, roiRaster);
            break;
        }

        d.copyDataToRaster();
    }
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();
        int dstPixelStrideImag = 1;
        int dstLineStrideImag = destRect.width;
        if(complexDst) {
            dstPixelStrideImag = dstPixelStride;
            dstLineStrideImag = dstScanlineStride;
        }

        // Set indices and strides for image bands (real/imaginary).
        int srcBandIndex = 0;
        int srcBandStride = complexSrc ? 2 : 1;
        int dstBandIndex = 0;
        int dstBandStride = complexDst ? 2 : 1;

        // Get the number of components.
        int numComponents = (complexDst ?
                             dest.getSampleModel().getNumBands() / 2 :
                             dest.getSampleModel().getNumBands());

        // Loop over the components.
        for(int comp = 0; comp < numComponents; comp++) {
            // Get the real source data for this component.
            Object srcReal = srcAccessor.getDataArray(srcBandIndex);

            // Get the imaginary source data for this component if present.
            Object srcImag = null;
            if(complexSrc) {
                srcImag = srcAccessor.getDataArray(srcBandIndex+1);
            }

            // Specify the destination components.
            Object dstReal = dstAccessor.getDataArray(dstBandIndex);
            Object dstImag = null;
            if(complexDst) {
                dstImag = dstAccessor.getDataArray(dstBandIndex+1);
            } else {
                // Need to allocate an array for the entire band anyway
                // even though the destination is real because it is needed
                // for storage of the result of the row transforms.
                if(dstDataType == DataBuffer.TYPE_FLOAT) {
                    dstImag = new float[destRect.width*destRect.height];
                } else {
                    dstImag = new double[destRect.width*destRect.height];
                }
            }

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

                // Initialize the source offsets for this component.
                int srcOffsetReal =
                    srcAccessor.getBandOffset(srcBandIndex);
                int srcOffsetImag = 0;
                if(complexSrc) {
                    srcOffsetImag =
                        srcAccessor.getBandOffset(srcBandIndex+1);
                }

                // Initialize destination offsets and strides.
                int dstOffsetReal =
                    dstAccessor.getBandOffset(dstBandIndex);
                int dstOffsetImag = 0;
                if(complexDst) {
                    dstOffsetImag =
                        dstAccessor.getBandOffset(dstBandIndex+1);
                }

                // Perform the row transforms.
                for(int row = 0; row < srcHeight; row++) {
                    // Set the input data of the FFT.
                    fft.setData(srcDataType,
                                srcReal, srcOffsetReal, srcPixelStride,
                                srcImag, srcOffsetImag, srcPixelStride,
                                srcWidth);

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

                    // Get the output data of the FFT.
                    fft.getData(dstDataType,
                                dstReal, dstOffsetReal, dstPixelStride,
                                dstImag, dstOffsetImag, dstPixelStrideImag);

                    // Increment the data offsets.
                    srcOffsetReal += srcScanlineStride;
                    srcOffsetImag += srcScanlineStride;
                    dstOffsetReal += dstScanlineStride;
                    dstOffsetImag += dstLineStrideImag;
                }
            }

            if(destRect.width == 1) { // destRect.height > 1
                // NB 1) destRect.height has to be greater than one or this
                // would be the degenerate case of a single point which is
                // handled above. 2) There is no need to do setLength() on
                // the FFT object here as the length will already have been
                // set to the maximum of destRect.width amd destRect.height
                // which must be destRect.height.

                // Initialize the source offsets for this component.
                int srcOffsetReal =
                    srcAccessor.getBandOffset(srcBandIndex);
                int srcOffsetImag = 0;
                if(complexSrc) {
                    srcOffsetImag =
                        srcAccessor.getBandOffset(srcBandIndex+1);
                }

                // Initialize destination offsets and strides.
                int dstOffsetReal =
                    dstAccessor.getBandOffset(dstBandIndex);
                int dstOffsetImag = 0;
                if(complexDst) {
                    dstOffsetImag =
                        dstAccessor.getBandOffset(dstBandIndex+1);
                }

                // Set the input data of the FFT.
                fft.setData(srcDataType,
                            srcReal, srcOffsetReal, srcScanlineStride,
                            srcImag, srcOffsetImag, srcScanlineStride,
                            srcHeight);

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

                // Get the output data of the FFT.
                fft.getData(dstDataType,
                            dstReal, dstOffsetReal, dstScanlineStride,
                            dstImag, dstOffsetImag, dstLineStrideImag);
            } else if(destRect.height > 1) { // destRect.width > 1
                // Reset the FFT length.
                fft.setLength(getHeight());

                // Initialize destination offsets and strides.
                int dstOffsetReal =
                    dstAccessor.getBandOffset(dstBandIndex);
                int dstOffsetImag = 0;
                if(complexDst) {
                    dstOffsetImag =
                        dstAccessor.getBandOffset(dstBandIndex+1);
                }

                // Perform the column transforms.
                for(int col = 0; col < destRect.width; col++) {
                    // Set the input data of the FFT.
                    fft.setData(dstDataType,
                                dstReal, dstOffsetReal, dstScanlineStride,
                                dstImag, dstOffsetImag, dstLineStrideImag,
                                destRect.height);

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

                    // Get the output data of the FFT.
                    fft.getData(dstDataType,
                                dstReal, dstOffsetReal, dstScanlineStride,
                                complexDst ? dstImag : null,
                                dstOffsetImag, dstLineStrideImag);

                    // Increment the data offset.
                    dstOffsetReal += dstPixelStride;
                    dstOffsetImag += dstPixelStrideImag;
                }
            }

            // Increment the indices of the real bands in both images.
            srcBandIndex += srcBandStride;
            dstBandIndex += dstBandStride;
        }

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

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

        // Get RasterAccessor tags (initialized in OpImage superclass).
        RasterFormatTag[] formatTags = getFormatTags();

        // Get destination accessor.
        RasterAccessor dst = new RasterAccessor(dest, destRect,
                                                formatTags[1],
                                                getColorModel());

        // Get source accessor.
        RasterAccessor src = new RasterAccessor(sources[0],
                                                mapDestRect(destRect, 0),
                                                formatTags[0],
                                                getSourceImage(0).getColorModel());

        switch (dst.getDataType()) {
View Full Code Here

TOP

Related Classes of com.lightcrafts.mediax.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.