示例#1
0
文件: Program.cs 项目: ewxrjk/Defect
        static void Main(string[] args)
        {
            int    width  = int.Parse(args[0]);
            int    height = int.Parse(args[1]);
            int    colors = int.Parse(args[2]);
            string path   = args[3];

            using (FileStream fs = new FileStream(path, FileMode.Create)) {
                GIF gif = new GIF()
                {
                    Output           = fs,
                    ScreenWidth      = width,
                    ScreenHeight     = height,
                    GlobalColorTable = new GIF.ColorTable()
                    {
                        Table = new Color[colors],
                    },
                    Debug = true,
                };
                for (int n = 0; n < colors; ++n)
                {
                    gif.GlobalColorTable.Table[n] = Color.FromArgb(n, n, n);
                }
                GIF.Image image = new GIF.Image()
                {
                    ImageData = new byte[width * height],
                };
                for (int n = 0; n < image.ImageData.Length; ++n)
                {
                    image.ImageData[n] = (byte)(n % colors);
                }
                gif.Begin();
                gif.WriteImage(image);
                gif.End();
                fs.Flush();
            }
        }
示例#2
0
 public void TinyGifTest()
 {
     using (MemoryStream stream = new MemoryStream()) {
         GIF gif = new GIF()
         {
             Output           = stream,
             ScreenWidth      = 1,
             ScreenHeight     = 1,
             GlobalColorTable = new GIF.ColorTable()
             {
                 Table = new Color[2] {
                     Color.White, Color.Black
                 }
             }
         };
         gif.Begin();
         gif.WriteImage(new GIF.Image()
         {
             ImageData = new byte[] { 0 },
         });
         gif.End();
         int    codeSize = 2;
         int    clear    = 1 << codeSize;
         int    end      = 1 + clear;
         byte[] got      = stream.ToArray();
         byte[] expected = new byte[] {
             // 0: Signature
             (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a',
             // 6: Logical screen descriptor
             1, 0,
             1, 0,
             0xF0,
             0,
             49,
             // 13: Global Color Table
             0xFF, 0xFF, 0xFF,
             0, 0, 0,
             // 19: Graphic control extension
             0x21, 0xF9, 0x04,
             1 << 2, 0, 0, 0,
                 0,
                 // 27: Image descriptor
                 0x2C,
                 0, 0,
                 0, 0,
                 1, 0,
                 1, 0,
                 0,
                 // 37: Image data
                 // 37: Minimum code size
                 2,
                 // 38: Data block
                 2,
                 (byte)(clear
                        | 0 << 3
                        | (end << 6)),
                 (byte)(end >> 2),
                 // 41: Block terminator
                 0,
                 // 42: Trailer
                 0x3B
         };
         TestUtils.AreEqual(expected, got, "TinyGifTest");
     }
 }