Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.RasterAccessor


     */
    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],
                                               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++) {
                dstBits[i] = (byte)(src1Bits[i] ^ src2Bits[i]);
            }

            d.copyBinaryDataToRaster();

      return;
        }

        int src1LineStride = s1.getScanlineStride();
        int src1PixelStride = s1.getPixelStride();
        int[] src1BandOffsets = s1.getBandOffsets();

        int src2LineStride = s2.getScanlineStride();
        int src2PixelStride = s2.getPixelStride();
        int[] src2BandOffsets = s2.getBandOffsets();

        int dstNumBands = d.getNumBands();
        int dstWidth = d.getWidth();
        int dstHeight = d.getHeight();
        int dstLineStride = d.getScanlineStride();
        int dstPixelStride = d.getPixelStride();
        int[] dstBandOffsets = d.getBandOffsets();

        switch (d.getDataType()) {
     
        case DataBuffer.TYPE_BYTE:
            byteLoop(dstNumBands, dstWidth, dstHeight,
                     src1LineStride, src1PixelStride,
                     src1BandOffsets, s1.getByteDataArrays(),
                     src2LineStride, src2PixelStride,
                     src2BandOffsets, s2.getByteDataArrays(),
                     dstLineStride, dstPixelStride,
                     dstBandOffsets, d.getByteDataArrays());
            break;
     
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_SHORT:
            shortLoop(dstNumBands, dstWidth, dstHeight,
          src1LineStride, src1PixelStride,
          src1BandOffsets, s1.getShortDataArrays(),
          src2LineStride, src2PixelStride,
          src2BandOffsets, s2.getShortDataArrays(),
          dstLineStride, dstPixelStride,
          dstBandOffsets, d.getShortDataArrays());
            break;
     
        case DataBuffer.TYPE_INT:
            intLoop(dstNumBands, dstWidth, dstHeight,
                    src1LineStride, src1PixelStride,
                    src1BandOffsets, s1.getIntDataArrays(),
                    src2LineStride, src2PixelStride,
                    src2BandOffsets, s2.getIntDataArrays(),
                    dstLineStride, dstPixelStride,
                    dstBandOffsets, d.getIntDataArrays());
            break;
        }
 
        d.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

        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

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

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

        if(dst.isBinary()) {
            byte[] srcBits = src.getBinaryDataArray();
            byte[] dstBits = dst.getBinaryDataArray();

            int length = dstBits.length;
            for(int i = 0; i < length; i++) {
                dstBits[i] = (byte)(~(srcBits[i]));
            }

            dst.copyBinaryDataToRaster();

      return;
        }

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

        int dstNumBands = dst.getNumBands();
        int dstWidth = dst.getWidth();
        int dstHeight = dst.getHeight();
        int dstLineStride = dst.getScanlineStride();
        int dstPixelStride = dst.getPixelStride();
        int[] dstBandOffsets = dst.getBandOffsets();

        switch (dst.getDataType()) {
     
        case DataBuffer.TYPE_BYTE:
            byteLoop(dstNumBands, dstWidth, dstHeight,
                     srcLineStride, srcPixelStride,
                     srcBandOffsets, src.getByteDataArrays(),
                     dstLineStride, dstPixelStride,
                     dstBandOffsets, dst.getByteDataArrays());
            break;
     
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_SHORT:
            shortLoop(dstNumBands, dstWidth, dstHeight,
          srcLineStride, srcPixelStride,
          srcBandOffsets, src.getShortDataArrays(),
          dstLineStride, dstPixelStride,
          dstBandOffsets, dst.getShortDataArrays());
            break;
     
        case DataBuffer.TYPE_INT:
            intLoop(dstNumBands, dstWidth, dstHeight,
                    srcLineStride, srcPixelStride,
                    srcBandOffsets, src.getIntDataArrays(),
                    dstLineStride, dstPixelStride,
                    dstBandOffsets, dst.getIntDataArrays());
            break;
        }
 
        dst.copyDataToRaster();
    }
View Full Code Here

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

        Rectangle srcRect = mapDestRect(destRect, 0);

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

        switch (dst.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());
        if(d.isBinary()) {
            byte[] dstBits = d.getBinaryDataArray();

            // Subtraction in this case boils down to copying image 1.
            System.arraycopy(s1.getBinaryDataArray(), 0,
                             dstBits, 0, dstBits.length);

            d.copyBinaryDataToRaster();

      return;
        }

        int src1LineStride = s1.getScanlineStride();
        int src1PixelStride = s1.getPixelStride();
        int[] src1BandOffsets = s1.getBandOffsets();

        int src2LineStride = s2.getScanlineStride();
        int src2PixelStride = s2.getPixelStride();
        int[] src2BandOffsets = s2.getBandOffsets();

        int dstNumBands = d.getNumBands();
        int dstWidth = d.getWidth();
        int dstHeight = d.getHeight();
        int dstLineStride = d.getScanlineStride();
        int dstPixelStride = d.getPixelStride();
        int[] dstBandOffsets = d.getBandOffsets();

        switch (d.getDataType()) {

        case DataBuffer.TYPE_BYTE:
            byteLoop(dstNumBands, dstWidth, dstHeight,
                     src1LineStride, src1PixelStride,
                     src1BandOffsets, s1.getByteDataArrays(),
                     src2LineStride, src2PixelStride,
                     src2BandOffsets, s2.getByteDataArrays(),
                     dstLineStride, dstPixelStride,
                     dstBandOffsets, d.getByteDataArrays());
            break;

  case DataBuffer.TYPE_USHORT:
            ushortLoop(dstNumBands, dstWidth, dstHeight,
                       src1LineStride, src1PixelStride,
                       src1BandOffsets, s1.getShortDataArrays(),
                       src2LineStride, src2PixelStride,
                       src2BandOffsets, s2.getShortDataArrays(),
                       dstLineStride, dstPixelStride,
                       dstBandOffsets, d.getShortDataArrays());
            break;

  case DataBuffer.TYPE_SHORT:
            shortLoop(dstNumBands, dstWidth, dstHeight,
                      src1LineStride, src1PixelStride,
                      src1BandOffsets, s1.getShortDataArrays(),
                      src2LineStride, src2PixelStride,
                      src2BandOffsets, s2.getShortDataArrays(),
                      dstLineStride, dstPixelStride,
                      dstBandOffsets, d.getShortDataArrays());
            break;

  case DataBuffer.TYPE_INT:
            intLoop(dstNumBands, dstWidth, dstHeight,
                    src1LineStride, src1PixelStride,
                    src1BandOffsets, s1.getIntDataArrays(),
                    src2LineStride, src2PixelStride,
                    src2BandOffsets, s2.getIntDataArrays(),
                    dstLineStride, dstPixelStride,
                    dstBandOffsets, d.getIntDataArrays());
            break;

  case DataBuffer.TYPE_FLOAT:
            floatLoop(dstNumBands, dstWidth, dstHeight,
                      src1LineStride, src1PixelStride,
                      src1BandOffsets, s1.getFloatDataArrays(),
                      src2LineStride, src2PixelStride,
                      src2BandOffsets, s2.getFloatDataArrays(),
                      dstLineStride, dstPixelStride,
                      dstBandOffsets, d.getFloatDataArrays());
            break;

        case DataBuffer.TYPE_DOUBLE:
            doubleLoop(dstNumBands, dstWidth, dstHeight,
                       src1LineStride, src1PixelStride,
                       src1BandOffsets, s1.getDoubleDataArrays(),
                       src2LineStride, src2PixelStride,
                       src2BandOffsets, s2.getDoubleDataArrays(),
                       dstLineStride, dstPixelStride,
                       dstBandOffsets, d.getDoubleDataArrays());
            break;
        }

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

        d.copyDataToRaster();
    }
View Full Code Here

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

        RasterAccessor src1Accessor =
            new RasterAccessor(sources[0], destRect, 
                               formatTags[0],
                               getSourceImage(0).getColorModel());
        RasterAccessor src2Accessor =
            new RasterAccessor(sources[1], destRect, 
                               formatTags[1],
                               getSourceImage(1).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, 
                               formatTags[2], getColorModel());

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

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

        int[] errBuf = new int[sourceWidthPadded*NBANDS];

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

        RasterAccessor srcAccessor =
            new RasterAccessor(source,
                               new Rectangle(startX, startY,
                                             source.getWidth(),
                                             source.getHeight()),
                               formatTags[0], getSourceImage(0).getColorModel());
        RasterAccessor dstAccessor =
            new RasterAccessor(dest, destRect, formatTags[1], getColorModel());

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

        // Set data arrays.
        byte[] srcData0 = srcAccessor.getByteDataArray(0);
        byte[] srcData1 = srcAccessor.getByteDataArray(1);
        byte[] srcData2 = srcAccessor.getByteDataArray(2);
        byte[] dstData = dstAccessor.getByteDataArray(0);

        // Initialize line offset in each band.
        int srcLine0 = srcAccessor.getBandOffset(0);
        int srcLine1 = srcAccessor.getBandOffset(1);
        int srcLine2 = srcAccessor.getBandOffset(2);
        int dstLine = dstAccessor.getBandOffset(0);

        //
        //  For each line, calculate and distribute the error into
        //  a 3 line error buffer (one line for each band).
        //  Also accumulate the contributions of the 3 bands
        //  into the same line of the temporary output buffer.
        //
        //  The error buffer starts out with all zeroes as the
        //  amount of error to propagate forward.
        //
        for (int y = startY; y <= endY; y++) {
            // Initialize pixel offset in each line in each band.
            int srcPixel0 = srcLine0;
            int srcPixel1 = srcLine1;
            int srcPixel2 = srcLine2;
            int dstPixel = dstLine;

            //
            // Determine the error and index contribution for
            // the each band. Keep the transitory errors
            // (errA, errC and errD) in local variables
            // (hopefully registers). The calculated value
            // of errB gets put into the error buffer, to be used
            // on the next line.
            //
            // This is the logic here. Floyd-Steinberg dithering
            // distributes errors to four neighboring pixels,
            // as shown below. X is the pixel being operated on.
            //
            //    7/16 of the error goes to pixel A
            //    3/16 of the error goes to pixel B
            //    5/16 of the error goes to pixel C
            //    1/16 of the error goes to pixel D
            //
            //         X A
            //       B C D
            //
            // The error distributed to pixel A is reused immediately
            // in the calculation of the next pixel on the same line.
            // The errors distributed to B, C and D will be used on the
            // following line. As we move from left to right, the
            // new error distributed to B gets added to the error
            // at the previous C. Likewise, the new C error gets added
            // to the previous D error. So only the errors propagating
            // to position B survive in the saved error buffer. The
            // only exception is at the line end, where error C must be
            // saved. The scheme is shown below.
            //
            //      XA
            //     BCD
            //      BCD
            //       BCD
            //        BCD
            //
            // Treat the error buffer as pixel sequential.
            // This lets us use a single pointer with offsets
            // for the entries for all three bands.
            //

            //
            // Zero the error holders for all bands
            // The bands are called Red, Grn and Blu, but are
            // really just the first, second and third bands.
            //
            int errRedA = 0;
            int errRedC = 0;
            int errRedD = 0;
            int errGrnA = 0;
            int errGrnC = 0;
            int errGrnD = 0;
            int errBluA = 0;
            int errBluC = 0;
            int errBluD = 0;

            int pErr = 0;
            int dstOffset = 0;
            for (int x = startX; x <= endX; x++) {
                //
                // First band (Red)
                // The color index is initialized here.
                // Set the table pointer to the "Red" band
                //
                int pTab = UNDERSHOOT;

                int adjVal =
                    ((errRedA + errBuf[pErr+3] + 8) >> 4) +
                    (int)(srcData0[srcPixel0] & 0xff);
                srcPixel0 += srcPixelStride;
                int tabval = ditherTable[pTab+adjVal];
                int err = tabval >> 8;
                int err1 = err;
                int index = (tabval & 0xff);
                int err2 = err + err;
                errBuf[pErr] = errRedC + (err += err2); // 3/16 (B)
                errRedC = errRedD + (err += err2); // 5/16 (C)
                errRedD = err1;                    // 1/16 (D)
                errRedA = (err += err2);           // 7/16 (A)

                //
                // Second band (Green)
                // Set the table pointer to the "Green" band
                // The color index is incremented here.
                //
                pTab += TOTALGRAYS;

                adjVal =
                    ((errGrnA + errBuf[pErr+4] + 8) >> 4) +
                    (int)(srcData1[srcPixel1] & 0xff);
                srcPixel1 += srcPixelStride;
                tabval = ditherTable[pTab+adjVal];
                err = tabval >> 8;
                err1 = err;
                index += (tabval & 0xff);
                err2 = err + err;
                errBuf[pErr+1] = errGrnC + (err += err2);
                errGrnC = errGrnD + (err += err2);
                errGrnD = err1;
                errGrnA = (err += err2);

                pTab += TOTALGRAYS;

                //
                // Third band (Blue)
                // Set the table pointer to the "Blue" band
                // The color index is incremented here.
                //
                adjVal =
                    ((errBluA + errBuf[pErr+5] + 8) >> 4) +
                    (int)(srcData2[srcPixel2] & 0xff);
                srcPixel2 += srcPixelStride;
                tabval = ditherTable[pTab+adjVal];
                err = tabval >> 8;
                err1 = err;
                index += (tabval & 0xff);
                err2 = err + err;
                errBuf[pErr+2] = errBluC + (err += err2);
                errBluC = errBluD + (err += err2);
                errBluD = err1;
                errBluA = (err += err2);

                // Save the result in the output data buffer.
                dstData[dstPixel] = (byte)(index&0xff);
                dstPixel += dstPixelStride;

                pErr += 3;

            } // End pixel loop

            //
            // Save last error in line
            //
            int last = 3 * (sourceWidthPadded - 2);
            errBuf[last]   = errRedC;
            errBuf[last+1] = errGrnC;
            errBuf[last+2] = errBluC;

            // Increment offset in each band to next line.
            srcLine0 += srcScanlineStride;
            srcLine1 += srcScanlineStride;
            srcLine2 += srcScanlineStride;
            dstLine += dstScanlineStride;
        } // End scanline loop


        // Make sure that the output data is copied to the destination.
        dstAccessor.copyDataToRaster();
    }
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.