Java Code Examples for java.awt.image.Raster#getPixels()

The following examples show how to use java.awt.image.Raster#getPixels() . 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: TissueFeaturesPlain.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public double[] buildFeatures(final Raster r, final int x, final int y, final double classVal) throws OrbitImageServletException {
    if (r != null)  // faster if raster is pre-assigned (e.g. the shape fits into memory)
    {
        buf = r.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        //p = r.getPixel(x, y, p); // mid-pixel
    } else { // slower, but works for very large shapes
        Raster r2 = bimg.getData(new Rectangle(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1), featureDescription);
        if (r2 == null) System.out.println("r2 is null!!");
        buf = r2.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        //p = r2.getPixel(x, y, p);
    }

    double[] feats = prepareDoubleArray();
    for (int i = 0; i < buf.length; i++) {
        feats[i] = buf[i];
    }
    feats[feats.length - 1] = classVal;
    //logger.trace(Arrays.toString(feats));
    return feats;
}
 
Example 2
Source File: DCTFilter.java    From sambox with Apache License 2.0 6 votes vote down vote up
private WritableRaster fromBGRtoRGB(Raster raster)
{
    WritableRaster writableRaster = raster.createCompatibleWritableRaster();

    int width = raster.getWidth();
    int height = raster.getHeight();
    int w3 = width * 3;
    int[] tab = new int[w3];
    // BEWARE: handling the full image at a time is slower than one line at a time
    for (int y = 0; y < height; y++)
    {
        raster.getPixels(0, y, width, 1, tab);
        for (int off = 0; off < w3; off += 3)
        {
            int tmp = tab[off];
            tab[off] = tab[off + 2];
            tab[off + 2] = tmp;
        }
        writableRaster.setPixels(0, y, width, 1, tab);
    }
    return writableRaster;
}
 
Example 3
Source File: RGBComposite.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
@Override
        public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
            float alpha = this.alpha;

            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 srclength = srcPix.length;
//                int dstlength = dstPix.length;
//                if(srclength > dstlength) {
//                    continue;
//                }
                // System.out.println("RGBComposite$RGBCompositeContext.compose dstlength = " + dstlength + ", srclength = " + srclength);
                composeRGB(srcPix, dstPix, alpha);
                dstOut.setPixels(x, y, w, 1, dstPix);
            }
        }
 
Example 4
Source File: DLSegment.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private static Raster flipRaster(Raster r) {
    int w = r.getWidth();
    int h = r.getHeight();
    WritableRaster rf = r.createCompatibleWritableRaster(r.getMinX(),r.getMinY(), w,h);
    int[] p = new int[w*3];
    for (int y=r.getMinY(); y<r.getMinY()+h; y++) {
        p = r.getPixels(r.getMinX(),y,w,1,p);
        rf.setPixels(r.getMinX(),r.getMinY()+h-(y-r.getMinY())-1,w,1,p);
    }
    return rf;
}
 
Example 5
Source File: TissueFeaturesOld.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private double[] buildIntensFeatures(final Raster r, final int x, final int y, final double classVal) throws OrbitImageServletException {
    // init
    for (int i = 0; i < samples; i++) {
        mean[i] = 0d;
    }
    if (r != null)  // faster if raster is pre-assigned (e.g. the shape fits into memory)
    {
        buf = r.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        p = r.getPixel(x, y, p); // mid-pixel
    } else { // slower, but works for very large shapes
        Raster r2 = bimg.getData(new Rectangle(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1), featureDescription);
        if (r2 == null) System.out.println("r2 is null!!");
        buf = r2.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        p = r2.getPixel(x, y, p);
    }

    for (int i = 0; i < samples; i++) {
        mean[0] += p[i];
    }
    mean[0] /= (double) samples;
    double[] feats = new double[featuresPerSample * samples + 1];
    for (int i = 0; i < samples; i++) {
        if ((i == 0) && (featureDescription.isSkipRed())) continue;
        if ((i == 1) && (featureDescription.isSkipGreen())) continue;
        if ((i == 2) && (featureDescription.isSkipBlue())) continue;
        feats[(samples * 0) + i] = mean[i];
    }
    feats[feats.length - 1] = classVal;
    //logger.trace(Arrays.toString(feats));
    return feats;
}
 
Example 6
Source File: TissueFeatures.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private double[] buildIntensFeatures(final Raster r, final int x, final int y, final double classVal) throws OrbitImageServletException {
    // init
    for (int i = 0; i < samples; i++) {
        mean[i] = 0d;
    }
    if (r != null)  // faster if raster is pre-assigned (e.g. the shape fits into memory)
    {
        buf = r.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        p = r.getPixel(x, y, p); // mid-pixel
    } else { // slower, but works for very large shapes
        Raster r2 = bimg.getData(new Rectangle(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1), featureDescription);
        if (r2 == null) System.out.println("r2 is null!!");
        buf = r2.getPixels(x - windowSize, y - windowSize, (windowSize * 2) + 1, (windowSize * 2) + 1, buf);
        p = r2.getPixel(x, y, p);
    }

    for (int i = 0; i < samples; i++) {
        mean[0] += p[i];
    }
    mean[0] /= (double) samples;
    double[] feats = new double[featuresPerSample * samples + 1];
    for (int i = 0; i < samples; i++) {
        if ((i == 0) && (featureDescription.isSkipRed())) continue;
        if ((i == 1) && (featureDescription.isSkipGreen())) continue;
        if ((i == 2) && (featureDescription.isSkipBlue())) continue;
        feats[(samples * 0) + i] = mean[i];
    }
    feats[feats.length - 1] = classVal;
    //logger.trace(Arrays.toString(feats));
    return feats;
}
 
Example 7
Source File: ImageUtils.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Compose src onto dst using the alpha of sel to interpolate between the two.
 * I can't think of a way to do this using AlphaComposite.
    * @param src the source raster
    * @param dst the destination raster
    * @param sel the mask raster
 */
public static void composeThroughMask(Raster src, WritableRaster dst, Raster sel) {
	int x = src.getMinX();
	int y = src.getMinY();
	int w = src.getWidth();
	int h = src.getHeight();

	int srcRGB[] = null;
	int selRGB[] = null;
	int dstRGB[] = null;

	for ( int i = 0; i < h; i++ ) {
		srcRGB = src.getPixels(x, y, w, 1, srcRGB);
		selRGB = sel.getPixels(x, y, w, 1, selRGB);
		dstRGB = dst.getPixels(x, y, w, 1, dstRGB);

		int k = x;
		for ( int j = 0; j < w; j++ ) {
			int sr = srcRGB[k];
			int dir = dstRGB[k];
			int sg = srcRGB[k+1];
			int dig = dstRGB[k+1];
			int sb = srcRGB[k+2];
			int dib = dstRGB[k+2];
			int sa = srcRGB[k+3];
			int dia = dstRGB[k+3];

			float a = selRGB[k+3]/255f;
			float ac = 1-a;

			dstRGB[k] = (int)(a*sr + ac*dir); 
			dstRGB[k+1] = (int)(a*sg + ac*dig); 
			dstRGB[k+2] = (int)(a*sb + ac*dib); 
			dstRGB[k+3] = (int)(a*sa + ac*dia);
			k += 4;
		}

		dst.setPixels(x, y, w, 1, dstRGB);
		y++;
	}
}
 
Example 8
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 9
Source File: JPEGImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 10
Source File: GradientColorFilter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void apply(Diagram d) {
    boolean logarithmic = mode.equalsIgnoreCase(LOGARITHMIC);
    if (!logarithmic && !mode.equalsIgnoreCase(LINEAR)) {
        throw new RuntimeException("Unknown mode: " + mode);
    }

    Rectangle bounds = new Rectangle(shadeCount, 1);
    LinearGradientPaint lgp = new LinearGradientPaint(bounds.x, bounds.y, bounds.width, bounds.y, fractions, colors);
    PaintContext context = lgp.createContext(null, bounds, bounds.getBounds2D(), AffineTransform.getTranslateInstance(0, 0), new RenderingHints(null));
    Raster raster = context.getRaster(bounds.x, bounds.y, bounds.width, bounds.height);
    int[] rgb = raster.getPixels(bounds.x, bounds.y, bounds.width, bounds.height, (int[]) null);
    Color[] shades = new Color[rgb.length / 3];
    for (int i = 0; i < shades.length; ++i) {
        shades[i] = new Color(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]);
    }

    List<Figure> figures = d.getFigures();
    for (Figure f : figures) {
        String property = f.getProperties().get(propertyName);
        if (property != null) {
            try {
                float value = Float.parseFloat(property);

                Color nodeColor;
                if (value <= minValue) {
                    nodeColor = colors[0];
                } else if (value >= maxValue) {
                    nodeColor = colors[colors.length - 1];
                } else {
                    double normalized = value - minValue;
                    double interval = maxValue - minValue;
                    int index;
                    // Use Math.ceil() to make values above zero distinguishable from zero
                    if (logarithmic) {
                        index = (int) Math.ceil(shades.length * Math.log(1 + normalized) / Math.log(1 + interval));
                    } else {
                        index = (int) Math.ceil(shades.length * normalized / interval);
                    }
                    nodeColor = shades[index];
                }
                f.setColor(nodeColor);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 11
Source File: JPEGImageWriter.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 12
Source File: JPEGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 13
Source File: DefaultIterator.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the transfer between the underlying raster and this window.
 */
@Override
Object getPixels(Raster raster, int subX, int subY, int subWidth, int subHeight, boolean direct) {
    return raster.getPixels(subX, subY, subWidth, subHeight, direct ? data : transfer);
}
 
Example 14
Source File: JPEGImageWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 15
Source File: JPEGImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 16
Source File: JPEGImageWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 17
Source File: JPEGImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
Example 18
Source File: DefaultIterator.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the transfer between the underlying raster and this window.
 */
@Override
Object getPixels(Raster raster, int subX, int subY, int subWidth, int subHeight, boolean direct) {
    return raster.getPixels(subX, subY, subWidth, subHeight, direct ? data : transfer);
}
 
Example 19
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);

    }
}
 
Example 20
Source File: JPEGImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}