Skip to content

Add ConvertRGBToYUV Operation - #344

Merged
morousg merged 3 commits into
mainfrom
copilot/add-convert-rgb-to-yuv
Aug 18, 2026
Merged

Add ConvertRGBToYUV Operation#344
morousg merged 3 commits into
mainfrom
copilot/add-convert-rgb-to-yuv

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

The library had ConvertYUVToRGB but no Operation for the opposite direction, even though the RGB→YCbCr matrices already exist in ccMatrix.

include/fused_kernel/algorithms/image_processing/color_conversion.h

  • Adds ConvertRGBToYUV<ColorDepth, ColorRange, ColorPrimitives>, mirroring ConvertYUVToRGB: a UnaryOperation<ColorDepthPixelType<CD>, float3> that applies ccMatrix<CR, CP, ColorConversionDir::RGB2YCbCr, CD> through MxVFloat3<UnaryType> and then adds the chroma offset (plus the luma offset for limited range) from subCoefficients<CD>.
const auto toYUV = ConvertRGBToYUV<ColorDepth::p8bit, ColorRange::Limited, ColorPrimitives::bt709>::build();
// exec({R, G, B}) -> float3{Y, Cb, Cr} in the value range of the color depth

utests/algorithm/image_processing/utest_color_conversion.h

  • New testConvertRGBToYUV() covering all 36 combinations of ColorDepth × ColorRange × ColorPrimitives over 7 RGB samples (black, white, primaries, mid-gray, arbitrary).
  • Each sample is checked against referenceRGBToYUV, an independent implementation written straight from the ITU equations (weights, offsets, range scaling) rather than reusing ccMatrix, so a wrong matrix pick or missing offset is caught.
  • Each sample is also round-tripped through ConvertYUVToRGB, with the intermediate YUV saturated and quantized to the depth's pixel type; the round-trip tolerance (1% of the depth range) accounts for that quantization.

Copilot AI lite review requested due to automatic review settings August 18, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI linked an issue Aug 18, 2026 that may be closed by this pull request
Co-authored-by: morousg <6429408+morousg@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 18, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Suppressed comments (2)

include/fused_kernel/algorithms/image_processing/color_conversion.h:177

  • The struct is named ConvertRGBToYUV, but the implementation explicitly uses ColorConversionDir::RGB2YCbCr and names the intermediate YCbCr. Since YUV and YCbCr are not interchangeable in many APIs, this can mislead callers. Either rename the operation to ConvertRGBToYCbCr (and update the output comment accordingly), or switch to a true RGB→YUV conversion path if the project distinguishes them.
    template <ColorDepth CD, ColorRange CR, ColorPrimitives CP>
    struct ConvertRGBToYUV {

include/fused_kernel/algorithms/image_processing/color_conversion.h:191

  • The struct is named ConvertRGBToYUV, but the implementation explicitly uses ColorConversionDir::RGB2YCbCr and names the intermediate YCbCr. Since YUV and YCbCr are not interchangeable in many APIs, this can mislead callers. Either rename the operation to ConvertRGBToYCbCr (and update the output comment accordingly), or switch to a true RGB→YUV conversion path if the project distinguishes them.
        // The output is { Y, Cb(U), Cr(V) }
        FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) {
            constexpr M3x3Float coefficients = ccMatrix<CR, CP, ColorConversionDir::RGB2YCbCr, CD>;
            constexpr float CAdd = subCoefficients<CD>.chroma;
            const float3 YCbCr = MxVFloat3<UnaryType>::exec(

Comment thread include/fused_kernel/algorithms/image_processing/color_conversion.h
Comment thread include/fused_kernel/algorithms/image_processing/color_conversion.h
Comment thread include/fused_kernel/algorithms/image_processing/color_conversion.h
Co-authored-by: morousg <6429408+morousg@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 18, 2026 15:32
Copilot AI changed the title [WIP] Add ConvertRGBToYUV operation with unit tests Add ConvertRGBToYUV Operation Aug 18, 2026
Copilot AI requested a review from morousg August 18, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (3)

utests/algorithm/image_processing/utest_color_conversion.h:661

  • Test-only helpers are being added directly under namespace fk, which is also the library’s public namespace. This increases the risk of name collisions/ADL surprises with production code (especially as more operations are added). Consider moving these helpers under a dedicated test namespace (e.g., namespace fk::utest / fk::test) or an unnamed namespace within the test translation unit, and qualify library types with fk:: where needed.
namespace fk {
// Independent implementation of the ITU RGB -> YCbCr equations, used as ground truth for
// the ConvertRGBToYUV Operation. All the values are expressed in the value range of CD.

utests/algorithm/image_processing/utest_color_conversion.h:758

  • The ANSI escape sequence is applied twice and never reset on this line (\\033[1;33m is repeated). This can leave subsequent output colored/bold in CI logs or terminals. Replace the second escape with a reset (\\033[0m) (or otherwise ensure the color is reset immediately after printing testName).
        std::cout << "Running test for " << "\033[1;33m" << testName << "\033[1;33m" << ": ";

include/fused_kernel/algorithms/image_processing/color_conversion.h:188

  • The API name is ConvertRGBToYUV, but the implementation/comments reference YCbCr and also label components as Cb(U), Cr(V). Since YUV vs YCbCr and U/V vs Cb/Cr are commonly confused (and can imply different scaling/offset conventions), please clarify in the comment what exact digital format is produced (e.g., 'YCbCr with chroma offset applied; full/limited range handled via offsets/matrix') and what numeric range the returned float3 is in for each ColorDepth.
        // R -> input.x
        // G -> input.y
        // B -> input.z
        // The output is { Y, Cb(U), Cr(V) }
        FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) {

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@morousg
morousg marked this pull request as ready for review August 18, 2026 16:47
@morousg
morousg merged commit f6de69d into main Aug 18, 2026
8 of 9 checks passed
@morousg
morousg deleted the copilot/add-convert-rgb-to-yuv branch August 18, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create ConvertRGBToYUV

3 participants