@@ -1963,6 +1963,10 @@ __kernel void BGR2Luv(__global const uchar * srcptr, int src_step, int src_offse
1963
1963
1964
1964
float R = src [0 ], G = src [1 ], B = src [2 ];
1965
1965
1966
+ R = clamp (R , 0.f , 1.f );
1967
+ G = clamp (G , 0.f , 1.f );
1968
+ B = clamp (B , 0.f , 1.f );
1969
+
1966
1970
#ifdef SRGB
1967
1971
R = splineInterpolate (R * GammaTabScale , gammaTab , GAMMA_TAB_SIZE );
1968
1972
G = splineInterpolate (G * GammaTabScale , gammaTab , GAMMA_TAB_SIZE );
@@ -2067,15 +2071,21 @@ __kernel void Luv2BGR(__global const uchar * srcptr, int src_step, int src_offse
2067
2071
__global const float * src = (__global const float * )(srcptr + src_index );
2068
2072
__global float * dst = (__global float * )(dstptr + dst_index );
2069
2073
2070
- float L = src [0 ], u = src [1 ], v = src [2 ], d , X , Y , Z ;
2071
- Y = (L + 16.f ) * (1.f /116.f );
2072
- Y = Y * Y * Y ;
2073
- d = (1.f /13.f )/L ;
2074
- u = fma (u , d , _un );
2075
- v = fma (v , d , _vn );
2076
- float iv = 1.f /v ;
2077
- X = 2.25f * u * Y * iv ;
2078
- Z = (12 - fma (3.0f , u , 20.0f * v )) * Y * 0.25f * iv ;
2074
+ float L = src [0 ], u = src [1 ], v = src [2 ], X , Y , Z ;
2075
+ if (L >= 8 )
2076
+ {
2077
+ Y = fma (L , 1.f /116.f , 16.f /116.f );
2078
+ Y = Y * Y * Y ;
2079
+ }
2080
+ else
2081
+ {
2082
+ Y = L * (1.0f /903.3f ); // L*(3./29.)^3
2083
+ }
2084
+ float up = 3.f * fma (L , _un , u );
2085
+ float vp = 0.25f /fma (L , _vn , v );
2086
+ vp = clamp (vp , -0.25f , 0.25f );
2087
+ X = 3.f * Y * up * vp ;
2088
+ Z = Y * fma (fma (12.f * 13.f , L , - up ), vp , -5.f );
2079
2089
2080
2090
float R = fma (X , coeffs [0 ], fma (Y , coeffs [1 ], Z * coeffs [2 ]));
2081
2091
float G = fma (X , coeffs [3 ], fma (Y , coeffs [4 ], Z * coeffs [5 ]));
@@ -2129,14 +2139,20 @@ __kernel void Luv2BGR(__global const uchar * src, int src_step, int src_offset,
2129
2139
float L = src [0 ]* (100.f /255.f );
2130
2140
float u = fma (convert_float (src [1 ]), 1.388235294117647f , -134.f );
2131
2141
float v = fma (convert_float (src [2 ]), 1.027450980392157f , - 140.f );
2132
- Y = (L + 16.f ) * (1.f /116.f );
2133
- Y = Y * Y * Y ;
2134
- d = (1.f /13.f )/L ;
2135
- u = fma (u , d , _un );
2136
- v = fma (v , d , _vn );
2137
- float iv = 1.f /v ;
2138
- X = 2.25f * u * Y * iv ;
2139
- Z = (12 - fma (3.0f , u , 20.0f * v )) * Y * 0.25f * iv ;
2142
+ if (L >= 8 )
2143
+ {
2144
+ Y = fma (L , 1.f /116.f , 16.f /116.f );
2145
+ Y = Y * Y * Y ;
2146
+ }
2147
+ else
2148
+ {
2149
+ Y = L * (1.0f /903.3f ); // L*(3./29.)^3
2150
+ }
2151
+ float up = 3.f * fma (L , _un , u );
2152
+ float vp = 0.25f /fma (L , _vn , v );
2153
+ vp = clamp (vp , -0.25f , 0.25f );
2154
+ X = 3.f * Y * up * vp ;
2155
+ Z = Y * fma (fma (12.f * 13.f , L , - up ), vp , -5.f );
2140
2156
2141
2157
float R = fma (X , coeffs [0 ], fma (Y , coeffs [1 ], Z * coeffs [2 ]));
2142
2158
float G = fma (X , coeffs [3 ], fma (Y , coeffs [4 ], Z * coeffs [5 ]));
0 commit comments