本文整理汇总了Java中org.apache.batik.ext.awt.image.GraphicsUtil.coerceColorModel方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtil.coerceColorModel方法的具体用法?Java GraphicsUtil.coerceColorModel怎么用?Java GraphicsUtil.coerceColorModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.ext.awt.image.GraphicsUtil
的用法示例。
在下文中一共展示了GraphicsUtil.coerceColorModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ComponentTransferRed
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
/**
* The constructor will instantiate a LookupOp instance using
* a LookupOp, which is built using the four LUT
* data obtained by the TransferFunction objects
* funcs[0] : Alpha component transfer function
* funcs[1] : Red component transfer function
* funcs[2] : Green component transfer function
* funcs[3] : Blue component transfer function
*/
public ComponentTransferRed(CachableRed src,
TransferFunction [] funcs,
RenderingHints hints) {
super(src, src.getBounds(),
GraphicsUtil.coerceColorModel(src.getColorModel(), false),
src.getSampleModel(),
null);
byte [][] tableData = {funcs[1].getLookupTable(),
funcs[2].getLookupTable(),
funcs[3].getLookupTable(),
funcs[0].getLookupTable()};
// Note that we create an anonymous subclass here.
// For what ever reason this makes the Op work correctly.
// If you remove this, it seems to get the color channels messed
// up. The downside is that I suspect that this means we are
// falling into a more general, and hence slower case, but
// at least it works....
operation = new LookupOp(new ByteLookupTable(0, tableData), hints)
{ };
}
示例2: fixColorModel
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
protected static ColorModel fixColorModel(CachableRed src) {
ColorModel cm = src.getColorModel();
if (cm.hasAlpha()) {
if (!cm.isAlphaPremultiplied())
cm = GraphicsUtil.coerceColorModel(cm, true);
return cm;
}
int b = src.getSampleModel().getNumBands()+1;
if (b > 4)
throw new IllegalArgumentException
("CompositeRed can only handle up to three band images");
int [] masks = new int[4];
for (int i=0; i < b-1; i++)
masks[i] = 0xFF0000 >> (8*i);
masks[3] = 0xFF << (8*(b-1));
ColorSpace cs = cm.getColorSpace();
return new DirectColorModel(cs, 8*b, masks[0], masks[1],
masks[2], masks[3],
true, DataBuffer.TYPE_INT);
}
示例3: fixColorModel
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
protected static ColorModel fixColorModel(CachableRed src) {
ColorModel cm = src.getColorModel();
if (cm.hasAlpha()) {
if (!cm.isAlphaPremultiplied())
cm = GraphicsUtil.coerceColorModel(cm, true);
return cm;
}
ColorSpace cs = cm.getColorSpace();
int b = src.getSampleModel().getNumBands()+1;
if (b == 4) {
int [] masks = new int[4];
for (int i=0; i < b-1; i++)
masks[i] = 0xFF0000 >> (8*i);
masks[3] = 0xFF << (8*(b-1));
return new DirectColorModel(cs, 8*b, masks[0], masks[1],
masks[2], masks[3],
true, DataBuffer.TYPE_INT);
}
int [] bits = new int[b];
for (int i=0; i<b; i++)
bits[i] = 8;
return new ComponentColorModel(cs, bits, true, true,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_INT);
}
示例4: PatternPaintContext
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
/**
* @param destCM ColorModel that receives the paint data
* @param usr2dev user space to device space transform
* @param hints RenderingHints
* @param patternRegion region tiled by this paint. In user space.
* @param overflow controls whether the pattern region clips the
* pattern tile
*/
public PatternPaintContext(ColorModel destCM,
AffineTransform usr2dev,
RenderingHints hints,
Filter tile,
Rectangle2D patternRegion,
boolean overflow) {
if(usr2dev == null){
throw new IllegalArgumentException();
}
if(hints == null){
hints = new RenderingHints(null);
}
if(tile == null){
throw new IllegalArgumentException();
}
this.usr2dev = usr2dev;
// System.out.println("PatB: " + patternRegion);
// System.out.println("Tile: " + tile);
TileRable tileRable = new TileRable8Bit(tile,
EVERYTHING,
patternRegion,
overflow);
ColorSpace destCS = destCM.getColorSpace();
if (destCS == ColorSpace.getInstance(ColorSpace.CS_sRGB))
tileRable.setColorSpaceLinear(false);
else if (destCS == ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB))
tileRable.setColorSpaceLinear(true);
RenderContext rc = new RenderContext(usr2dev, EVERYTHING, hints);
tiled = tileRable.createRendering(rc);
// System.out.println("tileRed: " + tiled);
// org.apache.batik.test.gvt.ImageDisplay.showImage("Tiled: ", tiled);
//System.out.println("Created rendering");
if(tiled != null) {
Rectangle2D devRgn = usr2dev.createTransformedShape
(patternRegion).getBounds();
if ((devRgn.getWidth() > 128) ||
(devRgn.getHeight() > 128))
tiled = new TileCacheRed(GraphicsUtil.wrap(tiled), 256, 64);
} else {
//System.out.println("Tile was null");
rasterCM = ColorModel.getRGBdefault();
WritableRaster wr;
wr = rasterCM.createCompatibleWritableRaster(32, 32);
tiled = GraphicsUtil.wrap
(new BufferedImage(rasterCM, wr, false, null));
return;
}
rasterCM = tiled.getColorModel();
if (rasterCM.hasAlpha()) {
if (destCM.hasAlpha())
rasterCM = GraphicsUtil.coerceColorModel
(rasterCM, destCM.isAlphaPremultiplied());
else
rasterCM = GraphicsUtil.coerceColorModel(rasterCM, false);
}
}
示例5: DisplacementMapRed
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
/**
* @param image the image to distort
* @param offsets the displacement map
* @param xChannel defines the channel of off whose values will be
* on X-axis operation
* @param yChannel defines the channel of off whose values will be
* @param scaleX defines the scale factor of the filter operation
* on the X axis.
* @param scaleY defines the scale factor of the filter operation
* on the Y axis
* @param rh the rendering hints
*/
public DisplacementMapRed(CachableRed image,
CachableRed offsets,
ARGBChannel xChannel,
ARGBChannel yChannel,
float scaleX, float scaleY,
RenderingHints rh) {
if(xChannel == null){
throw new IllegalArgumentException("Must provide xChannel");
}
if(yChannel == null){
throw new IllegalArgumentException("Must provide yChannel");
}
this.offsets = offsets;
this.scaleX = scaleX;
this.scaleY = scaleY;
this.xChannel = xChannel;
this.yChannel = yChannel;
this.hints = rh;
maxOffX = (int)Math.ceil(scaleX/2);
maxOffY = (int)Math.ceil(scaleY/2);
Rectangle rect = image.getBounds();
Rectangle r = image.getBounds();
r.x -= maxOffX; r.width += 2*maxOffX;
r.y -= maxOffY; r.height += 2*maxOffY;
image = new PadRed(image, r, PadMode.ZERO_PAD, null);
image = new TileCacheRed(image);
this.image = image;
ColorModel cm = image.getColorModel();
if (!USE_NN)
// For Bilinear we need alpha premult.
cm = GraphicsUtil.coerceColorModel(cm, true);
init(image, rect, cm, image.getSampleModel(),
rect.x, rect.y, null);
xOffsets = new TileOffsets[getNumXTiles()];
yOffsets = new TileOffsets[getNumYTiles()];
}
示例6: filter
import org.apache.batik.ext.awt.image.GraphicsUtil; //导入方法依赖的package包/类
/**
* This implementation of filter does the morphology operation
* on a premultiplied alpha image. This tends to muddy the
* colors. so something that is supposed to be a mostly
* transparent bright red may well become a muddy opaque red.
* Where as I think it should become a bright opaque red. Which
* is the result you would get if you were using unpremult data.
*/
public BufferedImage filter(BufferedImage src, BufferedImage dest){
if (src == null)
throw new NullPointerException("Source image should not be null");
BufferedImage origSrc = src;
BufferedImage finalDest = dest;
if (!isCompatible(src.getColorModel(), src.getSampleModel())) {
src = new BufferedImage(src.getWidth(), src.getHeight(),
BufferedImage.TYPE_INT_ARGB_PRE);
GraphicsUtil.copyData(origSrc, src);
}
else if (!src.isAlphaPremultiplied()) {
// Get a Premultipled CM.
ColorModel srcCM, srcCMPre;
srcCM = src.getColorModel();
srcCMPre = GraphicsUtil.coerceColorModel(srcCM, true);
src = new BufferedImage(srcCMPre, src.getRaster(),
true, null);
GraphicsUtil.copyData(origSrc, src);
}
if (dest == null) {
dest = createCompatibleDestImage(src, null);
finalDest = dest;
} else if (!isCompatible(dest.getColorModel(),
dest.getSampleModel())) {
dest = createCompatibleDestImage(src, null);
} else if (!dest.isAlphaPremultiplied()) {
// Get a Premultipled CM.
ColorModel dstCM, dstCMPre;
dstCM = dest.getColorModel();
dstCMPre = GraphicsUtil.coerceColorModel(dstCM, true);
dest = new BufferedImage(dstCMPre, finalDest.getRaster(),
true, null);
}
filter(src.getRaster(), dest.getRaster());
// Check to see if we need to 'fix' our source (divide out alpha).
if ((src.getRaster() == origSrc.getRaster()) &&
(src.isAlphaPremultiplied() != origSrc.isAlphaPremultiplied())) {
// Copy our source back the way it was...
GraphicsUtil.copyData(src, origSrc);
}
// Check to see if we need to store our result...
if ((dest.getRaster() != finalDest.getRaster()) ||
(dest.isAlphaPremultiplied() != finalDest.isAlphaPremultiplied())){
// Coerce our source back the way it was requested...
GraphicsUtil.copyData(dest, finalDest);
}
return finalDest;
}