Skip to content

cudacodec: fix black/white/uvWhite of BT2020/BT2020C#4076

Open
quink-black wants to merge 8 commits intoopencv:4.xfrom
quink-black:cudacodec-yuv2rgb
Open

cudacodec: fix black/white/uvWhite of BT2020/BT2020C#4076
quink-black wants to merge 8 commits intoopencv:4.xfrom
quink-black:cudacodec-yuv2rgb

Conversation

@quink-black
Copy link
Copy Markdown

@quink-black quink-black commented Feb 7, 2026

This patch addresses two critical issues in color conversion:

  • The previous implementation caused severe color shifts because uvWhite was handled as an 8-bit value while the luminance was processed as 10-bit P010.

  • Additionally, the code was hardcoded to Limited Range.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • x There is a reference to the original bug report and related work
  • x There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

This patch addresses two critical issues in color conversion:

- The previous implementation caused severe color shifts because
uvWhite was handled as an 8-bit value while the luminance was
processed as 10-bit P010.

- Additionally, the code was hardcoded to Limited Range.
@asmorkalov
Copy link
Copy Markdown
Contributor

cc @cudawarped

@asmorkalov
Copy link
Copy Markdown
Contributor

@quink-black Could you a simple test for the case? E.g. encode syntetic image as video, decode with the cudacodecs and check pixel colors?

Move PARAM_TEST_CASE(YuvConverter) and CUDA_TEST_P(YuvConverter) and
their INSTANTIATE to a dedicated HAVE_CUDA block, so YuvConverter
tests run when CUDA is available even without NVCUVID/NVCUVENC.

No functional changes.
Replace imread with a cv::randu-generated 64x128 BGR image to remove
the dependency on external test data and make the test self-contained.

No functional changes to the conversion logic.
So that the Y row (i==0) uses the luma range (white-black)/max
and the Cb/Cr rows (i!=0) use the chroma range (uvWhite-black)/max.
Previously the column index was checked instead of the row index,
which applied incorrect scaling when the luma and chroma ranges differ.
@quink-black
Copy link
Copy Markdown
Author

@quink-black Could you a simple test for the case? E.g. encode syntetic image as video, decode with the cudacodecs and check pixel colors?

Done. colorspace conversion doesn't need encoder/decoder.

@asmorkalov asmorkalov self-requested a review February 24, 2026 09:20
@asmorkalov asmorkalov self-assigned this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants