cvpersistence.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 2,051 行 · 第 1/5 页
SVN-BASE
2,051 行
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255 };
static int
icvReadBase64Block( CvFileStorage* storage )
{
int ok = 0;
/*CV_FUNCNAME( "icvReadBase64Block" );*/
__BEGIN__;
uchar* dst = (uchar*)storage->base64_buffer_start;
uchar* limit = (uchar*)storage->base64_buffer_end;
uchar* src = (uchar*)storage->buffer;
int c[4], k = 0;
int len = storage->base64_buffer_read - storage->base64_buffer;
if( len > 0 )
{
// copy remaining bytes to the beginning of the buffer
memmove( storage->base64_buffer_start, storage->base64_buffer, len );
dst += len;
}
while( dst < limit )
{
for( k = 0; k < 4; k++ )
{
c[k] = icvInvBase64Tab[src[0]];
if( c[k] > 63 )
{
while( isspace((char)src[0]))
src++;
c[k] = icvInvBase64Tab[src[0]];
if( c[k] > 63 )
goto loop_end;
}
src++;
}
dst[0] = (uchar)((c[0] << 2)|(c[1] >> 4));
dst[1] = (uchar)((c[1] << 4)|(c[2] >> 2));
dst[2] = (uchar)((c[2] << 6)|c[3]);
dst += 3;
}
loop_end:
switch( k & 3 )
{
case 0:
break;
case 1:
EXIT; // error
case 2:
dst[0] = (uchar)((c[0] << 2)|(c[1] >> 4));
dst++;
break;
case 3:
dst[0] = (uchar)((c[0] << 2)|(c[1] >> 4));
dst[1] = (uchar)((c[1] << 4)|(c[2] >> 2));
dst += 2;
}
storage->base64_buffer = storage->base64_buffer_start;
storage->base64_buffer_read = (char*)dst;
storage->buffer = (char*)src;
ok = 1;
__END__;
return ok;
}
static void
icvPopXMLTag( CvFileStorage* storage )
{
/*CV_FUNCNAME( "icvPopXMLTag" );*/
__BEGIN__;
assert( storage && storage->file && storage->root && storage->parent &&
storage->parent->tagname );
icvWriteBase64Block( storage, 1 );
fprintf( storage->file, "%s</%s>\n",
storage->width == 0 ? "" : "\n",
storage->parent->tagname );
storage->width = 0;
storage->parent = storage->parent->v_prev;
__END__;
}
static void
icvWriteRawData( CvFileStorage* storage, const char* dt, int format,
const void* _data, int count )
{
const char* data = (const char*)_data;
CV_FUNCNAME( "icvWriteRawData" );
__BEGIN__;
int i = 0, k = 0;
int pl = strlen( dt );
if( pl == 0 )
CV_ERROR( CV_StsBadArg, "Empty format specification" );
if( format == ICV_FORMAT_TEXT )
{
if( pl == 1 || (pl == 2 && dt[0] == '1') )
{
switch( dt[pl-1] )
{
case 'u':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file, " %3d%n", ((uchar*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 'c':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file, " %4d%n", ((char*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 's':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file, " %6d%n", ((short*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 'i':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file, " %6d%n", ((int*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 'f':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file," %14.6e%n", ((float*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 'd':
for( i = 0; i < count; i++ )
{
int dl = 0;
fprintf( storage->file," %23.15e%n", ((double*)data)[i], &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
case 'a':
if( count != 1 )
CV_ERROR( CV_StsBadArg, "Only a single string can be written at once" );
{
int dl = 0;
fprintf( storage->file,"%s%n", (char*)data, &dl );
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
break;
default:
CV_ERROR( CV_StsBadArg, "Unknown format specifier" );
}
}
else
{
for( i = 0; i < count; i++ )
{
int n = 0;
char c = '\0';
const char* dtp = dt;
for( ;; )
{
int dl = 0;
if( --n <= 0 )
{
if( !dtp[0] )
break;
n = 1;
if( isdigit(dtp[0]))
{
if( !isdigit(dtp[1]))
{
n = dtp[0] - '0';
dtp++;
}
else
{
if( sscanf( dtp, "%d%n", &n, &dl ) <= 0 )
CV_ERROR(CV_StsBadArg,
"Invalid data type specification");
dtp += dl;
dl = 0;
}
if( n == 0 )
CV_ERROR(CV_StsBadArg,
"Invalid data type specification");
}
c = *dtp++;
}
switch( c )
{
case 'u':
fprintf( storage->file, " %3d%n", *(uchar*)(data+k), &dl );
k++;
break;
case 'c':
fprintf( storage->file, " %4d%n", *(char*)(data+k), &dl );
k++;
break;
case 's':
k = (k + sizeof(short) - 1) & -(int)sizeof(short);
fprintf( storage->file, " %6d%n", *(short*)(data+k), &dl );
k += sizeof(short);
break;
case 'i':
k = (k + sizeof(int) - 1) & -(int)sizeof(int);
fprintf( storage->file, " %6d%n", *(int*)(data+k), &dl );
k += sizeof(int);
break;
case 'f':
k = (k + sizeof(float) - 1) & -(int)sizeof(float);
fprintf( storage->file, " %14.6e%n", *(float*)(data+k), &dl );
k += sizeof(float);
break;
case 'd':
k = (k + sizeof(double) - 1) & -(int)sizeof(double);
fprintf( storage->file, " %23.15e%n", *(double*)(data+k), &dl );
k += sizeof(double);
break;
case 'p':
k = (k + sizeof(void*) - 1) & -(int)sizeof(void*);
k += sizeof(void*);
break;
case 'r':
k = (k + sizeof(void*) - 1) & -(int)sizeof(void*);
fprintf( storage->file, " %6u%n",
(unsigned)(unsigned long)*(void**)(data+k), &dl );
k += sizeof(void*);
break;
default:
CV_ERROR( CV_StsBadArg, "Unknown format specifier" );
}
storage->width += dl;
if( storage->width >= storage->max_width )
{
fprintf( storage->file, "\n" );
storage->width = 0;
}
}
}
}
}
else if( format == ICV_FORMAT_BINARY )
{
char* buffer = storage->base64_buffer;
char* buffer_end = storage->base64_buffer_end;
assert( sizeof(float) == sizeof(int) &&
sizeof(float) == 4 &&
sizeof(double) == 8 );
if( pl == 1 )
{
i = 0;
for( ;; )
{
switch( dt[0] )
{
case 'u':
case 'c':
while( i < count )
{
*buffer++ = ((char*)data)[i++];
if( buffer >= buffer_end )
break;
}
break;
case 's':
while( i < count )
{
int val = ((short*)data)[i++];
buffer[0] = (char)(val >> 8);
buffer[1] = (char)val;
if( (buffer += 2) >= buffer_end )
break;
}
break;
case 'i':
case 'f':
while( i < count )
{
int val = ((int*)data)[i++];
buffer[0] = (char)(val >> 24);
buffer[1] = (char)(val >> 16);
buffer[2] = (char)(val >> 8);
buffer[3] = (char)val;
if( (buffer += 4) >= buffer_end )
break;
}
break;
case 'd':
while( i < count )
{
int hi = (int)(((uint64*)data)[i] >> 32);
int lo = (int)(((uint64*)data)[i++]);
buffer[0] = (char)(hi >> 24);
buffer[1] = (char)(hi >> 16);
buffer[2] = (char)(hi >> 8);
buffer[3] = (char)hi;
buffer[4] = (char)(lo >> 24);
buffer[5] = (char)(lo >> 16);
buffer[6] = (char)(lo >> 8);
buffer[7] = (char)lo;
if( (buffer += 8) >= buffer_end )
break;
}
break;
default:
CV_ERROR( CV_StsBadArg, "Unknown format specifier" );
}
if( buffer >= buffer_end )
{
storage->base64_buffer = buffer;
icvWriteBase64Block( storage, 0 );
buffer = storage->base64_buffer;
}
if( i == count )
break;
}
}
else
{
for( i = 0; i < count; i++ )
{
int n = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?