Exemplo n.º 1
0
 public ImageBuffer(Size size, ConsolePixel[,] buffer, IReadOnlyDictionary<string, object> properties)
 {
     _buffer = buffer;
     _properties = properties;
     Size = size;
 }
Exemplo n.º 2
0
            private IImageBuffer BuildBuffer(Size size, Bitmap bmp, FrameDimension frameDimension, int idx)
            {
                ConsolePixel[,] buffer = new ConsolePixel[size.Height, size.Width];
                bmp.SelectActiveFrame(frameDimension, idx);

                for (int i = 0; i < size.Height; i++)
                {
                    for (int j = 0; j < size.Width; j++)
                    {
                        Color c = _sampler.GetSampleColor(size, bmp, j, i, _transparencyColor);
                        ConsolePixel pixel = _converter.CreatePixel(c);
                        buffer[i, j] = pixel;
                    }
                }

                Dictionary<string, object> properties = null;

                // TODO: Move PropertyItem parsing out into separate classes? Do existing libraries exist that might
                // do this for us?
                // TODO: Are there any other per-frame properties we want?
                PropertyItem gifFrameTimeProp = bmp.PropertyItems.FirstOrDefault(pi => pi.Id == 0x5100);
                if (gifFrameTimeProp != null)
                {
                    byte[] b = gifFrameTimeProp.Value;
                    long value = b[idx * 4] | (b[(idx * 4) + 1] << 8) | (b[(idx * 4) + 2] << 16) | (b[(idx * 4) + 3] << 24);
                    value = value * 10; // gif frame times are in centi-seconds, not milli-seconds
                    properties = new Dictionary<string, object>();
                    properties.Add(ImagePropertyConstants.GifFrameTimeMs, value);
                }

                return new ImageBuffer(size, buffer, properties);
            }