示例#1
0
        public WicImageContainer(IWICBitmapDecoder dec, WicPipelineContext ctx, FileFormat fmt)
        {
            WicDecoder = ctx.AddRef(dec);

            ContainerFormat = fmt;
            FrameCount      = (int)dec.GetFrameCount();
        }
示例#2
0
        private WicImageContainer(IWICBitmapDecoder dec, WicPipelineContext ctx)
        {
            wicContext = ctx;
            WicDecoder = ctx.AddRef(dec);

            WicContainerFormat = dec.GetContainerFormat();
            ContainerFormat    = formatMap.GetValueOrDefault(WicContainerFormat, FileFormat.Unknown);
            FrameCount         = (int)dec.GetFrameCount();
        }
示例#3
0
        unsafe public static WicImageContainer Create(ReadOnlySpan <byte> inBuffer, WicPipelineContext ctx)
        {
            fixed(byte *pbBuffer = inBuffer)
            {
                var istm = ctx.AddRef(Wic.Factory.CreateStream());

                istm.InitializeFromMemory((IntPtr)pbBuffer, (uint)inBuffer.Length);

                var dec = createDecoder(stm => Wic.Factory.CreateDecoderFromStream(stm, null, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), istm);

                return(new WicImageContainer(dec, ctx));
            }
        }
示例#4
0
        public WicGifContainer(IWICBitmapDecoder dec, WicPipelineContext ctx) : base(dec, ctx, FileFormat.Gif)
        {
            using var wicmeta = ComHandle.Wrap(dec.GetMetadataQueryReader());
            var meta = wicmeta.ComObject;

            ScreenWidth  = meta.GetValueOrDefault <ushort>(Wic.Metadata.Gif.LogicalScreenWidth);
            ScreenHeight = meta.GetValueOrDefault <ushort>(Wic.Metadata.Gif.LogicalScreenHeight);

            if (meta.GetValueOrDefault <bool>(Wic.Metadata.Gif.GlobalPaletteFlag))
            {
                using var wicpal = ComHandle.Wrap(Wic.Factory.CreatePalette());
                var pal = wicpal.ComObject;
                dec.CopyPalette(pal);

                uint pcc = pal.GetColorCount();
                uint idx = meta.GetValueOrDefault <byte>(Wic.Metadata.Gif.BackgroundColorIndex);
                if (idx < pcc)
                {
                    var buff = ArrayPool <uint> .Shared.Rent((int)pcc);

                    pal.GetColors(pcc, buff);
                    BackgroundColor = buff[idx];

                    ArrayPool <uint> .Shared.Return(buff);
                }
            }

            var appext = meta.GetValueOrDefault <byte[]>(Wic.Metadata.Gif.AppExtension).AsSpan();

            if (appext.Length == 11 && netscape2_0.SequenceEqual(appext) || animexts1_0.SequenceEqual(appext))
            {
                var appdata = meta.GetValueOrDefault <byte[]>(Wic.Metadata.Gif.AppExtensionData).AsSpan();
                if (appdata.Length >= 4 && appdata[0] >= 3 && appdata[1] == 1)
                {
                    LoopCount = BinaryPrimitives.ReadUInt16LittleEndian(appdata.Slice(2));
                }
            }
        }
示例#5
0
        public static WicImageContainer Create(Stream inStream, WicPipelineContext ctx)
        {
            var dec = createDecoder(stm => Wic.Factory.CreateDecoderFromStream(stm, null, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), inStream.AsIStream());

            return(new WicImageContainer(dec, ctx));
        }
示例#6
0
        public static WicImageContainer Create(string fileName, WicPipelineContext ctx)
        {
            var dec = createDecoder(fn => Wic.Factory.CreateDecoderFromFilename(fn, null, GenericAccessRights.GENERIC_READ, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), fileName);

            return(new WicImageContainer(dec, ctx));
        }