Skip to content

Commit

Permalink
♻️ Discriminate WebP flavors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Feb 2, 2025
1 parent 08b1ee5 commit fbb50e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Exo/Core/Exo.Core/Images/ImageFormat.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace Exo.Images;

/// <summary>Describe know supported image formats.</summary>
public enum ImageFormat
public enum ImageFormat : byte
{
// NB: Enum must be kept in sync with ImageFormats
Raw = 0,
Bitmap = 1,
Gif = 2,
Jpeg = 3,
Png = 4,
WebP = 5,
WebPLossy = 5,
WebPLossless = 6,
}
3 changes: 2 additions & 1 deletion src/Exo/Core/Exo.Core/Images/ImageFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public enum ImageFormats : uint
Gif = 0b00000100,
Jpeg = 0b00001000,
Png = 0b00010000,
WebP = 0b00100000,
WebPLossy = 0b00100000,
WebPLossless = 0b01000000,
}
4 changes: 3 additions & 1 deletion src/Exo/Service/Exo.Service.Core/ImageStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public async ValueTask AddImageAsync(string imageName, ReadOnlyMemory<byte> data
}
else if (info.Metadata.DecodedImageFormat == SixLabors.ImageSharp.Formats.Webp.WebpFormat.Instance)
{
imageFormat = ImageFormat.WebP;
imageFormat = info.Metadata.GetFormatMetadata(SixLabors.ImageSharp.Formats.Webp.WebpFormat.Instance).FileFormat == SixLabors.ImageSharp.Formats.Webp.WebpFileFormatType.Lossless ?
ImageFormat.WebPLossless :
ImageFormat.WebPLossy;
isAnimated = info.FrameMetadataCollection.Count > 1;
}
else
Expand Down
8 changes: 6 additions & 2 deletions src/Exo/Ui/Exo.Contracts.Ui.Settings/ImageFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public enum ImageFormat : uint
[EnumMember]
Png = 4,
[EnumMember]
WebP = 5,
WebPLossy = 5,
[EnumMember]
WebPLossless = 6,
}

[DataContract]
Expand All @@ -34,5 +36,7 @@ public enum ImageFormats : uint
[EnumMember]
Png = 0b00010000,
[EnumMember]
WebP = 0b00100000,
WebPLossy = 0b00100000,
[EnumMember]
WebPLossless = 0b01000000,
}

0 comments on commit fbb50e6

Please sign in to comment.