Esempio n. 1
0
        /////////////////////////////////////////////////////////////////////////// 
        public static Bitmap DecodeImage(PsdFile psdFile)
        {
            Bitmap bitmap = new Bitmap(psdFile.Columns, psdFile.Rows, PixelFormat.Format32bppArgb);

            return bitmap;
        }
Esempio n. 2
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

            PsdFile = psdFile;
            Rect = new Rectangle
                       {
                           Y = reader.ReadInt32(),
                           X = reader.ReadInt32(),
                           Height = reader.ReadInt32() - Rect.Y,
                           Width = reader.ReadInt32() - Rect.X
                       };

            //-----------------------------------------------------------------------

            int numberOfChannels = reader.ReadUInt16();
            _channels.Clear();
            for (var channel = 0; channel < numberOfChannels; channel++)
            {
                var ch = new Channel(reader, this);
                _channels.Add(ch);
                _sortedChannels.Add(ch.Id, ch);
            }

            //-----------------------------------------------------------------------

            var signature = new string(reader.ReadChars(4));
            if (signature != "8BIM")
                throw (new IOException("Layer Channelheader error!"));

            _blendModeKey = new string(reader.ReadChars(4));
            Opacity = reader.ReadByte();

            Clipping = reader.ReadByte() > 0;

            //-----------------------------------------------------------------------

            byte flags = reader.ReadByte();
            _flags = new BitVector32(flags);

            //-----------------------------------------------------------------------

            reader.ReadByte(); //padding

            //-----------------------------------------------------------------------

            Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position.ToString());

            // this is the total size of the MaskData, the BlendingRangesData, the
            // Name and the AdjustmenLayerInfo
            uint extraDataSize = reader.ReadUInt32();

            // remember the start position for calculation of the
            // AdjustmenLayerInfo size
            long extraDataStartPosition = reader.BaseStream.Position;

            m_maskData = new Mask(reader, this);
            m_blendingRangesData = new BlendingRanges(reader, this);

            //-----------------------------------------------------------------------

            long namePosition = reader.BaseStream.Position;

            Name = reader.ReadPascalString();

            var paddingBytes = (int)((reader.BaseStream.Position - namePosition) % 4);

            Debug.Print("Layer {0} padding bytes after name", paddingBytes);
            reader.ReadBytes(paddingBytes);

            //-----------------------------------------------------------------------

            m_adjustmentInfo.Clear();

            long adjustmenLayerEndPos = extraDataStartPosition + extraDataSize;
            while (reader.BaseStream.Position < adjustmenLayerEndPos)
            {
                try
                {
                    m_adjustmentInfo.Add(new AdjusmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = adjustmenLayerEndPos;
                }
            }

            //-----------------------------------------------------------------------
            // make shure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = adjustmenLayerEndPos;
        }
Esempio n. 3
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.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;
        }
Esempio n. 4
0
 ///////////////////////////////////////////////////////////////////////////
 public Layer(PsdFile psdFile)
 {
     Rect = Rectangle.Empty;
     PsdFile = psdFile;
     PsdFile.Layers.Add(this);
 }