0N/A/*
3261N/A * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**********************************************************************
0N/A **********************************************************************
0N/A **********************************************************************
0N/A *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
0N/A *** As an unpublished work pursuant to Title 17 of the United ***
0N/A *** States Code. All rights reserved. ***
0N/A **********************************************************************
0N/A **********************************************************************
0N/A **********************************************************************/
0N/A
0N/Apackage sun.java2d.cmm.lcms;
0N/A
0N/Aimport java.awt.color.ICC_Profile;
0N/Aimport java.awt.color.ProfileDataException;
0N/Aimport java.awt.color.CMMException;
0N/Aimport java.awt.color.ColorSpace;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.DirectColorModel;
0N/Aimport java.awt.image.ComponentColorModel;
0N/Aimport java.awt.image.SampleModel;
0N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.image.SinglePixelPackedSampleModel;
0N/Aimport java.awt.image.ComponentSampleModel;
0N/Aimport sun.java2d.cmm.*;
0N/Aimport sun.java2d.cmm.lcms.*;
5818N/Aimport static sun.java2d.cmm.lcms.LCMSImageLayout.ImageLayoutException;
0N/A
0N/A
0N/Apublic class LCMSTransform implements ColorTransform {
0N/A long ID;
2693N/A private int inFormatter;
2693N/A private int outFormatter;
2693N/A
0N/A ICC_Profile[] profiles;
0N/A long [] profileIDs;
0N/A int renderType;
0N/A int transformType;
0N/A
2693N/A private int numInComponents = -1;
2693N/A private int numOutComponents = -1;
2693N/A
0N/A private Object disposerReferent = new Object();
0N/A
0N/A /* the class initializer */
0N/A static {
0N/A if (ProfileDeferralMgr.deferring) {
0N/A ProfileDeferralMgr.activateProfiles();
0N/A }
0N/A }
0N/A
0N/A public LCMSTransform(ICC_Profile profile, int renderType,
0N/A int transformType)
0N/A {
0N/A /* Actually, it is not a complete transform but just part of it */
0N/A profiles = new ICC_Profile[1];
0N/A profiles[0] = profile;
0N/A profileIDs = new long[1];
0N/A profileIDs[0] = LCMS.getProfileID(profile);
0N/A this.renderType = (renderType == ColorTransform.Any)?
0N/A ICC_Profile.icPerceptual : renderType;
0N/A this.transformType = transformType;
2693N/A
2693N/A /* Note that ICC_Profile.getNumComponents() is quite expensive
2693N/A * (it may results in a reading of the profile header).
2693N/A * So, here we cache the number of components of input and
2693N/A * output profiles for further usage.
2693N/A */
2693N/A numInComponents = profiles[0].getNumComponents();
2693N/A numOutComponents = profiles[profiles.length - 1].getNumComponents();
0N/A }
0N/A
0N/A public LCMSTransform (ColorTransform[] transforms) {
0N/A int size = 0;
0N/A for (int i=0; i < transforms.length; i++) {
0N/A size+=((LCMSTransform)transforms[i]).profiles.length;
0N/A }
0N/A profiles = new ICC_Profile[size];
0N/A profileIDs = new long[size];
0N/A int j = 0;
0N/A for (int i=0; i < transforms.length; i++) {
0N/A LCMSTransform curTrans = (LCMSTransform)transforms[i];
0N/A System.arraycopy(curTrans.profiles, 0, profiles, j,
0N/A curTrans.profiles.length);
0N/A System.arraycopy(curTrans.profileIDs, 0, profileIDs, j,
0N/A curTrans.profileIDs.length);
0N/A j += curTrans.profiles.length;
0N/A }
0N/A renderType = ((LCMSTransform)transforms[0]).renderType;
2693N/A
2693N/A /* Note that ICC_Profile.getNumComponents() is quite expensive
2693N/A * (it may results in a reading of the profile header).
2693N/A * So, here we cache the number of components of input and
2693N/A * output profiles for further usage.
2693N/A */
2693N/A numInComponents = profiles[0].getNumComponents();
2693N/A numOutComponents = profiles[profiles.length - 1].getNumComponents();
0N/A }
0N/A
0N/A public int getNumInComponents() {
2693N/A return numInComponents;
0N/A }
0N/A
0N/A public int getNumOutComponents() {
2693N/A return numOutComponents;
2693N/A }
2693N/A
2693N/A private synchronized void doTransform(LCMSImageLayout in,
2693N/A LCMSImageLayout out) {
2693N/A // update native transfrom if needed
2693N/A if (ID == 0L ||
2693N/A inFormatter != in.pixelType ||
2693N/A outFormatter != out.pixelType) {
2693N/A
2693N/A if (ID != 0L) {
2693N/A // Disposer will destroy forgotten transform
2693N/A disposerReferent = new Object();
2693N/A }
2693N/A inFormatter = in.pixelType;
2693N/A outFormatter = out.pixelType;
2693N/A
2693N/A ID = LCMS.createNativeTransform(profileIDs, renderType,
2693N/A inFormatter, outFormatter,
2693N/A disposerReferent);
2693N/A }
2693N/A
2693N/A LCMS.colorConvert(this, in, out);
0N/A }
0N/A
0N/A public void colorConvert(BufferedImage src, BufferedImage dst) {
0N/A if (LCMSImageLayout.isSupported(src) &&
0N/A LCMSImageLayout.isSupported(dst))
0N/A {
5818N/A try {
5818N/A doTransform(new LCMSImageLayout(src), new LCMSImageLayout(dst));
5818N/A return;
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert images");
5818N/A }
0N/A }
0N/A LCMSImageLayout srcIL, dstIL;
0N/A Raster srcRas = src.getRaster();
0N/A WritableRaster dstRas = dst.getRaster();
0N/A ColorModel srcCM = src.getColorModel();
0N/A ColorModel dstCM = dst.getColorModel();
0N/A int w = src.getWidth();
0N/A int h = src.getHeight();
0N/A int srcNumComp = srcCM.getNumColorComponents();
0N/A int dstNumComp = dstCM.getNumColorComponents();
0N/A int precision = 8;
0N/A float maxNum = 255.0f;
0N/A for (int i = 0; i < srcNumComp; i++) {
0N/A if (srcCM.getComponentSize(i) > 8) {
0N/A precision = 16;
0N/A maxNum = 65535.0f;
0N/A }
0N/A }
0N/A for (int i = 0; i < dstNumComp; i++) {
0N/A if (dstCM.getComponentSize(i) > 8) {
0N/A precision = 16;
0N/A maxNum = 65535.0f;
0N/A }
0N/A }
0N/A float[] srcMinVal = new float[srcNumComp];
0N/A float[] srcInvDiffMinMax = new float[srcNumComp];
0N/A ColorSpace cs = srcCM.getColorSpace();
0N/A for (int i = 0; i < srcNumComp; i++) {
0N/A srcMinVal[i] = cs.getMinValue(i);
0N/A srcInvDiffMinMax[i] = maxNum / (cs.getMaxValue(i) - srcMinVal[i]);
0N/A }
0N/A cs = dstCM.getColorSpace();
0N/A float[] dstMinVal = new float[dstNumComp];
0N/A float[] dstDiffMinMax = new float[dstNumComp];
0N/A for (int i = 0; i < dstNumComp; i++) {
0N/A dstMinVal[i] = cs.getMinValue(i);
0N/A dstDiffMinMax[i] = (cs.getMaxValue(i) - dstMinVal[i]) / maxNum;
0N/A }
0N/A boolean dstHasAlpha = dstCM.hasAlpha();
0N/A boolean needSrcAlpha = srcCM.hasAlpha() && dstHasAlpha;
0N/A float[] dstColor;
0N/A if (dstHasAlpha) {
0N/A dstColor = new float[dstNumComp + 1];
0N/A } else {
0N/A dstColor = new float[dstNumComp];
0N/A }
0N/A if (precision == 8) {
0N/A byte[] srcLine = new byte[w * srcNumComp];
0N/A byte[] dstLine = new byte[w * dstNumComp];
0N/A Object pixel;
0N/A float[] color;
0N/A float[] alpha = null;
0N/A if (needSrcAlpha) {
0N/A alpha = new float[w];
0N/A }
0N/A int idx;
0N/A // TODO check for src npixels = dst npixels
5818N/A try {
5818N/A srcIL = new LCMSImageLayout(
5818N/A srcLine, srcLine.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumInComponents());
5818N/A dstIL = new LCMSImageLayout(
5818N/A dstLine, dstLine.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert images");
5818N/A }
0N/A // process each scanline
0N/A for (int y = 0; y < h; y++) {
0N/A // convert src scanline
0N/A pixel = null;
0N/A color = null;
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++) {
0N/A pixel = srcRas.getDataElements(x, y, pixel);
0N/A color = srcCM.getNormalizedComponents(pixel, color, 0);
0N/A for (int i = 0; i < srcNumComp; i++) {
0N/A srcLine[idx++] = (byte)
0N/A ((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] +
0N/A 0.5f);
0N/A }
0N/A if (needSrcAlpha) {
0N/A alpha[x] = color[srcNumComp];
0N/A }
0N/A }
0N/A // color convert srcLine to dstLine
2693N/A doTransform(srcIL, dstIL);
2693N/A
0N/A // convert dst scanline
0N/A pixel = null;
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++) {
0N/A for (int i = 0; i < dstNumComp; i++) {
0N/A dstColor[i] = ((float) (dstLine[idx++] & 0xff)) *
0N/A dstDiffMinMax[i] + dstMinVal[i];
0N/A }
0N/A if (needSrcAlpha) {
0N/A dstColor[dstNumComp] = alpha[x];
0N/A } else if (dstHasAlpha) {
0N/A dstColor[dstNumComp] = 1.0f;
0N/A }
0N/A pixel = dstCM.getDataElements(dstColor, 0, pixel);
0N/A dstRas.setDataElements(x, y, pixel);
0N/A }
0N/A }
0N/A } else {
0N/A short[] srcLine = new short[w * srcNumComp];
0N/A short[] dstLine = new short[w * dstNumComp];
0N/A Object pixel;
0N/A float[] color;
0N/A float[] alpha = null;
0N/A if (needSrcAlpha) {
0N/A alpha = new float[w];
0N/A }
0N/A int idx;
5818N/A try {
5818N/A srcIL = new LCMSImageLayout(
5818N/A srcLine, srcLine.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
0N/A
5818N/A dstIL = new LCMSImageLayout(
5818N/A dstLine, dstLine.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert images");
5818N/A }
0N/A // process each scanline
0N/A for (int y = 0; y < h; y++) {
0N/A // convert src scanline
0N/A pixel = null;
0N/A color = null;
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++) {
0N/A pixel = srcRas.getDataElements(x, y, pixel);
0N/A color = srcCM.getNormalizedComponents(pixel, color, 0);
0N/A for (int i = 0; i < srcNumComp; i++) {
0N/A srcLine[idx++] = (short)
0N/A ((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] +
0N/A 0.5f);
0N/A }
0N/A if (needSrcAlpha) {
0N/A alpha[x] = color[srcNumComp];
0N/A }
0N/A }
0N/A // color convert srcLine to dstLine
2693N/A doTransform(srcIL, dstIL);
2693N/A
0N/A // convert dst scanline
0N/A pixel = null;
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++) {
0N/A for (int i = 0; i < dstNumComp; i++) {
0N/A dstColor[i] = ((float) (dstLine[idx++] & 0xffff)) *
0N/A dstDiffMinMax[i] + dstMinVal[i];
0N/A }
0N/A if (needSrcAlpha) {
0N/A dstColor[dstNumComp] = alpha[x];
0N/A } else if (dstHasAlpha) {
0N/A dstColor[dstNumComp] = 1.0f;
0N/A }
0N/A pixel = dstCM.getDataElements(dstColor, 0, pixel);
0N/A dstRas.setDataElements(x, y, pixel);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void colorConvert(Raster src, WritableRaster dst,
0N/A float[] srcMinVal, float[]srcMaxVal,
0N/A float[] dstMinVal, float[]dstMaxVal) {
0N/A LCMSImageLayout srcIL, dstIL;
0N/A
0N/A // Can't pass src and dst directly to CMM, so process per scanline
0N/A SampleModel srcSM = src.getSampleModel();
0N/A SampleModel dstSM = dst.getSampleModel();
0N/A int srcTransferType = src.getTransferType();
0N/A int dstTransferType = dst.getTransferType();
0N/A boolean srcIsFloat, dstIsFloat;
0N/A if ((srcTransferType == DataBuffer.TYPE_FLOAT) ||
0N/A (srcTransferType == DataBuffer.TYPE_DOUBLE)) {
0N/A srcIsFloat = true;
0N/A } else {
0N/A srcIsFloat = false;
0N/A }
0N/A if ((dstTransferType == DataBuffer.TYPE_FLOAT) ||
0N/A (dstTransferType == DataBuffer.TYPE_DOUBLE)) {
0N/A dstIsFloat = true;
0N/A } else {
0N/A dstIsFloat = false;
0N/A }
0N/A int w = src.getWidth();
0N/A int h = src.getHeight();
0N/A int srcNumBands = src.getNumBands();
0N/A int dstNumBands = dst.getNumBands();
0N/A float[] srcScaleFactor = new float[srcNumBands];
0N/A float[] dstScaleFactor = new float[dstNumBands];
0N/A float[] srcUseMinVal = new float[srcNumBands];
0N/A float[] dstUseMinVal = new float[dstNumBands];
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A if (srcIsFloat) {
0N/A srcScaleFactor[i] = 65535.0f / (srcMaxVal[i] - srcMinVal[i]);
0N/A srcUseMinVal[i] = srcMinVal[i];
0N/A } else {
0N/A if (srcTransferType == DataBuffer.TYPE_SHORT) {
0N/A srcScaleFactor[i] = 65535.0f / 32767.0f;
0N/A } else {
0N/A srcScaleFactor[i] = 65535.0f /
0N/A ((float) ((1 << srcSM.getSampleSize(i)) - 1));
0N/A }
0N/A srcUseMinVal[i] = 0.0f;
0N/A }
0N/A }
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A if (dstIsFloat) {
0N/A dstScaleFactor[i] = (dstMaxVal[i] - dstMinVal[i]) / 65535.0f;
0N/A dstUseMinVal[i] = dstMinVal[i];
0N/A } else {
0N/A if (dstTransferType == DataBuffer.TYPE_SHORT) {
0N/A dstScaleFactor[i] = 32767.0f / 65535.0f;
0N/A } else {
0N/A dstScaleFactor[i] =
0N/A ((float) ((1 << dstSM.getSampleSize(i)) - 1)) /
0N/A 65535.0f;
0N/A }
0N/A dstUseMinVal[i] = 0.0f;
0N/A }
0N/A }
0N/A int ys = src.getMinY();
0N/A int yd = dst.getMinY();
0N/A int xs, xd;
0N/A float sample;
0N/A short[] srcLine = new short[w * srcNumBands];
0N/A short[] dstLine = new short[w * dstNumBands];
0N/A int idx;
5818N/A try {
5818N/A srcIL = new LCMSImageLayout(
5818N/A srcLine, srcLine.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
0N/A
5818N/A dstIL = new LCMSImageLayout(
5818N/A dstLine, dstLine.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert rasters");
5818N/A }
0N/A // process each scanline
0N/A for (int y = 0; y < h; y++, ys++, yd++) {
0N/A // get src scanline
0N/A xs = src.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xs++) {
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A sample = src.getSampleFloat(xs, ys, i);
0N/A srcLine[idx++] = (short)
0N/A ((sample - srcUseMinVal[i]) * srcScaleFactor[i] + 0.5f);
0N/A }
0N/A }
0N/A
0N/A // color convert srcLine to dstLine
2693N/A doTransform(srcIL, dstIL);
0N/A
0N/A // store dst scanline
0N/A xd = dst.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xd++) {
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A sample = ((dstLine[idx++] & 0xffff) * dstScaleFactor[i]) +
0N/A dstUseMinVal[i];
0N/A dst.setSample(xd, yd, i, sample);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void colorConvert(Raster src, WritableRaster dst) {
0N/A
0N/A LCMSImageLayout srcIL, dstIL;
0N/A // Can't pass src and dst directly to CMM, so process per scanline
0N/A SampleModel srcSM = src.getSampleModel();
0N/A SampleModel dstSM = dst.getSampleModel();
0N/A int srcTransferType = src.getTransferType();
0N/A int dstTransferType = dst.getTransferType();
0N/A int w = src.getWidth();
0N/A int h = src.getHeight();
0N/A int srcNumBands = src.getNumBands();
0N/A int dstNumBands = dst.getNumBands();
0N/A int precision = 8;
0N/A float maxNum = 255.0f;
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A if (srcSM.getSampleSize(i) > 8) {
0N/A precision = 16;
0N/A maxNum = 65535.0f;
0N/A }
0N/A }
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A if (dstSM.getSampleSize(i) > 8) {
0N/A precision = 16;
0N/A maxNum = 65535.0f;
0N/A }
0N/A }
0N/A float[] srcScaleFactor = new float[srcNumBands];
0N/A float[] dstScaleFactor = new float[dstNumBands];
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A if (srcTransferType == DataBuffer.TYPE_SHORT) {
0N/A srcScaleFactor[i] = maxNum / 32767.0f;
0N/A } else {
0N/A srcScaleFactor[i] = maxNum /
0N/A ((float) ((1 << srcSM.getSampleSize(i)) - 1));
0N/A }
0N/A }
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A if (dstTransferType == DataBuffer.TYPE_SHORT) {
0N/A dstScaleFactor[i] = 32767.0f / maxNum;
0N/A } else {
0N/A dstScaleFactor[i] =
0N/A ((float) ((1 << dstSM.getSampleSize(i)) - 1)) / maxNum;
0N/A }
0N/A }
0N/A int ys = src.getMinY();
0N/A int yd = dst.getMinY();
0N/A int xs, xd;
0N/A int sample;
0N/A if (precision == 8) {
0N/A byte[] srcLine = new byte[w * srcNumBands];
0N/A byte[] dstLine = new byte[w * dstNumBands];
0N/A int idx;
0N/A // TODO check for src npixels = dst npixels
5818N/A try {
5818N/A srcIL = new LCMSImageLayout(
5818N/A srcLine, srcLine.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumInComponents());
5818N/A dstIL = new LCMSImageLayout(
5818N/A dstLine, dstLine.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert rasters");
5818N/A }
0N/A // process each scanline
0N/A for (int y = 0; y < h; y++, ys++, yd++) {
0N/A // get src scanline
0N/A xs = src.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xs++) {
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A sample = src.getSample(xs, ys, i);
0N/A srcLine[idx++] = (byte)
0N/A ((sample * srcScaleFactor[i]) + 0.5f);
0N/A }
0N/A }
0N/A
0N/A // color convert srcLine to dstLine
2693N/A doTransform(srcIL, dstIL);
0N/A
0N/A // store dst scanline
0N/A xd = dst.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xd++) {
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A sample = (int) (((dstLine[idx++] & 0xff) *
0N/A dstScaleFactor[i]) + 0.5f);
0N/A dst.setSample(xd, yd, i, sample);
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A short[] srcLine = new short[w * srcNumBands];
0N/A short[] dstLine = new short[w * dstNumBands];
0N/A int idx;
5818N/A
5818N/A try {
5818N/A srcIL = new LCMSImageLayout(
5818N/A srcLine, srcLine.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
0N/A
5818N/A dstIL = new LCMSImageLayout(
5818N/A dstLine, dstLine.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert rasters");
5818N/A }
0N/A // process each scanline
0N/A for (int y = 0; y < h; y++, ys++, yd++) {
0N/A // get src scanline
0N/A xs = src.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xs++) {
0N/A for (int i = 0; i < srcNumBands; i++) {
0N/A sample = src.getSample(xs, ys, i);
0N/A srcLine[idx++] = (short)
0N/A ((sample * srcScaleFactor[i]) + 0.5f);
0N/A }
0N/A }
0N/A
0N/A // color convert srcLine to dstLine
2693N/A doTransform(srcIL, dstIL);
2693N/A
0N/A // store dst scanline
0N/A xd = dst.getMinX();
0N/A idx = 0;
0N/A for (int x = 0; x < w; x++, xd++) {
0N/A for (int i = 0; i < dstNumBands; i++) {
0N/A sample = (int) (((dstLine[idx++] & 0xffff) *
0N/A dstScaleFactor[i]) + 0.5f);
0N/A dst.setSample(xd, yd, i, sample);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /* convert an array of colors in short format */
0N/A /* each color is a contiguous set of array elements */
0N/A /* the number of colors is (size of the array) / (number of input/output
0N/A components */
0N/A public short[] colorConvert(short[] src, short[] dst) {
0N/A
0N/A if (dst == null) {
0N/A dst = new short [(src.length/getNumInComponents())*getNumOutComponents()];
0N/A }
0N/A
5818N/A try {
5818N/A LCMSImageLayout srcIL = new LCMSImageLayout(
5818N/A src, src.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
0N/A
5818N/A LCMSImageLayout dstIL = new LCMSImageLayout(
5818N/A dst, dst.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
0N/A
5818N/A doTransform(srcIL, dstIL);
0N/A
5818N/A return dst;
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert data");
5818N/A }
0N/A }
0N/A
0N/A public byte[] colorConvert(byte[] src, byte[] dst) {
0N/A if (dst == null) {
0N/A dst = new byte [(src.length/getNumInComponents())*getNumOutComponents()];
0N/A }
0N/A
5818N/A try {
5818N/A LCMSImageLayout srcIL = new LCMSImageLayout(
5818N/A src, src.length/getNumInComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumInComponents());
0N/A
5818N/A LCMSImageLayout dstIL = new LCMSImageLayout(
5818N/A dst, dst.length/getNumOutComponents(),
5818N/A LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
5818N/A LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
0N/A
5818N/A doTransform(srcIL, dstIL);
0N/A
5818N/A return dst;
5818N/A } catch (ImageLayoutException e) {
5818N/A throw new CMMException("Unable to convert data");
5818N/A }
0N/A }
0N/A}