Closed bmegli closed 1 year ago
The current code was taken from Photoneo example:
In the example code we can read:
/**
* Utility class providing conversion function for images.
* Provides conversion
* BGR <--> YCoCg 4:2:0,
* where the chromatic channels Co, Cg are subsampled in half resolution.
* The 2x2 plaquette of the YCoCg format consists of:
* (0, 0): Y (10 bits), 1st half of Co (6 bits)
* (1, 0): Y (10 bits), 2nd half of Co (6 bits)
* (0, 1): Y (10 bits), 1st half of Cg (6 bits)
* (1, 1): Y (10 bits), 2nd half of Cg (6 bits)
*
* Black pixels are treated specially in order to prevent artifacts in images containing valid pixels only in a subregion.
*
* NOTE: The YCoCg format used here differs from the reference by:
* - a factor 2 in the both chromatic channels Co, Cg,
* - an offset equal to the saturation value, which is added to Co and Cg to prevent negative values.
*
* @see https://en.wikipedia.org/wiki/YCoCg
// Subsampling of the chromatic channels Co, Cg.
// The subsampling is meant both in horizontal and vertical direction.
static const int chromaSubsampling = 2;
// Pixel depth of B, G, R, and Y channels. Chromatic channels Co and Cg have an additional bit.
static const int pixelDepth = 10;
*/
Examining the code:
YCoCg
It looks as reversible YCoCg-R
Y
Co
, Cg
YCoCg-R was introduced in this Microsoft paper:
The 10 bit depth variant is also described in the VESA standard
"7.7 Color Space Conversion" has algorithm for converting back to RGB
Looking at Photoneo comments
/*
NOTE: The YCoCg format used here differs from the reference by:
* - a factor 2 in the both chromatic channels Co, Cg,
* - an offset equal to the saturation value, which is added to Co and Cg to prevent negative values.
*/
This also looks as YCoCg-R
defined in VESA
"6.1 Color Space Conversion"
Original
Quick and dirty optimization trial
We need to fix the clock or check in performance mode to eliminate variability of test result.
Retesting in performance mode
Systems don't run on maxed clocks so the expected behavior in production is closer to previous tests
That's good enough for now.
In case we need faster processing
One more test
The second one maps directly to VAAPI bgr0 so avoids another color conversion later (not in the scope of this repository)
The time measured here
As identified in:
After enabling internal benchmark: