Java Code Examples for java.awt.image.WritableRaster#getWidth()

The following examples show how to use java.awt.image.WritableRaster#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDIndexed.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
    // use lookup table
    int width = raster.getWidth();
    int height = raster.getHeight();

    BufferedImage rgbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();

    int[] src = new int[1];
    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            raster.getPixel(x, y, src);

            // lookup
            int index = Math.min(src[0], actualMaxIndex);
            rgbRaster.setPixel(x, y, rgbColorTable[index]);
        }
    }

    return rgbImage;
}
 
Example 2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Extracts pixel data as arrays of unsigned bytes, one per channel. */
public static byte[][] getBytes(final WritableRaster r, final int x,
	final int y, final int w, final int h)
{
	if (canUseBankDataDirectly(r, DataBuffer.TYPE_BYTE, DataBufferByte.class) &&
		x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight())
	{
		return ((DataBufferByte) r.getDataBuffer()).getBankData();
	}
	final int c = r.getNumBands();
	final byte[][] samples = new byte[c][w * h];
	final int[] buf = new int[w * h];
	for (int i = 0; i < c; i++) {
		r.getSamples(x, y, w, h, i, buf);
		for (int j = 0; j < buf.length; j++)
			samples[i][j] = (byte) buf[j];
	}
	return samples;
}
 
Example 3
Source File: PDDeviceGray.java    From sambox with Apache License 2.0 6 votes vote down vote up
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
    int width = raster.getWidth();
    int height = raster.getHeight();

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    int[] gray = new int[1];
    int[] rgb = new int[3];
    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            raster.getPixel(x, y, gray);
            rgb[0] = gray[0];
            rgb[1] = gray[0];
            rgb[2] = gray[0];
            image.getRaster().setPixel(x, y, rgb);
        }
    }

    return image;
}
 
Example 4
Source File: TexturePaintContext.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
synchronized static WritableRaster makeByteRaster(Raster srcRas,
                                                  int w, int h)
{
    if (byteRasRef != null) {
        WritableRaster wr = (WritableRaster) byteRasRef.get();
        if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
            byteRasRef = null;
            return wr;
        }
    }
    // If we are going to cache this Raster, make it non-tiny
    if (w <= 32 && h <= 32) {
        w = h = 32;
    }
    return srcRas.createCompatibleWritableRaster(w, h);
}
 
Example 5
Source File: TexturePaintContext.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
synchronized static WritableRaster makeByteRaster(Raster srcRas,
                                                  int w, int h)
{
    if (byteRasRef != null) {
        WritableRaster wr = (WritableRaster) byteRasRef.get();
        if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
            byteRasRef = null;
            return wr;
        }
    }
    // If we are going to cache this Raster, make it non-tiny
    if (w <= 32 && h <= 32) {
        w = h = 32;
    }
    return srcRas.createCompatibleWritableRaster(w, h);
}
 
Example 6
Source File: ColorPaintContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public synchronized Raster getRaster(int x, int y, int w, int h) {
    WritableRaster t = savedTile;

    if (t == null || w > t.getWidth() || h > t.getHeight()) {
        t = getColorModel().createCompatibleWritableRaster(w, h);
        IntegerComponentRaster icr = (IntegerComponentRaster) t;
        Arrays.fill(icr.getDataStorage(), color);
        // Note - markDirty is probably unnecessary since icr is brand new
        icr.markDirty();
        if (w <= 64 && h <= 64) {
            savedTile = t;
        }
    }

    return t;
}
 
Example 7
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks two rasters for equality of content.
 * 
 * @param wr1 the first raster.
 * @param wr2 the second raster.
 * @return <code>true</code>, if the rasters contain the same values.
 */
public static boolean equals( WritableRaster wr1, WritableRaster wr2 ) {
    int w1 = wr1.getWidth();
    int h1 = wr1.getHeight();
    int w2 = wr2.getWidth();
    int h2 = wr2.getHeight();

    if (w1 != w2 || h1 != h2) {
        return false;
    }
    for( int c = 0; c < w1; c++ ) {
        for( int r = 0; r < h1; r++ ) {
            double v1 = wr1.getSampleDouble(c, r, 0);
            double v2 = wr2.getSampleDouble(c, r, 0);
            if (isNovalue(v1) && isNovalue(v2)) {
                continue;
            }
            if (!NumericsUtilities.dEq(v1, v2)) {
                return false;
            }
        }
    }
    return true;
}
 
Example 8
Source File: ColorPaintContext.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public synchronized Raster getRaster(int x, int y, int w, int h) {
    WritableRaster t = savedTile;

    if (t == null || w > t.getWidth() || h > t.getHeight()) {
        t = getColorModel().createCompatibleWritableRaster(w, h);
        IntegerComponentRaster icr = (IntegerComponentRaster) t;
        Arrays.fill(icr.getDataStorage(), color);
        // Note - markDirty is probably unnecessary since icr is brand new
        icr.markDirty();
        if (w <= 64 && h <= 64) {
            savedTile = t;
        }
    }

    return t;
}
 
Example 9
Source File: SimpleAbstractMergeStrategy.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected void mergeRasters(
    final RasterTile<T> thisTile,
    final RasterTile<T> nextTile,
    final WritableRaster thisRaster,
    final WritableRaster nextRaster) {
  final int maxX = nextRaster.getMinX() + nextRaster.getWidth();
  final int maxY = nextRaster.getMinY() + nextRaster.getHeight();
  for (int b = 0; b < nextRaster.getNumBands(); b++) {
    for (int x = nextRaster.getMinX(); x < maxX; x++) {
      for (int y = nextRaster.getMinY(); y < maxY; y++) {
        final double thisSample = thisRaster.getSampleDouble(x, y, b);

        final double nextSample = nextRaster.getSampleDouble(x, y, b);
        thisRaster.setSample(x, y, b, getSample(x, y, b, thisSample, nextSample));
      }
    }
  }
}
 
Example 10
Source File: TexturePaintContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 11
Source File: TexturePaintContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 12
Source File: TexturePaintContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 13
Source File: TexturePaintContext.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 14
Source File: OmsSkyview.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the angle.
 * 
 * @param x the x index.
 * @param y the y index.
 * @param tmpWR the sky map.
 * @param pitWR the elevation map.
 * @param res the resolution of the map.
 * @param normalSunVector
 * @param inverseSunVector
 * @param sunVector
 */
protected WritableRaster shadow( int x, int y, WritableRaster tmpWR, WritableRaster pitWR, double res,
        double[] normalSunVector, double[] inverseSunVector, double[] sunVector ) {
    int n = 0;
    double zcompare = -Double.MAX_VALUE;
    double dx = (inverseSunVector[0] * n);
    double dy = (inverseSunVector[1] * n);
    int nCols = tmpWR.getWidth();
    int nRows = tmpWR.getHeight();
    int idx = (int) (x + dx);
    int jdy = (int) (y + dy);
    double vectorToOrigin[] = new double[3];
    while( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) {
        vectorToOrigin[0] = dx * res;
        vectorToOrigin[1] = dy * res;
        vectorToOrigin[2] = pitWR.getSampleDouble(idx, jdy, 0);
        double zprojection = scalarProduct(vectorToOrigin, normalSunVector);
        double nGrad[] = normalVectorWR.getPixel(idx, jdy, new double[3]);
        double cosinc = scalarProduct(sunVector, nGrad);
        double elevRad = elevation;
        if ((cosinc >= 0) && (zprojection > zcompare)) {
            tmpWR.setSample(idx, jdy, 0, elevRad);
            zcompare = zprojection;
        }
        n = n + 1;
        dy = (inverseSunVector[1] * n);
        dx = (inverseSunVector[0] * n);
        idx = (int) Math.round(x + dx);
        jdy = (int) Math.round(y + dy);
    }
    return tmpWR;

}
 
Example 15
Source File: MultiplyARGBComposite.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public CompositeContext createContext( ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints )
{
	final Composer c;
	if ( srcColorModel.getNumColorComponents() > 1 )
	{
		if ( srcColorModel.hasAlpha() )
			c = new ARGB2ARGB();
		else
			c = new RGB2ARGB();
	}
	else
		c = new Gray2ARGB();
	
	return new CompositeContext()
	{
		private Composer composer = c;
		public void compose( Raster src, Raster dstIn, WritableRaster dstOut )
		{
			final int[] srcPixel = new int[ 4 ];
			final int[] dstInPixel = new int[ 4 ];
			
			for ( int x = 0; x < dstOut.getWidth(); x++ )
			{
				for ( int y = 0; y < dstOut.getHeight(); y++ )
				{
					src.getPixel( x, y, srcPixel );
					dstIn.getPixel( x, y, dstInPixel );
					
					composer.compose( srcPixel, dstInPixel, alpha );
					
					dstOut.setPixel( x, y, dstInPixel );
				}
			}
		}

		public void dispose()
		{}
	};
}
 
Example 16
Source File: GeomorphUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void orizzonte7( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
        WritableRaster curvatureImage, int[][] shadow ) {
    int rows = curvatureImage.getHeight();
    int cols = curvatureImage.getWidth();
    /*=====================*/

    int y, I, J;
    double zenith;

    /*======================*/

    for( int i = quadrata - 1; i >= 0; i-- ) {
        I = -1;
        J = -1;
        y = 0;
        for( int ii = i; ii < quadrata - 1; ii++ ) {
            for( int j = (int) floor(1 / tan(beta) * (ii - i)); j <= (int) floor(1 / tan(beta) * (ii - i + 1)) - 1
                    && j < cols; j++ ) {
                if (ii >= (rows + 2 * cols) && !isNovalue(elevImageIterator.getSampleDouble(j, ii - (rows + 2 * cols), 0))) {
                    /*shadow.element[ii-(Z0.nrh+2*Z0.nch)][j]=i;}}}}*/
                    if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I == -1) {
                        I = ii - (rows + 2 * cols);
                        J = j;
                        y = 1;
                    } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I != -1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                - (rows + 2 * cols), 0))
                                / sqrt(pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[ii - (rows + 2 * cols)][j] = 0;
                            I = ii - (rows + 2 * cols);
                            J = j;
                        } else {
                            shadow[ii - (rows + 2 * cols)][j] = 1;
                        }
                    } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 0 && y == 1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                - (rows + 2 * cols), 0))
                                / sqrt(pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[ii - (rows + 2 * cols)][j] = 0;
                            y = 0;
                        } else {
                            shadow[ii - (rows + 2 * cols)][j] = 1;
                        }
                    }
                }
            }
        }
    }

}
 
Example 17
Source File: GeomorphUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void orizzonte6( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
        WritableRaster curvatureImage, int[][] shadow ) {
    int rows = curvatureImage.getHeight();
    int cols = curvatureImage.getWidth();
    /*=====================*/

    int y, I, J;
    double zenith;

    /*======================*/

    if (beta != 0) {
        for( int i = 0; i < quadrata; i++ ) {
            I = -1;
            J = -1;
            y = 0;
            for( int ii = i; ii >= 0; ii-- ) {
                for( int j = (int) floor(1 / tan(beta) * (i - ii)); j <= (int) floor(1 / tan(beta) * (i - ii + 1)) - 1
                        && j < cols; j++ ) {
                    if (ii < rows && !isNovalue(elevImageIterator.getSampleDouble(j, ii, 0))) {
                        /*shadow.element[ii][j]=i;}}}}}*/
                        if (curvatureImage.getSampleDouble(j, ii, 0) == 1 && I == -1) {
                            I = ii;
                            J = j;
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(j, ii, 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator
                                    .getSampleDouble(j, ii, 0))
                                    / sqrt(pow((double) (I - ii) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii][j] = 0;
                                I = ii;
                                J = j;
                            } else {
                                shadow[ii][j] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(j, ii, 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator
                                    .getSampleDouble(j, ii, 0))
                                    / sqrt((double) pow((I - ii) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii][j] = 0;
                                y = 0;
                            } else {
                                shadow[ii][j] = 1;
                            }
                        }
                    }
                }
            }
        }
    } else {
        for( int i = 0; i < rows; i++ ) {
            I = -1;
            J = -1;
            y = 0;
            for( int j = 0; j < cols; j++ ) {
                if (!isNovalue(elevImageIterator.getSampleDouble(j, i, 0))) {
                    if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I == -1) {
                        I = i;
                        J = j;
                        y = 1;
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I != -1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            I = i;
                            J = j;
                        } else {
                            shadow[i][j] = 1;
                        }
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 0 && y == 1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            y = 0;
                        } else {
                            shadow[i][j] = 1;
                        }
                    }
                }
            }
        }
    }

}
 
Example 18
Source File: GeomorphUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void orizzonte2( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
        WritableRaster curvatureImage, int[][] shadow ) {
    int rows = curvatureImage.getHeight();
    int cols = curvatureImage.getWidth();
    /*=====================*/

    int y, I, J;
    double zenith;

    /*======================*/

    if (beta != 0) {
        for( int i = quadrata; i >= 0; i-- ) {
            I = -1;
            J = -1;
            y = 0;
            for( int ii = i; ii < quadrata; ii++ ) {
                for( int j = cols - (int) floor(1 / tan(beta) * (ii - i)) - 1; j >= cols
                        - (int) floor(1 / tan(beta) * (ii - i + 1)) - 1
                        && j >= 0; j-- ) {
                    if (ii >= (rows + 2 * cols)
                            && !isNovalue(elevImageIterator.getSampleDouble(j, ii - (rows + 2 * cols), 0))) {
                        /*shadow->element[ii-(Z0->nrh+2*Z0->nch)][j]=i}}}}}*/
                        if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I == -1) {
                            I = ii - (rows + 2 * cols);
                            J = j;
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                    - (rows + 2 * cols), 0))
                                    / sqrt(Math.pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii - (rows + 2 * cols)][j] = 0;
                                I = ii - (rows + 2 * cols);
                                J = j;
                            } else {
                                shadow[ii - (rows + 2 * cols)][j] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                    - (rows + 2 * cols), 0))
                                    / sqrt(Math.pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii - (rows + 2 * cols)][j] = 0;
                                y = 0;
                            } else {
                                shadow[ii - (rows + 2 * cols)][j] = 1;
                            }
                        }
                    }
                }
            }
        }
    } else {
        for( int i = 0; i < rows; i++ ) {
            I = -1;
            J = -1;
            y = 0;
            for( int j = cols - 1; j >= 0; j-- ) {
                if (!isNovalue(elevImageIterator.getSampleDouble(j, i, 0))) {
                    if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I == -1) {
                        I = i;
                        J = j;
                        y = 1;
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I != -1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            I = i;
                            J = j;
                        } else {
                            shadow[i][j] = 1;
                        }
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 0 && y == 1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            y = 0;
                        } else {
                            shadow[i][j] = 1;
                        }
                    }
                }
            }
        }
    }

}
 
Example 19
Source File: MinCompositeDouble.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //log.debug("minX,minY,maxX,maxY: " + minX + "," + minY + "," + maxX + "," + maxY);
  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      double s = src.getSampleDouble(x, y, 0) * weight;

      double sample;

      if (isNodataNaN)
      {
        if (Double.isNaN(d))
        {
          sample = s;
        }
        else if (Double.isNaN(s))
        {
          sample = d;
        }
        else if (s < d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }
      else
      {
        if (FloatUtils.isEqual(d, nodata))
        {
          sample = s;
        }
        else if (FloatUtils.isEqual(s, nodata))
        {
          sample = d;
        }
        else if (s < d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 20
Source File: MiscCompositeContext.java    From scrimage with Apache License 2.0 4 votes vote down vote up
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
    float a = 0, ac = 0;
    float alpha = this.alpha;
    int t;

    int[] srcPix = null;
    int[] dstPix = null;

    int x = dstOut.getMinX();
    int w = dstOut.getWidth();

    int y0 = dstOut.getMinY();
    int y1 = y0 + dstOut.getHeight();

    for (int y = y0; y < y1; y++) {
        srcPix = src.getPixels(x, y, w, 1, srcPix);
        dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
        int i = 0;
        int end = w * 4;

        while (i < end) {
            int sr = srcPix[i];
            int dir = dstPix[i];
            int sg = srcPix[i + 1];
            int dig = dstPix[i + 1];
            int sb = srcPix[i + 2];
            int dib = dstPix[i + 2];
            int sa = srcPix[i + 3];
            int dia = dstPix[i + 3];
            int dor, dog, dob, doa;

            switch (rule) {
                case MiscComposite.ADD:
                default:
                    dor = dir + sr;
                    if (dor > 255)
                        dor = 255;
                    dog = dig + sg;
                    if (dog > 255)
                        dog = 255;
                    dob = dib + sb;
                    if (dob > 255)
                        dob = 255;
                    break;

                case MiscComposite.SUBTRACT:
                    dor = dir - sr;
                    if (dor < 0)
                        dor = 0;
                    dog = dig - sg;
                    if (dog < 0)
                        dog = 0;
                    dob = dib - sb;
                    if (dob < 0)
                        dob = 0;
                    break;

            }

            a = alpha * sa / 255f;
            ac = 1 - a;

            dstPix[i] = (int) (a * dor + ac * dir);
            dstPix[i + 1] = (int) (a * dog + ac * dig);
            dstPix[i + 2] = (int) (a * dob + ac * dib);
            dstPix[i + 3] = (int) (sa * alpha + dia * ac);
            i += 4;
        }
        dstOut.setPixels(x, y, w, 1, dstPix);

    }
}