After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 797091 - cairooverlay: passes un-premultiplied ARGB to Cairo
cairooverlay: passes un-premultiplied ARGB to Cairo
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
unspecified
Other Linux
: Normal normal
: 1.15.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-09-06 17:45 UTC by Sebastian Dröge (slomo)
Modified: 2018-10-03 20:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
cairooverlay: Add property for drawing on a transparent surface and then blending (7.05 KB, patch)
2018-09-25 14:03 UTC, Sebastian Dröge (slomo)
committed Details | Review
cairooverlay: Pre-multiply and un-premultiply alpha in case of ARGB32 (5.10 KB, patch)
2018-09-25 14:03 UTC, Sebastian Dröge (slomo)
committed Details | Review
cairooverlay: Add overlay as meta to the buffers if we can (4.78 KB, patch)
2018-09-25 14:03 UTC, Sebastian Dröge (slomo)
none Details | Review
cairooverlay: Don't map input buffers if we just attach the overlay as meta (8.20 KB, patch)
2018-09-25 15:08 UTC, Sebastian Dröge (slomo)
none Details | Review
cairooverlay: Add overlay as meta to the buffers if we can (5.02 KB, patch)
2018-10-01 16:26 UTC, Sebastian Dröge (slomo)
committed Details | Review
cairooverlay: Don't map input buffers if we just attach the overlay as meta (8.23 KB, patch)
2018-10-01 16:26 UTC, Sebastian Dröge (slomo)
committed Details | Review

Description Sebastian Dröge (slomo) 2018-09-06 17:45:51 UTC
Cairo expects pre-multiplied alpha, we don't. So before and afterwards we need to convert between the two for every frame, which is kind of suboptimal.
Comment 1 Sebastian Dröge (slomo) 2018-09-06 18:16:51 UTC
This is not an enhancement but a bug. We provide wrong data to cairo, and cairo gives us even worse data back
Comment 2 Nicolas Dufresne (ndufresne) 2018-09-06 20:25:27 UTC
Reworded, the way you wrote it initially, it sounded more like it was "suboptimal" rather then broken. For textoverlay we use premultiply alpha support from GstVideoOverlayComposition helpers. So in that case, if it's broken it's a regression.
Comment 3 Sebastian Dröge (slomo) 2018-09-06 21:27:48 UTC
It's a simple bug in cairooverlay, unrelated to any other code :)

Our ARGB is un-pre-multipled, Cairo's is pre-multiplied. As such we need to convert before passing to Cairo, and another time in reverse after getting the data from Cairo.

In textoverlay (where we also use Cairo) it's handled correctly.
Comment 4 Nicolas Dufresne (ndufresne) 2018-09-06 23:34:07 UTC
I don't kow what iss faster, but we could render to a separate RGB buffer, and then blend (with our existing blend function) on top of the video frame. This reduces at least the color washing caused by de-pre-multiplying.
Comment 5 Sebastian Dröge (slomo) 2018-09-07 07:10:11 UTC
The problem is that the signal handler might look at the image surface pixels we pass to it, and that wouldn't be possible anymore then.
Comment 6 Sebastian Dröge (slomo) 2018-09-19 07:55:48 UTC
This should probably go together with defining a new set of video formats for RGB with pre-multiplied alpha so that in some cases the double-conversion can be prevented.

Let's call them aRGB, i.e. small a instead of capital A? :)
Comment 7 Nicolas Dufresne (ndufresne) 2018-09-19 12:24:57 UTC
Naming is hard, I'm worried it's too subtle, but I like that it's short. New formats seems like the most straightforward, then we can implement the conversion in videoconvert, and avoid over converting.
Comment 8 Sebastian Dröge (slomo) 2018-09-25 05:46:00 UTC
(In reply to Nicolas Dufresne (ndufresne) from comment #4)
> I don't kow what iss faster, but we could render to a separate RGB buffer,
> and then blend (with our existing blend function) on top of the video frame.
> This reduces at least the color washing caused by de-pre-multiplying.

I think we would want this behind a property. By first rendering to a transparent surface and then blending it over the video you also get different blending behaviour.

But it would also allow for using the overlay meta and e.g. not downloading/uploading GL memories all the time.
Comment 9 Sebastian Dröge (slomo) 2018-09-25 14:03:16 UTC
Created attachment 373755 [details] [review]
cairooverlay: Add property for drawing on a transparent surface and then blending

This allows us to use the GstVideoOverlayComposition API and correctly
handle pre-multiplied alpha, while also only doing the alpha conversion
once instead of twice for the whole frame.

At a later point we can attach the meta to the buffer instead of
blending ourselves if downstream supports that.
Comment 10 Sebastian Dröge (slomo) 2018-09-25 14:03:22 UTC
Created attachment 373756 [details] [review]
cairooverlay: Pre-multiply and un-premultiply alpha in case of ARGB32

Cairo expects pre-multiplied alpha, we work on un-premultiplied alpha.
Comment 11 Sebastian Dröge (slomo) 2018-09-25 14:03:26 UTC
Created attachment 373757 [details] [review]
cairooverlay: Add overlay as meta to the buffers if we can

This requires that downstream supports it and
draw-on-transparent-surface is enabled.
Comment 12 Sebastian Dröge (slomo) 2018-09-25 15:08:23 UTC
Created attachment 373758 [details] [review]
cairooverlay: Don't map input buffers if we just attach the overlay as meta
Comment 13 Sebastian Dröge (slomo) 2018-10-01 16:26:11 UTC
Created attachment 373819 [details] [review]
cairooverlay: Add overlay as meta to the buffers if we can

This requires that downstream supports it and
draw-on-transparent-surface is enabled.
Comment 14 Sebastian Dröge (slomo) 2018-10-01 16:26:17 UTC
Created attachment 373820 [details] [review]
cairooverlay: Don't map input buffers if we just attach the overlay as meta
Comment 15 Sebastian Dröge (slomo) 2018-10-03 20:24:44 UTC
Attachment 373755 [details] pushed as 9844bdb - cairooverlay: Add property for drawing on a transparent surface and then blending
Attachment 373756 [details] pushed as f1c5a22 - cairooverlay: Pre-multiply and un-premultiply alpha in case of ARGB32
Attachment 373819 [details] pushed as 10446bd - cairooverlay: Add overlay as meta to the buffers if we can
Attachment 373820 [details] pushed as a766dce - cairooverlay: Don't map input buffers if we just attach the overlay as meta