@@ -68,6 +68,14 @@ class CV_ColorCvtBaseTest : public cvtest::ArrayTest
68
68
// called from default implementation of convert_backward
69
69
virtual void convert_row_abc2bgr_32f_c3 ( const float * src_row, float * dst_row, int n );
70
70
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
+
71
79
const char * fwd_code_str;
72
80
const char * inv_code_str;
73
81
@@ -226,19 +234,23 @@ void CV_ColorCvtBaseTest::convert_forward( const Mat& src, Mat& dst )
226
234
const uchar* src_row = src.ptr (i);
227
235
uchar* dst_row = dst.ptr (i);
228
236
229
- for ( j = 0 ; j < cols; j++ )
237
+ int processed = convert_row_bgr2abc_8u_c3 ( src_row, dst_row, cols );
238
+ if (processed != cols)
230
239
{
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
+ }
235
246
236
- convert_row_bgr2abc_32f_c3 ( src_buf, dst_buf, cols );
247
+ convert_row_bgr2abc_32f_c3 ( src_buf, dst_buf, cols );
237
248
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
+ }
242
254
}
243
255
}
244
256
break ;
@@ -297,6 +309,19 @@ void CV_ColorCvtBaseTest::convert_row_abc2bgr_32f_c3( const float* /*src_row*/,
297
309
}
298
310
299
311
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
+
300
325
void CV_ColorCvtBaseTest::convert_backward ( const Mat& src, const Mat& dst, Mat& dst2 )
301
326
{
302
327
if ( custom_inv_transform )
@@ -321,21 +346,26 @@ void CV_ColorCvtBaseTest::convert_backward( const Mat& src, const Mat& dst, Mat&
321
346
const uchar* src_row = dst.ptr (i);
322
347
uchar* dst_row = dst2.ptr (i);
323
348
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);
326
350
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)
330
352
{
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
+ }
339
369
}
340
370
}
341
371
break ;
0 commit comments