From 87dbbe60cf5b0eaee3dfe4084eff748231dbdbfe Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 15 Jan 2020 12:39:30 +0100 Subject: [PATCH] Add bits per pixel in webp image info --- .../Formats/WebP/WebPBitsPerPixel.cs | 21 +++++++++++++++++++ .../Formats/WebP/WebPDecoderCore.cs | 8 +++---- src/ImageSharp/Formats/WebP/WebPImageInfo.cs | 5 +++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs diff --git a/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs b/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs new file mode 100644 index 000000000..57bc16a66 --- /dev/null +++ b/src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.WebP +{ + /// + /// Enumerates the available bits per pixel the webp image uses. + /// + public enum WebPBitsPerPixel : short + { + /// + /// 24 bits per pixel. Each pixel consists of 3 bytes. + /// + Pixel24 = 24, + + /// + /// 32 bits per pixel. Each pixel consists of 4 bytes (an alpha channel is present). + /// + Pixel32 = 32 + } +} diff --git a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs index c72216344..214b385e4 100644 --- a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs +++ b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs @@ -118,9 +118,7 @@ namespace SixLabors.ImageSharp.Formats.WebP this.ReadImageHeader(); WebPImageInfo imageInfo = this.ReadVp8Info(); - // TODO: not sure yet where to get this info. Assuming 24 bits for now. - int bitsPerPixel = 24; - return new ImageInfo(new PixelTypeInfo(bitsPerPixel), imageInfo.Width, imageInfo.Height, this.Metadata); + return new ImageInfo(new PixelTypeInfo((int)imageInfo.BitsPerPixel), imageInfo.Width, imageInfo.Height, this.Metadata); } /// @@ -341,9 +339,10 @@ namespace SixLabors.ImageSharp.Formats.WebP { Width = width, Height = height, + BitsPerPixel = features?.Alpha is true ? WebPBitsPerPixel.Pixel32 : WebPBitsPerPixel.Pixel24, IsLossLess = false, ImageDataSize = dataSize, - Features = features + Features = features, }; } @@ -388,6 +387,7 @@ namespace SixLabors.ImageSharp.Formats.WebP { Width = (int)width, Height = (int)height, + BitsPerPixel = WebPBitsPerPixel.Pixel32, IsLossLess = true, ImageDataSize = imageDataSize, Features = features, diff --git a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs index cf692289a..14d2c0ff7 100644 --- a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs +++ b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs @@ -15,6 +15,11 @@ namespace SixLabors.ImageSharp.Formats.WebP /// public int Height { get; set; } + /// + /// Gets or sets the bits per pixel. + /// + public WebPBitsPerPixel BitsPerPixel { get; set; } + /// /// Gets or sets a value indicating whether this image uses a lossless compression. ///