MCPcopy Create free account
hub / github.com/creatale/node-dv / cvScalarToRawData

Function cvScalarToRawData

deps/opencv/modules/core/src/array.cpp:1449–1519  ·  view source on GitHub ↗

Converts CvScalar to specified type

Source from the content-addressed store, hash-verified

1447
1448// Converts CvScalar to specified type
1449CV_IMPL void
1450cvScalarToRawData( const CvScalar* scalar, void* data, int type, int extend_to_12 )
1451{
1452 type = CV_MAT_TYPE(type);
1453 int cn = CV_MAT_CN( type );
1454 int depth = type & CV_MAT_DEPTH_MASK;
1455
1456 assert( scalar && data );
1457 if( (unsigned)(cn - 1) >= 4 )
1458 CV_Error( CV_StsOutOfRange, "The number of channels must be 1, 2, 3 or 4" );
1459
1460 switch( depth )
1461 {
1462 case CV_8UC1:
1463 while( cn-- )
1464 {
1465 int t = cvRound( scalar->val[cn] );
1466 ((uchar*)data)[cn] = CV_CAST_8U(t);
1467 }
1468 break;
1469 case CV_8SC1:
1470 while( cn-- )
1471 {
1472 int t = cvRound( scalar->val[cn] );
1473 ((char*)data)[cn] = CV_CAST_8S(t);
1474 }
1475 break;
1476 case CV_16UC1:
1477 while( cn-- )
1478 {
1479 int t = cvRound( scalar->val[cn] );
1480 ((ushort*)data)[cn] = CV_CAST_16U(t);
1481 }
1482 break;
1483 case CV_16SC1:
1484 while( cn-- )
1485 {
1486 int t = cvRound( scalar->val[cn] );
1487 ((short*)data)[cn] = CV_CAST_16S(t);
1488 }
1489 break;
1490 case CV_32SC1:
1491 while( cn-- )
1492 ((int*)data)[cn] = cvRound( scalar->val[cn] );
1493 break;
1494 case CV_32FC1:
1495 while( cn-- )
1496 ((float*)data)[cn] = (float)(scalar->val[cn]);
1497 break;
1498 case CV_64FC1:
1499 while( cn-- )
1500 ((double*)data)[cn] = (double)(scalar->val[cn]);
1501 break;
1502 default:
1503 assert(0);
1504 CV_Error( CV_BadDepth, "" );
1505 }
1506

Callers 5

cvSet1DFunction · 0.85
cvSet2DFunction · 0.85
cvSet3DFunction · 0.85
cvSetNDFunction · 0.85
cvFloodFillFunction · 0.85

Calls 1

cvRoundFunction · 0.85

Tested by

no test coverage detected