📄 componentcolormodel.java
字号:
return (getAlpha(inData) << 24) | (gray << 16) | (gray << 8) | gray; } float[] norm = getNormalizedComponents(inData, null, 0); // Note that getNormalizedComponents returns non-premult values float[] rgb = colorSpace.toRGB(norm); return (getAlpha(inData) << 24) | (((int) (rgb[0] * 255.0f + 0.5f)) << 16) | (((int) (rgb[1] * 255.0f + 0.5f)) << 8) | (((int) (rgb[2] * 255.0f + 0.5f)) << 0); } /** * Returns a data element array representation of a pixel in this * <CODE>ColorModel</CODE>, given an integer pixel representation * in the default RGB color model. * This array can then be passed to the <CODE>setDataElements</CODE> * method of a <CODE>WritableRaster</CODE> object. If the * <CODE>pixel</CODE> * parameter is null, a new array is allocated. Since * <code>ComponentColorModel</code> can be subclassed, subclasses * inherit the implementation of this method and if they don't * override it then * they throw an exception if they use an unsupported * <code>transferType</code>. * * @param rgb the integer representation of the pixel in the RGB * color model * @param pixel the specified pixel * @return The data element array representation of a pixel * in this <CODE>ColorModel</CODE>. * @throws ClassCastException If <CODE>pixel</CODE> is not null and * is not a primitive array of type <CODE>transferType</CODE>. * @throws ArrayIndexOutOfBoundsException If <CODE>pixel</CODE> is * not large enough to hold a pixel value for this * <CODE>ColorModel</CODE>. * @throws UnsupportedOperationException If the transfer type of * this <CODE>ComponentColorModel</CODE> * is not one of the supported transfer types: * <CODE>DataBuffer.TYPE_BYTE</CODE>, <CODE>DataBuffer.TYPE_USHORT</CODE>, * <CODE>DataBuffer.TYPE_INT</CODE>, <CODE>DataBuffer.TYPE_SHORT</CODE>, * <CODE>DataBuffer.TYPE_FLOAT</CODE>, or <CODE>DataBuffer.TYPE_DOUBLE</CODE>. * * @see WritableRaster#setDataElements * @see SampleModel#setDataElements */ public Object getDataElements(int rgb, Object pixel) { // REMIND: Use rendering hints? int red, grn, blu, alp; red = (rgb>>16) & 0xff; grn = (rgb>>8) & 0xff; blu = rgb & 0xff; if (needScaleInit) { initScale(); } if (signed) { // Handle SHORT, FLOAT, & DOUBLE here switch(transferType) { case DataBuffer.TYPE_SHORT: { short sdata[]; if (pixel == null) { sdata = new short[numComponents]; } else { sdata = (short[])pixel; } float factor; if (is_sRGB_stdScale || is_LinearRGB_stdScale) { factor = 32767.0f / 255.0f; if (is_LinearRGB_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; factor = 32767.0f / 65535.0f; } if (supportsAlpha) { alp = (rgb>>24) & 0xff; sdata[3] = (short) (alp * (32767.0f / 255.0f) + 0.5f); if (isAlphaPremultiplied) { factor = alp * factor * (1.0f / 255.0f); } } sdata[0] = (short) (red * factor + 0.5f); sdata[1] = (short) (grn * factor + 0.5f); sdata[2] = (short) (blu * factor + 0.5f); } else if (is_LinearGray_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; float gray = ((0.2125f * red) + (0.7154f * grn) + (0.0721f * blu)) / 65535.0f; factor = 32767.0f; if (supportsAlpha) { alp = (rgb>>24) & 0xff; sdata[1] = (short) (alp * (32767.0f / 255.0f) + 0.5f); if (isAlphaPremultiplied) { factor = alp * factor * (1.0f / 255.0f); } } sdata[0] = (short) (gray * factor + 0.5f); } else if (is_ICCGray_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; int gray = (int) ((0.2125f * red) + (0.7154f * grn) + (0.0721f * blu) + 0.5f); gray = fromLinearGray16ToOtherGray16LUT[gray] & 0xffff; factor = 32767.0f / 65535.0f; if (supportsAlpha) { alp = (rgb>>24) & 0xff; sdata[1] = (short) (alp * (32767.0f / 255.0f) + 0.5f); if (isAlphaPremultiplied) { factor = alp * factor * (1.0f / 255.0f); } } sdata[0] = (short) (gray * factor + 0.5f); } else { factor = 1.0f / 255.0f; float norm[] = new float[3]; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (nonStdScale) { for (int i = 0; i < numColorComponents; i++) { norm[i] = (norm[i] - compOffset[i]) * compScale[i]; // REMIND: need to analyze whether this // clamping is necessary if (norm[i] < 0.0f) { norm[i] = 0.0f; } if (norm[i] > 1.0f) { norm[i] = 1.0f; } } } factor = 32767.0f; if (supportsAlpha) { alp = (rgb>>24) & 0xff; sdata[numColorComponents] = (short) (alp * (32767.0f / 255.0f) + 0.5f); if (isAlphaPremultiplied) { factor *= alp * (1.0f / 255.0f); } } for (int i = 0; i < numColorComponents; i++) { sdata[i] = (short) (norm[i] * factor + 0.5f); } } return sdata; } case DataBuffer.TYPE_FLOAT: { float fdata[]; if (pixel == null) { fdata = new float[numComponents]; } else { fdata = (float[])pixel; } float factor; if (is_sRGB_stdScale || is_LinearRGB_stdScale) { if (is_LinearRGB_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; factor = 1.0f / 65535.0f; } else { factor = 1.0f / 255.0f; } if (supportsAlpha) { alp = (rgb>>24) & 0xff; fdata[3] = alp * (1.0f / 255.0f); if (isAlphaPremultiplied) { factor *= fdata[3]; } } fdata[0] = red * factor; fdata[1] = grn * factor; fdata[2] = blu * factor; } else if (is_LinearGray_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; fdata[0] = ((0.2125f * red) + (0.7154f * grn) + (0.0721f * blu)) / 65535.0f; if (supportsAlpha) { alp = (rgb>>24) & 0xff; fdata[1] = alp * (1.0f / 255.0f); if (isAlphaPremultiplied) { fdata[0] *= fdata[1]; } } } else if (is_ICCGray_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; int gray = (int) ((0.2125f * red) + (0.7154f * grn) + (0.0721f * blu) + 0.5f); fdata[0] = (fromLinearGray16ToOtherGray16LUT[gray] & 0xffff) / 65535.0f; if (supportsAlpha) { alp = (rgb>>24) & 0xff; fdata[1] = alp * (1.0f / 255.0f); if (isAlphaPremultiplied) { fdata[0] *= fdata[1]; } } } else { float norm[] = new float[3]; factor = 1.0f / 255.0f; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (supportsAlpha) { alp = (rgb>>24) & 0xff; fdata[numColorComponents] = alp * factor; if (isAlphaPremultiplied) { factor *= alp; for (int i = 0; i < numColorComponents; i++) { norm[i] *= factor; } } } for (int i = 0; i < numColorComponents; i++) { fdata[i] = norm[i]; } } return fdata; } case DataBuffer.TYPE_DOUBLE: { double ddata[]; if (pixel == null) { ddata = new double[numComponents]; } else { ddata = (double[])pixel; } if (is_sRGB_stdScale || is_LinearRGB_stdScale) { double factor; if (is_LinearRGB_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; factor = 1.0 / 65535.0; } else { factor = 1.0 / 255.0; } if (supportsAlpha) { alp = (rgb>>24) & 0xff; ddata[3] = alp * (1.0 / 255.0); if (isAlphaPremultiplied) { factor *= ddata[3]; } } ddata[0] = red * factor; ddata[1] = grn * factor; ddata[2] = blu * factor; } else if (is_LinearGray_stdScale) { red = fromsRGB8LUT16[red] & 0xffff; grn = fromsRGB8LUT16[grn] & 0xffff; blu = fromsRGB8LUT16[blu] & 0xffff; ddata[0] = ((0.2125 * red) + (0.7154 * grn) + (0.0721 * blu)) / 65535.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -