Browse Source

Add bits per pixel in webp image info

pull/1552/head
Brian Popow 6 years ago
parent
commit
87dbbe60cf
  1. 21
      src/ImageSharp/Formats/WebP/WebPBitsPerPixel.cs
  2. 8
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  3. 5
      src/ImageSharp/Formats/WebP/WebPImageInfo.cs

21
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
{
/// <summary>
/// Enumerates the available bits per pixel the webp image uses.
/// </summary>
public enum WebPBitsPerPixel : short
{
/// <summary>
/// 24 bits per pixel. Each pixel consists of 3 bytes.
/// </summary>
Pixel24 = 24,
/// <summary>
/// 32 bits per pixel. Each pixel consists of 4 bytes (an alpha channel is present).
/// </summary>
Pixel32 = 32
}
}

8
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);
}
/// <summary>
@ -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,

5
src/ImageSharp/Formats/WebP/WebPImageInfo.cs

@ -15,6 +15,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// </summary>
public int Height { get; set; }
/// <summary>
/// Gets or sets the bits per pixel.
/// </summary>
public WebPBitsPerPixel BitsPerPixel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this image uses a lossless compression.
/// </summary>

Loading…
Cancel
Save