Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.RasterAccessor


        // 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],
                                                getSourceImage(0).getColorModel());

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


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

        // Construct RasterAccessors.
        RasterAccessor magAccessor =
            new RasterAccessor(sources[0], destRect, formatTags[0],
                               getSource(0).getColorModel());
        RasterAccessor phsAccessor =
            new RasterAccessor(sources[1], destRect, formatTags[1],
                               getSource(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(magAccessor, phsAccessor, dstAccessor,
                            destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_SHORT:
            computeRectShort(magAccessor, phsAccessor, dstAccessor,
                             destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_USHORT:
            computeRectUShort(magAccessor, phsAccessor, dstAccessor,
                              destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_INT:
            computeRectInt(magAccessor, phsAccessor, dstAccessor,
                           destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_FLOAT:
            computeRectFloat(magAccessor, phsAccessor, dstAccessor,
                             destRect.height, destRect.width);
            break;
        case DataBuffer.TYPE_DOUBLE:
            computeRectDouble(magAccessor, phsAccessor, dstAccessor,
                              destRect.height, destRect.width);
            break;
        default:
            // NB: This statement should be unreachable.
            throw new RuntimeException(JaiI18N.getString("PolarToComplexOpImage0"));
        }

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

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

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

        /* For ColormapOpImage, srcRect = destRect. */
        RasterAccessor s = new RasterAccessor(sources[0], destRect, 
                                              formatTags[0],
                                              getSourceImage(0).getColorModel());
        RasterAccessor d = new RasterAccessor(dest, destRect, 
                                              formatTags[1], getColorModel());

        if(d.isBinary()) {
            byte[] srcBits = s.getBinaryDataArray();
            byte[] dstBits = d.getBinaryDataArray();
            int length = dstBits.length;
            for(int i = 0; i < length; i++) {
                dstBits[i] = (byte)(~(srcBits[i]));
            }
            d.copyBinaryDataToRaster();
        } else {
            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:
            case DataBuffer.TYPE_DOUBLE:
                throw new RuntimeException(JaiI18N.getString("InvertOpImage0"));
            }

            d.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

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

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

        Rectangle srcRect = mapDestRect(destRect, 0);

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

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

        dst.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],
                                               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[] 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

        if(areBinarySampleModels) {
            // 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[] src1Bits = s1.getBinaryDataArray();
                byte[] src2Bits = s2.getBinaryDataArray();
                byte[] dstBits = d.getBinaryDataArray();

                int length = dstBits.length;
                for(int i = 0; i < length; i++) {
                    // "Add" is equivalent to "Or" when 1+1 is clamped to 1.
                    dstBits[i] = (byte)(src1Bits[i] | src2Bits[i]);
                }

                d.copyBinaryDataToRaster();

                return;
            }
        }

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

        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.needsClamping()) {
            d.clampDataArrays();
        }
        d.copyDataToRaster();
    }
View Full Code Here

        Rectangle srcRect = source.getBounds();

  int srcRectX = srcRect.x;
  int srcRectY = srcRect.y;

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

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

        int srcScanlineStride = srcAccessor.getScanlineStride();
        int srcPixelStride = srcAccessor.getPixelStride();

  // Destination rectangle dimensions.
  int dx = destRect.x;
  int dy = destRect.y;
  int dwidth = destRect.width;
  int dheight = destRect.height;

  // Precalculate the x positions and store them in an array.
  int[] xvalues = new int[dwidth];

  long sxNum = dx, sxDenom = 1;

  // Subtract the X translation factor sx -= transX
  sxNum = sxNum * transXRationalDenom - transXRationalNum * sxDenom;
  sxDenom *= transXRationalDenom;
 
  // Add 0.5
  sxNum = 2 * sxNum + sxDenom;
  sxDenom *= 2;

  // Multply by invScaleX
  sxNum *= invScaleXRationalNum;
  sxDenom *= invScaleXRationalDenom;

  // Separate the x source coordinate into integer and fractional part
  // int part is floor(sx), frac part is sx - floor(sx)
  int srcXInt = Rational.floor(sxNum , sxDenom);
  long srcXFrac = sxNum % sxDenom;
  if (srcXInt < 0) {
      srcXFrac = sxDenom + srcXFrac;
  }

  // Normalize - Get a common denominator for the fracs of
  // src and invScaleX
  long commonXDenom = sxDenom * invScaleXRationalDenom;
  srcXFrac *= invScaleXRationalDenom;
  long newInvScaleXFrac = invScaleXFrac * sxDenom;

  for (int i = 0; i < dwidth; i++) {

      // Calculate the position
      xvalues[i] = (srcXInt - srcRectX) * srcPixelStride;

      // Move onto the next source pixel.

      // Add the integral part of invScaleX to the integral part
      // of srcX
      srcXInt += invScaleXInt;

      // Add the fractional part of invScaleX to the fractional part
      // of srcX
      srcXFrac += newInvScaleXFrac;

      // If the fractional part is now greater than equal to the
      // denominator, divide so as to reduce the numerator to be less
      // than the denominator and add the overflow to the integral part.
      if (srcXFrac >= commonXDenom) {
    srcXInt += 1;
    srcXFrac -= commonXDenom;
      }
  }

  // Precalculate the y positions and store them in an array.      
  int[] yvalues = new int[dheight];

  long syNum = dy, syDenom = 1;

  // Subtract the X translation factor sy -= transY
  syNum = syNum * transYRationalDenom - transYRationalNum * syDenom;
  syDenom *= transYRationalDenom;
 
  // Add 0.5
  syNum = 2 * syNum + syDenom;
  syDenom *= 2;

  // Multply by invScaleX
  syNum *= invScaleYRationalNum;
  syDenom *= invScaleYRationalDenom;

  // Separate the x source coordinate into integer and fractional part
  int srcYInt = Rational.floor(syNum , syDenom);
  long srcYFrac = syNum % syDenom;
  if (srcYInt < 0) {
      srcYFrac = syDenom + srcYFrac;
  }

  // Normalize - Get a common denominator for the fracs of
  // src and invScaleY
  long commonYDenom = syDenom * invScaleYRationalDenom;
  srcYFrac *= invScaleYRationalDenom;
  long newInvScaleYFrac = invScaleYFrac * syDenom;

  for (int i = 0; i < dheight; i++) {

      // Calculate the position
      yvalues[i] = (srcYInt - srcRectY) * srcScanlineStride;

      // Move onto the next source pixel.

      // Add the integral part of invScaleY to the integral part
      // of srcY
      srcYInt += invScaleYInt;

      // Add the fractional part of invScaleY to the fractional part
      // of srcY
      srcYFrac += newInvScaleYFrac;

      // If the fractional part is now greater than equal to the
      // denominator, divide so as to reduce the numerator to be less
      // than the denominator and add the overflow to the integral part.
      if (srcYFrac >= commonYDenom) {
    srcYInt += 1;
    srcYFrac -= commonYDenom;
      }
  }

        switch (dstAccessor.getDataType()) {

        case DataBuffer.TYPE_BYTE:
            byteLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
            break;

        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_USHORT:
            shortLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
            break;

        case DataBuffer.TYPE_INT:
            intLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
            break;

  case DataBuffer.TYPE_FLOAT:
      floatLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
      break;
  case DataBuffer.TYPE_DOUBLE:
      doubleLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
      break;

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

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

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

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.