コード例 #1
0
 public Direct3D9FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream, Format preferedFormat)
     : base(textureFactory, memoryPool, preferedFormat)
 {
     FStream           = stream;
     FImageInformation = ImageInformation.FromStream(stream);
     Width             = FImageInformation.Width;
     Height            = FImageInformation.Height;
     if (preferedFormat == Format.Unknown)
     {
         FChosenFormat = FImageInformation.Format;
     }
 }
コード例 #2
0
 public virtual void Dispose()
 {
     FTextureFactory = null;
     FMemoryPool     = null;
 }
コード例 #3
0
            public BitmapFrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream)
                : base(textureFactory, memoryPool)
            {
                var dataStream = stream as SharpDX.DataStream;

                using (var wicStream = new WICStream(Factory, new SharpDX.DataPointer(dataStream.DataPointer, (int)dataStream.Length)))
                    using (var decoder = new BitmapDecoder(Factory, wicStream, DecodeOptions.CacheOnLoad))
                    {
                        using (var frame = decoder.GetFrame(0))
                        {
                            var dstPixelFormat = PixelFormat.Format32bppBGRA;

                            FWidth  = frame.Size.Width;
                            FHeight = frame.Size.Height;
                            FStride = PixelFormat.GetStride(dstPixelFormat, FWidth);
                            FLength = FStride * FHeight;

                            FBuffer = memoryPool.UnmanagedPool.GetMemory(FLength);

                            if (frame.PixelFormat != dstPixelFormat)
                            {
                                using (var converter = new FormatConverter(Factory))
                                {
                                    converter.Initialize(frame, dstPixelFormat);
                                    converter.CopyPixels(FStride, FBuffer);
                                }
                            }
                            else
                            {
                                frame.CopyPixels(FStride, FBuffer);
                            }
                        }
                    }
                memoryPool.StreamPool.PutStream(stream);
            }
コード例 #4
0
 public FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool)
 {
     FTextureFactory = textureFactory;
     FMemoryPool     = memoryPool;
 }
コード例 #5
0
        public static FrameDecoder Create(string filename, Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream)
        {
            var extension = Path.GetExtension(filename);

            Func <Func <Device, int, int, int, Format, Usage, Texture>, MemoryPool, Stream, FrameDecoder> decoderFactory = null;

            if (!FDecoderFactories.TryGetValue(extension, out decoderFactory))
            {
                return(new BitmapFrameDecoder(textureFactory, memoryPool, stream));
            }
            return(decoderFactory(textureFactory, memoryPool, stream));
        }
コード例 #6
0
 public Direct3D9FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream)
     : base(textureFactory, memoryPool)
 {
     FStream           = stream;
     FImageInformation = ImageInformation.FromStream(stream);
 }
コード例 #7
0
 public FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Format preferedFormat)
 {
     FTextureFactory = textureFactory;
     FMemoryPool     = memoryPool;
     FChosenFormat   = preferedFormat;
 }
コード例 #8
0
        public static FrameDecoder Create(string filename, Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream, Format preferedFormat)
        {
            var extension = Path.GetExtension(filename).ToLowerInvariant();
            // In case the prefered format is not supported on one device, fall back to one which works.
            var format = GetFallbackFormatIfPreferedFormatIsNotSupported(preferedFormat);
            Func <Func <Device, int, int, int, Format, Usage, Texture>, MemoryPool, Stream, Format, FrameDecoder> decoderFactory = null;

            if (!FDecoderFactories.TryGetValue(extension, out decoderFactory))
            {
                return(new BitmapFrameDecoder(textureFactory, memoryPool, stream, format));
            }
            return(decoderFactory(textureFactory, memoryPool, stream, format));
        }