From 6bda08f5338eba94bf53d81ce78051a03aa0762e Mon Sep 17 00:00:00 2001 From: Peter Amrehn Date: Sun, 19 Jan 2020 17:37:53 +0100 Subject: [PATCH] introduce function Is8bOptimizable --- .../Formats/WebP/WebPLossyDecoder.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs index b41e5b1e32..da84079cf7 100644 --- a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; +using System.Collections.Generic; using System.IO; using SixLabors.ImageSharp.Memory; @@ -54,6 +56,28 @@ namespace SixLabors.ImageSharp.Formats.WebP return new Vp8Profile(); } } + + static bool Is8bOptimizable(Vp8LMetadata hdr) + { + int i; + if (hdr.ColorCacheSize > 0) + return false; + + // When the Huffman tree contains only one symbol, we can skip the + // call to ReadSymbol() for red/blue/alpha channels. + for (i = 0; i < hdr.NumHTreeGroups; ++i) + { + List htrees = hdr.HTreeGroups[i].HTrees; + if (htrees[HuffIndex.Red][0].Value > 0) + return false; + if (htrees[HuffIndex.Blue][0].Value > 0) + return false; + if (htrees[HuffIndex.Alpha][0].Value > 0) + return false; + } + + return true; + } } struct YUVPixel