private unsafe int ExtractXYZ(ColorID colorID, CS_XYZ *xyz)
        {
            if (xyz == null)
            {
                return(PSError.kSPBadParameterError);
            }

            Color item = colors[colorID];

            byte c0 = item.Component0;
            byte c1 = item.Component1;
            byte c2 = item.Component2;
            byte c3 = item.Component3;

            if (item.ColorSpace != ColorSpace.XYZSpace)
            {
                int error = ColorServicesConvert.Convert(item.ColorSpace, ColorSpace.XYZSpace, ref c0, ref c1, ref c2, ref c3);
                if (error != PSError.kSPNoError)
                {
                    return(error);
                }
            }

            xyz->x = c0;
            xyz->y = c1;
            xyz->z = c2;

            return(PSError.kSPNoError);
        }
        private int ExtractComponents(IntPtr colorID, ColorSpace colorSpace, ref byte c0, ref byte c1, ref byte c2, ref byte c3, ref byte gamutFlag)
        {
            if (!IsValidColorSpace(colorSpace))
            {
                return(PSError.kSPBadParameterError);
            }

            Color item = colors[colorID];

            c0 = item.Component0;
            c1 = item.Component1;
            c2 = item.Component2;
            c3 = item.Component3;

            int error = PSError.kSPNoError;

            if (item.ColorSpace != colorSpace)
            {
                error = ColorServicesConvert.Convert(item.ColorSpace, colorSpace, ref c0, ref c1, ref c2, ref c3);
            }

            return(error);
        }
        private unsafe int ExtractComponents(ColorID colorID, ColorSpace colorSpace, byte *c0, byte *c1, byte *c2, byte *c3, byte *gamutFlag)
        {
            if (!IsValidColorSpace(colorSpace) || c0 == null || c1 == null || c2 == null || c3 == null)
            {
                return(PSError.kSPBadParameterError);
            }

            Color item = colors[colorID];

            *c0 = item.Component0;
            *c1 = item.Component1;
            *c2 = item.Component2;
            *c3 = item.Component3;

            int error = PSError.kSPNoError;

            if (item.ColorSpace != colorSpace)
            {
                error = ColorServicesConvert.Convert(item.ColorSpace, colorSpace, ref *c0, ref *c1, ref *c2, ref *c3);
            }

            return(error);
        }
        private int ExtractXYZ(IntPtr colorID, ref CS_XYZ xyz)
        {
            Color item = colors[colorID];

            byte c0 = item.Component0;
            byte c1 = item.Component1;
            byte c2 = item.Component2;
            byte c3 = item.Component3;

            if (item.ColorSpace != ColorSpace.XYZSpace)
            {
                int error = ColorServicesConvert.Convert(item.ColorSpace, ColorSpace.XYZSpace, ref c0, ref c1, ref c2, ref c3);
                if (error != PSError.kSPNoError)
                {
                    return(error);
                }
            }

            xyz.x = c0;
            xyz.y = c1;
            xyz.z = c2;

            return(PSError.kSPNoError);
        }
        private unsafe int Convert8(ColorSpace inputCSpace, ColorSpace outputCSpace, IntPtr colorArray, short count)
        {
            if (!IsValidColorSpace(inputCSpace) || !IsValidColorSpace(outputCSpace) || colorArray == IntPtr.Zero)
            {
                return(PSError.kSPBadParameterError);
            }

            int        error = PSError.kSPNoError;
            byte       c0    = 0;
            byte       c1    = 0;
            byte       c2    = 0;
            byte       c3    = 0;
            CS_Color8 *color = (CS_Color8 *)colorArray.ToPointer();

            for (int i = 0; i < count; i++)
            {
                // 0RGB, CMYK, 0HSB , 0HSL, 0LAB, 0XYZ, 000Gray
                // all modes except CMYK and GrayScale begin at the second byte
                switch (inputCSpace)
                {
                case ColorSpace.GraySpace:
                    c0 = color->c3;
                    break;

                case ColorSpace.CMYKSpace:
                    c0 = color->c0;
                    c1 = color->c1;
                    c2 = color->c2;
                    c3 = color->c3;
                    break;

                case ColorSpace.RGBSpace:
                case ColorSpace.HSBSpace:
                case ColorSpace.HSLSpace:
                case ColorSpace.LabSpace:
                case ColorSpace.XYZSpace:
                default:
                    c0 = color->c1;
                    c1 = color->c2;
                    c2 = color->c3;
                    break;
                }

                error = ColorServicesConvert.Convert(inputCSpace, outputCSpace, ref c0, ref c1, ref c2, ref c3);
                if (error != PSError.kSPNoError)
                {
                    break;
                }

                switch (outputCSpace)
                {
                case ColorSpace.CMYKSpace:
                    color->c0 = c0;
                    color->c1 = c1;
                    color->c2 = c2;
                    color->c3 = c3;
                    break;

                case ColorSpace.GraySpace:
                    color->c3 = c0;
                    break;

                case ColorSpace.RGBSpace:
                case ColorSpace.HSBSpace:
                case ColorSpace.HSLSpace:
                case ColorSpace.LabSpace:
                case ColorSpace.XYZSpace:
                default:
                    color->c1 = c0;
                    color->c2 = c1;
                    color->c3 = c2;
                    break;
                }

                color++;
            }

            return(error);
        }