List of usage examples for java.awt.image ColorModel getColorSpace
public final ColorSpace getColorSpace()
From source file:lucee.runtime.img.Image.java
public void resize(int width, int height, int interpolation, double blurFactor) throws ExpressionException { ColorModel cm = image().getColorModel(); if (interpolation == IP_HIGHESTPERFORMANCE) { interpolation = IPC_BICUBIC;/*from w w w. ja va2s . c o m*/ } if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY && cm.getComponentSize()[0] == 8) { if (interpolation == IP_HIGHESTQUALITY || interpolation == IP_HIGHPERFORMANCE || interpolation == IP_HIGHQUALITY || interpolation == IP_MEDIUMPERFORMANCE || interpolation == IP_MEDIUMQUALITY) { interpolation = IPC_BICUBIC; } if (interpolation != IPC_BICUBIC && interpolation != IPC_BILINEAR && interpolation != IPC_NEAREST) { throw new ExpressionException("invalid grayscale interpolation"); } } if (interpolation <= IPC_MAX) { resizeImage(width, height, interpolation); } else { image(ImageResizer.resize(image(), width, height, interpolation, blurFactor)); } }
From source file:lucee.runtime.img.Image.java
public Struct info() throws ExpressionException { if (sctInfo != null) return sctInfo; Struct sctInfo = new StructImpl(), sct; sctInfo.setEL("height", new Double(getHeight())); sctInfo.setEL("width", new Double(getWidth())); sctInfo.setEL("source", source == null ? "" : source.getAbsolutePath()); //sct.setEL("mime_type",getMimeType()); ColorModel cm = image().getColorModel(); sct = new StructImpl(); sctInfo.setEL("colormodel", sct); sct.setEL("alpha_channel_support", Caster.toBoolean(cm.hasAlpha())); sct.setEL("alpha_premultiplied", Caster.toBoolean(cm.isAlphaPremultiplied())); sct.setEL("transparency", toStringTransparency(cm.getTransparency())); sct.setEL("pixel_size", Caster.toDouble(cm.getPixelSize())); sct.setEL("num_components", Caster.toDouble(cm.getNumComponents())); sct.setEL("num_color_components", Caster.toDouble(cm.getNumColorComponents())); sct.setEL("colorspace", toStringColorSpace(cm.getColorSpace())); //bits_component int[] bitspercomponent = cm.getComponentSize(); Array arr = new ArrayImpl(); Double value;//from w w w.j a v a 2 s.c om for (int i = 0; i < bitspercomponent.length; i++) { sct.setEL("bits_component_" + (i + 1), value = new Double(bitspercomponent[i])); arr.appendEL(value); } sct.setEL("bits_component", arr); // colormodel_type if (cm instanceof ComponentColorModel) sct.setEL("colormodel_type", "ComponentColorModel"); else if (cm instanceof IndexColorModel) sct.setEL("colormodel_type", "IndexColorModel"); else if (cm instanceof PackedColorModel) sct.setEL("colormodel_type", "PackedColorModel"); else sct.setEL("colormodel_type", ListUtil.last(cm.getClass().getName(), '.')); getMetaData(sctInfo); ImageMeta.addInfo(format, source, sctInfo); this.sctInfo = sctInfo; return sctInfo; }
From source file:org.apache.xmlgraphics.ps.PSImageUtils.java
private static void prepareColorSpace(PSGenerator gen, ColorModel cm) throws IOException { //Prepare color space if ((cm instanceof IndexColorModel)) { ColorSpace cs = cm.getColorSpace(); IndexColorModel im = (IndexColorModel) cm; gen.write("[/Indexed " + getColorSpaceName(cs)); int c = im.getMapSize(); int hival = c - 1; if (hival > 4095) { throw new UnsupportedOperationException("hival must not go beyond 4095"); }// w ww.j ava2 s .com gen.writeln(" " + Integer.toString(hival)); gen.write(" <"); int[] palette = new int[c]; im.getRGBs(palette); for (int i = 0; i < c; i++) { if (i > 0) { if ((i % 8) == 0) { gen.newLine(); gen.write(" "); } else { gen.write(" "); } } gen.write(rgb2Hex(palette[i])); } gen.writeln(">"); gen.writeln("] setcolorspace"); } else { gen.writeln(getColorSpaceName(cm.getColorSpace()) + " setcolorspace"); } }
From source file:org.photovault.image.PhotovaultImage.java
/** Create a color mapping LUT based on current color channel mapping. @return the created LUT. If not channel mapping is specified, returns an identity mapping./*from w w w .j av a 2 s . c om*/ */ private LookupTableJAI createColorMappingLUT() { ColorModel colorModel = this.getCorrectedImageColorModel(); ColorSpace colorSpace = colorModel.getColorSpace(); int[] componentSizes = colorModel.getComponentSize(); ColorCurve valueCurve = null; ColorCurve[] componentCurves = new ColorCurve[componentSizes.length]; boolean[] applyValueCurve = new boolean[componentSizes.length]; for (int n = 0; n < componentSizes.length; n++) { applyValueCurve[n] = false; } if (channelMap != null) { valueCurve = channelMap.getChannelCurve("value"); switch (colorSpace.getType()) { case ColorSpace.TYPE_GRAY: // Gray scale image - just apply value curve to 1st channel componentCurves[0] = valueCurve; break; case ColorSpace.TYPE_RGB: componentCurves[0] = channelMap.getChannelCurve("red"); componentCurves[1] = channelMap.getChannelCurve("green"); componentCurves[2] = channelMap.getChannelCurve("blue"); applyValueCurve[0] = true; applyValueCurve[1] = true; applyValueCurve[2] = true; break; default: // Unsupported color format. Just return identity transform break; } } if (valueCurve == null) { // No color mapping found, use identity mapping valueCurve = new ColorCurve(); } LookupTableJAI jailut = null; if (componentSizes[0] == 8) { byte[][] lut = new byte[componentSizes.length][256]; double dx = 1.0 / 256.0; for (int band = 0; band < colorModel.getNumComponents(); band++) { for (int n = 0; n < lut[band].length; n++) { double x = dx * n; double val = x; if (band < componentCurves.length && componentCurves[band] != null) { val = componentCurves[band].getValue(val); } if (band < applyValueCurve.length && applyValueCurve[band]) { val = valueCurve.getValue(val); } val = Math.max(0.0, Math.min(val, 1.0)); lut[band][n] = (byte) ((lut[band].length - 1) * val); } } jailut = new LookupTableJAI(lut); } else if (componentSizes[0] == 16) { short[][] lut = new short[componentSizes.length][0x10000]; double dx = 1.0 / 65536.0; for (int band = 0; band < colorModel.getNumComponents(); band++) { for (int n = 0; n < lut[band].length; n++) { double x = dx * n; double val = x; if (band < componentCurves.length && componentCurves[band] != null) { val = componentCurves[band].getValue(val); } if (band < applyValueCurve.length && applyValueCurve[band]) { val = valueCurve.getValue(val); } val = Math.max(0.0, Math.min(val, 1.0)); lut[band][n] = (short) ((lut[band].length - 1) * val); } } jailut = new LookupTableJAI(lut, true); } else { log.error("Unsupported data type with with = " + componentSizes[0]); } return jailut; }