Пример #1
0
        ///////////////////////////////////////////////////////////////////////////

        private static Color GetColor(PsdFile psdFile, int pos)
        {
            Color c = Color.White;

            switch (psdFile.ColorMode)
            {
            case PsdFile.ColorModes.RGB:
                c = Color.FromArgb(psdFile.ImageData[0][pos],
                                   psdFile.ImageData[1][pos],
                                   psdFile.ImageData[2][pos]);
                break;

            case PsdFile.ColorModes.CMYK:
                c = CMYKToRGB(psdFile.ImageData[0][pos],
                              psdFile.ImageData[1][pos],
                              psdFile.ImageData[2][pos],
                              psdFile.ImageData[3][pos]);
                break;

            case PsdFile.ColorModes.Multichannel:
                c = CMYKToRGB(psdFile.ImageData[0][pos],
                              psdFile.ImageData[1][pos],
                              psdFile.ImageData[2][pos],
                              0);
                break;

            case PsdFile.ColorModes.Bitmap:
                byte bwValue = ImageDecoder.GetBitmapValue(psdFile.ImageData[0], pos);
                c = Color.FromArgb(bwValue, bwValue, bwValue);
                break;

            case PsdFile.ColorModes.Grayscale:
            case PsdFile.ColorModes.Duotone:
                c = Color.FromArgb(psdFile.ImageData[0][pos],
                                   psdFile.ImageData[0][pos],
                                   psdFile.ImageData[0][pos]);
                break;

            case PsdFile.ColorModes.Indexed:
            {
                int index = (int)psdFile.ImageData[0][pos];
                c = Color.FromArgb((int)psdFile.ColorModeData[index],
                                   psdFile.ColorModeData[index + 256],
                                   psdFile.ColorModeData[index + 2 * 256]);
            }
            break;

            case PsdFile.ColorModes.Lab:
            {
                c = LabToRGB(psdFile.ImageData[0][pos],
                             psdFile.ImageData[1][pos],
                             psdFile.ImageData[2][pos]);
            }
            break;
            }

            return(c);
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Builds a color instance from the specified layer and position. Adds alpha value if channel exists.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        private static Color GetColor(LayerWrapper layer, int pos)
        {
            Color c = Color.White;

            switch (layer.colorMode)
            {
            case PsdFile.ColorModes.RGB:
                c = Color.FromArgb(layer.ch0bytes[pos],
                                   layer.ch1bytes[pos],
                                   layer.ch2bytes[pos]);
                break;

            case PsdFile.ColorModes.CMYK:
                c = CMYKToRGB(layer.ch0bytes[pos],
                              layer.ch1bytes[pos],
                              layer.ch2bytes[pos],
                              layer.ch3bytes[pos]);
                break;

            case PsdFile.ColorModes.Multichannel:
                c = CMYKToRGB(layer.ch0bytes[pos],
                              layer.ch1bytes[pos],
                              layer.ch2bytes[pos],
                              0);
                break;

            case PsdFile.ColorModes.Bitmap:
                byte bwValue = ImageDecoder.GetBitmapValue(layer.ch0bytes, pos);
                c = Color.FromArgb(bwValue, bwValue, bwValue);
                break;

            case PsdFile.ColorModes.Grayscale:
            case PsdFile.ColorModes.Duotone:
                c = Color.FromArgb(layer.ch0bytes[pos],
                                   layer.ch0bytes[pos],
                                   layer.ch0bytes[pos]);
                break;

            case PsdFile.ColorModes.Indexed:
            {
                int index = (int)layer.ch0bytes[pos];
                c = Color.FromArgb((int)layer.colorModeData[index],
                                   layer.colorModeData[index + 256],
                                   layer.colorModeData[index + 2 * 256]);
            }
            break;

            case PsdFile.ColorModes.Lab:
            {
                c = LabToRGB(layer.ch0bytes[pos],
                             layer.ch1bytes[pos],
                             layer.ch2bytes[pos]);
            }
            break;
            }

            if (layer.hasalpha)
            {
                c = Color.FromArgb(layer.alphabytes[pos], c);
            }

            return(c);
        }