Exemplo n.º 1
0
        public EpfImage(Stream stream, bool leaveOpen = true)
        {
            this.frames = new List <EpfFrame>();

            var reader = new BinaryReader(stream);

            var frameCount = reader.ReadUInt16();

            this.width  = reader.ReadInt16();
            this.height = reader.ReadInt16();

            var unknown     = reader.ReadUInt16();
            var tableOffset = reader.ReadUInt32();

            reader.BaseStream.Position += tableOffset;

            for (int i = 0; i < frameCount; i++)
            {
                var left   = reader.ReadInt16();
                var top    = reader.ReadInt16();
                var right  = reader.ReadInt16();
                var bottom = reader.ReadInt16();

                long startAddress = reader.ReadUInt32();
                long endAddress   = reader.ReadUInt32();

                var frameWidth  = Math.Abs(right - left);
                var frameHeight = Math.Abs(bottom - top);

                var size = frameWidth * frameHeight;
                var bits = new byte[size];

                if (size > 0)
                {
                    long previousPosition = reader.BaseStream.Position;

                    reader.BaseStream.Position = startAddress;
                    reader.Read(bits, 0, size);

                    reader.BaseStream.Position = previousPosition;
                }

                var frame = new EpfFrame(i, left, top, frameWidth, frameHeight, bits);
                frames.Add(frame);
            }

            if (!leaveOpen)
            {
                stream.Dispose();
            }
        }
Exemplo n.º 2
0
        public EpfImage(Stream stream, bool leaveOpen = true)
        {
            this.frames = new List<EpfFrame>();

              var reader = new BinaryReader(stream);

              var frameCount = reader.ReadUInt16();

              this.width = reader.ReadInt16();
              this.height = reader.ReadInt16();

              var unknown = reader.ReadUInt16();
              var tableOffset = reader.ReadUInt32();

              reader.BaseStream.Position += tableOffset;

              for (int i = 0; i < frameCount; i++)
              {
            var left = reader.ReadInt16();
            var top = reader.ReadInt16();
            var right = reader.ReadInt16();
            var bottom = reader.ReadInt16();

            long startAddress = reader.ReadUInt32();
            long endAddress = reader.ReadUInt32();

            var frameWidth = Math.Abs(right - left);
            var frameHeight = Math.Abs(bottom - top);

            var size = frameWidth * frameHeight;
            var bits = new byte[size];

            if (size > 0)
            {
              long previousPosition = reader.BaseStream.Position;

              reader.BaseStream.Position = startAddress;
              reader.Read(bits, 0, size);

              reader.BaseStream.Position = previousPosition;
            }

            var frame = new EpfFrame(i, left, top, frameWidth, frameHeight, bits);
            frames.Add(frame);
              }

              if (!leaveOpen)
            stream.Dispose();
        }
Exemplo n.º 3
0
        public RenderedBitmap Render(EpfFrame frame, ColorPalette palette)
        {
            if (frame == null)
            throw new ArgumentNullException("frame");

              if (palette == null)
            throw new ArgumentNullException("palette");

              palette = palette.MakeGrayscale();
              var format = PixelFormats.Bgra32;

              var width = frame.Width;
              var height = frame.Height;
              var stride = (width * 4) + (width % 4);

              var bits = new byte[height * stride];

              for (int x = 0; x < width; x++)
            for (int y = 0; y < height; y++)
            {
              var fixedX = x;
              var fixedY = y;

              var threshold = 12;

              if (fixedX < threshold)
              {
            if (width >= threshold)
              fixedX = width - (threshold - fixedX);

            if (fixedY > 0)
              fixedY--;
              }
              else
            fixedX -= threshold;

              var pixel = frame.RawData[x + y * width];

              if (pixel > 0)
            SetPixel(bits, fixedX, fixedY, stride, palette[pixel]);
              else
            SetPixel(bits, fixedX, fixedY, stride, Colors.Transparent);
            }

              var bitmap = new RenderedBitmap(width, height, stride, format, bits);
              return bitmap;
        }
Exemplo n.º 4
0
        public RenderedBitmap Render(EpfFrame frame, ColorPalette palette)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            if (palette == null)
            {
                throw new ArgumentNullException("palette");
            }

            palette = palette.MakeGrayscale();
            var format = PixelFormats.Bgra32;

            var width  = frame.Width;
            var height = frame.Height;
            var stride = (width * 4) + (width % 4);

            var bits = new byte[height * stride];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var fixedX = x;
                    var fixedY = y;

                    var threshold = 12;

                    if (fixedX < threshold)
                    {
                        if (width >= threshold)
                        {
                            fixedX = width - (threshold - fixedX);
                        }

                        if (fixedY > 0)
                        {
                            fixedY--;
                        }
                    }
                    else
                    {
                        fixedX -= threshold;
                    }

                    var pixel = frame.RawData[x + y * width];

                    if (pixel > 0)
                    {
                        SetPixel(bits, fixedX, fixedY, stride, palette[pixel]);
                    }
                    else
                    {
                        SetPixel(bits, fixedX, fixedY, stride, Colors.Transparent);
                    }
                }
            }

            var bitmap = new RenderedBitmap(width, height, stride, format, bits);

            return(bitmap);
        }