static void SkipLine2Style(SwfStreamReader reader)
        {
            reader.ReadUInt16();                      // Width
            reader.ReadUnsignedBits(2);               // StartCapStyle
            var join_style    = reader.ReadUnsignedBits(2);
            var has_fill_flag = reader.ReadBit();

            reader.ReadBit();                         // NoHScaleFlag
            reader.ReadBit();                         // NoVScaleFlag
            reader.ReadBit();                         // PixelHintingFlag
            reader.ReadUnsignedBits(5);               // Reserved
            reader.ReadBit();                         // NoClose
            reader.ReadUnsignedBits(2);               // EndCapStyle
            if (join_style == 2)
            {
                reader.ReadFixedPoint_8_8();                 // MiterLimitFactor
            }
            if (has_fill_flag)
            {
                ReadFillStyle(reader, true);                 // FillStyle
            }
            else
            {
                SwfColor.Read(reader, true);
            }
        }
Beispiel #2
0
 static Filter ReadConcreteFilter(BlurFilter filter, SwfStreamReader reader)
 {
     filter.BlurX  = reader.ReadFixedPoint_16_16();
     filter.BlurY  = reader.ReadFixedPoint_16_16();
     filter.Passes = reader.ReadUnsignedBits(5);
     reader.ReadUnsignedBits(3);             // reserved
     return(filter);
 }
        // -----------------------------
        // Gradient
        // -----------------------------

        static void SkipGradient(SwfStreamReader reader, bool with_alpha)
        {
            reader.ReadUnsignedBits(2);             // SpreadMode
            reader.ReadUnsignedBits(2);             // InterpolationMode
            var count = reader.ReadUnsignedBits(4);

            for (var i = 0; i < count; ++i)
            {
                reader.ReadByte();                 // Ratio
                SwfColor.Read(reader, with_alpha);
            }
        }
        // ---------------------------------------------------------------------
        //
        // ShapeRecords
        //
        // ---------------------------------------------------------------------

        static void ReadShapeRecords(
            SwfStreamReader reader, List <FillStyle> fill_styles,
            bool allow_big_array, bool with_alpha, bool line2_type)
        {
            var fill_style_bits = reader.ReadUnsignedBits(4);
            var line_style_bits = reader.ReadUnsignedBits(4);

            while (!ReadShapeRecord(
                       reader, fill_styles,
                       ref fill_style_bits, ref line_style_bits,
                       allow_big_array, with_alpha, line2_type))
            {
                continue;
            }
        }
Beispiel #5
0
        public static SwfColorTransform Read(SwfStreamReader reader, bool with_alpha)
        {
            var transform = SwfColorTransform.identity;

            transform.HasAdd = reader.ReadBit();
            transform.HasMul = reader.ReadBit();
            var bits = reader.ReadUnsignedBits(4);

            if (transform.HasMul)
            {
                transform.RMul = (short)reader.ReadSignedBits(bits);
                transform.GMul = (short)reader.ReadSignedBits(bits);
                transform.BMul = (short)reader.ReadSignedBits(bits);
                transform.AMul = with_alpha ? (short)reader.ReadSignedBits(bits) : byte.MaxValue;
            }
            if (transform.HasAdd)
            {
                transform.RAdd = (short)reader.ReadSignedBits(bits);
                transform.GAdd = (short)reader.ReadSignedBits(bits);
                transform.BAdd = (short)reader.ReadSignedBits(bits);
                transform.AAdd = with_alpha ? (short)reader.ReadSignedBits(bits) : (short)0;
            }
            reader.AlignToByte();
            return(transform);
        }
Beispiel #6
0
        static Filter ReadConcreteFilter(GradientBevelFilter filter, SwfStreamReader reader)
        {
            var num_colors = reader.ReadByte();

            filter.GradientColors = new SwfColor[num_colors];
            for (var i = 0; i < num_colors; ++i)
            {
                filter.GradientColors[i] = SwfColor.Read(reader, true);
            }
            filter.GradientRatio = new byte[num_colors];
            for (var i = 0; i < num_colors; ++i)
            {
                filter.GradientRatio[i] = reader.ReadByte();
            }
            filter.BlurX           = reader.ReadFixedPoint_16_16();
            filter.BlurY           = reader.ReadFixedPoint_16_16();
            filter.Angle           = reader.ReadFixedPoint_16_16();
            filter.Distance        = reader.ReadFixedPoint_16_16();
            filter.Strength        = reader.ReadFixedPoint_8_8();
            filter.InnerShadow     = reader.ReadBit();
            filter.Knockout        = reader.ReadBit();
            filter.CompositeSource = reader.ReadBit();
            filter.OnTop           = reader.ReadBit();
            filter.Passes          = reader.ReadUnsignedBits(4);
            return(filter);
        }
        static void SkipCurvedEdgeShapeRecord(SwfStreamReader reader)
        {
            var num_bits = reader.ReadUnsignedBits(4) + 2;

            reader.ReadSignedBits(num_bits);             // control_delta_x
            reader.ReadSignedBits(num_bits);             // control_delta_y
            reader.ReadSignedBits(num_bits);             // anchor_delta_x
            reader.ReadSignedBits(num_bits);             // anchor_delta_y
        }
Beispiel #8
0
        public override uint ReadUnsignedBits(uint count)
        {
            var a = _first.ReadUnsignedBits(count);
            var b = _second.ReadUnsignedBits(count);

            if (a != b)
            {
                throw new Exception(string.Format("a={0}, b={1}", a, b));
            }
            return(a);
        }
Beispiel #9
0
 static Filter ReadConcreteFilter(GlowFilter filter, SwfStreamReader reader)
 {
     filter.GlowColor       = SwfColor.Read(reader, true);
     filter.BlurX           = reader.ReadFixedPoint_16_16();
     filter.BlurY           = reader.ReadFixedPoint_16_16();
     filter.Strength        = reader.ReadFixedPoint_8_8();
     filter.InnerGlow       = reader.ReadBit();
     filter.Knockout        = reader.ReadBit();
     filter.CompositeSource = reader.ReadBit();
     filter.Passes          = reader.ReadUnsignedBits(5);
     return(filter);
 }
Beispiel #10
0
        public static SwfMatrix Read(SwfStreamReader reader, bool fill_style)
        {
            var matrix    = SwfMatrix.identity;
            var has_scale = reader.ReadBit();

            if (has_scale)
            {
                var bits = (byte)reader.ReadUnsignedBits(5);
                matrix.ScaleX = reader.ReadFixedPoint16(bits);
                matrix.ScaleY = reader.ReadFixedPoint16(bits);
            }
            else
            {
                matrix.ScaleX     =
                    matrix.ScaleY = 1.0f;
            }
            var has_rotate = reader.ReadBit();

            if (has_rotate)
            {
                var bits = (byte)reader.ReadUnsignedBits(5);
                matrix.RotateSkew0 = reader.ReadFixedPoint16(bits);
                matrix.RotateSkew1 = reader.ReadFixedPoint16(bits);
            }
            else
            {
                matrix.RotateSkew0     =
                    matrix.RotateSkew1 = 0.0f;
            }
            var translate_bits = (byte)reader.ReadUnsignedBits(5);

            matrix.TranslateX = reader.ReadSignedBits(translate_bits) / 20.0f;
            matrix.TranslateY = reader.ReadSignedBits(translate_bits) / 20.0f;
            reader.AlignToByte();
            return(matrix);
        }
        static void SkipStraigtEdgeShapeRecord(SwfStreamReader reader)
        {
            var num_bits          = reader.ReadUnsignedBits(4) + 2;
            var general_line_flag = reader.ReadBit();
            var vert_line_flag    = general_line_flag ? false : reader.ReadBit();

            if (general_line_flag || !vert_line_flag)
            {
                reader.ReadSignedBits(num_bits);                 // delta_x
            }
            if (general_line_flag || vert_line_flag)
            {
                reader.ReadSignedBits(num_bits);                 // delta_y
            }
        }
Beispiel #12
0
 static Filter ReadConcreteFilter(BevelFilter filter, SwfStreamReader reader)
 {
     filter.ShadowColor     = SwfColor.Read(reader, true);
     filter.HighlightColor  = SwfColor.Read(reader, true);
     filter.BlurX           = reader.ReadFixedPoint_16_16();
     filter.BlurY           = reader.ReadFixedPoint_16_16();
     filter.Angle           = reader.ReadFixedPoint_16_16();
     filter.Distance        = reader.ReadFixedPoint_16_16();
     filter.Strength        = reader.ReadFixedPoint_8_8();
     filter.InnerShadow     = reader.ReadBit();
     filter.Knockout        = reader.ReadBit();
     filter.CompositeSource = reader.ReadBit();
     filter.OnTop           = reader.ReadBit();
     filter.Passes          = reader.ReadUnsignedBits(4);
     return(filter);
 }
Beispiel #13
0
        public static SwfRect Read(SwfStreamReader reader)
        {
            var bits = reader.ReadUnsignedBits(5);
            var xmin = reader.ReadSignedBits(bits) / 20.0f;
            var xmax = reader.ReadSignedBits(bits) / 20.0f;
            var ymin = reader.ReadSignedBits(bits) / 20.0f;
            var ymax = reader.ReadSignedBits(bits) / 20.0f;

            reader.AlignToByte();
            return(new SwfRect {
                XMin = xmin,
                XMax = xmax,
                YMin = ymin,
                YMax = ymax
            });
        }
Beispiel #14
0
 public void ReadRectMustBeByteAlignedTest()
 {
     var etalon = new SwfRect {
         XMin = 0,
         XMax = 11000,
         YMin = 0,
         YMax = 8000
     };
     var mem = new MemoryStream(new byte[] { 0x78, 0x00, 0x05, 0x5f, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0xb3 });
     var reader = new SwfStreamReader(mem);
     SwfRect rect = reader.ReadRect();
     Assert.IsTrue(AreEqual(etalon, rect));
     var tail = reader.ReadUnsignedBits(8);
     Assert.AreEqual(0xb3, tail);
     Assert.AreEqual(mem.Length, mem.Position);
 }
Beispiel #15
0
 static Filter ReadConcreteFilter(ConvolutionFilter filter, SwfStreamReader reader)
 {
     filter.MatrixX = reader.ReadByte();
     filter.MatrixY = reader.ReadByte();
     filter.Divisor = reader.ReadFloat32();
     filter.Bias    = reader.ReadFloat32();
     filter.Matrix  = new float[filter.MatrixX * filter.MatrixY];
     for (var i = 0; i < filter.Matrix.Length; ++i)
     {
         filter.Matrix[i] = reader.ReadFloat32();
     }
     filter.DefaultColor = SwfColor.Read(reader, true);
     reader.ReadUnsignedBits(6);             // reserved
     filter.Clamp         = reader.ReadBit();
     filter.PreserveAlpha = reader.ReadBit();
     return(filter);
 }
Beispiel #16
0
        public void ReadRectMustBeByteAlignedTest()
        {
            var etalon = new SwfRect {
                XMin = 0,
                XMax = 11000,
                YMin = 0,
                YMax = 8000
            };
            var     mem    = new MemoryStream(new byte[] { 0x78, 0x00, 0x05, 0x5f, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0xb3 });
            var     reader = new SwfStreamReader(mem);
            SwfRect rect   = reader.ReadRect();

            Assert.IsTrue(AreEqual(etalon, rect));
            var tail = reader.ReadUnsignedBits(8);

            Assert.AreEqual(0xb3, tail);
            Assert.AreEqual(mem.Length, mem.Position);
        }
Beispiel #17
0
        public void ReadUnsignedBitsTest()
        {
            var mem = new MemoryStream();

            mem.WriteByte(0xaa);
            mem.WriteByte(0xc3);
            mem.Seek(0, SeekOrigin.Begin);
            var reader = new SwfStreamReader(mem);

            const int bits = 10;

            Assert.AreEqual(0x2ab, reader.ReadUnsignedBits(bits), "Value");

            Assert.AreEqual(false, reader.ReadBit(), "Bit 10");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 11");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 12");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 13");
            Assert.AreEqual(true, reader.ReadBit(), "Bit 14");
            Assert.AreEqual(true, reader.ReadBit(), "Bit 15");

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Beispiel #18
0
        public void ReadUnsignedBitsTest()
        {
            var mem = new MemoryStream();
            mem.WriteByte(0xaa);
            mem.WriteByte(0xc3);
            mem.Seek(0, SeekOrigin.Begin);
            var reader = new SwfStreamReader(mem);

            const int bits = 10;

            Assert.AreEqual(0x2ab, reader.ReadUnsignedBits(bits), "Value");

            Assert.AreEqual(false, reader.ReadBit(), "Bit 10");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 11");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 12");
            Assert.AreEqual(false, reader.ReadBit(), "Bit 13");
            Assert.AreEqual(true, reader.ReadBit(), "Bit 14");
            Assert.AreEqual(true, reader.ReadBit(), "Bit 15");

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
        static bool ReadShapeRecord(
            SwfStreamReader reader, List <FillStyle> fill_styles,
            ref uint fill_style_bits, ref uint line_style_bits,
            bool allow_big_array, bool with_alpha, bool line2_type)
        {
            var is_edge = reader.ReadBit();

            if (is_edge)
            {
                var straight = reader.ReadBit();
                if (straight)
                {
                    SkipStraigtEdgeShapeRecord(reader);
                }
                else
                {
                    SkipCurvedEdgeShapeRecord(reader);
                }
                return(false);
            }
            else
            {
                var state_new_styles    = reader.ReadBit();
                var state_line_style    = reader.ReadBit();
                var state_fill_style1   = reader.ReadBit();
                var state_fill_style0   = reader.ReadBit();
                var state_move_to       = reader.ReadBit();
                var is_end_shape_record =
                    !state_new_styles && !state_line_style &&
                    !state_fill_style0 && !state_fill_style1 && !state_move_to;
                if (is_end_shape_record)
                {
                    return(true);
                }
                else
                {
                    if (state_move_to)
                    {
                        var move_bits = reader.ReadUnsignedBits(5);
                        reader.ReadSignedBits(move_bits);                         // move_delta_x
                        reader.ReadSignedBits(move_bits);                         // move_delta_y
                    }
                    if (state_fill_style0)
                    {
                        reader.ReadUnsignedBits(fill_style_bits);                         // fill_style_0
                    }
                    if (state_fill_style1)
                    {
                        reader.ReadUnsignedBits(fill_style_bits);                         // fill_style_1
                    }
                    if (state_line_style)
                    {
                        reader.ReadUnsignedBits(line_style_bits);                         // line_style
                    }
                    if (state_new_styles)
                    {
                        reader.AlignToByte();
                        fill_styles.AddRange(ReadFillStyles(reader, allow_big_array, with_alpha));
                        SkipLineStyles(reader, allow_big_array, with_alpha, line2_type);
                        fill_style_bits = reader.ReadUnsignedBits(4);
                        line_style_bits = reader.ReadUnsignedBits(4);
                    }
                    return(false);
                }
            }
        }