Skip to content

Apply the luma AC sharpening in the vectorized WebP quantizer - #3234

Merged
JimBobSquarePants merged 3 commits into
SixLabors:mainfrom
jafin:jf/webp-vector-quantizer-sharpening
Oct 27, 2026
Merged

JimBobSquarePants merged 3 commits into
SixLabors:mainfrom
jafin:jf/webp-vector-quantizer-sharpening

Conversation

@jafin

@jafin jafin commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

The AVX2 and SSE4.1 WebP quantizers discarded the sharpening additions. They now quantize abs(input) + sharpen, matching the scalar path and libwebp. This removes a CPU-dependent difference in luma AC quantization.

The existing SIMD paths and buffers remain in use. Assembly shows one additional AVX2 word addition or two additional SSE word additions. The compiler removed the discarded additions from the original code. This fix therefore adds the required arithmetic to the executed code.

The coefficient regression checks fixed levels and reconstructed values from the local libwebp source. It runs with the available intrinsics, without AVX2, and without hardware intrinsics. Its comments describe the calculation and coefficient order. The scalar test name now states that hardware intrinsics are disabled.

The two alpha encoding tests now use one size bound across architectures. The bounds are 64,060 bytes without alpha compression and 16,240 bytes with alpha compression. These were already the ARM64 bounds and match the corrected x64 output. Pixel-comparison tolerances and reference images are unchanged.

No test inputs are encoded or patched at runtime. Image tests use the existing stored Png/transparency.png. The quantizer tests use fixed coefficient arrays. No data-integrity policy changed.

Verification

  • The original code fails the sharpening regression with AVX2 and SSE4.1. The scalar case passes.
  • The local libwebp scalar quantizer produces the exact expected levels and reconstructed coefficients.
  • The fixed code passes all three instruction-set cases.
  • Both alpha encoding cases produce identical encoded bytes with AVX2, SSE4.1 and scalar execution.
  • All 474 WebP tests pass in Release on .NET 10 and .NET 11.

V4 backport: #3257.

Fixes #3246

The AVX2 and SSE4.1 paths of QuantEnc.QuantizeBlock computed
abs(in) + sharpen but discarded the sum, so they quantized without the
luma AC sharpening bias that the scalar path applies. Lossy output
therefore depended on the CPU: x64 machines with SSE4.1 produced a
different bitstream from the scalar path used on ARM64 or with hardware
intrinsics disabled.

Assign the sums back so every path quantizes the same value. Lossy
output is now byte-identical with AVX2, with SSE4.1 only and without
hardware intrinsics, and the lossy-with-alpha size bounds no longer
need a separate value for ARM64.
@JimBobSquarePants
JimBobSquarePants merged commit b2b1ca9 into SixLabors:main Oct 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lossy WebP output differs between the SIMD and scalar paths: the vectorized quantizer skips luma AC sharpening

2 participants