Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mask"/> class.
        /// </summary>
        /// <param name="reader">The reader to use to initialize the instance.</param>
        /// <param name="layer">The layer this mask belongs to.</param>
        internal Mask(BinaryReverseReader reader, Layer layer)
        {
            Layer = layer;
            uint num1 = reader.ReadUInt32();
            if (num1 <= 0U)
            {
                return;
            }

            long position = reader.BaseStream.Position;
            rect = new Rect();
            rect.y = reader.ReadInt32();
            rect.x = reader.ReadInt32();
            rect.height = reader.ReadInt32() - rect.y;
            rect.width = reader.ReadInt32() - rect.x;
            DefaultColor = reader.ReadByte();
            flags = new BitVector32(reader.ReadByte());
            if ((int)num1 == 36)
            {
                reader.ReadByte();  // bit vector
                reader.ReadByte();  // ???
                reader.ReadInt32(); // rect Y
                reader.ReadInt32(); // rect X
                reader.ReadInt32(); // rect total height (actual height = this - Y)
                reader.ReadInt32(); // rect total width (actual width = this - Y)
            }

            reader.BaseStream.Position = position + num1;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageResource"/> class using a reader.
        /// </summary>
        /// <param name="reader">The reader to use to create the instance.</param>
        public ImageResource(BinaryReverseReader reader)
        {
            // read the OS type
            string osType = new string(reader.ReadChars(4));
            if (osType != "8BIM" && osType != "MeSa")
            {
                throw new InvalidOperationException("Could not read an image resource");
            }

            // read the ID
            ID = reader.ReadInt16();

            // read the name
            Name = string.Empty;
            Name = reader.ReadPascalString();

            // read the length of the data in bytes
            uint length = reader.ReadUInt32();

            // read the actual data
            Data = reader.ReadBytes((int)length);
            if (reader.BaseStream.Position % 2L != 1L)
            {
                return;
            }

            reader.ReadByte();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads all of the layers from the reader.
        /// </summary>
        /// <param name="reader">The reader to use to read the layers.</param>
        private void LoadLayers(BinaryReverseReader reader)
        {
            int num1 = reader.ReadInt32(); //.ReadUInt32(); ;// reader.ReadUInt32();

            //  Debug.Log(Time.time + "LoadLayers num1=" + num1 + ",return ?" + (num1 <= 0U));

            if (num1 <= 0U)
            {
                return;
            }

            long  position = reader.BaseStream.Position;
            short num2     = reader.ReadInt16();

            if (num2 < 0)
            {
                AbsoluteAlpha = true;
                num2          = Math.Abs(num2);
            }

            Layers.Clear();

            //Debug.Log(Time.time + "LoadLayers num2=" + num2 + ",return ?" + (num2 == 0));
            if (num2 == 0)
            {
                return;
            }

            for (int index = 0; index < (int)num2; ++index)
            {
                Layers.Add(new Layer(reader, this));
            }

            foreach (Layer layer in Layers)
            {
                foreach (Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                    {
                        channel.LoadPixelData(reader);
                    }
                }

                layer.MaskData.LoadPixelData(reader);
            }

            if (reader.BaseStream.Position % 2L == 1L)
            {
                reader.ReadByte();
            }

            reader.BaseStream.Position = position + num1;
        }
Ejemplo n.º 4
0
        internal Mask(BinaryReverseReader reader, Layer layer)
        {
            Layer = layer;
            // 从文档 五 - 4 - 14)
            uint num1 = reader.ReadUInt32();

            if (num1 <= 0U)
            {
                return;
            }

            long position = reader.BaseStream.Position;

            _rect         = new Rect();
            _rect.y       = reader.ReadInt32();
            _rect.x       = reader.ReadInt32();
            _rect.height  = reader.ReadInt32() - _rect.y;
            _rect.width   = reader.ReadInt32() - _rect.x;
            _defaultColor = reader.ReadByte();
            _flags        = new BitVector32(reader.ReadByte());

            int tempNum1 = -1;
            int tempNum2 = -1;
            int tempNum3 = -1;
            int tempNum4 = -1;
            int tempNum5 = -1;
            int tempNum6 = -1;

            if ((int)num1 == 36)
            {
                tempNum1 = reader.ReadByte();  // bit vector
                tempNum2 = reader.ReadByte();  // ???
                tempNum3 = reader.ReadInt32(); // rect Y
                tempNum4 = reader.ReadInt32(); // rect X
                tempNum5 = reader.ReadInt32(); // rect total height (actual height = this - Y)
                tempNum6 = reader.ReadInt32(); // rect total width (actual width = this - Y)
            }
            reader.BaseStream.Position = position + num1;
        }
Ejemplo n.º 5
0
 private byte readByte(BinaryReverseReader stream)
 {
     if (useCachedByte)
     {
         Debug.Assert(cachedByte != -1);
         useCachedByte = false;
         return((byte)cachedByte);
     }
     else
     {
         cachedByte = stream.ReadByte();
         return((byte)cachedByte);
     }
 }
Ejemplo n.º 6
0
        public AlphaChannels(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryReverseReader reader = imgRes.DataReader;

            // the names are pascal strings without padding!!!
            while ((reader.BaseStream.Length - reader.BaseStream.Position) > 0)
            {
                byte   stringLength = reader.ReadByte();
                string s            = new string(reader.ReadChars(stringLength));
                if (s.Length > 0)
                {
                    m_channelNames.Add(s);
                }
            }
            reader.Close();
        }
Ejemplo n.º 7
0
        //////////////////////////////////////////////////////////////////

        public ImageResource(BinaryReverseReader reader)
        {
            m_osType = new string(reader.ReadChars(4));
            if (m_osType != "8BIM" && m_osType != "MeSa")
            {
                throw new InvalidOperationException("Could not read an image resource");
            }

            m_id   = reader.ReadInt16();
            m_name = reader.ReadPascalString();

            uint settingLength = reader.ReadUInt32();

            m_data = reader.ReadBytes((int)settingLength);

            if (reader.BaseStream.Position % 2 == 1)
            {
                reader.ReadByte();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the text information for the layer.
        /// </summary>
        /// <param name="dataReader">The reader to use to read the text data.</param>
        private void ReadTextLayer(BinaryReverseReader dataReader)
        {
            IsTextLayer = true;

            // read the text layer's text string
            dataReader.Seek("/Text");
            dataReader.ReadBytes(4);
            Text = dataReader.ReadString();

            // read the text justification
            dataReader.Seek("/Justification ");
            int justification = dataReader.ReadByte() - 48;
            Justification = TextJustification.Left;
            if (justification == 1)
            {
                Justification = TextJustification.Right;
            }
            else if (justification == 2)
            {
                Justification = TextJustification.Center;
            }

            // read the font size
            dataReader.Seek("/FontSize ");
            FontSize = dataReader.ReadFloat();

            // read the font fill color
            dataReader.Seek("/FillColor");
            dataReader.Seek("/Values [ ");
            float alpha = dataReader.ReadFloat();
            dataReader.ReadByte();
            float red = dataReader.ReadFloat();
            dataReader.ReadByte();
            float green = dataReader.ReadFloat();
            dataReader.ReadByte();
            float blue = dataReader.ReadFloat();
            FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue);

            // read the font name
            dataReader.Seek("/FontSet ");
            dataReader.Seek("/Name");
            dataReader.ReadBytes(4);
            FontName = dataReader.ReadString();

            // read the warp style
            dataReader.Seek("warpStyle");
            dataReader.Seek("warpStyle");
            dataReader.ReadBytes(3);
            int num13 = dataReader.ReadByte();
            WarpStyle = string.Empty;

            for (; num13 > 0; --num13)
            {
                string str = WarpStyle + dataReader.ReadChar();
                WarpStyle = str;
            }
        }
Ejemplo n.º 9
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

            m_psdFile     = psdFile;
            m_rect        = new Rectangle();
            m_rect.Y      = reader.ReadInt32();
            m_rect.X      = reader.ReadInt32();
            m_rect.Height = reader.ReadInt32() - m_rect.Y;
            m_rect.Width  = reader.ReadInt32() - m_rect.X;

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

            int numberOfChannels = reader.ReadUInt16();

            this.m_channels.Clear();
            for (int channel = 0; channel < numberOfChannels; channel++)
            {
                Channel ch = new Channel(reader, this);
                m_channels.Add(ch);
                m_sortedChannels.Add(ch.ID, ch);
            }

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

            string signature = new string(reader.ReadChars(4));

            if (signature != "8BIM")
            {
                throw (new IOException("Layer Channelheader error!"));
            }

            m_blendModeKey = new string(reader.ReadChars(4));
            m_opacity      = reader.ReadByte();

            m_clipping = reader.ReadByte() > 0;

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

            byte flags = reader.ReadByte();

            m_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 AdjustmentLayerInfo
            uint extraDataSize = reader.ReadUInt32();

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

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

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

            long namePosition = reader.BaseStream.Position;

            m_name = reader.ReadPascalString();

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

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

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

            m_adjustmentInfo.Clear();

            long adjustmentLayerEndPos = extraDataStartPosition + extraDataSize;

            while (reader.BaseStream.Position < adjustmentLayerEndPos)
            {
                try
                {
                    AdjustmentLayerInfo ali = new AdjustmentLayerInfo(reader, this);
                    if (ali.Key.Equals("lrFX"))
                    {
                        //A sub-key - we want to merge its sub-layer info items with this dict.
                        m_adjustmentInfo.AddRange(new Effects(ali)._resources.Values);
                    }
                    else
                    {
                        m_adjustmentInfo.Add(ali); // Just add the items
                    }
                }
                catch
                {
                    reader.BaseStream.Position = adjustmentLayerEndPos;
                }
            }


            //-----------------------------------------------------------------------
            // make sure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = adjustmentLayerEndPos;
        }
Ejemplo n.º 10
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

              m_psdFile = psdFile;
              m_rect = new Rectangle();
              m_rect.Y = reader.ReadInt32();
              m_rect.X = reader.ReadInt32();
              m_rect.Height = reader.ReadInt32() - m_rect.Y;
              m_rect.Width = reader.ReadInt32() - m_rect.X;

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

              int numberOfChannels = reader.ReadUInt16();
              this.m_channels.Clear();
              for (int channel = 0; channel < numberOfChannels; channel++)
              {
            Channel ch = new Channel(reader, this);
            m_channels.Add(ch);
            m_sortedChannels.Add(ch.ID, ch);
              }

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

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

              m_blendModeKey = new string(reader.ReadChars(4));
              m_opacity = reader.ReadByte();

              m_clipping = reader.ReadByte() > 0;

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

              byte flags = reader.ReadByte();
              m_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 AdjustmentLayerInfo
              uint extraDataSize = reader.ReadUInt32();

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

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

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

              long namePosition = reader.BaseStream.Position;

              m_name = reader.ReadPascalString();

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

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

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

              m_adjustmentInfo.Clear();

              long adjustmentLayerEndPos = extraDataStartPosition + extraDataSize;
              while (reader.BaseStream.Position < adjustmentLayerEndPos)
              {
            try
            {
            AdjustmentLayerInfo ali = new AdjustmentLayerInfo(reader, this);
            if (ali.Key.Equals("lrFX"))
            {
                //A sub-key - we want to merge its sub-layer info items with this dict.
                m_adjustmentInfo.AddRange(new Effects(ali)._resources.Values);
            } else
                m_adjustmentInfo.Add(ali); // Just add the items
            }
            catch
            {
              reader.BaseStream.Position = adjustmentLayerEndPos;
            }
              }

              //-----------------------------------------------------------------------
              // make sure we are not on a wrong offset, so set the stream position
              // manually
              reader.BaseStream.Position = adjustmentLayerEndPos;
        }
Ejemplo n.º 11
0
        //////////////////////////////////////////////////////////////////

        public ImageResource(BinaryReverseReader reader)
        {
            m_osType = new string(reader.ReadChars(4));
            if (m_osType != "8BIM" && m_osType != "MeSa")
            {
                throw new InvalidOperationException("Could not read an image resource");
            }

            m_id = reader.ReadInt16();
            m_name = reader.ReadPascalString();

            uint settingLength = reader.ReadUInt32();
            m_data = reader.ReadBytes((int) settingLength);

            if (reader.BaseStream.Position%2 == 1)
                reader.ReadByte();
        }
Ejemplo n.º 12
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position);

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


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

            int numberOfChannels = reader.ReadUInt16();

            m_channels.Clear();
            for (int channel = 0; channel < numberOfChannels; channel++)
            {
                var ch = new Channel(reader, this);
                m_channels.Add(ch);
                m_sortedChannels.Add(ch.ID, ch);
            }

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

            var signature = new string(reader.ReadChars(4));

            if (signature != LayerConstants.EightBimSignature)
            {
                throw (new IOException("Layer Channelheader error!"));
            }

            m_blendModeKey = new string(reader.ReadChars(4));
            m_opacity      = reader.ReadByte();

            m_clipping = reader.ReadByte() > 0;

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

            byte flags = reader.ReadByte();

            m_flags = new BitVector32(flags);

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

            reader.ReadByte(); //padding

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

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

            // 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);

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

            var namePosition = reader.BaseStream.Position;

            m_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;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data.
        /// </summary>
        /// <param name="reader">The reader containing the PSD file data.</param>
        /// <param name="psdFile">The PSD file to set as the parent.</param>
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Children = new List <Layer>();
            PsdFile  = psdFile;

            // read the rect
            Rect rect = new Rect();

            rect.y      = reader.ReadInt32();
            rect.x      = reader.ReadInt32();
            rect.height = reader.ReadInt32() - rect.y;
            rect.width  = reader.ReadInt32() - rect.x;
            Rect        = rect;

            // read the channels
            int channelCount = reader.ReadUInt16();

            Channels       = new List <Channel>();
            SortedChannels = new SortedList <short, Channel>();
            for (int index = 0; index < channelCount; ++index)
            {
                Channel channel = new Channel(reader, this);
                Channels.Add(channel);

                //Debug.Log(Time.time + "channel.ID=" + channel.ID + ",layer=" + this.Name);
                SortedChannels.Add(channel.ID, channel);
            }

            string head = reader.readStringNew(4);

            //Debug.Log(Time.time + ",head=" + head);
            // read the header and verify it
            if (head != "8BIM")
            {
                throw new IOException("Layer Channelheader error!");
            }

            // read the blend mode key (unused) (defaults to "norm")
            //reader.ReadChars(4);
            string layerRecordsBlendModeKey = reader.readStringNew(4);

            // read the opacity
            Opacity = reader.ReadByte();

            // read the clipping (unused) (< 0 = base, > 0 = non base)
            int Clipping = reader.ReadByte();

            // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant)
            flags = new BitVector32(reader.ReadByte());

            // skip a padding byte
            int Filler = reader.ReadByte();

            imageTransparent = Convert.ToSingle(Opacity) / byte.MaxValue;
            Debug.Log("layerRecordsBlendModeKey=" + layerRecordsBlendModeKey
                      + ",Opacity=" + Opacity
                      + ",Clipping=" + Clipping
                      + ",flags=" + flags
                      + ", Filler=" + Filler
                      + ",LayerTransparent=" + imageTransparent);

            uint num3      = reader.ReadUInt32();
            long position1 = reader.BaseStream.Position;

            MaskData = new Mask(reader, this);

            BlendingRangesData = new BlendingRanges(reader);
            long position2 = reader.BaseStream.Position;

            // read the name
            Name = reader.ReadPascalString();
            //Debug.Log(Time.time + ",read layer Name=" + Name + ".end");

            // read the adjustment info
            int count = (int)((reader.BaseStream.Position - position2) % 4L);

            reader.ReadBytes(count);
            //Debug.Log(Time.time + ",read count=" + count + ".end");

            AdjustmentInfo = new List <AdjustmentLayerInfo>();
            long num4 = position1 + num3;

            while (reader.BaseStream.Position < num4)
            {
                try
                {
                    AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = num4;
                }
            }


            string keyInfo = "";

            foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo)
            {
                keyInfo += ",key=" + adjustmentLayerInfo.Key + "\n";

                if (adjustmentLayerInfo.Key == "TySh")
                {
                    ReadTextLayer(adjustmentLayerInfo.DataReader);
                }
                else if (adjustmentLayerInfo.Key == "luni")
                {
                    // read the unicode name
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] temp1     = dataReader.ReadBytes(3);
                    byte   charCount = dataReader.ReadByte();
                    //本来 charCount 是文本串的长度,可以传入ReadString()限定读取长度,但Text除串头无文本长度信息,因此改为读一段Unicode字符串
                    Name = dataReader.ReadString();
                    if (Name == "")
                    {
                        Name = defaultLayerName;
                    }
                }
                //此处针对字体  图层样式
                else if (adjustmentLayerInfo.Key == "lrFX") //样式 相关,对于字体来说,就是描边之类的
                {
                    parseLrfxKeyword(adjustmentLayerInfo);  //yanruTODO测试屏蔽
                }
                //仅对于图片的
                else if (adjustmentLayerInfo.Key == "lspf")
                {
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] data = dataReader.ReadBytes(4);
                    printbytes(data, "lspf data", true);
                }
                else if (adjustmentLayerInfo.Key == "lclr")
                {
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] data = dataReader.ReadBytes(10);
                    printbytes(data, "lclr data", true);
                }
            }

            Debug.Log("layer=" + Name + ",Totalkey=\n" + keyInfo);

            reader.BaseStream.Position = num4;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Reads the text information for the layer.
        /// </summary>
        /// <param name="dataReader">The reader to use to read the text data.</param>
        private void ReadTextLayer(BinaryReverseReader dataReader)
        {
            IsTextLayer = true;

            // read the text layer's text string
            dataReader.Seek("/Text");
            dataReader.ReadBytes(4);
            Text = dataReader.ReadString();

            // read the text justification
            dataReader.Seek("/Justification ");
            int justification = dataReader.ReadByte() - 48;

            Justification = TextJustification.Left;
            if (justification == 1)
            {
                Justification = TextJustification.Right;
            }
            else if (justification == 2)
            {
                Justification = TextJustification.Center;
            }

            // read the font size
            dataReader.Seek("/FontSize ");
            FontSize = dataReader.ReadFloat();

            // read the font fill color
            dataReader.Seek("/FillColor");
            dataReader.Seek("/Values [ ");
            float alpha = dataReader.ReadFloat();

            dataReader.ReadByte();
            float red = dataReader.ReadFloat();

            dataReader.ReadByte();
            float green = dataReader.ReadFloat();

            dataReader.ReadByte();
            float blue = dataReader.ReadFloat();

            FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue);

            // read the font name
            dataReader.Seek("/FontSet ");
            dataReader.Seek("/Name");
            dataReader.ReadBytes(4);
            FontName = dataReader.ReadString();

            // read the warp style
            dataReader.Seek("warpStyle");
            dataReader.Seek("warpStyle");
            dataReader.ReadBytes(3);
            int num13 = dataReader.ReadByte();

            WarpStyle = string.Empty;

            for (; num13 > 0; --num13)
            {
                string str = WarpStyle + dataReader.ReadChar();
                WarpStyle = str;
            }
        }
Ejemplo n.º 15
0
        private void ReadTextLayer(BinaryReverseReader dataReader)
        {
            //文档 五 - 4 - 22) -d - 15
            IsTextLayer = true;
            dataReader.Seek("/Text");
            byte[] temp = dataReader.ReadBytes(4);

            Text = dataReader.ReadString();// ( true);

            dataReader.Seek("/Justification");
            int justification = dataReader.ReadByte();// - 48;

            Justification = TextJustification.Left;
            if (justification == 1)
            {
                Justification = TextJustification.Right;
            }
            else if (justification == 2)
            {
                Justification = TextJustification.Center;
            }

            dataReader.Seek("/FontSize ");
            FontSize = dataReader.ReadFloat();

            // read the font fill color
            dataReader.Seek("/FillColor");
            dataReader.Seek("/Values [ ");
            float alpha = dataReader.ReadFloat();

            dataReader.ReadByte();
            float red = dataReader.ReadFloat();

            dataReader.ReadByte();
            float green = dataReader.ReadFloat();

            dataReader.ReadByte();
            float blue = dataReader.ReadFloat();

            FillColor = new Color(red, green, blue, alpha);

            //  read the font name
            dataReader.Seek("/FontSet ");

            dataReader.Seek("/Name");

            FontName = dataReader.ReadString();

            // read the warp style
            dataReader.Seek("warpStyle");
            dataReader.Seek("warpStyle");
            byte[] wrapBytes = dataReader.ReadBytes(3);

            int num13 = dataReader.ReadByte();

            WarpStyle = string.Empty;

            for (; num13 > 0; --num13)
            {
                string str = WarpStyle + dataReader.ReadChar();
                WarpStyle = str;
            }
        }
Ejemplo n.º 16
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            //从文档 五 - 4 - 1) 开始读
            Children = new List <Layer>();
            PsdFile  = psdFile;

            Rect rect = new Rect();

            rect.y      = reader.ReadInt32();
            rect.x      = reader.ReadInt32();
            rect.height = reader.ReadInt32() - rect.y;
            rect.width  = reader.ReadInt32() - rect.x;
            Rect        = rect;

            int channelCount = reader.ReadUInt16();

            Channels       = new List <Channel>();
            SortedChannels = new SortedList <short, Channel>();
            for (int index = 0; index < channelCount; ++index)
            {
                Channel channel = new Channel(reader, this);
                Channels.Add(channel);
                SortedChannels.Add(channel.ID, channel);
            }

            string head = reader.ReadStringNew(4);

            if (head != "8BIM")
            {
                throw new IOException("Layer Channelheader error!");
            }

            string layerRecordsBlendModeKey = reader.ReadStringNew(4);

            Opacity = reader.ReadByte();

            int Clipping = reader.ReadByte();

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

            int Filler = reader.ReadByte();

            _imageTransparent = Convert.ToSingle(Opacity) / byte.MaxValue;

            //文档 五 - 4 - 13)
            uint num3      = reader.ReadUInt32();
            long position1 = reader.BaseStream.Position;

            MaskData = new Mask(reader, this);

            _blendingRangesData = new BlendingRanges(reader);
            long position2 = reader.BaseStream.Position;

            // 文档 五 - 4 - 21)
            Name = reader.ReadPascalString();
            // read the adjustment info
            int count = (int)((reader.BaseStream.Position - position2) % 4L);

            reader.ReadBytes(count);

            _adjustmentInfo = new List <AdjustmentLayerInfo>();
            long num4 = position1 + num3;

            while (reader.BaseStream.Position < num4)
            {
                try
                {
                    _adjustmentInfo.Add(new AdjustmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = num4;
                }
            }


            foreach (AdjustmentLayerInfo adjustmentLayerInfo in _adjustmentInfo)
            {
                if (adjustmentLayerInfo.Key == "TySh")
                {
                    ReadTextLayer(adjustmentLayerInfo.DataReader);
                }
                else if (adjustmentLayerInfo.Key == "luni")
                {
                    // read the unicode name
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] temp1     = dataReader.ReadBytes(3);
                    byte   charCount = dataReader.ReadByte();
                    //本来 charCount 是文本串的长度,可以传入ReadString()限定读取长度,但Text除串头无文本长度信息,因此改为读一段Unicode字符串
                    Name = dataReader.ReadString();
                    if (Name == "")
                    {
                        Name = DefaultLayerName;
                    }
                }
                //此处针对字体  图层样式
                else if (adjustmentLayerInfo.Key == "lrFX") //样式 相关,对于字体来说,就是描边之类的
                {
                    ParseLrfxKeyword(adjustmentLayerInfo);  //yanruTODO测试屏蔽
                }
                //仅对于图片的
                else if (adjustmentLayerInfo.Key == "lspf")
                {
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] data = dataReader.ReadBytes(4);
                }
                else if (adjustmentLayerInfo.Key == "lclr")
                {
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    byte[] data = dataReader.ReadBytes(10);
                }
            }

            reader.BaseStream.Position = num4;

            int deltaL = (int)(MaskData.Rect.x - Rect.x);
            int deltaR = (int)(Rect.xMax - MaskData.Rect.xMax);
            int deltaT = (int)(MaskData.Rect.y - Rect.y);
            int deltaB = (int)(Rect.yMax - MaskData.Rect.yMax);
            int l      = deltaL > 0 ? deltaL : 0;
            int r      = deltaR > 0 ? deltaR : 0;
            int t      = deltaT > 0 ? deltaT : 0;
            int b      = deltaB > 0 ? deltaB : 0;

            //Unity Document TextureImporter.spriteBorder  X=left, Y=bottom, Z=right, W=top.
            _border = new Vector4(l, b, r, t);
            //_is9Slice = SLICE_REG.Match(_name).Success;
            _is9Slice = _name.Contains(SLICE_HEAD);
        }
Ejemplo n.º 17
0
        ///////////////////////////////////////////////////////////////////////////
        private void LoadLayers(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position.ToString());

              uint layersInfoSectionLength = reader.ReadUInt32();

              if (layersInfoSectionLength <= 0)
            return;

              long startPosition = reader.BaseStream.Position;

              short numberOfLayers = reader.ReadInt16();

              // If <0, then number of layers is absolute value,
              // and the first alpha channel contains the transparency data for
              // the merged result.
              if (numberOfLayers < 0)
              {
            AbsoluteAlpha = true;
            numberOfLayers = Math.Abs(numberOfLayers);
              }

              m_layers.Clear();

              if (numberOfLayers == 0)
            return;

              for (int i = 0; i < numberOfLayers; i++)
              {
            m_layers.Add(new Layer(reader, this));
              }

              PrivateThreadPool threadPool = new PrivateThreadPool();

              foreach (Layer layer in m_layers)
              {
            foreach (Layer.Channel channel in layer.Channels)
            {
              if (channel.ID != -2)
              {
            channel.LoadPixelData(reader);
            DecompressChannelContext dcc = new DecompressChannelContext(channel);
            WaitCallback waitCallback = new WaitCallback(dcc.DecompressChannel);
            threadPool.QueueUserWorkItem(waitCallback);
              }
            }

            layer.MaskData.LoadPixelData(reader);
              }

              threadPool.Drain();

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

              if (reader.BaseStream.Position % 2 == 1)
            reader.ReadByte();

              //-----------------------------------------------------------------------
              // make sure we are not on a wrong offset, so set the stream position
              // manually
              reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }
Ejemplo n.º 18
0
        ///////////////////////////////////////////////////////////////////////////

        private void LoadLayers(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position.ToString());

            uint layersInfoSectionLength = reader.ReadUInt32();

            if (layersInfoSectionLength <= 0)
            {
                return;
            }

            long startPosition = reader.BaseStream.Position;

            short numberOfLayers = reader.ReadInt16();

            // If <0, then number of layers is absolute value,
            // and the first alpha channel contains the transparency data for
            // the merged result.
            if (numberOfLayers < 0)
            {
                AbsoluteAlpha  = true;
                numberOfLayers = Math.Abs(numberOfLayers);
            }

            m_layers.Clear();

            if (numberOfLayers == 0)
            {
                return;
            }

            for (int i = 0; i < numberOfLayers; i++)
            {
                m_layers.Add(new Layer(reader, this));
            }

            PrivateThreadPool threadPool = new PrivateThreadPool();

            foreach (Layer layer in m_layers)
            {
                foreach (Layer.Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                    {
                        channel.LoadPixelData(reader);
                        DecompressChannelContext dcc          = new DecompressChannelContext(channel);
                        WaitCallback             waitCallback = new WaitCallback(dcc.DecompressChannel);
                        threadPool.QueueUserWorkItem(waitCallback);
                    }
                }

                layer.MaskData.LoadPixelData(reader);
            }

            threadPool.Drain();


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

            if (reader.BaseStream.Position % 2 == 1)
            {
                reader.ReadByte();
            }

            //-----------------------------------------------------------------------
            // make sure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Reads all of the layers from the reader.
        /// </summary>
        /// <param name="reader">The reader to use to read the layers.</param>
        private void LoadLayers(BinaryReverseReader reader)
        {
            uint num1 = reader.ReadUInt32();
            if (num1 <= 0U)
            {
                return;
            }

            long position = reader.BaseStream.Position;
            short num2 = reader.ReadInt16();
            if (num2 < 0)
            {
                AbsoluteAlpha = true;
                num2 = Math.Abs(num2);
            }

            Layers.Clear();
            if (num2 == 0)
            {
                return;
            }

            for (int index = 0; index < (int)num2; ++index)
            {
                Layers.Add(new Layer(reader, this));
            }

            foreach (Layer layer in Layers)
            {
                foreach (Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                    {
                        channel.LoadPixelData(reader);
                    }
                }

                layer.MaskData.LoadPixelData(reader);
            }

            if (reader.BaseStream.Position % 2L == 1L)
            {
                reader.ReadByte();
            }

            reader.BaseStream.Position = position + num1;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Reads the text information for the layer.
        /// </summary>
        /// <param name="dataReader">The reader to use to read the text data.</param>
        private void ReadTextLayer(BinaryReverseReader dataReader)
        {
            IsTextLayer = true;

            // read the text layer's text string
            dataReader.Seek("/Text");
            byte[] temp = dataReader.ReadBytes(4); //注意:解析的起点是对的,但是终点不对
            //Debug.Log("text layer temp[0]=" + temp[0] + ",temp[1]=" + temp[1] + ",temp[2]=" + temp[2]+",temp[3]=" + temp[3]);
            Text = dataReader.ReadString();        // ( true);

            //  read the text justification
            dataReader.Seek("/Justification");
            int justification = dataReader.ReadByte();// - 48;

            Justification = TextJustification.Left;
            if (justification == 1)
            {
                Justification = TextJustification.Right;
            }
            else if (justification == 2)
            {
                Justification = TextJustification.Center;
            }
            //Debug.Log("text layer justification=" + justification);
            // read the font size
            dataReader.Seek("/FontSize ");
            FontSize = dataReader.ReadFloat();
            //Debug.Log("text layer FontSize=" + FontSize);

            // read the font fill color
            dataReader.Seek("/FillColor");
            dataReader.Seek("/Values [ ");
            float alpha = dataReader.ReadFloat();

            dataReader.ReadByte();
            float red = dataReader.ReadFloat();

            dataReader.ReadByte();
            float green = dataReader.ReadFloat();

            dataReader.ReadByte();
            float blue = dataReader.ReadFloat();

            FillColor = new Color(red, green, blue, alpha);
            //Debug.Log("text text="+ Text + ",red=" + red + ",green=" + green + ",blue=" + blue+ ",alpha="+ alpha+",position="+dataReader.BaseStream.Position+ ", byte.MaxValue=" + byte.MaxValue);

            //  read the font name
            dataReader.Seek("/FontSet ");

            dataReader.Seek("/Name");

            FontName = dataReader.ReadString();
            //Debug.Log("text layer FontName=" + FontName);

            // read the warp style
            dataReader.Seek("warpStyle");
            dataReader.Seek("warpStyle");
            byte [] wrapBytes = dataReader.ReadBytes(3);

            int num13 = dataReader.ReadByte();

            WarpStyle = string.Empty;

            for (; num13 > 0; --num13)
            {
                string str = WarpStyle + dataReader.ReadChar();
                WarpStyle = str;
            }
        }
Ejemplo n.º 21
0
        //public BitVector32 Flags
        //{
        //    get { return flags; }
        //}
        /// <summary>
        /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data.
        /// </summary>
        /// <param name="reader">The reader containing the PSD file data.</param>
        /// <param name="psdFile">The PSD file to set as the parent.</param>
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Children = new List<Layer>();
            PsdFile = psdFile;

            // read the rect
            Rect rect = new Rect();
            rect.y = reader.ReadInt32();
            rect.x = reader.ReadInt32();
            rect.height = reader.ReadInt32() - rect.y;
            rect.width = reader.ReadInt32() - rect.x;
            Rect = rect;

            // read the channels
            int channelCount = reader.ReadUInt16();
            Channels = new List<Channel>();
            SortedChannels = new SortedList<short, Channel>();
            for (int index = 0; index < channelCount; ++index)
            {
                Channel channel = new Channel(reader, this);
                Channels.Add(channel);
                SortedChannels.Add(channel.ID, channel);
            }

            // read the header and verify it
            if (new string(reader.ReadChars(4)) != "8BIM")
            {
                throw new IOException("Layer Channelheader error!");
            }

            // read the blend mode key (unused) (defaults to "norm")
            reader.ReadChars(4);

            // read the opacity
            Opacity = reader.ReadByte();

            // read the clipping (unused) (< 0 = base, > 0 = non base)
            reader.ReadByte();

            // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant)
            flags = new BitVector32(reader.ReadByte());

            // skip a padding byte
            reader.ReadByte();

            uint num3 = reader.ReadUInt32();
            long position1 = reader.BaseStream.Position;
            MaskData = new Mask(reader, this);
            BlendingRangesData = new BlendingRanges(reader);
            long position2 = reader.BaseStream.Position;

            // read the name
            Name = reader.ReadPascalString();

            // read the adjustment info
            int count = (int)((reader.BaseStream.Position - position2) % 4L);
            reader.ReadBytes(count);
            AdjustmentInfo = new List<AdjustmentLayerInfo>();
            long num4 = position1 + num3;
            while (reader.BaseStream.Position < num4)
            {
                try
                {
                    AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = num4;
                }
            }

            foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo)
            {
                if (adjustmentLayerInfo.Key == "TySh")
                {
                    ReadTextLayer(adjustmentLayerInfo.DataReader);
                }
                else if (adjustmentLayerInfo.Key == "luni")
                {
                    // read the unicode name
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    dataReader.ReadBytes(3);
                    dataReader.ReadByte();
                    Name = dataReader.ReadString().TrimEnd(new char[1]);
                }
            }

            reader.BaseStream.Position = num4;
        }
Ejemplo n.º 22
0
            ///////////////////////////////////////////////////////////////////////////
            internal Mask(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Mask started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;

                uint maskLength = reader.ReadUInt32();

                if (maskLength <= 0)
                  return;

                long startPosition = reader.BaseStream.Position;

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

                m_rect = new Rectangle();
                m_rect.Y = reader.ReadInt32();
                m_rect.X = reader.ReadInt32();
                m_rect.Height = reader.ReadInt32() - m_rect.Y;
                m_rect.Width = reader.ReadInt32() - m_rect.X;

                m_defaultColor = reader.ReadByte();

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

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

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

                if (maskLength == 36)
                {
                  BitVector32 realFlags = new BitVector32(reader.ReadByte());

                  byte realUserMaskBackground = reader.ReadByte();

                  Rectangle rect = new Rectangle();
                  rect.Y = reader.ReadInt32();
                  rect.X = reader.ReadInt32();
                  rect.Height = reader.ReadInt32() - m_rect.Y;
                  rect.Width = reader.ReadInt32() - m_rect.X;
                }

                // there is other stuff following, but we will ignore this.
                reader.BaseStream.Position = startPosition + maskLength;
            }
Ejemplo n.º 23
0
        //图层效果相关
        private void parseLrfxKeyword(AdjustmentLayerInfo adjustmentLayerInfo)
        {
            BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;

            int version     = dataReader.ReadInt16();
            int effectCount = dataReader.ReadInt16();
            //Debug.Log("lrfx version=" + version + ",effectCount=" + effectCount);

            string effectStr = "";

            for (int index = 0; index < effectCount; index++)
            {
                string sigNature = dataReader.readStringNew(4);
                string type      = dataReader.readStringNew(4);
                //Debug.Log("cur read type=" + type + ",sigNature=" + sigNature);

                switch (type)
                {
                case "cmnS":    //OK
                    int  cmnsSize    = dataReader.ReadInt32();
                    int  cmnsVersion = dataReader.ReadInt32();
                    bool cmnsBool    = dataReader.ReadBoolean();
                    int  cmnsUnused  = dataReader.ReadInt16();

                    Debug.Log("cmnsSize =" + cmnsSize + ",cmnsBool=" + cmnsBool);
                    break;

                case "dsdw":    //可能有用
                //byte[] testbyte2 = dataReader.ReadBytes(55);
                //effectStr += "\n" + printbytes(testbyte2, "dsdw");
                //break;
                case "isdw":
                    int dropSize            = dataReader.ReadInt32();
                    int dropVersion         = dataReader.ReadInt32();
                    int dropBlurValue       = dataReader.ReadInt32();
                    int Intensityasapercent = dataReader.ReadInt32();
                    int angleindegrees      = dataReader.ReadInt32();
                    int distanceinp         = dataReader.ReadInt32();

                    byte[] colortest = dataReader.ReadBytes(10);

                    dataReader.ReadBytes(4);
                    string dropBlendmode = dataReader.readStringNew(4);

                    bool dropeffectEnable = dataReader.ReadBoolean();
                    byte usethisangle     = dataReader.ReadByte();
                    int  dropOpacity      = dataReader.ReadByte();


                    int dropSpace11 = dataReader.ReadInt16();
                    int color111    = dataReader.ReadInt16();
                    int color211    = dataReader.ReadInt16();
                    int color311    = dataReader.ReadInt16();
                    int color411    = dataReader.ReadInt16();

                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    effectStr += "\n" + dataReader.ReadBytes(10);
                    string sign1 = dataReader.readStringNew(4);
                    string key1  = dataReader.readStringNew(4);

                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    if (dropVersion == 2)
                    {
                        dataReader.ReadBytes(10);
                    }

                    break;

                case "oglw":    //有用:字体的描边!
                    int sizeofRemainItems = dataReader.ReadInt32();
                    int oglwversion       = dataReader.ReadInt32();

                    byte[] blurdata = dataReader.ReadBytes(4);

                    outLineDis = Convert.ToInt32(blurdata[1]);     //也是小坑,四个故意放在第二个字节 也不说明( ▼-▼ )

                    effectStr += printbytes(blurdata, "blurdata ");

                    //int blurvalue = dataReader.ReadInt32();

                    int intensityPercent = dataReader.ReadInt32();

                    byte outline_r = 0;
                    byte outline_g = 0;
                    byte outline_b = 0;
                    byte outline_a = 0;

                    dataReader.ReadBytes(2);
                    outline_r = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_g = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_b = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_a = dataReader.ReadByte();
                    dataReader.ReadByte();

                    string curSign = dataReader.readStringNew(4);
                    string key     = dataReader.readStringNew(4);

                    bool effectEnable = dataReader.ReadBoolean();     //yanruTODO 不可靠,如果整个effect 层 禁用了,子字段可能依然为true,暂时找不到上层effect开关


                    byte opacityPercent = dataReader.ReadByte();    //描边透明度

                    if (oglwversion == 2)
                    {
                        byte[] oglwColor2 = dataReader.ReadBytes(10);
                    }


                    if (!effectEnable)     //指明了没有描边
                    {
                        TextOutlineColor = new Color(0, 0, 0, 0);
                    }
                    else
                    {
                        TextOutlineColor = new Color(outline_r / 255f, outline_g / 255f, outline_b / 255f, opacityPercent / 255f);
                    }
                    Debug.Log("sizeofRemainItems=" + sizeofRemainItems +
                              ",oglwversion=" + oglwversion +

                              ",intensityPercent=" + intensityPercent +
                              ",curSign=" + curSign +
                              ",key=" + key +

                              ",color_r=" + outline_r +
                              ",color_g=" + outline_g +
                              ",color_b=" + outline_b +
                              ",color_a=" + outline_a
                              + ",effectEnable=" + effectEnable
                              + ",opacityPercent=" + opacityPercent
                              + ",outLineDis=" + outLineDis
                              );
                    break;

                case "iglw":
                    byte[] testdata5 = dataReader.ReadBytes(47);
                    //effectStr += "\n" + printbytes(testdata5, "iglw");

                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(10);
                    //dataReader.ReadBytes(8);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(10);
                    break;

                case "bevl":

                    int bevelSizeofRemain = dataReader.ReadInt32();    //.ReadBytes(4);
                    int bevelversion      = dataReader.ReadInt32();
                    //dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);

                    dataReader.ReadBytes(8);
                    dataReader.ReadBytes(8);

                    dataReader.ReadBytes(10);
                    dataReader.ReadBytes(10);

                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);

                    if (bevelversion == 2)
                    {
                        dataReader.ReadBytes(10);
                        dataReader.ReadBytes(10);
                    }

                    break;
                    //case "sofi":
                    //    int solidSize = dataReader.ReadInt32();//.ReadBytes(4);
                    //    int solidVersion = dataReader.ReadInt32();// (4);
                    //    string solidBlendmode = dataReader.readStringNew(4);//.ReadBytes(4);

                    //    byte[] solidColor = dataReader.ReadBytes(10);
                    //    effectStr += printbytes(solidColor, "sofi solidColor");

                    //    byte opacity = dataReader.ReadByte();

                    //    byte solidenable = dataReader.ReadByte();

                    //    //dataReader.ReadBytes(1);
                    //    //dataReader.ReadBytes(1);

                    //    dataReader.ReadBytes(10);

                    //    Debug.Log("sofi  solidSize=" + solidSize
                    //        + ",solidVersion=" + solidVersion
                    //        + ",solidBlendmode=" + solidBlendmode
                    //        + ",opacity=" + opacity
                    //        + ",solidenable=" + solidenable
                    //        );
                    //    break;
                }
            }

            Debug.Log("effectStr=" + effectStr);
        }
Ejemplo n.º 24
0
        private void ParseLrfxKeyword(AdjustmentLayerInfo adjustmentLayerInfo)
        {
            BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;

            int version     = dataReader.ReadInt16();
            int effectCount = dataReader.ReadInt16();

            for (int index = 0; index < effectCount; index++)
            {
                string sigNature = dataReader.ReadStringNew(4);
                string type      = dataReader.ReadStringNew(4);

                switch (type)
                {
                case "cmnS":    //OK
                    int  cmnsSize    = dataReader.ReadInt32();
                    int  cmnsVersion = dataReader.ReadInt32();
                    bool cmnsBool    = dataReader.ReadBoolean();
                    int  cmnsUnused  = dataReader.ReadInt16();
                    break;

                case "dsdw":    // 投影效果
                    byte[] testbyte2 = dataReader.ReadBytes(55);
                    break;

                case "isdw":     //内阴影效果
                    int dropSize            = dataReader.ReadInt32();
                    int dropVersion         = dataReader.ReadInt32();
                    int dropBlurValue       = dataReader.ReadInt32();
                    int Intensityasapercent = dataReader.ReadInt32();
                    int angleindegrees      = dataReader.ReadInt32();
                    int distanceinp         = dataReader.ReadInt32();

                    byte[] colortest = dataReader.ReadBytes(10);

                    dataReader.ReadBytes(4);
                    string dropBlendmode = dataReader.ReadStringNew(4);

                    bool dropeffectEnable = dataReader.ReadBoolean();
                    byte usethisangle     = dataReader.ReadByte();
                    int  dropOpacity      = dataReader.ReadByte();


                    int dropSpace11 = dataReader.ReadInt16();
                    int color111    = dataReader.ReadInt16();
                    int color211    = dataReader.ReadInt16();
                    int color311    = dataReader.ReadInt16();
                    int color411    = dataReader.ReadInt16();

                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(10);
                    string sign1 = dataReader.ReadStringNew(4);
                    string key1  = dataReader.ReadStringNew(4);

                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    if (dropVersion == 2)
                    {
                        dataReader.ReadBytes(10);
                    }

                    break;

                case "oglw":    //有用:字体的描边!
                    int sizeofRemainItems = dataReader.ReadInt32();
                    int oglwversion       = dataReader.ReadInt32();

                    byte[] blurdata = dataReader.ReadBytes(4);

                    _outLineDis = Convert.ToInt32(blurdata[1]);     //也是小坑,四个故意放在第二个字节 也不说明( ▼-▼ )

                    //int blurvalue = dataReader.ReadInt32();

                    int intensityPercent = dataReader.ReadInt32();

                    byte outline_r = 0;
                    byte outline_g = 0;
                    byte outline_b = 0;
                    byte outline_a = 0;

                    dataReader.ReadBytes(2);
                    outline_r = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_g = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_b = dataReader.ReadByte();
                    dataReader.ReadByte();
                    outline_a = dataReader.ReadByte();
                    dataReader.ReadByte();

                    string curSign = dataReader.ReadStringNew(4);
                    string key     = dataReader.ReadStringNew(4);

                    bool effectEnable = dataReader.ReadBoolean();     //yanruTODO 不可靠,如果整个effect 层 禁用了,子字段可能依然为true,暂时找不到上层effect开关


                    byte opacityPercent = dataReader.ReadByte();    //描边透明度

                    if (oglwversion == 2)
                    {
                        byte[] oglwColor2 = dataReader.ReadBytes(10);
                    }


                    if (!effectEnable)     //指明了没有描边
                    {
                        TextOutlineColor = new Color(0, 0, 0, 0);
                    }
                    else
                    {
                        TextOutlineColor = new Color(outline_r / 255f, outline_g / 255f, outline_b / 255f, opacityPercent / 255f);
                    }
                    break;

                case "iglw":
                    byte[] testdata5 = dataReader.ReadBytes(47);
                    //effectStr += "\n" + printbytes(testdata5, "iglw");

                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(4);
                    //dataReader.ReadBytes(10);
                    //dataReader.ReadBytes(8);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(1);
                    //dataReader.ReadBytes(10);
                    break;

                case "bevl":

                    int bevelSizeofRemain = dataReader.ReadInt32();    //.ReadBytes(4);
                    int bevelversion      = dataReader.ReadInt32();
                    //dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);
                    dataReader.ReadBytes(4);

                    dataReader.ReadBytes(8);
                    dataReader.ReadBytes(8);

                    dataReader.ReadBytes(10);
                    dataReader.ReadBytes(10);

                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);
                    dataReader.ReadBytes(1);

                    if (bevelversion == 2)
                    {
                        dataReader.ReadBytes(10);
                        dataReader.ReadBytes(10);
                    }

                    break;

                case "sofi":
                    int    solidSize      = dataReader.ReadInt32();      //.ReadBytes(4);
                    int    solidVersion   = dataReader.ReadInt32();      // (4);
                    string sign           = dataReader.ReadStringNew(4);
                    string solidBlendmode = dataReader.ReadStringNew(4); //.ReadBytes(4);

                    byte[] solidColor = dataReader.ReadBytes(10);

                    byte opacity     = dataReader.ReadByte();
                    byte solidenable = dataReader.ReadByte();
                    dataReader.ReadBytes(10);
                    break;
                }
            }
        }
Ejemplo n.º 25
0
            ///////////////////////////////////////////////////////////////////////////

            internal Mask(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Mask started at " + reader.BaseStream.Position);

                m_layer = layer;

                uint maskLength = reader.ReadUInt32();

                if (maskLength <= 0)
                    return;

                long startPosition = reader.BaseStream.Position;

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

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

                m_defaultColor = reader.ReadByte();

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

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

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

                if (maskLength == 36)
                {
                    //var realFlags = new BitVector32(reader.ReadByte());

                    //var realUserMaskBackground = reader.ReadByte();
#if false
                    var y = reader.ReadInt32();
                    var x = reader.ReadInt32();
                    var rect = new Rectangle
                    {
                        Y = y,
                        X = x,
                        Height = reader.ReadInt32() - y,
                        Width = reader.ReadInt32() - x
                    };
#else // this is just reading unused bytes...
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
#endif
                }


                // there is other stuff following, but we will ignore this.
                reader.BaseStream.Position = startPosition + maskLength;
            }
Ejemplo n.º 26
0
        ///////////////////////////////////////////////////////////////////////////

        private void LoadLayers(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position);

            uint layersInfoSectionLength = reader.ReadUInt32();

            if (layersInfoSectionLength <= 0)
                return;

            long startPosition = reader.BaseStream.Position;

            short numberOfLayers = reader.ReadInt16();

            // If <0, then number of layers is absolute value,
            // and the first alpha channel contains the transparency data for
            // the merged result.
            if (numberOfLayers < 0)
            {
                AbsoluteAlpha = true;
                numberOfLayers = Math.Abs(numberOfLayers);
            }

            m_layers.Clear();

            if (numberOfLayers == 0)
                return;

            for (int i = 0; i < numberOfLayers; i++)
            {
                m_layers.Add(new Layer(reader, this));
            }

            foreach (Layer layer in m_layers)
            {
                foreach (Layer.Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                        channel.LoadPixelData(reader);
                }

                layer.MaskData.LoadPixelData(reader);
            }

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

            if (reader.BaseStream.Position%2 == 1)
                reader.ReadByte();

            //-----------------------------------------------------------------------
            // make shure we are not on a wrong offset, so set the stream position 
            // manually
            reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }
Ejemplo n.º 27
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position);

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


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

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

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

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

            m_blendModeKey = new string(reader.ReadChars(4));
            m_opacity = reader.ReadByte();

            m_clipping = reader.ReadByte() > 0;

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

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

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

            reader.ReadByte(); //padding

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

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

            // 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);

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

            var namePosition = reader.BaseStream.Position;

            m_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;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data.
        /// </summary>
        /// <param name="reader">The reader containing the PSD file data.</param>
        /// <param name="psdFile">The PSD file to set as the parent.</param>
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Children = new List <Layer>();
            PsdFile  = psdFile;

            // read the rect
            Rect rect = new Rect();

            rect.y      = reader.ReadInt32();
            rect.x      = reader.ReadInt32();
            rect.height = reader.ReadInt32() - rect.y;
            rect.width  = reader.ReadInt32() - rect.x;
            Rect        = rect;

            // read the channels
            int channelCount = reader.ReadUInt16();

            Channels       = new List <Channel>();
            SortedChannels = new SortedList <short, Channel>();
            for (int index = 0; index < channelCount; ++index)
            {
                Channel channel = new Channel(reader, this);
                Channels.Add(channel);
                SortedChannels.Add(channel.ID, channel);
            }

            // read the header and verify it
            if (new string(reader.ReadChars(4)) != "8BIM")
            {
                throw new IOException("Layer Channelheader error!");
            }

            // read the blend mode key (unused) (defaults to "norm")
            reader.ReadChars(4);

            // read the opacity
            Opacity = reader.ReadByte();

            // read the clipping (unused) (< 0 = base, > 0 = non base)
            reader.ReadByte();

            // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant)
            flags = new BitVector32(reader.ReadByte());

            // skip a padding byte
            reader.ReadByte();

            uint num3      = reader.ReadUInt32();
            long position1 = reader.BaseStream.Position;

            MaskData           = new Mask(reader, this);
            BlendingRangesData = new BlendingRanges(reader);
            long position2 = reader.BaseStream.Position;

            // read the name
            Name = reader.ReadPascalString();

            // read the adjustment info
            int count = (int)((reader.BaseStream.Position - position2) % 4L);

            reader.ReadBytes(count);
            AdjustmentInfo = new List <AdjustmentLayerInfo>();
            long num4 = position1 + num3;

            while (reader.BaseStream.Position < num4)
            {
                try
                {
                    AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = num4;
                }
            }

            foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo)
            {
                if (adjustmentLayerInfo.Key == "TySh")
                {
                    ReadTextLayer(adjustmentLayerInfo.DataReader);
                }
                else if (adjustmentLayerInfo.Key == "luni")
                {
                    // read the unicode name
                    BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader;
                    dataReader.ReadBytes(3);
                    dataReader.ReadByte();
                    Name = dataReader.ReadString().TrimEnd(new char[1]);
                }
            }

            reader.BaseStream.Position = num4;
        }
Ejemplo n.º 29
0
            ///////////////////////////////////////////////////////////////////////////

            internal Mask(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Mask started at " + reader.BaseStream.Position);

                m_layer = layer;

                uint maskLength = reader.ReadUInt32();

                if (maskLength <= 0)
                {
                    return;
                }

                long startPosition = reader.BaseStream.Position;

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

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

                m_defaultColor = reader.ReadByte();

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

                byte flags = reader.ReadByte();

                m_flags = new BitVector32(flags);

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

                if (maskLength == 36)
                {
                    //var realFlags = new BitVector32(reader.ReadByte());

                    //var realUserMaskBackground = reader.ReadByte();
#if false
                    var y    = reader.ReadInt32();
                    var x    = reader.ReadInt32();
                    var rect = new Rectangle
                    {
                        Y      = y,
                        X      = x,
                        Height = reader.ReadInt32() - y,
                        Width  = reader.ReadInt32() - x
                    };
#else // this is just reading unused bytes...
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
#endif
                }


                // there is other stuff following, but we will ignore this.
                reader.BaseStream.Position = startPosition + maskLength;
            }