public unsafe bool MoveNext()
        {
            // Read next frame
            int  ccomp;
            byte two_back;
            var  result = StbImage.stbi__gif_load_next(_context, _gif, &ccomp, (int)ColorComponents, &two_back);

            if (result == null)
            {
                return(false);
            }

            if (Current == null)
            {
                Current = new AnimatedFrameResult
                {
                    Width      = _gif.w,
                    Height     = _gif.h,
                    SourceComp = (ColorComponents)ccomp,
                    Comp       = ColorComponents == ColorComponents.Default ? (ColorComponents)ccomp : ColorComponents
                };

                Current.Data = new byte[Current.Width * Current.Height * (int)Current.Comp];
            }

            Current.DelayInMs = _gif.delay;

            Marshal.Copy(new IntPtr(result), Current.Data, 0, Current.Data.Length);

            return(true);
        }
Ejemplo n.º 2
0
        public unsafe static ImageInfo?FromStream(Stream stream)
        {
            int width, height, comp;
            var context = new StbImage.stbi__context(stream);

            var is16Bit = StbImage.stbi__is_16_main(context) == 1;

            StbImage.stbi__rewind(context);

            var infoResult = StbImage.stbi__info_main(context, &width, &height, &comp);

            StbImage.stbi__rewind(context);

            if (infoResult == 0)
            {
                return(null);
            }

            return(new ImageInfo
            {
                Width = width,
                Height = height,
                ColorComponents = (ColorComponents)comp,
                BitsPerChannel = is16Bit ? 16 : 8
            });
        }
        public AnimatedGifEnumerator(Stream input, ColorComponents colorComponents)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            _context = new StbImage.stbi__context(input);

            if (StbImage.stbi__gif_test(_context) == 0)
            {
                throw new Exception("Input stream is not GIF file.");
            }

            _gif            = new StbImage.stbi__gif();
            ColorComponents = colorComponents;
        }
Ejemplo n.º 4
0
        public static unsafe ImageResultFloat FromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default)
        {
            float *result = null;

            try
            {
                int x, y, comp;

                var context = new StbImage.stbi__context(stream);

                result = StbImage.stbi__loadf_main(context, &x, &y, &comp, (int)requiredComponents);

                return(FromResult(result, x, y, (ColorComponents)comp, requiredComponents));
            }
            finally
            {
                if (result != null)
                {
                    CRuntime.free(result);
                }
            }
        }