Package javax.media.jai

Examples of javax.media.jai.RasterAccessor


        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

        } else {
            // Retrieve format tags.
            formatTags = getFormatTags();
        }

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

        switch (src.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            computeRectByte(src, dst);
            break;
        case DataBuffer.TYPE_SHORT:
            computeRectShort(src, dst);
            break;
        case DataBuffer.TYPE_USHORT:
            computeRectUShort(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;
        default:
            throw new RuntimeException(JaiI18N.getString("OrderedDitherOpImage1"));
        }

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

        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

/*  512 */     RasterAccessor[] s = new RasterAccessor[numSources];
/*  513 */     for (int i = 0; i < numSources; i++) {
/*  514 */       if (sources[i] != null) {
/*  515 */         RasterFormatTag formatTag = new RasterFormatTag(sources[i].getSampleModel(), formatTagID);
/*      */
/*  518 */         s[i] = new RasterAccessor(sources[i], destRect, formatTag, null);
/*      */       }
/*      */
/*      */     }
/*      */
/*  524 */     RasterAccessor d = new RasterAccessor(dest, destRect, new RasterFormatTag(dest.getSampleModel(), formatTagID), null);
/*      */
/*  531 */     RasterAccessor[] a = new RasterAccessor[numSources];
/*  532 */     if (alphaRaster != null) {
/*  533 */       for (int i = 0; i < numSources; i++) {
/*  534 */         if (alphaRaster[i] != null) {
/*  535 */           SampleModel alphaSM = alphaRaster[i].getSampleModel();
/*  536 */           int alphaFormatTagID = RasterAccessor.findCompatibleTag(null, alphaSM);
/*      */
/*  538 */           RasterFormatTag alphaFormatTag = new RasterFormatTag(alphaSM, alphaFormatTagID);
/*      */
/*  540 */           a[i] = new RasterAccessor(alphaRaster[i], destRect, alphaFormatTag, this.sourceAlpha[i].getColorModel());
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */
/*  548 */     switch (d.getDataType()) {
/*      */     case 0:
/*  550 */       computeRectByte(s, d, a, roiRaster);
/*  551 */       break;
/*      */     case 1:
/*  553 */       computeRectUShort(s, d, a, roiRaster);
/*  554 */       break;
/*      */     case 2:
/*  556 */       computeRectShort(s, d, a, roiRaster);
/*  557 */       break;
/*      */     case 3:
/*  559 */       computeRectInt(s, d, a, roiRaster);
/*  560 */       break;
/*      */     case 4:
/*  562 */       computeRectFloat(s, d, a, roiRaster);
/*  563 */       break;
/*      */     case 5:
/*  565 */       computeRectDouble(s, d, a, roiRaster);
/*      */     }
/*      */
/*  569 */     d.copyDataToRaster();
/*      */   }
View Full Code Here

/*     */
/*     */   protected void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect)
/*     */   {
/* 125 */     RasterFormatTag[] formatTags = getFormatTags();
/*     */
/* 128 */     RasterAccessor s1 = new RasterAccessor(sources[0], destRect, formatTags[0], getSourceImage(0).getColorModel());
/*     */
/* 131 */     RasterAccessor s2 = new RasterAccessor(sources[1], destRect, formatTags[1], getSourceImage(1).getColorModel());
/*     */
/* 134 */     RasterAccessor d = new RasterAccessor(dest, destRect, formatTags[2], getColorModel());
/*     */
/* 137 */     switch (d.getDataType()) {
/*     */     case 0:
/* 139 */       computeRectByte(s1, s2, d);
/* 140 */       break;
/*     */     case 1:
/* 142 */       computeRectUShort(s1, s2, d);
/* 143 */       break;
/*     */     case 2:
/* 145 */       computeRectShort(s1, s2, d);
/* 146 */       break;
/*     */     case 3:
/* 148 */       computeRectInt(s1, s2, d);
/* 149 */       break;
/*     */     case 4:
/* 151 */       computeRectFloat(s1, s2, d);
/* 152 */       break;
/*     */     case 5:
/* 154 */       computeRectDouble(s1, s2, d);
/*     */     }
/*     */
/* 158 */     if (d.isDataCopy()) {
/* 159 */       d.clampDataArrays();
/* 160 */       d.copyDataToRaster();
/*     */     }
/*     */   }
View Full Code Here

/* 118 */     RasterFormatTag[] formatTags = getFormatTags();
/*     */
/* 120 */     Raster source = sources[0];
/* 121 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 124 */     RasterAccessor srcAccessor = new RasterAccessor(source, srcRect, formatTags[0], getSource(0).getColorModel());
/*     */
/* 127 */     RasterAccessor dstAccessor = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
/*     */
/* 131 */     switch (dstAccessor.getDataType()) {
/*     */     case 0:
/* 133 */       byteLoop(srcAccessor, dstAccessor);
/* 134 */       break;
/*     */     case 3:
/* 136 */       intLoop(srcAccessor, dstAccessor);
/* 137 */       break;
/*     */     case 2:
/* 139 */       shortLoop(srcAccessor, dstAccessor);
/* 140 */       break;
/*     */     case 1:
/* 142 */       ushortLoop(srcAccessor, dstAccessor);
/* 143 */       break;
/*     */     case 4:
/* 145 */       floatLoop(srcAccessor, dstAccessor);
/* 146 */       break;
/*     */     case 5:
/* 148 */       doubleLoop(srcAccessor, dstAccessor);
/* 149 */       break;
/*     */     }
/*     */
/* 157 */     if (dstAccessor.isDataCopy()) {
/* 158 */       dstAccessor.clampDataArrays();
/* 159 */       dstAccessor.copyDataToRaster();
/*     */     }
/*     */   }
View Full Code Here

/* 113 */     RasterFormatTag[] formatTags = getFormatTags();
/*     */
/* 115 */     Raster source = sources[0];
/* 116 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 118 */     RasterAccessor srcAccessor = new RasterAccessor(source, srcRect, formatTags[0], getSourceImage(0).getColorModel());
/*     */
/* 122 */     RasterAccessor dstAccessor = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
/*     */
/* 127 */     switch (dstAccessor.getDataType()) {
/*     */     case 0:
/* 129 */       byteLoop(srcAccessor, dstAccessor);
/* 130 */       break;
/*     */     case 3:
/* 132 */       intLoop(srcAccessor, dstAccessor);
/* 133 */       break;
/*     */     case 2:
/* 135 */       shortLoop(srcAccessor, dstAccessor);
/* 136 */       break;
/*     */     case 1:
/* 138 */       ushortLoop(srcAccessor, dstAccessor);
/* 139 */       break;
/*     */     case 4:
/* 141 */       floatLoop(srcAccessor, dstAccessor);
/* 142 */       break;
/*     */     case 5:
/* 144 */       doubleLoop(srcAccessor, dstAccessor);
/* 145 */       break;
/*     */     }
/*     */
/* 153 */     if (dstAccessor.isDataCopy()) {
/* 154 */       dstAccessor.clampDataArrays();
/* 155 */       dstAccessor.copyDataToRaster();
/*     */     }
/*     */   }
View Full Code Here

/*     */
/*     */   protected void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect)
/*     */   {
/* 108 */     RasterFormatTag[] formatTags = getFormatTags();
/*     */
/* 111 */     RasterAccessor src = new RasterAccessor(sources[0], destRect, formatTags[0], getSource(0).getColorModel());
/*     */
/* 114 */     RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
/*     */
/* 117 */     if (dst.isBinary()) {
/* 118 */       byte[] srcBits = src.getBinaryDataArray();
/* 119 */       byte[] dstBits = dst.getBinaryDataArray();
/*     */
/* 121 */       int length = dstBits.length;
/* 122 */       for (int i = 0; i < length; i++) {
/* 123 */         dstBits[i] = ((byte)(srcBits[i] ^ 0xFFFFFFFF));
/*     */       }
/*     */
/* 126 */       dst.copyBinaryDataToRaster();
/*     */
/* 128 */       return;
/*     */     }
/*     */
/* 131 */     int srcLineStride = src.getScanlineStride();
/* 132 */     int srcPixelStride = src.getPixelStride();
/* 133 */     int[] srcBandOffsets = src.getBandOffsets();
/*     */
/* 135 */     int dstNumBands = dst.getNumBands();
/* 136 */     int dstWidth = dst.getWidth();
/* 137 */     int dstHeight = dst.getHeight();
/* 138 */     int dstLineStride = dst.getScanlineStride();
/* 139 */     int dstPixelStride = dst.getPixelStride();
/* 140 */     int[] dstBandOffsets = dst.getBandOffsets();
/*     */
/* 142 */     switch (dst.getDataType())
/*     */     {
/*     */     case 0:
/* 145 */       byteLoop(dstNumBands, dstWidth, dstHeight, srcLineStride, srcPixelStride, srcBandOffsets, src.getByteDataArrays(), dstLineStride, dstPixelStride, dstBandOffsets, dst.getByteDataArrays());
/*     */
/* 150 */       break;
/*     */     case 1:
/*     */     case 2:
/* 154 */       shortLoop(dstNumBands, dstWidth, dstHeight, srcLineStride, srcPixelStride, srcBandOffsets, src.getShortDataArrays(), dstLineStride, dstPixelStride, dstBandOffsets, dst.getShortDataArrays());
/*     */
/* 159 */       break;
/*     */     case 3:
/* 162 */       intLoop(dstNumBands, dstWidth, dstHeight, srcLineStride, srcPixelStride, srcBandOffsets, src.getIntDataArrays(), dstLineStride, dstPixelStride, dstBandOffsets, dst.getIntDataArrays());
/*     */     }
/*     */
/* 170 */     dst.copyDataToRaster();
/*     */   }
View Full Code Here

/*  72 */     RasterFormatTag[] formatTags = getFormatTags();
/*     */
/*  74 */     Raster source = sources[0];
/*  75 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/*  77 */     RasterAccessor srcAccessor = new RasterAccessor(source, srcRect, formatTags[0], getSourceImage(0).getColorModel());
/*     */
/*  82 */     RasterAccessor dstAccessor = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
/*     */
/*  86 */     if (dstAccessor.isBinary()) {
/*  87 */       byte[] srcBits = srcAccessor.getBinaryDataArray();
/*  88 */       byte[] dstBits = dstAccessor.getBinaryDataArray();
/*     */
/*  90 */       System.arraycopy(srcBits, 0, dstBits, 0, dstBits.length);
/*     */
/*  92 */       dstAccessor.copyBinaryDataToRaster();
/*     */     } else {
/*  94 */       switch (dstAccessor.getDataType()) {
/*     */       case 0:
/*  96 */         byteLoop(srcAccessor, dstAccessor);
/*  97 */         break;
/*     */       case 1:
/*     */       case 2:
/* 100 */         shortLoop(srcAccessor, dstAccessor);
/* 101 */         break;
/*     */       case 3:
/* 103 */         intLoop(srcAccessor, dstAccessor);
/* 104 */         break;
/*     */       case 4:
/* 106 */         floatLoop(srcAccessor, dstAccessor);
/* 107 */         break;
/*     */       case 5:
/* 109 */         doubleLoop(srcAccessor, dstAccessor);
/* 110 */         break;
/*     */       default:
/* 112 */         String className = getClass().getName();
/* 113 */         throw new RuntimeException(JaiI18N.getString("Convolve3x3OpImage1"));
/*     */       }
/*     */
/* 119 */       if (dstAccessor.isDataCopy()) {
/* 120 */         dstAccessor.clampDataArrays();
/* 121 */         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.