[FFmpeg-devel] [PATCH] libavutil/hwcontext_opencl.c: fix bug in `opencl_get_plane_format`

Mark Thompson sw at jkqxz.net
Mon Apr 8 00:16:03 EEST 2019


On 06/04/2019 00:05, Jarek Samic wrote:
> The `opencl_get_plane_format` function was incorrectly determining the
> value used to set the image channel order. This resulted in all RGB
> pixel formats being set to the `CL_RGBA` pixel format, regardless of
> whether or not they actually *were* RGBA.
> 
> This patch fixes the issue by using the `offset` field on components
> rather than the loop index to determine the value of `order` for RGB
> pixel formats (and leaves the formula to determine `order` the same for
> other formats so as not to break those cases).
> 
> Signed-off-by: Jarek Samic <cldfire3 at gmail.com>
> ---
> I'm including this in the email (but not the commit description) to
> make this patch easier to review. In order to make sure I was fixing
> the bug and not messing up channel order mapping for any of the other
> formats, I set up a few quick print statements within the function
> after the `order` value was set.
> 
> Here's the output without this patch:
> 
> ```
> [AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
> [AVHWDeviceContext @ _] Format yuv410p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
> [AVHWDeviceContext @ _] Format yuv411p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
> [AVHWDeviceContext @ _] Format gray supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
> [AVHWDeviceContext @ _] Format nv12 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
> [AVHWDeviceContext @ _] Format nv21 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: argb, plane: 0
> [AVHWDeviceContext @ _] Format argb supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
> [AVHWDeviceContext @ _] Format rgba supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: abgr, plane: 0
> [AVHWDeviceContext @ _] Format abgr supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: bgra, plane: 0
> [AVHWDeviceContext @ _] Format bgra supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
> [AVHWDeviceContext @ _] Format gray16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
> [AVHWDeviceContext @ _] Format yuv440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p16le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
> [AVHWDeviceContext @ _] Format ya8 supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrp, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrp, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
> [AVHWDeviceContext @ _] Format gbrp supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrp16le, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrp16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
> [AVHWDeviceContext @ _] Format gbrp16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
> [AVHWDeviceContext @ _] Format nv16 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
> [AVHWDeviceContext @ _] Format rgba64le supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: bgra64le, plane: 0
> [AVHWDeviceContext @ _] Format bgra64le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
> [AVHWDeviceContext @ _] Format ya16le supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrap, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrap, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: gbrap, plane: 3
> [AVHWDeviceContext @ _] Format gbrap supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrap16le, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrap16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: gbrap16le, plane: 3
> [AVHWDeviceContext @ _] Format gbrap16le supported.
> [opencl_get_plane_format] order_num: 123, pixel_format: 0rgb, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: 0bgr, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: bgr0, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj411p supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
> [AVHWDeviceContext @ _] Format ayuv64le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
> [AVHWDeviceContext @ _] Format p010le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
> [AVHWDeviceContext @ _] Format p016le supported.
> ```
> 
> Here's the output with this patch:
> 
> ```
> [AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
> [AVHWDeviceContext @ _] Format yuv410p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
> [AVHWDeviceContext @ _] Format yuv411p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
> [AVHWDeviceContext @ _] Format gray supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
> [AVHWDeviceContext @ _] Format nv12 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
> [AVHWDeviceContext @ _] Format nv21 supported.
> [opencl_get_plane_format] order_num: 2341, pixel_format: argb, plane: 0
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
> [AVHWDeviceContext @ _] Format rgba supported.
> [opencl_get_plane_format] order_num: 4321, pixel_format: abgr, plane: 0
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra, plane: 0
> [AVHWDeviceContext @ _] Format bgra supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
> [AVHWDeviceContext @ _] Format gray16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
> [AVHWDeviceContext @ _] Format yuv440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p16le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
> [AVHWDeviceContext @ _] Format ya8 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
> [AVHWDeviceContext @ _] Format gbrp supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
> [AVHWDeviceContext @ _] Format gbrp16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
> [AVHWDeviceContext @ _] Format nv16 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
> [AVHWDeviceContext @ _] Format rgba64le supported.
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra64le, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
> [AVHWDeviceContext @ _] Format ya16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 3
> [AVHWDeviceContext @ _] Format gbrap supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 3
> [AVHWDeviceContext @ _] Format gbrap16le supported.
> [opencl_get_plane_format] order_num: 234, pixel_format: 0rgb, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
> [opencl_get_plane_format] order_num: 432, pixel_format: 0bgr, plane: 0
> [opencl_get_plane_format] order_num: 321, pixel_format: bgr0, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj411p supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
> [AVHWDeviceContext @ _] Format ayuv64le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
> [AVHWDeviceContext @ _] Format p010le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
> [AVHWDeviceContext @ _] Format p016le supported.
> ```
> 
> Feel free to compare the two with your favorite diff tool. You'll notice
> that the various RGB formats (RGBA, ARGB, BGRA...) are now having the
> correct channel order assigned and that the channel order for the other
> formats is unchanged.
> 
>  libavutil/hwcontext_opencl.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index b116c5b708..b6c389b95d 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -1376,6 +1376,7 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
>      int channels = 0, order = 0, depth = 0, step = 0;
>      int wsub, hsub, alpha;
>      int c;
> +    int add_to_ord;
>  
>      if (plane >= AV_NUM_DATA_POINTERS)
>          return AVERROR(ENOENT);
> @@ -1419,7 +1420,23 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
>          // from the same component.
>          if (step && comp->step != step)
>              return AVERROR(EINVAL);
> -        order = order * 10 + c + 1;
> +
> +        if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
> +            // If the format is RGB we determine the order number using the
> +            // component's offset values
> +
> +            // Here we handle 8 vs 16 bit components
> +            if (comp->depth <= 8) {
> +                add_to_ord = comp->offset;
> +            } else {
> +                add_to_ord = comp->offset / 2;
> +            }
> +        } else {
> +            // Otherwise we maintain the previous behavior that used the loop
> +            // index
> +            add_to_ord = c;
> +        }> +        order = order * 10 + add_to_ord + 1;

The RGB test really feels like it shouldn't be necessary here (why should RGB be special?).

Does anything go wrong if you unconditionally add comp->offset / (depth / 8)?  Looking through the cases in your output above, the only change I can see it would make would be to change the order of the chroma plane on the two-plane YUV formats (like NV12) from 23 to 12, but that's still RG so the result would be the same.

>          depth = comp->depth;
>          step  = comp->step;
>          alpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA &&
> 

(A further thought - given a change like that, can the cases not containing a 1 in the switch on order be removed?  They look redundant.)

Thanks,

- Mark


More information about the ffmpeg-devel mailing list