BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0); BufferedImage heightMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); gscale.filter(sourceImage, heightMap);
ColorModel srcCM = src.getColorModel(); ColorModel dstCM; BufferedImage origDst = dst; src = icm.convertToIntDiscrete(src.getRaster(), false); srcCM = src.getColorModel(); } else { dstCM = dst.getColorModel(); if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType())
@Override public int getNumberOfComponents() { return awtColorSpace.getNumComponents(); }
@Override public void extract(BufferedImage bimg) { if (bimg.getColorModel().getColorSpace().getType() != ColorSpace.TYPE_RGB) { BufferedImage img = new BufferedImage(bimg.getWidth(), bimg.getHeight(), BufferedImage.TYPE_INT_RGB); img.getGraphics().drawImage(bimg, 0, 0, null); bimg = img; } transform = createTransformArray(); int newWidth = bimg.getWidth() - bimg.getWidth() % BLOCK_SIZE; int newHeight = bimg.getHeight() - bimg.getHeight() % BLOCK_SIZE; int[][][] yuvImage = getYUVImage(bimg.getRaster(), newWidth, newHeight, -128); descriptorValues = new int[BLOCK_SIZE * BLOCK_SIZE * 3]; getComponentHistogram(yuvImage, newWidth, newHeight, 0, descriptorValues); getComponentHistogram(yuvImage, newWidth, newHeight, 1, descriptorValues); getComponentHistogram(yuvImage, newWidth, newHeight, 2, descriptorValues); }
ColorModel srcCM = src.getColorModel(); ColorModel dstCM; BufferedImage origDst = dst; src = icm.convertToIntDiscrete(src.getRaster(), false); srcCM = src.getColorModel(); } else { dstCM = dst.getColorModel(); if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType())
static protected BufferedImage readRawThumbnail(final byte[] thumbnail, final int size, final int offset, int w, int h) { DataBufferByte buffer = new DataBufferByte(thumbnail, size, offset); WritableRaster raster; ColorModel cm; if (thumbnail.length == w * h) { raster = Raster.createInterleavedRaster(buffer, w, h, w, 1, new int[] {0}, null); cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); } else { raster = Raster.createInterleavedRaster(buffer, w, h, w * 3, 3, new int[] {0, 1, 2}, null); cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); } return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); }
@Test public void testExpandGrayCaseC() { // create gray indexed image BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_BYTE_GRAY); Graphics2D gr = bi.createGraphics(); gr.setColor(Color.GRAY); gr.fillRect(0, 0, 10, 10); gr.dispose(); // create a RGB color model final ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, bi.getSampleModel().getDataType()); // set the destination image layout final ImageLayout2 il = new ImageLayout2(bi); il.setColorModel(cm); il.setSampleModel(cm.createCompatibleSampleModel(bi.getWidth(), bi.getHeight())); RenderingHints ri = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il); // perform color expansion ParameterBlockJAI pbj = new ParameterBlockJAI("ColorConvert"); pbj.addSource(bi); pbj.setParameter("colorModel", cm); pbj.setParameter("noData", RangeFactory.create(-1, -1)); RenderedOp finalimage = JAI.create("ColorConvert", pbj, ri); int[] pixel = new int[3]; finalimage.getData().getPixel(0, 0, pixel); assertEquals(128, pixel[0]); assertEquals(128, pixel[1]); assertEquals(128, pixel[2]); }
@Override public void extract(BufferedImage image) { histogram = new double[18]; double[] directionality; ColorConvertOp op = new ColorConvertOp(image.getColorModel().getColorSpace(), ColorSpace.getInstance(ColorSpace.CS_GRAY), new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY)); BufferedImage bimg = op.filter(image, null); bimg = ImageUtils.scaleImage(bimg, MAX_IMG_HEIGHT); Raster raster = bimg.getRaster(); int[] tmp = new int[3]; this.grayScales = new int[raster.getWidth()][raster.getHeight()]; for (int i = 0; i < raster.getWidth(); i++) { for (int j = 0; j < raster.getHeight(); j++) { raster.getPixel(i, j, tmp); this.grayScales[i][j] = tmp[0]; } } imgWidth = bimg.getWidth(); imgHeight = bimg.getHeight(); histogram[0] = this.coarseness(bimg.getWidth(), bimg.getHeight()); histogram[1] = this.contrast(); directionality = this.directionality(); for (int i = 2; i < histogram.length; i++) { histogram[i] = directionality[i - 2]; } }
private static void assertSameData(BufferedImage expected, BufferedImage actual) { for (int y = 0; y < expected.getHeight(); y++) { for (int x = 0; x < expected.getWidth(); x++) { int expectedRGB = expected.getRGB(x, y); int actualRGB = actual.getRGB(x, y); if (expected.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_GRAY) { // NOTE: For some reason, gray data seems to be one step off... assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000, 0x10000); assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00, 0x100); assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff, 0x1); } else { assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000); assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00); assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff); } } } }
int w = raster.getWidth(); int h = raster.getHeight(); byte[] rgb = new byte[w * h * 3]; float[] Y = raster.getSamples(0, 0, w, h, 0, (float[]) null); float[] Cb = raster.getSamples(0, 0, w, h, 1, (float[]) null); float[] Cr = raster.getSamples(0, 0, w, h, 2, (float[]) null); null); ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); return new BufferedImage(cm, (WritableRaster) raster, true, null);
DataBuffer videoBuffer = new DataBufferByte(frame, frame.length); ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 3, width * 3, new int[] {0, 1, 2}); this.grid = Raster.createWritableRaster(sampleModel, videoBuffer, null); ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), null, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); this.image = new BufferedImage(colorModel, this.grid, false, null); } catch (final OutOfMemoryError e) { this.frame = null; try { this.image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED); } catch (final OutOfMemoryError ee) { try { this.image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY); } catch (final OutOfMemoryError eee) { this.image = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY);
out = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); }else if ( (rgb && alpha) || (luminance && alpha) ){ if (do16bit){ if (fullalpha){ ColorModel model = AWTLoader.AWT_RGBA4444; WritableRaster raster = model.createCompatibleWritableRaster(width, width); out = new BufferedImage(model, raster, false, null); }else{ ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {5, 5, 5, 1}; int[] bOffs = {0, 1, 2, 3}; ColorModel colorModel = new ComponentColorModel(cs, nBits, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width*2, 2, bOffs, null); out = new BufferedImage(colorModel, raster, false, null);
@Test public void testGetDestinationParamGoodDestinationTypeAlt() throws IIOException { ImageReadParam param = new ImageReadParam(); // In essence, this is the same as TYPE_INT_ARGB ImageTypeSpecifier type = ImageTypeSpecifier.createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB), 0xff0000, 0xff00, 0xff, 0xff000000, DataBuffer.TYPE_INT, false); param.setDestinationType(type); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7); assertEquals(BufferedImage.TYPE_INT_ARGB, destination.getType()); assertEquals(6, destination.getWidth()); assertEquals(7, destination.getHeight()); }
private PDImageXObject preparePredictorPDImage(ByteArrayOutputStream stream, int bitsPerComponent) throws IOException int h = image.getHeight(); int w = image.getWidth(); ColorSpace srcCspace = image.getColorModel().getColorSpace(); PDColorSpace pdColorSpace = srcCspace.getType() != ColorSpace.TYPE_CMYK ? PDDeviceRGB.INSTANCE : PDDeviceCMYK.INSTANCE; srcCspace.getNumComponents()); pdProfile.getPDStream().getCOSObject().setItem(COSName.ALTERNATE, srcCspace.getType() == ColorSpace.TYPE_CMYK ? COSName.DEVICECMYK : COSName.DEVICERGB); decodeParms.setItem(COSName.PREDICTOR, COSInteger.get(15)); decodeParms.setItem(COSName.COLUMNS, COSInteger.get(w)); decodeParms.setItem(COSName.COLORS, COSInteger.get(srcCspace.getNumComponents())); imageXObject.getCOSObject().setItem(COSName.DECODE_PARMS, decodeParms);
/** * Converts the decoded buffer into a BufferedImage. * precision: 16 bit, componentCount = 1 * * @param decoded data buffer * @param precision * @param width of the image * @param height of the image @return a BufferedImage.TYPE_USHORT_GRAY */ private BufferedImage to16Bit1ComponentGrayScale(int[][] decoded, int precision, int width, int height) { BufferedImage image; if (precision == 16) { image = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY); } else { ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {precision}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT); image = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(width, height), colorModel.isAlphaPremultiplied(), null); } short[] imageBuffer = ((DataBufferUShort) image.getRaster().getDataBuffer()).getData(); for (int i = 0; i < imageBuffer.length; i++) { imageBuffer[i] = (short) decoded[0][i]; } return image; }
BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB); ColorSpace destCS = dest.getColorModel().getColorSpace(); WritableRaster destRaster = dest.getRaster(); float[] srcValues = new float[4]; float[] lastValues = new float[] { -1.0f, -1.0f, -1.0f, -1.0f }; destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues)); for (int k = 0; k < destValues.length; k++)
ColorModel srcCM = src.getColorModel(); ColorModel dstCM; BufferedImage origDst = dst; src = icm.convertToIntDiscrete(src.getRaster(), false); srcCM = src.getColorModel(); dstCM = dst.getColorModel(); if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType())
@MethodHook(value = "<init>", end = true) @Inject public void init(int width, int height, Component canvas) { if (!client.isGpu()) { return; } final int[] pixels = getPixels(); // we need to make our own buffered image for the client with the alpha channel enabled in order to // have alphas for the overlays applied correctly DataBufferInt dataBufferInt = new DataBufferInt(pixels, pixels.length); DirectColorModel directColorModel = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32, 0xff0000, 0xff00, 0xff, 0xff000000, true, DataBuffer.TYPE_INT); WritableRaster writableRaster = Raster.createWritableRaster(directColorModel.createCompatibleSampleModel(width, height), dataBufferInt, null); BufferedImage bufferedImage = new BufferedImage(directColorModel, writableRaster, true, new Hashtable()); setImage(bufferedImage); }
new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); final BufferedImage image = new BufferedImage(cm, raster, false, null);
ColorSpace cs = new ICC_ColorSpace(profile); int bands = cs.getNumComponents() + (pAlpha ? 1 : 0); new ComponentColorModel(cs, bits, true, true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE) : new ComponentColorModel(cs, bits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Raster.createInterleavedRaster(buffer, size.width, size.height, size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT); return new BufferedImage(cm, raster, pAlpha, null);