Free Core now2sdk v0.2.2 Core is free for commercial use with zero license key required
Docs Hub SDK Modules Release Notes Pricing Contact GitHub
Download Free SDK →
Filter Licensed Add-on Module Summary →

LColor Reference Manual & GPU Color Grading Guide

Header#include "LColor.h"
HierarchyLObject, LSink (GPU Color & Keying)
LicenseLicensed Add-on
TargetsLinux x64 · Win64 · C++17 / .NET

The LColor class is a dedicated, real-time GPU-accelerated color correction and 3D LUT grading engine within the now2sdk broadcast framework. Deriving from both LObject and LSink, it can be placed seamlessly between any upstream broadcast source (LFile, LLive, LMixer, LStreamPlay) and downstream sinks (LPreview, LMixer, LOutput, LStream).

LColor runs an asynchronous OpenGL GLSL compute pipeline coupled with dual Pixel Buffer Objects (PBO) to perform full primary color grading, 3D LUT tri-linear filtering, broadcast CCU adjustments, and statistical camera matching at up to 200 FPS with sub-millisecond execution latency.


1. Architecture Overview

graph TD
    A[Upstream Source<br/>LLive / LFile / LMixer] -->|AVFrame*| B[LColor Ingest Queue]
    B -->|PBO Texture Upload| C[GPU GLSL Color Pipeline]
    
    subgraph sg_1["GPU Fragment Shader"]
        C1[1. Exposure - exp2] --> C2[2. White Balance - Temp / Tint]
        C2 --> C3[3. CCU Lift / Gamma / Gain - RGB]
        C3 --> C4[4. Contrast & Brightness]
        C4 --> C5[5. HSV Hue Rotation]
        C5 --> C6[6. Saturation]
        C6 --> C7[7. 3D LUT Texture3D Interpolation]
    end
    
    C --> C1
    C7 -->|Async PBO Readback| D[Downstream Sinks<br/>LPreview / LMixer / LOutput]
    
    Ref[Reference Camera / Source] -.->|onRefVideoFrame| Match[Camera Matching Engine]
    Match -.->|Auto Lift / Gain / Gamma| C3
      

2. Primary Color Grading & Broadcast CCU Controls

All grading calculations operate in high-precision floating-point color space on the GPU:


3. Camera Matching (Reference Channel Alignment)

In multi-camera broadcast studios and outside broadcast (OB) vans, different camera sensors, lens coatings, and lighting conditions result in noticeable color mismatches. LColor provides two automated camera matching algorithms:

A. Single-Shot Statistical Calibration (matchColor)

Compares the statistical color distribution of the target camera against the chosen reference camera in real time:

  1. Black Floor Alignment (Lift): Matches the 5th percentile luminance and chromatic floor of both feeds.
  2. Dynamic Range & White Balance (Gain): Calculates the 95th percentile highlight ceiling ratio across Red, Green, and Blue channels.
  3. Midtone Curve (Gamma): Computes variance and standard deviation ratio (σref / σtgt) to match tonal distribution.

Once calculated, the values are locked onto the Lift, Gain, and Gamma parameters, allowing the operator to make fine manual touches afterwards.

B. Continuous Dynamic Auto-Matching (setReferenceSource)

When continuous matching is enabled (continuous = true), LColor dynamically monitors the reference camera and applies a gentle IIR low-pass filter (exponential moving average) to harmonize lighting and color temperature shifts across all slave cameras without flicker.


4. API Reference

C++ Methods (LColor)

bool setLicense(const std::string& licenseKey);
bool isLicensed() const;

Activates and queries licensing status for the "LColor" module.

void setSource(LObject* source);

Connects an upstream video source to this color processor.

LObject* getSource() const;

Returns the currently attached upstream source.

void setEnabled(bool enabled);

Enables or bypasses the GPU color correction engine.

void setBrightness(float val);

Sets global brightness offset (-1.0 to +1.0, default: 0.0).

void setContrast(float val);

Sets contrast multiplier (0.0 to 2.0, default: 1.0).

void setSaturation(float val);

Sets color saturation (0.0 for monochrome, 1.0 normal, up to 2.0).

void setGamma(float val);

Sets master power gamma curve (0.2 to 5.0, default: 1.0).

void setExposure(float val);

Sets photographic exposure stops (-3.0 to +3.0, default: 0.0).

void setTemperature(float val);

Adjusts color temperature along Amber/Blue axis (-1.0 to +1.0).

void setTint(float val);

Adjusts tint along Green/Magenta axis (-1.0 to +1.0).

void setHue(float val);

Rotates overall hue angle in degrees (-180.0 to +180.0).

void setLift(float r, float g, float b);

Sets shadow offsets independently for R, G, B (-1.0 to +1.0).

void setGammaRGB(float r, float g, float b);

Sets midtone gammas independently for R, G, B (0.1 to 3.0).

void setGain(float r, float g, float b);

Sets highlight multipliers independently for R, G, B (0.0 to 3.0).

void setRed(float val);
void setGreen(float val);
void setBlue(float val);

Sets Red, Green, or Blue channel gain multipliers (0.0 to 3.0, default 1.0).

bool matchColor(LObject* referenceSource);

Single-shot statistical calibration matching this channel's color to the reference channel.

void setReferenceSource(LObject* ref, bool continuous);

Sets the reference camera source and toggles continuous dynamic matching.

void setChromaKeyEnabled(bool enabled);

Enables or disables GPU YCbCr chrominance keying (outputs AV_PIX_FMT_RGBA with alpha when active).

void setChromaKeyColor(float r, float g, float b);

Sets target key color in normalized RGB (0.0..1.0, default green 0.0, 1.0, 0.0).

void setChromaKeySimilarity(float val);
void setChromaKeySmoothness(float val);

Adjusts chrominance tolerance (0.0..1.0) and edge feathering smoothness (0.0..1.0).

void setChromaKeySpill(float val);

Controls automatic green/blue spill suppression strength (0.0..1.0).

void setLumaKeyEnabled(bool enabled);

Enables or disables GPU luminance keying (outputs AV_PIX_FMT_RGBA with alpha when active).

void setLumaKeyRange(float minLuma, float maxLuma);
void setLumaKeySoftness(float val);
void setLumaKeyInvert(bool inv);

Configures luminance cutoff range, transition softness, and foreground/background inversion.

bool loadLUT(const std::string& cubePath);
bool saveLUT(const std::string& cubePath, int cubeSize = 33);
void clearLUT();

Loads or exports a standard 3D LUT (.cube) file, or clears the active LUT texture.

void setLUTMix(float mix);

Sets wet/dry blend factor for the 3D LUT (0.0 to 1.0).

void applyPreset(Preset preset);
bool savePreset(const std::string& filePath);
bool loadPreset(const std::string& filePath);

Applies a built-in look (Preset_Neutral, Preset_TealAndOrange, Preset_Monochrome, Preset_Vintage, Preset_Vibrant, Preset_Warm, Preset_Cool, Preset_Rec709) or saves/loads grading presets to disk.

void setAudioDelayMs(int ms);

Applies a synchronization delay offset (in milliseconds) to pass-through audio frames.

void setProps(const std::string& key, const std::string& value);

Dynamic key-value property interface (e.g. "enabled", "exposure", "contrast", "saturation", "temperature", "tint", "chroma_key", "load_lut", "lut_mix", "preset", "audio_delay_ms").

void reset();

Resets all color grading and CCU parameters back to neutral defaults.


5. Complete C++ Code Example

#include "now2sdk.h"
#include <iostream>

int main() {
    // 1. Create two live camera inputs (Cam 1: Reference, Cam 2: Target)
    LLive* cam1Ref = new LLive();
    cam1Ref->DeviceSet(0); // DeckLink Input 1
    cam1Ref->Start();

    LLive* cam2Target = new LLive();
    cam2Target->DeviceSet(1); // DeckLink Input 2
    cam2Target->Start();

    // 2. Attach LColor processor to Cam 2
    LColor* colorGrading = new LColor();
    colorGrading->setLicense("YOUR-LICENSE-KEY");
    colorGrading->setSource(cam2Target);

    // 3. Apply custom primary grade
    colorGrading->setContrast(1.15f);
    colorGrading->setSaturation(1.10f);
    colorGrading->setExposure(0.20f);

    // Adjust independent RGB gains
    colorGrading->setRed(1.05f);
    colorGrading->setBlue(0.95f);

    // 4. Perform automated camera matching to Cam 1
    std::cout << "Matching Cam 2 colors to Cam 1 reference..." << std::endl;
    bool matched = colorGrading->matchColor(cam1Ref);
    if (matched) {
        std::cout << "Camera matching calibrated successfully!" << std::endl;
    }

    // Optional: Enable continuous adaptive live tracking
    colorGrading->setReferenceSource(cam1Ref, true);

    // 5. Connect graded output to video preview
    LPreview* preview = new LPreview();
    preview->setProps("ui_framework", "qt");
    preview->previewEnable(nullptr, false, true);
    preview->previewObject(colorGrading);

    // ... run application loop ...

    return 0;
}
      

6. C API Integration (now2sdk_c_api.h)

#include "now2sdk_c_api.h"

void setup_grading(void* cam1_handle, void* cam2_handle) {
    void* color = now2sdk_color_create();
    now2sdk_color_set_source(color, cam2_handle);

    // Manual CCU adjustments
    now2sdk_color_set_red(color, 1.08f);
    now2sdk_color_set_contrast(color, 1.10f);

    // Automated single-shot match to Cam 1
    now2sdk_color_match_color(color, cam1_handle);

    // Or continuous dynamic matching
    now2sdk_color_set_reference_source(color, cam1_handle, 1);
}