Exemple #1
0
        public static BitmapInfo GetBitmapInfo(STBREAD.ImageResult image)
        {
            if (TryGetPixelFormat(image.ColorComponents, image.BitsPerChannel, out var fmt))
            {
                return(new BitmapInfo(image.Width, image.Height, fmt));
            }

            throw new ArgumentException("Unsupported format", nameof(image));
        }
Exemple #2
0
        public static ImageResult FromStream(Stream stream, ColorComponents?requiredComponents = null, bool use8BitsPerChannel = true)
        {
            ImageResult result = null;

            if (JpgDecoder.Test(stream))
            {
                result = JpgDecoder.Decode(stream, requiredComponents);
            }
            else if (PngDecoder.Test(stream))
            {
                result = PngDecoder.Decode(stream, requiredComponents);
            }
            else if (BmpDecoder.Test(stream))
            {
                result = BmpDecoder.Decode(stream, requiredComponents);
            }
            else if (GifDecoder.Test(stream))
            {
                result = GifDecoder.Decode(stream, requiredComponents);
            }
            else if (PsdDecoder.Test(stream))
            {
                result = PsdDecoder.Decode(stream, requiredComponents);
            }
            else if (TgaDecoder.Test(stream))
            {
                result = TgaDecoder.Decode(stream, requiredComponents);
            }

            if (result == null)
            {
                Decoder.stbi__err("unknown image type");
            }

            if (use8BitsPerChannel && result.BitsPerChannel != 8)
            {
                result.Data = Conversion.stbi__convert_16_to_8(result.Data, result.Width, result.Height, (int)result.ColorComponents);
            }

            return(result);
        }
        internal static unsafe ImageResult FromResult(byte *result, int width, int height, ColorComponents comp,
                                                      ColorComponents req_comp)
        {
            if (result == null)
            {
                throw new InvalidOperationException(LastError);
            }

            var image = new ImageResult
            {
                Width      = width,
                Height     = height,
                SourceComp = comp,
                Comp       = req_comp == ColorComponents.Default ? comp : req_comp
            };

            // Convert to array
            image.Data = new byte[width * height * (int)image.Comp];
            Marshal.Copy(new IntPtr(result), image.Data, 0, image.Data.Length);

            return(image);
        }
Exemple #4
0
        public static MemoryBitmap AsMemoryBitmap(STBREAD.ImageResult image)
        {
            var binfo = GetBitmapInfo(image);

            return(new MemoryBitmap(image.Data, binfo));
        }
Exemple #5
0
        public static SpanBitmap AsSpanBitmap(STBREAD.ImageResult image)
        {
            var binfo = GetBitmapInfo(image);

            return(new SpanBitmap(image.Data, binfo));
        }