Example #1
0
        public static void Write(Stream s, Size size, IEnumerable <byte[]> frames)
        {
            var compressedFrames = frames.Select(f => Format80.Encode(f)).ToList();

            // note: end-of-file and all-zeroes headers
            var dataOffset = 14 + (compressedFrames.Count + 2) * 8;

            using (var bw = new BinaryWriter(s))
            {
                bw.Write((ushort)compressedFrames.Count);
                bw.Write((ushort)0);
                bw.Write((ushort)0);
                bw.Write((ushort)size.Width);
                bw.Write((ushort)size.Height);
                bw.Write((uint)0);

                foreach (var f in compressedFrames)
                {
                    var ih = new ImageHeader {
                        Format = Format.Format80, FileOffset = (uint)dataOffset
                    };
                    dataOffset += f.Length;

                    ih.WriteTo(bw);
                }

                var eof = new ImageHeader {
                    FileOffset = (uint)dataOffset
                };
                eof.WriteTo(bw);

                var allZeroes = new ImageHeader {
                };
                allZeroes.WriteTo(bw);

                foreach (var f in compressedFrames)
                {
                    bw.Write(f);
                }
            }
        }
Example #2
0
        public static void Write(Stream s, int width, int height, IEnumerable <byte[]> frames)
        {
            var compressedFrames = frames.Select(f => Format80.Encode(f)).ToArray();

            // note: end-of-file and all-zeroes headers
            var dataOffset = 14 + (compressedFrames.Length + 2) * ImageHeader.SizeOnDisk;

            using (var bw = new BinaryWriter(s))
            {
                bw.Write((ushort)compressedFrames.Length);
                bw.Write((ushort)0);                    // unused
                bw.Write((ushort)0);                    // unused
                bw.Write((ushort)width);
                bw.Write((ushort)height);
                bw.Write((uint)0);                              // unused

                foreach (var f in compressedFrames)
                {
                    var ih = new ImageHeader {
                        Format = Format.Format80, Offset = (uint)dataOffset
                    };
                    dataOffset += f.Length;

                    ih.WriteTo(bw);
                }

                var eof = new ImageHeader {
                    Offset = (uint)dataOffset
                };
                eof.WriteTo(bw);

                var allZeroes = new ImageHeader {
                };
                allZeroes.WriteTo(bw);

                foreach (var f in compressedFrames)
                {
                    bw.Write(f);
                }
            }
        }