Пример #1
0
        private unsafe void Load(CancellationToken token)
        {
            sw.Restart();
            try
            {
                token.ThrowIfCancellationRequested();
                decoder.Device = device;
                lock (streamLock)
                {
                    decoder.Load(memoryStream);
                }
                token.ThrowIfCancellationRequested();

                description = decoder.Description;
                LoadingCompleted(description);
                decoder.Decode();
                token.ThrowIfCancellationRequested();

                Loaded = true;
            }
            catch (OperationCanceledException) { }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("load: {0}", e);
                throw e;
            }
            DecodeTime = sw.Elapsed.TotalMilliseconds;
        }
Пример #2
0
        public void Load(Stream stream)
        {
            bitmap = new Bitmap(stream);
            loaded = true;

            Description = new SlimDX.Direct3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = SlimDX.Direct3D11.BindFlags.ShaderResource,
                CpuAccessFlags    = SlimDX.Direct3D11.CpuAccessFlags.Write,
                Format            = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
                MipLevels         = 1,
                OptionFlags       = SlimDX.Direct3D11.ResourceOptionFlags.None,
                Usage             = SlimDX.Direct3D11.ResourceUsage.Dynamic,
                Width             = bitmap.Width,
                Height            = bitmap.Height,
                SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0)
            };
        }
        public void Load(Stream stream)
        {
            bmpImage = new BitmapImage();
            bmpImage.BeginInit();
            bmpImage.StreamSource = stream;
            bmpImage.CacheOption  = BitmapCacheOption.OnLoad;
            bmpImage.EndInit();
            bmpImage.Freeze();

            Description = new SlimDX.Direct3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = SlimDX.Direct3D11.BindFlags.ShaderResource,
                CpuAccessFlags    = SlimDX.Direct3D11.CpuAccessFlags.Write,
                Format            = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
                MipLevels         = 1,
                OptionFlags       = SlimDX.Direct3D11.ResourceOptionFlags.None,
                Usage             = SlimDX.Direct3D11.ResourceUsage.Dynamic,
                Width             = bmpImage.PixelWidth,
                Height            = bmpImage.PixelHeight,
                SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0)
            };
        }
        public static SlimDX.Direct3D11.Texture2D TextureFromColor(SlimDX.Direct3D11.Device device, Color4 color, out SlimDX.Direct3D11.ShaderResourceView srv)
        {
            /*SlimDX.Direct3D11.Texture2DDescription desc2 = new SlimDX.Direct3D11.Texture2DDescription();
            desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
            desc2.Width = 1;
            desc2.Height = 1;
            desc2.MipLevels = 1;
            desc2.ArraySize = 1;
            desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            desc2.Usage = SlimDX.Direct3D11.ResourceUsage.Dynamic;
            desc2.BindFlags = SlimDX.Direct3D11.BindFlags.ShaderResource;
            desc2.CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.Write;
            SlimDX.Direct3D11.Texture2D texture = new SlimDX.Direct3D11.Texture2D(device, desc2);

            // fill the texture with rgba values
            DataRectangle rect = texture.AsSurface().Map(SlimDX.DXGI.MapFlags.Write | SlimDX.DXGI.MapFlags.Discard);
            if (rect.Data.CanWrite)
            {
                for (int row = 0; row < texture.Description.Height; row++)
                {
                    int rowStart = row * rect.Pitch;
                    rect.Data.Seek(rowStart, System.IO.SeekOrigin.Begin);
                    for (int col = 0; col < texture.Description.Width; col++)
                    {
                        rect.Data.WriteByte((byte)(color.Red * 255));
                        rect.Data.WriteByte((byte)(color.Green * 255));
                        rect.Data.WriteByte((byte)(color.Blue * 255));
                        rect.Data.WriteByte((byte)(color.Alpha * 255));
                    }
                }
            }
            texture.AsSurface().Unmap();
            texture.AsSurface().Dispose();

            srv = GetShaderResourceView(device, texture);*/

            SlimDX.Direct3D11.Texture2DDescription desc2 = new SlimDX.Direct3D11.Texture2DDescription();
            desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
            desc2.Width = 1;
            desc2.Height = 1;
            desc2.MipLevels = 1;
            desc2.ArraySize = 1;
            desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            desc2.Usage = SlimDX.Direct3D11.ResourceUsage.Default;
            desc2.BindFlags = SlimDX.Direct3D11.BindFlags.ShaderResource;
            desc2.CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None;

            // fill the texture with rgba values
            DataStream stream = new DataStream(sizeof(byte) * 4, false, true);
            stream.WriteByte((byte)(color.Red * 255));
            stream.WriteByte((byte)(color.Green * 255));
            stream.WriteByte((byte)(color.Blue * 255));
            stream.WriteByte((byte)(color.Alpha * 255));
            stream.Position = 0;

            SlimDX.Direct3D11.Texture2D texture = new SlimDX.Direct3D11.Texture2D(device, desc2, new DataRectangle(1, stream));
            srv = GetShaderResourceView(device, texture);
            return texture;
        }