mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
core(persistence): fix types format handling, fix 16F support
This commit is contained in:
@@ -143,17 +143,17 @@ static const char symbols[9] = "ucwsifdh";
|
||||
static char typeSymbol(int depth)
|
||||
{
|
||||
CV_StaticAssert(CV_64F == 6, "");
|
||||
CV_Assert(depth >=0 && depth <= CV_64F);
|
||||
CV_CheckDepth(depth, depth >=0 && depth <= CV_16F, "");
|
||||
return symbols[depth];
|
||||
}
|
||||
|
||||
static int symbolToType(char c)
|
||||
{
|
||||
if (c == 'r')
|
||||
return CV_SEQ_ELTYPE_PTR;
|
||||
const char* pos = strchr( symbols, c );
|
||||
if( !pos )
|
||||
CV_Error( CV_StsBadArg, "Invalid data type specification" );
|
||||
if (c == 'r')
|
||||
return CV_SEQ_ELTYPE_PTR;
|
||||
return static_cast<int>(pos - symbols);
|
||||
}
|
||||
|
||||
@@ -245,8 +245,12 @@ int calcStructSize( const char* dt, int initial_size )
|
||||
{
|
||||
int size = calcElemSize( dt, initial_size );
|
||||
size_t elem_max_size = 0;
|
||||
for ( const char * type = dt; *type != '\0'; type++ ) {
|
||||
switch ( *type )
|
||||
for ( const char * type = dt; *type != '\0'; type++ )
|
||||
{
|
||||
char v = *type;
|
||||
if (v >= '0' && v <= '9')
|
||||
continue; // skip vector size
|
||||
switch (v)
|
||||
{
|
||||
case 'u': { elem_max_size = std::max( elem_max_size, sizeof(uchar ) ); break; }
|
||||
case 'c': { elem_max_size = std::max( elem_max_size, sizeof(schar ) ); break; }
|
||||
@@ -255,7 +259,9 @@ int calcStructSize( const char* dt, int initial_size )
|
||||
case 'i': { elem_max_size = std::max( elem_max_size, sizeof(int ) ); break; }
|
||||
case 'f': { elem_max_size = std::max( elem_max_size, sizeof(float ) ); break; }
|
||||
case 'd': { elem_max_size = std::max( elem_max_size, sizeof(double) ); break; }
|
||||
default: break;
|
||||
case 'h': { elem_max_size = std::max(elem_max_size, sizeof(float16_t)); break; }
|
||||
default:
|
||||
CV_Error_(Error::StsNotImplemented, ("Unknown type identifier: '%c' in '%s'", (char)(*type), dt));
|
||||
}
|
||||
}
|
||||
size = cvAlign( size, static_cast<int>(elem_max_size) );
|
||||
@@ -1054,6 +1060,7 @@ public:
|
||||
CV_Assert(write_mode);
|
||||
|
||||
size_t elemSize = fs::calcStructSize(dt.c_str(), 0);
|
||||
CV_Assert(elemSize);
|
||||
CV_Assert( len % elemSize == 0 );
|
||||
len /= elemSize;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user