commit 9c9445ba17a5b642305b42884aee015d48dad0de
parent 5089b45b2813af6723b8133fe90a73ee95ca1290
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Sun, 19 Oct 2025 17:56:10 -0300
lib/{dynamic,transpiled}: fix quality param
I thought the C api wanted the quality in the range 0-1 because they
picked float as the numeric type.
Turns out they actually just cast it to int and assume the range 0-100.
Thanks to JP Hastings-Edrei for calling this out!
Diffstat:
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/dynamic/webp/lib.go b/lib/dynamic/webp/lib.go
@@ -83,9 +83,9 @@ func EncodeImpl(w io.Writer, m *image.NRGBA, quality float32) error {
return fmt.Errorf("functions not initialized")
}
if quality >= 1.0 {
- return common.Encode(w, m, quality, wrappedLossless, WebPFree)
+ return common.Encode(w, m, 100, wrappedLossless, WebPFree)
}
- return common.Encode(w, m, quality, WebPEncodeRGBA, WebPFree)
+ return common.Encode(w, m, quality*100, WebPEncodeRGBA, WebPFree)
}
// wrappedLossless drops the quality param and does a lossless encode.
diff --git a/lib/transpiled/webp/lib.go b/lib/transpiled/webp/lib.go
@@ -32,7 +32,7 @@ func makeEncodeImpl(tls *libc.TLS) common.EncodeFunc {
if q >= 1.0 {
return WebPEncodeLosslessRGBA(tls, in, w, h, bps, out)
}
- return WebPEncodeRGBA(tls, in, w, h, bps, q, out)
+ return WebPEncodeRGBA(tls, in, w, h, bps, q*100, out)
}
}