Repository navigation
Conversation
Chromium's off-screen rendering paints premultiplied alpha, and cefsrc copies it into buffers as is. Raw video in GStreamer is conventionally straight alpha, and caps cannot say otherwise, so anything that blends a cefsrc stream (compositor, glvideomixer) renders partially transparent regions too dark: CSS rgba(255,255,255,.5) arrives as 128,128,128,128. When enabled, convert each video buffer to straight alpha in create(), in place, using a lookup table for c * 255 / a rounded to nearest. Pixels with alpha 0 or 255 are skipped. The default is off, leaving the output unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Hey, thanks for the proposed patch, I went looking for a bit but couldn't find definitive confirmation about whether CEF outputs straight or premultiplied alpha, do you have a source for that by any chance? |
|
@MathieuDuponchelle thanks for taking a look at this. AFAICT, the docs don't specify. However, in my own observations I saw that |
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit aaa8b24)
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit aaa8b24)
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit aaa8b24)
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit aaa8b24)
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Sorry, I kind of forgot about this one. Considering your experimental results and the fact that there's a property, this is enough for merging, I think we should make the default TRUE to be honest, what do you think @wagenet ? |
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cefsrc can now convert to straight alpha itself (centricular/gstcefsrc#113). Declaring such a source premultiplied as well converts twice and composites too bright, so the alpha mode description says to leave it straight. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
If I understand correctly, Chromium is rendering a premultiplied BGRA which is passed on directly by cefsrc. However, gstreamer expects conventional alpha. This change seeks to convert what Chromium provides to the more conventional format.
Claude's wordy analysis
Chromium's off-screen rendering paints premultiplied BGRA, and
cefsrccopiesOnPaintinto buffers unchanged. Raw video in GStreamer is conventionally straight alpha, and caps cannot say otherwise, socompositorandglvideomixerblend acefsrcstream too dark wherever alpha is partial: 50% white over grey 64 comes out 96 instead of 160.A new boolean property,
unpremultiply, converts each video buffer to straight alpha. It defaults to off, so existing output is byte-for-byte unchanged for anyone who already compensates downstream or wants premultiplied frames. I chose a boolean over analpha-modeenum because the enum would have only two values, one of them the status quo. The name says what the element does, in the same style as the existing properties. It can be changed in any state and is read once per buffer under the object lock.The conversion runs in
create()on the streaming thread, afterqueue_lockis released.OnPaintruns on the CEF UI thread (the main thread on macOS), so converting there would delay Chromium's next paint. The buffer allocated byOnPainthas no other reference, so it is converted in place without allocating. The formula isc' = min(255, (c*255 + a/2) / a), read from a 256×256 table built once inclass_init. Pixels with alpha 0 or 255 are skipped because both encodings store them the same way.On an M4 Max at 1080p, the loop takes 0.56 ms when all alpha is 0 and 1.23 ms when all alpha is partial. Random noise with 10% partial alpha, the worst case for branch prediction, takes 1.69 ms.
Verification
This repo has no test harness, so verification was manual. Setup: macOS arm64, GStreamer 1.28.6, CEF 144.0.21. The pipeline was
cefsrc ! video/x-raw,format=BGRA,width=320,height=180 ! multifilesink, run fromgst-launch-1.0inside an app bundle. The test page has columns of each colour below over a transparent body, plus a 1px element animated withrequestAnimationFrameso Chromium keeps painting. RGBA values were read from the last raw frame:unpremultiply=truergba(255,255,255,.5)rgb(255,0,0)rgba(255,0,0,.5)rgba(255,255,255,.1)rgba(255,0,0,.1)rgba(200,100,50,.25)rgba(10,20,30,.03)transparentAt
.03, Chromium has already quantized the colour to 0,1,1 beforecefsrcsees it, so the original colour cannot be recovered at the source.masterbuild.unpremultiply=true, every pixel equals the formula applied to the default-mode pixel (0 mismatches out of 57,599).cefdemux: thecefsrc ! cefdemuxpath gives the same values.This and #111 both edit
gstcefsrc.cc, but a test merge applies cleanly. #111 drops stale frames inOnPaint, beforecreate(), so dropped frames are never converted.🤖 Generated with Claude Code