List of usage examples for java.awt.image WritableRaster setPixel
public void setPixel(int x, int y, double[] dArray)
From source file:org.photovault.dcraw.DCRawReaderOp.java
@Override protected void computeRect(PlanarImage[] srcs, WritableRaster dst, Rectangle area) { log.debug("entry: computeRect " + area); checkDataUnpacked();/*from w ww . j a va 2 s . c o m*/ int[] intVals = new int[1]; for (int row = (int) area.getMinY(); row < area.getMaxY(); row++) { int py = row / 2; for (int col = (int) area.getMinX(); col < area.getMaxX(); col++) { int px = col / 2; int color = fc(row, col); intVals[0] = lrd.image.getChar(8 * (py * lrd.sizes.iwidth + px) + 2 * color) - black; if (intVals[0] < 0) intVals[0] = 0; dst.setPixel(col, row, intVals); } } log.debug("exit: computeRect" + area); }
From source file:Snippet156.java
static BufferedImage convertToAWT(ImageData data) { ColorModel colorModel = null; PaletteData palette = data.palette;/*from w w w . j av a 2s . c om*/ if (palette.isDirect) { colorModel = new DirectColorModel(data.depth, palette.redMask, palette.greenMask, palette.blueMask); BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[3]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { int pixel = data.getPixel(x, y); RGB rgb = palette.getRGB(pixel); pixelArray[0] = rgb.red; pixelArray[1] = rgb.green; pixelArray[2] = rgb.blue; raster.setPixels(x, y, 1, 1, pixelArray); } } return bufferedImage; } else { RGB[] rgbs = palette.getRGBs(); byte[] red = new byte[rgbs.length]; byte[] green = new byte[rgbs.length]; byte[] blue = new byte[rgbs.length]; for (int i = 0; i < rgbs.length; i++) { RGB rgb = rgbs[i]; red[i] = (byte) rgb.red; green[i] = (byte) rgb.green; blue[i] = (byte) rgb.blue; } if (data.transparentPixel != -1) { colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue, data.transparentPixel); } else { colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue); } BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[1]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { int pixel = data.getPixel(x, y); pixelArray[0] = pixel; raster.setPixel(x, y, pixelArray); } } return bufferedImage; } }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
protected void noiseEffects(Graphics2D gfx, BufferedImage image) { // XOR circle int dx = randomInt(width, 2 * width); int dy = randomInt(width, 2 * height); int x = randomInt(0, width / 2); int y = randomInt(0, height / 2); gfx.setXORMode(Color.GRAY);//from w w w .j a v a2 s .c o m if (config.isFontSizeRandom()) gfx.setStroke(new BasicStroke(randomInt(config.getFontSize() / 8, config.getFontSize() / 2))); else gfx.setStroke(new BasicStroke(config.getFontSize())); gfx.drawOval(x, y, dx, dy); WritableRaster rstr = image.getRaster(); int[] vColor = new int[3]; int[] oldColor = new int[3]; Random vRandom = new Random(System.currentTimeMillis()); // noise for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { rstr.getPixel(x, y, oldColor); // hard noise vColor[0] = 0 + (int) (Math.floor(vRandom.nextFloat() * 1.03) * 255); // soft noise vColor[0] = vColor[0] ^ (170 + (int) (vRandom.nextFloat() * 80)); // xor to image vColor[0] = vColor[0] ^ oldColor[0]; vColor[1] = vColor[0]; vColor[2] = vColor[0]; rstr.setPixel(x, y, vColor); } } }
From source file:org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.java
private BufferedImage applyMask(BufferedImage image, BufferedImage mask, boolean isSoft) throws IOException { if (mask == null) { return image; }/*from ww w . j a va 2 s . c o m*/ int width = image.getWidth(); int height = image.getHeight(); // scale mask to fit image, or image to fit mask, whichever is larger if (mask.getWidth() < width || mask.getHeight() < height) { mask = scaleImage(mask, width, height); } else if (mask.getWidth() > width || mask.getHeight() > height) { width = mask.getWidth(); height = mask.getHeight(); image = scaleImage(image, width, height); } // compose to ARGB BufferedImage masked = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); WritableRaster src = image.getRaster(); WritableRaster dest = masked.getRaster(); WritableRaster alpha = mask.getRaster(); float[] rgb = new float[4]; float[] rgba = new float[4]; float[] alphaPixel = null; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { src.getPixel(x, y, rgb); rgba[0] = rgb[0]; rgba[1] = rgb[1]; rgba[2] = rgb[2]; alphaPixel = alpha.getPixel(x, y, alphaPixel); if (isSoft) { rgba[3] = alphaPixel[0]; } else { rgba[3] = 255 - alphaPixel[0]; } dest.setPixel(x, y, rgba); } } return masked; }
From source file:org.sejda.sambox.pdmodel.graphics.image.PDImageXObject.java
private BufferedImage applyMask(BufferedImage image, BufferedImage mask, boolean isSoft) { if (mask == null) { return image; }//from ww w.j a va2 s .co m int width = image.getWidth(); int height = image.getHeight(); // scale mask to fit image, or image to fit mask, whichever is larger if (mask.getWidth() < width || mask.getHeight() < height) { mask = scaleImage(mask, width, height); } else if (mask.getWidth() > width || mask.getHeight() > height) { width = mask.getWidth(); height = mask.getHeight(); image = scaleImage(image, width, height); } // compose to ARGB BufferedImage masked = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); WritableRaster src = image.getRaster(); WritableRaster dest = masked.getRaster(); WritableRaster alpha = mask.getRaster(); float[] rgb = new float[4]; float[] rgba = new float[4]; float[] alphaPixel = null; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { src.getPixel(x, y, rgb); rgba[0] = rgb[0]; rgba[1] = rgb[1]; rgba[2] = rgb[2]; alphaPixel = alpha.getPixel(x, y, alphaPixel); if (isSoft) { rgba[3] = alphaPixel[0]; } else { rgba[3] = 255 - alphaPixel[0]; } dest.setPixel(x, y, rgba); } } return masked; }
From source file:org.photovault.dcraw.AHDInterpolateOp.java
/** * Compute a rectangle of destination image by downsampling original * @param img Array of soruce images (containing just one image in this case * @param dst Raster for the results/* www. ja v a 2s .c o m*/ * @param area Area of dst that needs to be computed */ private void computeDownsample(PlanarImage[] img, WritableRaster dst, Rectangle area) { log.debug("entry: computeDownsample " + area); long entryTime = System.currentTimeMillis(); // Current line of image int rgb[][] = new int[(int) area.getWidth()][3]; int sampleCount[][] = new int[(int) area.getWidth()][3]; Rectangle srcArea = mapDestRect(area, 0); int srcMinx = (int) srcArea.getMinX(); int srcMaxx = (int) srcArea.getMaxX(); int srcMiny = (int) srcArea.getMinY(); int srcMaxy = (int) srcArea.getMaxY(); int dstY = (int) area.getMinY(); int dstMinx = (int) area.getMinX(); int sampleY = 0; RandomIter riter = RandomIterFactory.create(img[0], srcArea); for (int y = srcMiny; y < srcMaxy; y++) { int sampleX = 0; int dstX = 0; for (int x = srcMinx; x < srcMaxx; x++) { int val = riter.getSample(x, y, 0); int color = fc(y, x); color = (color == 3) ? 1 : color; rgb[dstX][color] += val; sampleCount[dstX][color]++; sampleX++; if (sampleX >= downSample) { dstX++; sampleX = 0; } } sampleY++; if (sampleY >= downSample) { for (int x = 0; x < rgb.length; x++) { for (int c = 0; c < 3; c++) { int count = sampleCount[x][c]; if (count == 0) { throw new IllegalStateException("zero samples for color component"); } rgb[x][c] /= count; rgb[x][c] = (int) (rgb[x][c] * mult[c]); } dst.setPixel(dstMinx + x, dstY, rgb[x]); } for (int x = 0; x < rgb.length; x++) { for (int c = 0; c < 3; c++) { rgb[x][c] = 0; sampleCount[x][c] = 0; } } sampleY = 0; dstY++; } } long dur = System.currentTimeMillis() - entryTime; log.debug("exit: computeDownsample in " + dur + "ms"); }
From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java
private void processPixels(final int process, final Raster src, final WritableRaster dst, final int xOffset, final int step, final int y, final int width) { int srcX, dstX; // Create an array suitable for holding one pixel final int[] ps = src.getPixel(0, 0, (int[]) null); final int[] pd = dst.getPixel(0, 0, (int[]) null); dstX = xOffset;// w ww . j a v a 2 s. co m switch (process) { case POST_NONE: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); dst.setPixel(dstX, y, ps); dstX += step; } break; case POST_GAMMA: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); for (int i = 0; i < this.inputBands; ++i) { final int x = ps[i]; ps[i] = this.gammaLut[x]; } dst.setPixel(dstX, y, ps); dstX += step; } break; case POST_GRAY_LUT: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); pd[0] = this.grayLut[ps[0]]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_LUT_ADD_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.grayLut[val]; if (val == this.grayTransparentAlpha) { pd[1] = 0; } else { pd[1] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_PALETTE_TO_RGB: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.redPalette[val]; pd[1] = this.greenPalette[val]; pd[2] = this.bluePalette[val]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_PALETTE_TO_RGBA: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.redPalette[val]; pd[1] = this.greenPalette[val]; pd[2] = this.bluePalette[val]; pd[3] = this.alphaPalette[val]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_GRAY_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); int val = ps[0]; if (this.performGammaCorrection) { val = this.gammaLut[val]; } pd[0] = val; if (val == this.grayTransparentAlpha) { pd[1] = 0; } else { pd[1] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_RGB_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int r = ps[0]; final int g = ps[1]; final int b = ps[2]; if (this.performGammaCorrection) { pd[0] = this.gammaLut[r]; pd[1] = this.gammaLut[g]; pd[2] = this.gammaLut[b]; } else { pd[0] = r; pd[1] = g; pd[2] = b; } if (r == this.redTransparentAlpha && g == this.greenTransparentAlpha && b == this.blueTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_REMOVE_GRAY_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int g = ps[0]; if (this.performGammaCorrection) { pd[0] = this.gammaLut[g]; } else { pd[0] = g; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_REMOVE_RGB_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int r = ps[0]; final int g = ps[1]; final int b = ps[2]; if (this.performGammaCorrection) { pd[0] = this.gammaLut[r]; pd[1] = this.gammaLut[g]; pd[2] = this.gammaLut[b]; } else { pd[0] = r; pd[1] = g; pd[2] = b; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GAMMA_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int alpha = ps[1]; final int gamma = this.gammaLut[val]; pd[0] = gamma; pd[1] = gamma; pd[2] = gamma; pd[3] = alpha; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_ALPHA_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int alpha = ps[1]; pd[0] = val; pd[1] = val; pd[2] = val; pd[3] = alpha; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_GRAY_TRANS_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); int val = ps[0]; if (this.performGammaCorrection) { val = this.gammaLut[val]; } pd[0] = val; pd[1] = val; pd[2] = val; if (val == this.grayTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_LUT_ADD_TRANS_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int val2 = this.grayLut[val]; pd[0] = val2; pd[1] = val2; pd[2] = val2; if (val == this.grayTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; } }
From source file:org.apache.xmlgraphics.image.codec.png.PNGRed.java
private void processPixels(final int process, final Raster src, final WritableRaster dst, final int xOffset, final int step, final int y, final int width) { int srcX, dstX; // Create an array suitable for holding one pixel final int[] ps = src.getPixel(0, 0, (int[]) null); final int[] pd = dst.getPixel(0, 0, (int[]) null); dstX = xOffset;/*from www . j ava 2 s . c o m*/ switch (process) { case POST_NONE: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); dst.setPixel(dstX, y, ps); dstX += step; } break; case POST_GAMMA: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); for (int i = 0; i < this.inputBands; ++i) { final int x = ps[i]; ps[i] = this.gammaLut[x]; } dst.setPixel(dstX, y, ps); dstX += step; } break; case POST_GRAY_LUT: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); pd[0] = this.grayLut[ps[0]]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_LUT_ADD_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.grayLut[val]; if (val == this.grayTransparentAlpha) { pd[1] = 0; } else { pd[1] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_PALETTE_TO_RGB: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.redPalette[val]; pd[1] = this.greenPalette[val]; pd[2] = this.bluePalette[val]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_PALETTE_TO_RGBA: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; pd[0] = this.redPalette[val]; pd[1] = this.greenPalette[val]; pd[2] = this.bluePalette[val]; pd[3] = this.alphaPalette[val]; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_GRAY_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); int val = ps[0]; if (this.performGammaCorrection) { val = this.gammaLut[val]; } pd[0] = val; if (val == this.grayTransparentAlpha) { pd[1] = 0; } else { pd[1] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_RGB_TRANS: final boolean flagGammaCorrection = this.performGammaCorrection; // local // is // cheaper final int[] workGammaLut = this.gammaLut; for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int r = ps[0]; final int g = ps[1]; final int b = ps[2]; if (flagGammaCorrection) { pd[0] = workGammaLut[r]; pd[1] = workGammaLut[g]; pd[2] = workGammaLut[b]; } else { pd[0] = r; pd[1] = g; pd[2] = b; } if (r == this.redTransparentAlpha && g == this.greenTransparentAlpha && b == this.blueTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_REMOVE_GRAY_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int g = ps[0]; if (this.performGammaCorrection) { pd[0] = this.gammaLut[g]; } else { pd[0] = g; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_REMOVE_RGB_TRANS: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int r = ps[0]; final int g = ps[1]; final int b = ps[2]; if (this.performGammaCorrection) { pd[0] = this.gammaLut[r]; pd[1] = this.gammaLut[g]; pd[2] = this.gammaLut[b]; } else { pd[0] = r; pd[1] = g; pd[2] = b; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GAMMA_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int alpha = ps[1]; final int gamma = this.gammaLut[val]; pd[0] = gamma; pd[1] = gamma; pd[2] = gamma; pd[3] = alpha; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_ALPHA_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int alpha = ps[1]; pd[0] = val; pd[1] = val; pd[2] = val; pd[3] = alpha; dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_ADD_GRAY_TRANS_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); int val = ps[0]; if (this.performGammaCorrection) { val = this.gammaLut[val]; } pd[0] = val; pd[1] = val; pd[2] = val; if (val == this.grayTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; case POST_GRAY_LUT_ADD_TRANS_EXP: for (srcX = 0; srcX < width; srcX++) { src.getPixel(srcX, 0, ps); final int val = ps[0]; final int val2 = this.grayLut[val]; pd[0] = val2; pd[1] = val2; pd[2] = val2; if (val == this.grayTransparentAlpha) { pd[3] = 0; } else { pd[3] = this.maxOpacity; } dst.setPixel(dstX, y, pd); dstX += step; } break; } }
From source file:org.openmrs.api.ObsServiceTest.java
/** * @throws IOException//from w w w . ja v a 2s . c om * @see ObsService#getComplexObs(Integer,String) */ @Test public void getComplexObs_shouldNotFailWithNullView() throws IOException { executeDataSet(COMPLEX_OBS_XML); // create gif file // make sure the file isn't there to begin with AdministrationService as = Context.getAdministrationService(); File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory( as.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); File createdFile = new File(complexObsDir, "openmrs_logo_small.gif"); if (createdFile.exists()) createdFile.delete(); int width = 10; int height = 10; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); int[] colorArray = new int[3]; int h = 255; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (i == 0 || j == 0 || i == width - 1 || j == height - 1 || (i > width / 3 && i < 2 * width / 3) && (j > height / 3 && j < 2 * height / 3)) { colorArray[0] = h; colorArray[1] = h; colorArray[2] = 0; } else { colorArray[0] = 0; colorArray[1] = 0; colorArray[2] = h; } raster.setPixel(i, j, colorArray); } } ImageIO.write(image, "gif", createdFile); // end create gif file ObsService os = Context.getObsService(); os.getComplexObs(44, null); // delete gif file // we always have to delete this inside the same unit test because it is // outside the // database and hence can't be "rolled back" like everything else createdFile.delete(); }
From source file:org.openmrs.api.ObsServiceTest.java
/** * @throws IOException//from w w w . j av a2s . c om * @see ObsService#getComplexObs(Integer,String) */ @Test public void getComplexObs_shouldFillInComplexDataObjectForComplexObs() throws IOException { executeDataSet(COMPLEX_OBS_XML); // create gif file // make sure the file isn't there to begin with AdministrationService as = Context.getAdministrationService(); File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory( as.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); File createdFile = new File(complexObsDir, "openmrs_logo_small.gif"); if (createdFile.exists()) createdFile.delete(); int width = 10; int height = 10; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); int[] colorArray = new int[3]; int h = 255; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (i == 0 || j == 0 || i == width - 1 || j == height - 1 || (i > width / 3 && i < 2 * width / 3) && (j > height / 3 && j < 2 * height / 3)) { colorArray[0] = h; colorArray[1] = h; colorArray[2] = 0; } else { colorArray[0] = 0; colorArray[1] = 0; colorArray[2] = h; } raster.setPixel(i, j, colorArray); } } ImageIO.write(image, "gif", createdFile); // end create gif file ObsService os = Context.getObsService(); Obs complexObs = os.getComplexObs(44, ComplexObsHandler.RAW_VIEW); Assert.assertNotNull(complexObs); Assert.assertTrue(complexObs.isComplex()); Assert.assertNotNull(complexObs.getValueComplex()); Assert.assertNotNull(complexObs.getComplexData()); // delete gif file // we always have to delete this inside the same unit test because it is // outside the // database and hence can't be "rolled back" like everything else createdFile.delete(); }