Esempio n. 1
0
        public override float[] toRGB(float[] colorvalue)
        {
            if (toRGBTransform == null)
            {
                ICC_Profile sRGBProfile =
                    ((ICC_ColorSpace)ColorSpace.getInstance(CS_sRGB)).getProfile();
                ICC_Profile[] profiles = { getProfile(), sRGBProfile };
                toRGBTransform = new ICC_Transform(profiles);
                if (!scalingDataLoaded)
                {
                    scaler.loadScalingData(this);
                    scalingDataLoaded = true;
                }
            }

            short[] data = new short[getNumComponents()];

            scaler.scale(colorvalue, data, 0);

            short[] converted =
                converter.translateColor(toRGBTransform, data, null);

            // unscale to sRGB
            float[] res = new float[3];

            res[0] = ((converted[0] & 0xFFFF)) * INV_MAX_SHORT;
            res[1] = ((converted[1] & 0xFFFF)) * INV_MAX_SHORT;
            res[2] = ((converted[2] & 0xFFFF)) * INV_MAX_SHORT;

            return(res);
        }
Esempio n. 2
0
        public override float[] fromRGB(float[] rgbvalue)
        {
            if (fromRGBTransform == null)
            {
                ICC_Profile sRGBProfile =
                    ((ICC_ColorSpace)ColorSpace.getInstance(CS_sRGB)).getProfile();
                ICC_Profile[] profiles = { sRGBProfile, getProfile() };
                fromRGBTransform = new ICC_Transform(profiles);
                if (!scalingDataLoaded)
                {
                    scaler.loadScalingData(this);
                    scalingDataLoaded = true;
                }
            }

            // scale rgb value to short
            short[] scaledRGBValue = new short[3];
            scaledRGBValue[0] = (short)(rgbvalue[0] * MAX_SHORT + 0.5f);
            scaledRGBValue[1] = (short)(rgbvalue[1] * MAX_SHORT + 0.5f);
            scaledRGBValue[2] = (short)(rgbvalue[2] * MAX_SHORT + 0.5f);

            short[] converted =
                converter.translateColor(fromRGBTransform, scaledRGBValue, null);

            float[] res = new float[getNumComponents()];

            scaler.unscale(res, converted, 0);

            return(res);
        }
Esempio n. 3
0
        public override float[] toCIEXYZ(float[] colorvalue)
        {
            if (toXYZTransform == null)
            {
                ICC_Profile xyzProfile =
                    ((ICC_ColorSpace)ColorSpace.getInstance(CS_CIEXYZ)).getProfile();
                ICC_Profile[] profiles = { getProfile(), xyzProfile };
                try
                {
                    int[] intents =
                    {
                        ICC_Profile.icRelativeColorimetric,
                        ICC_Profile.icPerceptual
                    };
                    toXYZTransform = new ICC_Transform(profiles, intents);
                }
                catch (CMMException)
                { // No such tag, use what we can
                    toXYZTransform = new ICC_Transform(profiles);
                }

                if (!scalingDataLoaded)
                {
                    scaler.loadScalingData(this);
                    scalingDataLoaded = true;
                }
            }

            short[] data = new short[getNumComponents()];

            scaler.scale(colorvalue, data, 0);

            short[] converted =
                converter.translateColor(toXYZTransform, data, null);

            // unscale to XYZ
            float[] res = new float[3];

            res[0] = ((converted[0] & 0xFFFF)) * SHORT2XYZ_FACTOR;
            res[1] = ((converted[1] & 0xFFFF)) * SHORT2XYZ_FACTOR;
            res[2] = ((converted[2] & 0xFFFF)) * SHORT2XYZ_FACTOR;

            return(res);
        }
Esempio n. 4
0
        public override float[] fromCIEXYZ(float[] xyzvalue)
        {
            if (fromXYZTransform == null)
            {
                ICC_Profile xyzProfile =
                    ((ICC_ColorSpace)ColorSpace.getInstance(CS_CIEXYZ)).getProfile();
                ICC_Profile[] profiles = { xyzProfile, getProfile() };
                try
                {
                    int[] intents =
                    {
                        ICC_Profile.icPerceptual,
                        ICC_Profile.icRelativeColorimetric
                    };
                    fromXYZTransform = new ICC_Transform(profiles, intents);
                }
                catch (CMMException e)
                { // No such tag, use what we can
                    fromXYZTransform = new ICC_Transform(profiles);
                }

                if (!scalingDataLoaded)
                {
                    scaler.loadScalingData(this);
                    scalingDataLoaded = true;
                }
            }

            // scale xyz value to short
            short[] scaledXYZValue = new short[3];
            scaledXYZValue[0] = (short)(xyzvalue[0] * XYZ2SHORT_FACTOR + 0.5f);
            scaledXYZValue[1] = (short)(xyzvalue[1] * XYZ2SHORT_FACTOR + 0.5f);
            scaledXYZValue[2] = (short)(xyzvalue[2] * XYZ2SHORT_FACTOR + 0.5f);

            short[] converted =
                converter.translateColor(fromXYZTransform, scaledXYZValue, null);

            float[] res = new float[getNumComponents()];

            scaler.unscale(res, converted, 0);

            return(res);
        }