Exemplo n.º 1
0
        public override async Task <GLTexture> ReadTextureAsync(CancellationToken cancelationToken)
        {
            if (cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            using (Bitmap bitmap = new Bitmap(_width, _height, _format))
            {
                if (cancelationToken.IsCancellationRequested)
                {
                    return(RaiseTextureReaded(null));
                }

                BitmapData bmdata = bitmap.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadOnly, _format);
                using (new DisposableAction(() => bitmap.UnlockBits(bmdata)))
                {
                    if (cancelationToken.IsCancellationRequested)
                    {
                        return(RaiseTextureReaded(null));
                    }

                    using (UnmanagedMemoryStream output = bmdata.Scan0.OpenStream(bmdata.Stride * bmdata.Height, FileAccess.Write))
                        _input.CopyTo(output);
                }

                if (cancelationToken.IsCancellationRequested)
                {
                    return(RaiseTextureReaded(null));
                }

                BitmapGLTextureReader bitmapReader = new BitmapGLTextureReader(bitmap, _width, _height, _format);
                return(RaiseTextureReaded(await bitmapReader.ReadTextureAsync(cancelationToken)));
            }
        }
Exemplo n.º 2
0
        public override async Task <GLTexture> ReadTextureAsync(CancellationToken cancelationToken)
        {
            if (cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            using (Bitmap bitmap = new Bitmap(_filePath))
            {
                BitmapGLTextureReader bitmapReader = new BitmapGLTextureReader(bitmap, bitmap.Width, bitmap.Height, bitmap.PixelFormat);
                return(RaiseTextureReaded(await bitmapReader.ReadTextureAsync(cancelationToken)));
            }
        }
Exemplo n.º 3
0
        public override async Task <GLTexture> ReadTextureAsync(CancellationToken cancelationToken)
        {
            if (cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            string[] files = Directory.GetFiles(_dirPath, String.Format("{0}_*.act", _generalName));
            if (files.Length == 0 || cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            using (Bitmap bitmap = new Bitmap(256, files.Length, PixelFormat.Format32bppArgb))
            {
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);

                int size = bitmapData.Stride * bitmapData.Height;
                using (UnmanagedMemoryStream output = bitmapData.Scan0.OpenStream(size, FileAccess.Write))
                {
                    foreach (string file in files)
                    {
                        if (cancelationToken.IsCancellationRequested)
                        {
                            return(RaiseTextureReaded(null));
                        }

                        Read(file, output);
                    }
                }

                bitmap.UnlockBits(bitmapData);

                BitmapGLTextureReader bitmapReader = new BitmapGLTextureReader(bitmap, bitmap.Width, bitmap.Height, bitmap.PixelFormat);
                return(RaiseTextureReaded(await bitmapReader.ReadTextureAsync(cancelationToken)));
            }
        }
        public override async Task <GLTexture> ReadTextureAsync(CancellationToken cancelationToken)
        {
            if (_palettes.IsNullOrEmpty() || cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            using (Bitmap bitmap = new Bitmap(256, _palettes.Length, PixelFormat.Format32bppArgb))
            {
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);

                if (cancelationToken.IsCancellationRequested)
                {
                    return(RaiseTextureReaded(null));
                }

                int size = bitmapData.Stride * bitmapData.Height;
                using (UnmanagedMemoryStream output = bitmapData.Scan0.OpenStream(size, FileAccess.Write))
                {
                    foreach (BitmapPalette palette in _palettes)
                    {
                        if (cancelationToken.IsCancellationRequested)
                        {
                            return(RaiseTextureReaded(null));
                        }

                        Convert(palette, output);
                    }
                }

                bitmap.UnlockBits(bitmapData);

                BitmapGLTextureReader bitmapReader = new BitmapGLTextureReader(bitmap, bitmap.Width, bitmap.Height, bitmap.PixelFormat);
                return(RaiseTextureReaded(await bitmapReader.ReadTextureAsync(cancelationToken)));
            }
        }
Exemplo n.º 5
0
        public static async Task <GLTexture> FromBitmapAsync(CancellationToken cancelationToken, Bitmap bitmap, int width, int height, PixelFormatDescriptor format)
        {
            BitmapGLTextureReader reader = new BitmapGLTextureReader(bitmap, width, height, format);

            return(await reader.ReadTextureAsync(cancelationToken));
        }
Exemplo n.º 6
0
        public static GLTexture FromBitmap(Bitmap bitmap, int width, int height, PixelFormatDescriptor format)
        {
            BitmapGLTextureReader reader = new BitmapGLTextureReader(bitmap, width, height, format);

            return(reader.ReadTexture());
        }