/** * Coerces data within a bufferedImage to match newAlphaPreMult, * Note that this can not change the colormodel of bi so you * * @param wr The raster to change the state of. * @param cm The colormodel currently associated with data in wr. * @param newAlphaPreMult The desired state of alpha Premult for raster. * @return A new colormodel that matches newAlphaPreMult. */ public static ColorModel coerceData(WritableRaster wr, ColorModel cm, boolean newAlphaPreMult) { // System.out.println("CoerceData: " + cm.isAlphaPremultiplied() + // " Out: " + newAlphaPreMult); if ( ! cm.hasAlpha() ) // Nothing to do no alpha channel return cm; if (cm.isAlphaPremultiplied() == newAlphaPreMult) // nothing to do alpha state matches... return cm; // System.out.println("CoerceData: " + wr.getSampleModel()); if (newAlphaPreMult) { multiplyAlpha(wr); } else { divideAlpha(wr); } return coerceColorModel(cm, newAlphaPreMult); }
/** * Coerces data within a bufferedImage to match newAlphaPreMult, * Note that this can not change the colormodel of bi so you * * @param wr The raster to change the state of. * @param cm The colormodel currently associated with data in wr. * @param newAlphaPreMult The desired state of alpha Premult for raster. * @return A new colormodel that matches newAlphaPreMult. */ public static ColorModel coerceData(WritableRaster wr, ColorModel cm, boolean newAlphaPreMult) { // System.out.println("CoerceData: " + cm.isAlphaPremultiplied() + // " Out: " + newAlphaPreMult); if ( ! cm.hasAlpha() ) // Nothing to do no alpha channel return cm; if (cm.isAlphaPremultiplied() == newAlphaPreMult) // nothing to do alpha state matches... return cm; // System.out.println("CoerceData: " + wr.getSampleModel()); if (newAlphaPreMult) { multiplyAlpha(wr); } else { divideAlpha(wr); } return coerceColorModel(cm, newAlphaPreMult); }
/** * Coerces data within a bufferedImage to match newAlphaPreMult, * Note that this can not change the colormodel of bi so you * * @param wr The raster to change the state of. * @param cm The colormodel currently associated with data in wr. * @param newAlphaPreMult The desired state of alpha Premult for raster. * @return A new colormodel that matches newAlphaPreMult. */ public static ColorModel coerceData(WritableRaster wr, ColorModel cm, boolean newAlphaPreMult) { // System.out.println("CoerceData: " + cm.isAlphaPremultiplied() + // " Out: " + newAlphaPreMult); if ( ! cm.hasAlpha() ) // Nothing to do no alpha channel return cm; if (cm.isAlphaPremultiplied() == newAlphaPreMult) // nothing to do alpha state matches... return cm; // System.out.println("CoerceData: " + wr.getSampleModel()); if (newAlphaPreMult) { multiplyAlpha(wr); } else { divideAlpha(wr); } return coerceColorModel(cm, newAlphaPreMult); }
srcCMPre = GraphicsUtil.coerceColorModel(srcCM, true); dstCMPre = GraphicsUtil.coerceColorModel(dstCM, true);
srcCMPre = GraphicsUtil.coerceColorModel(srcCM, true); dstCMPre = GraphicsUtil.coerceColorModel(dstCM, true);
srcCMPre = GraphicsUtil.coerceColorModel(srcCM, true); dstCMPre = GraphicsUtil.coerceColorModel(dstCM, true);
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); } }
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); } }
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); } }
if (rasterCM.hasAlpha()) { if (destCM.hasAlpha()) rasterCM = GraphicsUtil.coerceColorModel (rasterCM, destCM.isAlphaPremultiplied()); else rasterCM = GraphicsUtil.coerceColorModel(rasterCM, false);
if (rasterCM.hasAlpha()) { if (destCM.hasAlpha()) rasterCM = GraphicsUtil.coerceColorModel (rasterCM, destCM.isAlphaPremultiplied()); else rasterCM = GraphicsUtil.coerceColorModel(rasterCM, false);
if (!USE_NN) cm = GraphicsUtil.coerceColorModel(cm, true);
if (!USE_NN) cm = GraphicsUtil.coerceColorModel(cm, true);
if (!USE_NN) cm = GraphicsUtil.coerceColorModel(cm, true);
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); }
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); }
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); }
/** * 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) { }; }
/** * 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) { }; }
/** * 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) { }; }