IENT / YUView

The Free and Open Source Cross Platform YUV Viewer with an advanced analytics toolset
http://ient.github.io/YUView
Other
1.93k stars 378 forks source link

Display controls for alpha component in RGB Display panel #369

Closed ao2 closed 3 years ago

ao2 commented 3 years ago

Hi,

I was looking into formats with an alpha channel and bumped into https://github.com/IENT/YUView/issues/146

YUView works fine with the sample files from that issue, after configuring the appropriate custom formats, however I noticed that there are no controls for the alpha component in the "RGB Display" panel on the right for formats with an alpha channel: RGB-display-misses-alpha-component

It would be handy to be able to control and visualize the alpha channel somehow in YUView.

Thanks, Antonio

ChristianFeldmann commented 3 years ago

Hi, Yes the conversions to RGB are currently just that. Conversions to RGB. We don't have advanced support for Alpha channels and that is also why there is no multiply/invert control for alpha there. What would be a desired outcome for you?

A proposal from me: In the right there is a component dropdown box where you can render individual components (currently R/G/B). In this drop-down we could add a line for the alpha component. Then one could inspect the Alpha component in a black/white style view.

ao2 commented 3 years ago

Hi @ChristianFeldmann,

my final goal would be to inspect the alpha channel to check that is has been properly represented/encoded, for example by video codecs that support it like HEVC (see https://github.com/strukturag/libde265/issues/288).

As a short-term goal, having a simple way to visualize the alpha channel in raw files would be a good start, the dropdown box you mention is perfectly fine for that; long-term the alpha channel may be treated like all the other components and have the same controls that they have.

Ideally this would be useful for YUV formats that support alpha too.

I am not sure whether the alpha should also be applied to the color components in the view when all components are enabled, like currently done for PNG files in YUView, what do you think about that? That could become an optional behavior too.

I am attaching a PNG file and a conversion script to generate some raw test samples to experiment with, note that the fully transparent pixels have a red color.

test_squared_alpha

#!/bin/sh

SOURCE="filesrc location=test_squared_alpha.png ! pngdec"

gst-launch-1.0 $SOURCE ! videoconvert ! pngenc ! filesink location=squared_640x480.png
gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=A420 ! filesink location=squared_640x480_a420.yuv
gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=ARGB ! filesink location=squared_640x480_argb.rgb
# Converting to the AV12 format is supported from GStreamer 1.19 only
#gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=AV12 ! filesink location=squared_640x480_av12.yuv
gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=BGRA ! filesink location=squared_640x480_bgra.rgb
gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=I420 ! filesink location=squared_640x480_i420.yuv
gst-launch-1.0 $SOURCE ! videoconvert ! video/x-raw,format=NV12 ! filesink location=squared_640x480_nv12.yuv

Thanks, Antonio

ChristianFeldmann commented 3 years ago

Ah you are right we already support alpha rendering in the view. We could also enable that for raw RGB sources. We just need some conversion / handling code for the conversion. Yep that sounds like a thing we should add. And for that you are right we should also add the same controls (multiply/invert). And also the dropdown. Then one can inspect the alpha plane individually.

ChristianFeldmann commented 3 years ago

Hi. I merged the PR. Maybe you can test the latest version again. Let me know if you find anything that is not working correctly.

ao2 commented 3 years ago

Hi. I merged the PR. Maybe you can test the latest version again. Let me know if you find anything that is not working correctly.

Thanks a lot @ChristianFeldmann, unfortunately rendering the alpha for raw RGBA data does not seem to work here on linux (gnome-shell 3.38 running on Wayland and QT5 5.15.2). I always get solid colors in the view in RGBA mode, even though the alpha channel is displayed correctly on its own. Alpha rendering works fine for PNG images.

Thank you, Antonio

ao2 commented 3 years ago

The issue seems to be that functionsGui::pixmapImageFormat() returns 4, which is QImage::Format_RGB32 according to https://doc.qt.io/qt-5/qimage.html#Format-enum

I noticed this message on the console:

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

and launchng YUView with QT_QPA_PLATFORM=wayland makes indeed functionsGui::pixmapImageFormat() return 6 which is QImage::Format_ARGB32_Premultiplied. In this case rendering kinda works, as I can see the alpha channel somehow, but there are visual glitches and update issues.

Well I guess this is more a Wayland and QT issue rather than a YUView issue.

ao2 commented 3 years ago

JFTR, forcing functionsGui::pixmapImageFormat() to return QImage::Format_ARGB32 works around the issue and alpha gets rendered on both xcb and wayland backends. Not sure if this is a proper solution tho.

To recap, on gnome+wayland:

  1. with the QT xcb backend functionsGui::pixmapImageFormat() returns QImage::Format_RGB32 and the alpha is not rendered
  2. with the QT wayland backend functionsGui::pixmapImageFormat() returns QImage::Format_ARGB32_Premultiplied but the view is buggy (translucent areas are corrupted, glitches all round in them when moving the window), probably because of a QT bug?
  3. Forcing QImage::Format_ARGB32 seems to work around the issues

It would be interesting to come up with a minimal example to confirm the bug in 2. but I would have to refresh my QT knowledge.