Java Code Examples for java.awt.image.Raster#createCompatibleWritableRaster()
The following examples show how to use
java.awt.image.Raster#createCompatibleWritableRaster() .
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: TexturePaintContext.java From hottub with GNU General Public License v2.0 | 6 votes |
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 2
Source File: PixelatedImageSectionFilter.java From cognitivej with Apache License 2.0 | 6 votes |
@NotNull @Override public BufferedImage applyFilter(@NotNull BufferedImage bufferedImage) { Raster src = bufferedImage.getData(); WritableRaster dest = src.createCompatibleWritableRaster(); bufferedImage.copyData(dest); for (int y = pixelateSection.y; y < pixelateSection.y + pixelateSection.getHeight(); y += PIX_SIZE) { for (int x = pixelateSection.x; x < pixelateSection.x + pixelateSection.getWidth(); x += PIX_SIZE) { double[] pixel = new double[3]; pixel = src.getPixel(x, y, pixel); for (int yd = y; (yd < y + PIX_SIZE) && (yd < dest.getHeight()); yd++) { for (int xd = x; (xd < x + PIX_SIZE) && (xd < dest.getWidth()); xd++) { dest.setPixel(xd, yd, pixel); } } } } bufferedImage.setData(dest); return bufferedImage; }
Example 3
Source File: TexturePaintContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static synchronized 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 4
Source File: TexturePaintContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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 openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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: TexturePaintContext.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 7
Source File: TexturePaintContext.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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 8
Source File: TexturePaintContext.java From jdk-1.7-annotated with Apache License 2.0 | 6 votes |
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 9
Source File: TexturePaintContext.java From JDKSourceCode1.8 with MIT License | 6 votes |
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 10
Source File: TexturePaintContext.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 11
Source File: TexturePaintContext.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 12
Source File: TexturePaintContext.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 13
Source File: DCTFilter.java From gcs with Mozilla Public License 2.0 | 5 votes |
private WritableRaster fromYCCKtoCMYK(Raster raster) { WritableRaster writableRaster = raster.createCompatibleWritableRaster(); int[] value = new int[4]; for (int y = 0, height = raster.getHeight(); y < height; y++) { for (int x = 0, width = raster.getWidth(); x < width; x++) { raster.getPixel(x, y, value); // 4-channels 0..255 float Y = value[0]; float Cb = value[1]; float Cr = value[2]; float K = value[3]; // YCCK to RGB, see http://software.intel.com/en-us/node/442744 int r = clamp(Y + 1.402f * Cr - 179.456f); int g = clamp(Y - 0.34414f * Cb - 0.71414f * Cr + 135.45984f); int b = clamp(Y + 1.772f * Cb - 226.816f); // naive RGB to CMYK int cyan = 255 - r; int magenta = 255 - g; int yellow = 255 - b; // update new raster value[0] = cyan; value[1] = magenta; value[2] = yellow; value[3] = (int)K; writableRaster.setPixel(x, y, value); } } return writableRaster; }
Example 14
Source File: DLSegment.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
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 15
Source File: JPEGImageWriter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * 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 hottub with GNU General Public License v2.0 | 4 votes |
/** * 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 openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * 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: JPEGImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 19
Source File: JPEGImageWriter.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * 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 20
Source File: JPEGImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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(); } } }