Skip to content

Commit f5dff87

Browse files
committed
CV_ColorCvtBaseTest: added methods for 8u implementations
1 parent f0ef7bd commit f5dff87

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

modules/imgproc/test/test_color.cpp

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ class CV_ColorCvtBaseTest : public cvtest::ArrayTest
6868
// called from default implementation of convert_backward
6969
virtual void convert_row_abc2bgr_32f_c3( const float* src_row, float* dst_row, int n );
7070

71+
// called from default implementation of convert_backward
72+
// for cases of bit-exact functions
73+
virtual int convert_row_abc2bgr_8u_c3( const uchar* src_row, uchar* dst_row, int n );
74+
75+
// called from default implementation of convert_forward
76+
// for cases of bit-exact functions
77+
virtual int convert_row_bgr2abc_8u_c3(const uchar *src_row, uchar *dst_row, int n );
78+
7179
const char* fwd_code_str;
7280
const char* inv_code_str;
7381

@@ -226,19 +234,23 @@ void CV_ColorCvtBaseTest::convert_forward( const Mat& src, Mat& dst )
226234
const uchar* src_row = src.ptr(i);
227235
uchar* dst_row = dst.ptr(i);
228236

229-
for( j = 0; j < cols; j++ )
237+
int processed = convert_row_bgr2abc_8u_c3( src_row, dst_row, cols );
238+
if(processed != cols)
230239
{
231-
src_buf[j*3] = src_row[j*cn + blue_idx]*c8u;
232-
src_buf[j*3+1] = src_row[j*cn + 1]*c8u;
233-
src_buf[j*3+2] = src_row[j*cn + (blue_idx^2)]*c8u;
234-
}
240+
for( j = 0; j < cols; j++ )
241+
{
242+
src_buf[j*3] = src_row[j*cn + blue_idx]*c8u;
243+
src_buf[j*3+1] = src_row[j*cn + 1]*c8u;
244+
src_buf[j*3+2] = src_row[j*cn + (blue_idx^2)]*c8u;
245+
}
235246

236-
convert_row_bgr2abc_32f_c3( src_buf, dst_buf, cols );
247+
convert_row_bgr2abc_32f_c3( src_buf, dst_buf, cols );
237248

238-
for( j = 0; j < dst_cols_n; j++ )
239-
{
240-
int t = cvRound( dst_buf[j] );
241-
dst_row[j] = saturate_cast<uchar>(t);
249+
for( j = 0; j < dst_cols_n; j++ )
250+
{
251+
int t = cvRound( dst_buf[j] );
252+
dst_row[j] = saturate_cast<uchar>(t);
253+
}
242254
}
243255
}
244256
break;
@@ -297,6 +309,19 @@ void CV_ColorCvtBaseTest::convert_row_abc2bgr_32f_c3( const float* /*src_row*/,
297309
}
298310

299311

312+
int CV_ColorCvtBaseTest::convert_row_abc2bgr_8u_c3(const uchar * /*src_row*/,
313+
uchar * /*dst_row*/, int /*n*/ )
314+
{
315+
return 0;
316+
}
317+
318+
319+
int CV_ColorCvtBaseTest::convert_row_bgr2abc_8u_c3( const uchar* /*src_row*/,
320+
uchar* /*dst_row*/, int /*n*/ )
321+
{
322+
return 0;
323+
}
324+
300325
void CV_ColorCvtBaseTest::convert_backward( const Mat& src, const Mat& dst, Mat& dst2 )
301326
{
302327
if( custom_inv_transform )
@@ -321,21 +346,26 @@ void CV_ColorCvtBaseTest::convert_backward( const Mat& src, const Mat& dst, Mat&
321346
const uchar* src_row = dst.ptr(i);
322347
uchar* dst_row = dst2.ptr(i);
323348

324-
for( j = 0; j < cols_n; j++ )
325-
src_buf[j] = src_row[j];
349+
int processed = convert_row_abc2bgr_8u_c3(src_row, dst_row, dst_cols);
326350

327-
convert_row_abc2bgr_32f_c3( src_buf, dst_buf, dst_cols );
328-
329-
for( j = 0; j < dst_cols; j++ )
351+
if(processed != dst_cols)
330352
{
331-
int b = cvRound( dst_buf[j*3]*255. );
332-
int g = cvRound( dst_buf[j*3+1]*255. );
333-
int r = cvRound( dst_buf[j*3+2]*255. );
334-
dst_row[j*cn + blue_idx] = saturate_cast<uchar>(b);
335-
dst_row[j*cn + 1] = saturate_cast<uchar>(g);
336-
dst_row[j*cn + (blue_idx^2)] = saturate_cast<uchar>(r);
337-
if( cn == 4 )
338-
dst_row[j*cn + 3] = 255;
353+
for( j = 0; j < cols_n; j++ )
354+
src_buf[j] = src_row[j];
355+
356+
convert_row_abc2bgr_32f_c3( src_buf, dst_buf, dst_cols );
357+
358+
for( j = 0; j < dst_cols; j++ )
359+
{
360+
int b = cvRound( dst_buf[j*3]*255. );
361+
int g = cvRound( dst_buf[j*3+1]*255. );
362+
int r = cvRound( dst_buf[j*3+2]*255. );
363+
dst_row[j*cn + blue_idx] = saturate_cast<uchar>(b);
364+
dst_row[j*cn + 1] = saturate_cast<uchar>(g);
365+
dst_row[j*cn + (blue_idx^2)] = saturate_cast<uchar>(r);
366+
if( cn == 4 )
367+
dst_row[j*cn + 3] = 255;
368+
}
339369
}
340370
}
341371
break;

0 commit comments

Comments
 (0)