webp_transform: inherited encoder quality, lost transparency, and cached Content-Type that doesn't match the body
Mantenedores costumam responder em até 2 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- cpp
- Domínio
- backend, infrastructure, performance
Direção de pesquisa
Start by reviewing the prototype branch phongn:webp-transform-png and the webp_transform_invalid_input autest, then trace ImageTransform::handleReadResponseHeaders(), handleSendResponseHeaders(), and HttpTransact::handle_transform_ready(). Compare the prototype with the stated quality, alpha, cache-label, and stats requirements. Done means the new tests cover alpha-to-PNG, q100-to-lossy output, and cached labels on pass-through, with the open compatibility questions resolved.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Three related output-policy problems in webp_transform:
- Encoder quality is inherited from the source image. The plugin has never set a quality, so it inherits whatever ImageMagick carries over from decoding. That produces two cliffs: a q100 JPEG becomes a lossless WebP, and a lossless WebP becomes a q100 JPEG.
- Transparency is lost. A WebP with alpha converted to JPEG shows the colour data stored under its transparent pixels.
- The cached
Content-Typecan disagree with the cached body. The target type is stamped before the body is seen, and only the client-facing copy is corrected afterwards.
Measurements below use ImageMagick 7.1.2-32 (Q16 HDRI, OpenMP) through traffic_server master, with sources encoded from lossless originals.
1. Inherited quality
ImageMagick's coders behave as follows (7.1.2-32):
- JPEG reader: estimates the source quality from the quantization tables.
- WebP reader: sets quality 100 for any lossless (VP8L) input (
coders/webp.c:301). - WebP writer: switches to lossless when quality >= 100 (
coders/webp.c:1170). - JPEG writer: uses the inherited quality, or 92 if none is set.
| input (6 photos, 768x512) | output today | size vs input |
|---|---|---|
| JPEG q85 | WebP q85 | 0.85x |
| JPEG q99 | WebP q99 | 0.48x |
| JPEG q100 | lossless WebP | 1.00x |
| lossy WebP | JPEG q92 | 2.05x |
| lossless WebP | JPEG q100 | 0.98x (photos), 4.2x (logos) |
- q100 JPEG is also a CPU problem. The lossless WebP encode runs on the ET_NET thread:
| input | q99 | q100 |
|---|---|---|
| 768x512 | 88 ms | 620–690 ms |
| 1920x1277 | 0.52 s | 2.58 s, output 3.2 MB from a 3.0 MB input |
- Lossless WebP is the normal format for logos and UI graphics. These are exactly the objects most likely to reach the WebP -> JPEG path. A 158 KB lossless logo becomes a 383 KB q100 JPEG.
2. Transparency
Image::magick("JPEG") drops the alpha channel. What gets encoded is the RGB stored under transparent pixels, which is often junk (visible coloured fringes or garbage outside the shape) rather than a background.
3. Content-Type labelling
ImageTransform::handleReadResponseHeaders() sets the server response's Content-Type to the target type before the body arrives. When the transform falls back to the original bytes (signature mismatch, decode error), handleSendResponseHeaders() relabels only the client response. The cached object keeps the target label over the original body; the code comment notes this as a known issue.
Reproduced on master with the cache on. Each row is two requests for the same URL; the second is a cache hit (cRs f).
| origin body | client Accept |
1st response | 2nd response (from cache) |
|---|---|---|---|
| truncated WebP (undecodable) | */* |
image/webp, WebP body | image/jpeg, WebP body |
| truncated WebP (undecodable) | image/jpeg |
image/webp, WebP body | image/jpeg, WebP body |
Content-Type: image/png, body not a PNG |
WebP-capable | image/png | image/webp, same body |
Proposal
A prototype (ImageMagick backend, docs included, not yet a PR) is on the branch phongn:webp-transform-png, commit db10c79.
Explicit, configurable quality:
- Add
webp_quality=<1-100>(default 80) andjpeg_quality=<1-100>(default 85). - Never inherit quality from the source.
- WebP output is always lossy:
webp:lossless=false, so 100 doesn't silently switch to lossless.
PNG for transparent WebP: a client without image/webp in Accept is treated as accepting JPEG/GIF/PNG.
- A WebP with an alpha channel converts to PNG, which is lossless and keeps transparency.
- An opaque WebP converts to JPEG as today.
- The decision uses the decoder's alpha flag. libwebp's encoders set it only when transparency is present; a file from another encoder that flags alpha on an opaque image would become a PNG, which costs size but is still correct.
Label the body actually sent:
- Set
Content-Typeon the transform response (TSHttpTxnTransformRespGet) immediately before the firstproduce(). HttpTransact::handle_transform_ready()builds both the client response and the cached copy's headers from the transform response when output starts. So one label covers converted output, the PNG fallback, and pass-through.- This removes the early stamp in
handleReadResponseHeaders()and the relabel inhandleSendResponseHeaders().
Optional: size guard. If the WebP output is not smaller than the original JPEG/PNG, send the original; the client accepts both. A fixed quality otherwise inflates low-quality sources: a q50 JPEG grows 1.26x at Q80.
Stats:
- Add
plugin.webp_transform.convert_to_png. - Count only successful conversions. Today the counter increments after decode, before encode.
Results with the prototype (defaults 80/85)
Averages over 6 photos unless noted:
| input | today | proposed |
|---|---|---|
| JPEG q100 | 521 KB lossless WebP | 71 KB lossy WebP |
| lossless WebP logo with alpha (one 158 KB logo), legacy client | 383 KB q100 JPEG, broken transparency | 325 KB PNG, pixel-exact |
| lossless WebP photo (opaque), legacy client | 475 KB q100 JPEG | 100 KB JPEG q85 |
| lossy WebP, legacy client | 144 KB JPEG q92 | 96 KB JPEG q85 |
Verified with the cache enabled:
- Every case's second request returns the same
Content-Typeand body, and all are cache hits except one.- The exception is a truncated WebP passed through to a
*/*client, which ATS core refetches each time by design. - The three labelling cases above are now correct on both requests.
- The exception is a truncated WebP passed through to a
- Invalid quality values are logged and the defaults kept.
- The chunked over-cap 502 path is unchanged.
Compatibility
These defaults change output for every existing deployment:
- smaller WebP for high-quality sources
- PNG instead of JPEG for transparent WebP
- different JPEG quality
This should go out with a release note, or in a release where output changes are expected.
Open question: PNG for clients that list only image/jpeg
A client whose Accept names only image/jpeg would receive PNG for a transparent WebP. The existing webp_transform_invalid_input replay sends exactly that header, though for an opaque image. One option is to send PNG only when Accept allows it (image/png, image/*, */*), and otherwise flatten onto white and send JPEG. Is that worth the extra rule?
Open question: default quality
Fixed Q80 beats inherited quality for sources at about q85 and above. It loses below that:
| source | today | fixed Q80 |
|---|---|---|
| q75 JPEG | 58 KB WebP | 69 KB WebP (+18%) |
| q50 JPEG | 42 KB WebP | the 62 KB original, via the size guard |
An alternative is to cap rather than fix: min(estimated source quality, configured). ImageMagick provides the estimate; other backends would need a small JPEG quantization-table parser. Feedback welcome.
Notes
- Autests:
webp_transform_invalid_input(empty body, 1-byte body, non-JPEG JPEG, valid 1x1 WebP -> JPEG) passes when replayed by hand against the prototype.- The other tests exercise unchanged paths.
- New tests should cover alpha -> PNG, q100 -> lossy, and cached labels on pass-through.
- Linguagem predominante
- C++
- Estrelas
- 2k
- Forks
- 903
- Merge médio
- 4d 4h
- PRs com merge (30d)
- 135
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de apache/trafficserver
-
UnixNetVConnection::do_io_write with a null reader leaves the previous reader in the write VIOTalvez já em andamento @NginxL assumiu hoje. AbertaBug Good First Issue IOBuffer Network
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/trafficserver#14220 ·
Mantenedores costumam responder em até 2 dias
-
MallocAllocator does not check for allocation failureTalvez já em andamento @umrndem assumiu hoje. AbertaBug Core Good First Issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/trafficserver#14218 · 2 comentários ·
Mantenedores costumam responder em até 2 dias
-
Bug Event System Threads
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/trafficserver#14217 ·
Mantenedores costumam responder em até 2 dias
-
TSContScheduleEveryOnPool and TSContScheduleEveryOnThread accept a zero or negative periodTalvez já em andamento @rajeetvk assumiu há 1 dia. AbertaBug Event System Good First Issue TS API
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
apache/trafficserver#14214 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
HostDBContinuation::init memsets a polymorphic ActionTalvez já em andamento @ANMOLSCRIPT assumiu hoje. AbertaBug Good First Issue HostDB
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
apache/trafficserver#14204 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
Todas as issues de apache/trafficserver
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
Mantenedores costumam responder em até 2 dias
-
bug data-types
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
ClickHouse/clickhouse-cpp#645 ·
Mantenedores costumam responder em até 1 dia
-
bug compatibility difficulty:easy prio:normal
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
NatronGitHub/openfx-misc#524 ·
Mantenedores costumam responder em até 1 dia
-
documentation enhancement help wanted P0
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#359 ·
Mantenedores costumam responder em até 1 dia
-
Type: Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
openscad/openscad#7360 · 2 comentários ·
Mantenedores costumam responder em até 1 dia