private ColorModel getColorModelWithAlpha(int currentBandCount) { if (currentBandCount == 3) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8, 8}; return new ComponentColorModel( cs, nBits, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); } else if (currentBandCount == 1) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); int[] nBits = {8, 8}; return new ComponentColorModel( cs, nBits, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); } else { throw new IllegalArgumentException( "Cannot create a color model with alpha" + "support starting with " + currentBandCount + " bands"); } }
/** * Call the ICC_ColorSpace.getType method and return the value. * * @return the color space type. */ public int getColorSpaceType() { return colorSpace.getType(); }
cmykProfile = ICC_Profile.getInstance(JpegReader.class.getResourceAsStream("/ISOcoated_v2_300_eci.icc")); if (cmykProfile.getProfileClass() != ICC_Profile.CLASS_DISPLAY) { byte[] profileData = cmykProfile.getData();
/** * 彩色转为黑白 * * @return this */ public Img gray() { final ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); this.targetImage = op.filter(getValidSrcImg(), null); return this; }
/** * Return true if the ColourSpace is Gray scale * * @return true if the ColourSpace is gray scale. */ public boolean isGrayColorSpace() { return ICC_ColorSpace.TYPE_GRAY == colorSpace.getType(); }
/** * 彩色转为黑白 * * @return this */ public Img gray() { final ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); this.targetImage = op.filter(getValidSrcImg(), null); return this; }
@Override public ColorModel createColorModel( SampleModel sampleModel, List sources, Map configuration) { final int dataType = sampleModel.getDataType(); final int numBands = sampleModel.getNumBands(); ColorSpace cs; switch (numBands) { case 1: case 2: cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); break; case 3: cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); break; default: cs = new BogusColorSpace(numBands); } return RasterFactory.createComponentColorModel( dataType, cs, false, false, Transparency.OPAQUE); } });
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 method converts the given texture into black and whit (grayscale) texture. * * @param source * the source texture * @return grayscale texture */ public static Image convertToGrayscaleTexture(Image source) { BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0); ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); op.filter(sourceImage, sourceImage); return ImageUtils.toJmeImage(sourceImage, source.getFormat()); }
null); ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, false,
ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); gscale.filter(sourceImage, heightMap);
@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); }
}else{ ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {5, 5, 5, 1}; int[] bOffs = {0, 1, 2, 3};