Skip to content

Low compression quality compared to cwebp CLI tool #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pawelmtw opened this issue Apr 1, 2025 · 1 comment
Open

Low compression quality compared to cwebp CLI tool #116

pawelmtw opened this issue Apr 1, 2025 · 1 comment

Comments

@pawelmtw
Copy link

pawelmtw commented Apr 1, 2025

Description

When using SDImageWebPCoder to encode images with lossless options, the resulting file size and compression quality appear to be worse compared to Google's cwebp command-line tool. Despite both using lossless compression settings, SDImageWebPCoder produces slightly lower quality images, with visible artifacts and banding on gradients and shadows.

I experimented with different encoding options such as: encodeCompressionQuality, encodeWebPMethod, encodeWebPPass etc. Despite these adjustments, the output quality and file size were still worse compared to cwebp -lossless. This suggests a fundamental difference in how the WebP encoding is implemented in SDImageWebPCoder versus the official WebP compression tool.

Code

SDImageWebPCoder:

if let data = SDImageWebPCoder.shared.encodedData(with: nsImage, format: .webP, options: [.encodeWebPLossless: 1]) {
  try data.write(to: destination))
}

cwebp:

cwebp -lossless input.png -o output.webp

Results

Image

@dreampiggy
Copy link
Contributor

dreampiggy commented Apr 3, 2025

Can you use cwebp's raw buffer mode ? When means, I guess the loseless happened during the decoding part from ImageIO PNG decoder, to the libwebp's encoder. The image's bitmap is stored via CGImageRef

But anyway, I can have a try to debug and find out the reason why whether this lossless mode actually work. By looping to decoding-encoding loop 10 times for the same CGImageRef input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants