mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #12570 from alalek:drop_usrtype1
* core: drop usage of CV_USRTYPE1 in OpenCV avoid OpenCV crashes due size change CV_ELEM_SIZE(CV_USRTYPE1): 8 -> 2 * ! fix persistence internal types
This commit is contained in:
committed by
GitHub
parent
861415133e
commit
5fb0f34e8a
@@ -388,7 +388,7 @@ cvCreateSeq( int seq_flags, size_t header_size, size_t elem_size, CvMemStorage*
|
||||
int elemtype = CV_MAT_TYPE(seq_flags);
|
||||
int typesize = CV_ELEM_SIZE(elemtype);
|
||||
|
||||
if( elemtype != CV_SEQ_ELTYPE_GENERIC && elemtype != CV_USRTYPE1 &&
|
||||
if( elemtype != CV_SEQ_ELTYPE_GENERIC && elemtype != CV_SEQ_ELTYPE_PTR &&
|
||||
typesize != 0 && typesize != (int)elem_size )
|
||||
CV_Error( CV_StsBadSize,
|
||||
"Specified element size doesn't match to the size of the specified element type "
|
||||
|
||||
@@ -515,11 +515,13 @@ void make_write_struct_delayed( CvFileStorage* fs, const char* key, int struct_f
|
||||
fs->is_write_struct_delayed = true;
|
||||
}
|
||||
|
||||
// FIXIT: conflict with 8UC8 (replacement for CV_USRTYPE1)
|
||||
static const char symbols[9] = "ucwsifdr";
|
||||
|
||||
char icvTypeSymbol(int depth)
|
||||
static char icvTypeSymbol(int depth)
|
||||
{
|
||||
CV_Assert(depth >=0 && depth < 9);
|
||||
CV_StaticAssert(CV_64F == 6, "");
|
||||
CV_Assert(depth >=0 && depth <= CV_64F);
|
||||
return symbols[depth];
|
||||
}
|
||||
|
||||
@@ -528,13 +530,17 @@ static int icvSymbolToType(char c)
|
||||
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);
|
||||
}
|
||||
|
||||
char* icvEncodeFormat( int elem_type, char* dt )
|
||||
char* icvEncodeFormat(int elem_type, char* dt)
|
||||
{
|
||||
sprintf( dt, "%d%c", CV_MAT_CN(elem_type), icvTypeSymbol(CV_MAT_DEPTH(elem_type)) );
|
||||
return dt + ( dt[2] == '\0' && dt[0] == '1' );
|
||||
int cn = (elem_type == CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/) ? 1 : CV_MAT_CN(elem_type);
|
||||
char symbol = (elem_type == CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/) ? 'r' : icvTypeSymbol(CV_MAT_DEPTH(elem_type));
|
||||
sprintf(dt, "%d%c", cn, symbol);
|
||||
return dt + (cn == 1 ? 1 : 0);
|
||||
}
|
||||
|
||||
int icvDecodeFormat( const char* dt, int* fmt_pairs, int max_len )
|
||||
|
||||
@@ -250,7 +250,6 @@ double icv_strtod( CvFileStorage* fs, char* ptr, char** endptr );
|
||||
char* icvFloatToString( char* buf, float value );
|
||||
char* icvDoubleToString( char* buf, double value );
|
||||
|
||||
char icvTypeSymbol(int depth);
|
||||
void icvClose( CvFileStorage* fs, cv::String* out );
|
||||
void icvCloseFile( CvFileStorage* fs );
|
||||
void icvPuts( CvFileStorage* fs, const char* str );
|
||||
|
||||
@@ -978,7 +978,7 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
|
||||
ptr = icvDoubleToString( buf, *(double*)data );
|
||||
data += sizeof(double);
|
||||
break;
|
||||
case CV_USRTYPE1: /* reference */
|
||||
case CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/: /* reference */
|
||||
ptr = icv_itoa( (int)*(size_t*)data, buf, 10 );
|
||||
data += sizeof(size_t);
|
||||
break;
|
||||
@@ -1118,7 +1118,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader,
|
||||
*(double*)data = (double)ival;
|
||||
data += sizeof(double);
|
||||
break;
|
||||
case CV_USRTYPE1: /* reference */
|
||||
case CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/: /* reference */
|
||||
*(size_t*)data = ival;
|
||||
data += sizeof(size_t);
|
||||
break;
|
||||
@@ -1167,7 +1167,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader,
|
||||
*(double*)data = fval;
|
||||
data += sizeof(double);
|
||||
break;
|
||||
case CV_USRTYPE1: /* reference */
|
||||
case CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/: /* reference */
|
||||
ival = cvRound(fval);
|
||||
*(size_t*)data = ival;
|
||||
data += sizeof(size_t);
|
||||
|
||||
@@ -408,8 +408,7 @@ static void icvWriteImage( CvFileStorage* fs, const char* name, const void* stru
|
||||
}
|
||||
|
||||
depth = IPL2CV_DEPTH(image->depth);
|
||||
sprintf( dt_buf, "%d%c", image->nChannels, icvTypeSymbol(depth) );
|
||||
dt = dt_buf + (dt_buf[2] == '\0' && dt_buf[0] == '1');
|
||||
dt = icvEncodeFormat(depth, dt_buf);
|
||||
cvWriteString( fs, "dt", dt, 0 );
|
||||
|
||||
size = cvSize(image->width, image->height);
|
||||
|
||||
Reference in New Issue
Block a user