Пример #1
0
        /// <summary>
        /// Reads bytes until a unescaped closing parenthesis in found. Unescapes escaped parenthesis.
        /// Leaves reader on the char following the closing parenthesis.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public static byte[] parseBinary(PsdBinaryReader r)
        {
            MemoryStream ms = new MemoryStream(128); //For writing the decoded binary
            byte         b  = 0;

            //Read bytes, keeping a two-byte shifting buffer so we can decode escaped chars.
            while (r.CanReadByte())
            {
                b = r.ReadByte();

                //Escaped parenthesis, skip slash
                if ((char)b == '\\')
                {
                    b = r.ReadByte();
                    ms.WriteByte(b);
                }
                else
                {
                    //We hit the end, an unescaped closng parenthesis.
                    if ((char)b == ')')
                    {
                        return(ms.ToArray());
                    }

                    ms.WriteByte(b);
                }
            }
            throw new TdTaParseException("Hit end of stream without finding closing parenthesis!");
        }
Пример #2
0
        public MaskInfo(PsdBinaryReader reader, Layer layer)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, MaskInfo");

            var maskLength = reader.ReadUInt32();

            if (maskLength <= 0)
            {
                return;
            }

            var startPosition = reader.BaseStream.Position;
            var endPosition   = startPosition + maskLength;

            // Read layer mask
            var rectangle       = reader.ReadRectangle();
            var backgroundColor = reader.ReadByte();
            var flagsByte       = reader.ReadByte();

            LayerMask = new Mask(layer, rectangle, backgroundColor, new BitVector32(flagsByte));

            // User mask is supplied separately when there is also a vector mask.
            if (maskLength == 36)
            {
                var userFlagsByte       = reader.ReadByte();
                var userBackgroundColor = reader.ReadByte();
                var userRectangle       = reader.ReadRectangle();
                UserMask = new Mask(layer, userRectangle, userBackgroundColor,
                                    new BitVector32(userFlagsByte));
            }

            // 20-byte mask data will end with padding.
            reader.BaseStream.Position = endPosition;

            Util.DebugMessage(reader.BaseStream, "Load, End, MaskInfo");
        }
Пример #3
0
        /// <summary>
        /// Reads bytes until a unescaped closing parenthesis in found. Unescapes escaped parenthesis.
        /// Leaves reader on the char following the closing parenthesis.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public static byte[] parseBinary(PsdBinaryReader r)
        {
            MemoryStream ms          = new MemoryStream(128); //For writing the decoded binary
            byte         b           = 0;
            byte         lastb       = 0;
            bool         hasLastByte = false;

            //Read bytes, keeping a two-byte shifting buffer so we can decode escaped chars.
            while (r.CanReadByte())
            {
                b = r.ReadByte();

                //Look for closing parenthesis
                if ((char)b == ')')
                {
                    if (hasLastByte && (char)lastb == '\\')
                    {
                        //Escaped parenthesis, skip slash
                        lastb       = 0;
                        hasLastByte = false;
                    }
                    else
                    {
                        //Unescaped closing parenthesis! We hit the end!
                        if (hasLastByte)
                        {
                            ms.WriteByte(lastb); //If we still have a byte in the buffer.
                        }
                        return(ms.ToArray());    //We hit the end, an unescaped closng parenthesis.
                    }
                }

                //Far as I know, nothing else is escaped.

                //Write lastb if present.
                if (hasLastByte)
                {
                    ms.WriteByte(lastb);
                }
                //Shift buffer
                lastb       = b;
                hasLastByte = true;
            }
            throw new TdTaParseException("Hit end of stream without finding closing parenthesis!");
        }