/**
* Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.
*
* @param raster the source raster
* @param colorSpace the AWT
* @return an (A)RGB buffered image
*/
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
//
// WARNING: this method is performance sensitive, modify with care!
//
// ICC Profile color transforms are only fast when performed using ColorConvertOp
ColorModel colorModel = new ComponentColorModel(colorSpace, false, false,
Transparency.OPAQUE, raster.getDataBuffer().getDataType());
BufferedImage src = new BufferedImage(colorModel, raster, false, null);
BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
BufferedImage.TYPE_INT_RGB);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, dest);
return dest;
}
java类java.awt.image.ComponentColorModel的实例源码
PDColorSpace.java 文件源码
项目:sambox
阅读 19
收藏 0
点赞 0
评论 0
ImageTypeSpecifier.java 文件源码
项目:jdk8u-dev-jdk
阅读 20
收藏 0
点赞 0
评论 0
static ColorModel createComponentCM(ColorSpace colorSpace,
int numBands,
int dataType,
boolean hasAlpha,
boolean isAlphaPremultiplied) {
int transparency =
hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
int[] numBits = new int[numBands];
int bits = DataBuffer.getDataTypeSize(dataType);
for (int i = 0; i < numBands; i++) {
numBits[i] = bits;
}
return new ComponentColorModel(colorSpace,
numBits,
hasAlpha,
isAlphaPremultiplied,
transparency,
dataType);
}
GraphicsUtilsTest.java 文件源码
项目:vectorgraphics2d
阅读 31
收藏 0
点赞 0
评论 0
@Test
public void getAlphaImageReturnsWhiteImageForOpaqueInputWithBitmaskAlpha() {
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel = new ComponentColorModel(
colorSpace, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(
DataBuffer.TYPE_BYTE, TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH, 4, null);
BufferedImage image = new BufferedImage(
colorModel, raster, colorModel.isAlphaPremultiplied(), null);
Graphics g = image.getGraphics();
g.setColor(Color.RED);
g.fillRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
BufferedImage result = GraphicsUtils.getAlphaImage(image);
assertBufferedImageContentEquals(whiteGrayscaleImage, result);
}
ThumbnailResource.java 文件源码
项目:pixymeta
阅读 20
收藏 0
点赞 0
评论 0
private void setThumbnailImage(ImageResourceID id, int dataType, int width, int height, int totalSize, byte[] thumbnailData) {
// JFIF data in RGB format. For resource ID 1033 (0x0409) the data is in BGR format.
if(dataType == Thumbnail.DATA_TYPE_KJpegRGB) {
thumbnail.setImage(width, height, dataType, thumbnailData);
} else if(dataType == Thumbnail.DATA_TYPE_KRawRGB) {
// kRawRGB - NOT tested yet!
//Create a BufferedImage
DataBuffer db = new DataBufferByte(thumbnailData, totalSize);
int[] off = {0, 1, 2};//RGB band offset, we have 3 bands
if(id == ImageResourceID.THUMBNAIL_RESOURCE_PS4)
off = new int[]{2, 1, 0}; // RGB band offset for BGR for photoshop4.0 BGR format
int numOfBands = 3;
int trans = Transparency.OPAQUE;
WritableRaster raster = Raster.createInterleavedRaster(db, width, height, paddedRowBytes, numOfBands, off, null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, trans, DataBuffer.TYPE_BYTE);
thumbnail.setImage(new BufferedImage(cm, raster, false, null));
} else
throw new UnsupportedOperationException("Unsupported IRB thumbnail data type: " + dataType);
}
FilterAsAlphaRed.java 文件源码
项目:feathers-sdk
阅读 20
收藏 0
点赞 0
评论 0
/**
* Construct an alpah channel from the given src, according to
* the SVG masking rules.
*
* @param src The image to convert to an alpha channel (mask image)
*/
public FilterAsAlphaRed(CachableRed src) {
super(new Any2LumRed(src),src.getBounds(),
new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int [] {8}, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE),
new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE,
src.getSampleModel().getWidth(),
src.getSampleModel().getHeight(),
1, src.getSampleModel().getWidth(),
new int [] { 0 }),
src.getTileGridXOffset(),
src.getTileGridYOffset(),
null);
props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
FormatRed.java 文件源码
项目:feathers-sdk
阅读 19
收藏 0
点赞 0
评论 0
public static CachableRed construct(CachableRed src, ColorModel cm) {
ColorModel srcCM = src.getColorModel();
if ((cm.hasAlpha() != srcCM.hasAlpha()) ||
(cm.isAlphaPremultiplied() != srcCM.isAlphaPremultiplied()))
return new FormatRed(src, cm);
if (cm.getNumComponents() != srcCM.getNumComponents())
throw new IllegalArgumentException
("Incompatible ColorModel given");
if ((srcCM instanceof ComponentColorModel) &&
(cm instanceof ComponentColorModel))
return src;
if ((srcCM instanceof DirectColorModel) &&
(cm instanceof DirectColorModel))
return src;
return new FormatRed(src, cm);
}
MultiplyAlphaRed.java 文件源码
项目:feathers-sdk
阅读 22
收藏 0
点赞 0
评论 0
public static ColorModel fixColorModel(CachableRed src) {
ColorModel cm = src.getColorModel();
if (cm.hasAlpha())
return cm;
int b = src.getSampleModel().getNumBands()+1;
int [] bits = new int[b];
for (int i=0; i < b; i++)
bits[i] = 8;
ColorSpace cs = cm.getColorSpace();
return new ComponentColorModel(cs, bits, true, false,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
}
ThumbnailResource.java 文件源码
项目:icafe
阅读 20
收藏 0
点赞 0
评论 0
private void setThumbnailImage(ImageResourceID id, int dataType, int width, int height, int totalSize, byte[] thumbnailData) {
// JFIF data in RGB format. For resource ID 1033 (0x0409) the data is in BGR format.
if(dataType == Thumbnail.DATA_TYPE_KJpegRGB) {
thumbnail.setImage(width, height, dataType, thumbnailData);
} else if(dataType == Thumbnail.DATA_TYPE_KRawRGB) {
// kRawRGB - NOT tested yet!
//Create a BufferedImage
DataBuffer db = new DataBufferByte(thumbnailData, totalSize);
int[] off = {0, 1, 2};//RGB band offset, we have 3 bands
if(id == ImageResourceID.THUMBNAIL_RESOURCE_PS4)
off = new int[]{2, 1, 0}; // RGB band offset for BGR for photoshop4.0 BGR format
int numOfBands = 3;
int trans = Transparency.OPAQUE;
WritableRaster raster = Raster.createInterleavedRaster(db, width, height, paddedRowBytes, numOfBands, off, null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, trans, DataBuffer.TYPE_BYTE);
thumbnail.setImage(new BufferedImage(cm, raster, false, null));
} else
throw new UnsupportedOperationException("Unsupported IRB thumbnail data type: " + dataType);
}
PCXReader.java 文件源码
项目:icafe
阅读 19
收藏 0
点赞 0
评论 0
private BufferedImage readTrueColorPcx(InputStream is) throws Exception {
byte brgb[] = IOUtils.readFully(is, 4096);
byte pixels[] = new byte[bytesPerLine*NPlanes*height];
/**
* A BufferedInputStream could have been constructed from the InputStream,
* but for maximum decoding speed, one time reading of the image data
* into memory is ideal though this is memory consuming.
*/
LOGGER.info("true color pcx image!");
readScanLines(brgb, brgb.length, pixels);
is.close();
DataBuffer db = new DataBufferByte(pixels, pixels.length);
int trans = Transparency.OPAQUE;
int[] nBits = {8, 8, 8};
WritableRaster raster = Raster.createBandedRaster(db, width, height, bytesPerLine*3,
new int[]{0, 0, 0}, new int[] {0, bytesPerLine, bytesPerLine*2}, null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), nBits, false, false,
trans, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, raster, false, null);
}
ImageTypeSpecifier.java 文件源码
项目:jdk7-jdk
阅读 28
收藏 0
点赞 0
评论 0
static ColorModel createComponentCM(ColorSpace colorSpace,
int numBands,
int dataType,
boolean hasAlpha,
boolean isAlphaPremultiplied) {
int transparency =
hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
int[] numBits = new int[numBands];
int bits = DataBuffer.getDataTypeSize(dataType);
for (int i = 0; i < numBands; i++) {
numBits[i] = bits;
}
return new ComponentColorModel(colorSpace,
numBits,
hasAlpha,
isAlphaPremultiplied,
transparency,
dataType);
}