Add ConvertRGBToYUV Operation - #344
Conversation
There was a problem hiding this comment.
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.
Co-authored-by: morousg <6429408+morousg@users.noreply.github.com>
There was a problem hiding this comment.
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 usesColorConversionDir::RGB2YCbCrand names the intermediateYCbCr. Since YUV and YCbCr are not interchangeable in many APIs, this can mislead callers. Either rename the operation toConvertRGBToYCbCr(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 usesColorConversionDir::RGB2YCbCrand names the intermediateYCbCr. Since YUV and YCbCr are not interchangeable in many APIs, this can mislead callers. Either rename the operation toConvertRGBToYCbCr(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(
Co-authored-by: morousg <6429408+morousg@users.noreply.github.com>
There was a problem hiding this comment.
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 withfk::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;33mis 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 printingtestName).
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 asCb(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 returnedfloat3is in for eachColorDepth.
// 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) {
The library had
ConvertYUVToRGBbut no Operation for the opposite direction, even though the RGB→YCbCr matrices already exist inccMatrix.include/fused_kernel/algorithms/image_processing/color_conversion.hConvertRGBToYUV<ColorDepth, ColorRange, ColorPrimitives>, mirroringConvertYUVToRGB: aUnaryOperation<ColorDepthPixelType<CD>, float3>that appliesccMatrix<CR, CP, ColorConversionDir::RGB2YCbCr, CD>throughMxVFloat3<UnaryType>and then adds the chroma offset (plus the luma offset for limited range) fromsubCoefficients<CD>.utests/algorithm/image_processing/utest_color_conversion.htestConvertRGBToYUV()covering all 36 combinations of ColorDepth × ColorRange × ColorPrimitives over 7 RGB samples (black, white, primaries, mid-gray, arbitrary).referenceRGBToYUV, an independent implementation written straight from the ITU equations (weights, offsets, range scaling) rather than reusingccMatrix, so a wrong matrix pick or missing offset is caught.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.