| 4039 | |
| 4040 | |
| 4041 | static void |
| 4042 | icvWriteHeaderData( CvFileStorage* fs, const CvSeq* seq, |
| 4043 | CvAttrList* attr, int initial_header_size ) |
| 4044 | { |
| 4045 | char header_dt_buf[128]; |
| 4046 | const char* header_dt = cvAttrValue( attr, "header_dt" ); |
| 4047 | |
| 4048 | if( header_dt ) |
| 4049 | { |
| 4050 | int dt_header_size; |
| 4051 | dt_header_size = icvCalcElemSize( header_dt, initial_header_size ); |
| 4052 | if( dt_header_size > seq->header_size ) |
| 4053 | CV_Error( CV_StsUnmatchedSizes, |
| 4054 | "The size of header calculated from \"header_dt\" is greater than header_size" ); |
| 4055 | } |
| 4056 | else if( seq->header_size > initial_header_size ) |
| 4057 | { |
| 4058 | if( CV_IS_SEQ(seq) && CV_IS_SEQ_POINT_SET(seq) && |
| 4059 | seq->header_size == sizeof(CvPoint2DSeq) && |
| 4060 | seq->elem_size == sizeof(int)*2 ) |
| 4061 | { |
| 4062 | CvPoint2DSeq* point_seq = (CvPoint2DSeq*)seq; |
| 4063 | |
| 4064 | cvStartWriteStruct( fs, "rect", CV_NODE_MAP + CV_NODE_FLOW ); |
| 4065 | cvWriteInt( fs, "x", point_seq->rect.x ); |
| 4066 | cvWriteInt( fs, "y", point_seq->rect.y ); |
| 4067 | cvWriteInt( fs, "width", point_seq->rect.width ); |
| 4068 | cvWriteInt( fs, "height", point_seq->rect.height ); |
| 4069 | cvEndWriteStruct( fs ); |
| 4070 | cvWriteInt( fs, "color", point_seq->color ); |
| 4071 | } |
| 4072 | else if( CV_IS_SEQ(seq) && CV_IS_SEQ_CHAIN(seq) && |
| 4073 | CV_MAT_TYPE(seq->flags) == CV_8UC1 ) |
| 4074 | { |
| 4075 | CvChain* chain = (CvChain*)seq; |
| 4076 | |
| 4077 | cvStartWriteStruct( fs, "origin", CV_NODE_MAP + CV_NODE_FLOW ); |
| 4078 | cvWriteInt( fs, "x", chain->origin.x ); |
| 4079 | cvWriteInt( fs, "y", chain->origin.y ); |
| 4080 | cvEndWriteStruct( fs ); |
| 4081 | } |
| 4082 | else |
| 4083 | { |
| 4084 | unsigned extra_size = seq->header_size - initial_header_size; |
| 4085 | // a heuristic to provide nice defaults for sequences of int's & float's |
| 4086 | if( extra_size % sizeof(int) == 0 ) |
| 4087 | sprintf( header_dt_buf, "%ui", (unsigned)(extra_size/sizeof(int)) ); |
| 4088 | else |
| 4089 | sprintf( header_dt_buf, "%uu", extra_size ); |
| 4090 | header_dt = header_dt_buf; |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | if( header_dt ) |
| 4095 | { |
| 4096 | cvWriteString( fs, "header_dt", header_dt, 0 ); |
| 4097 | cvStartWriteStruct( fs, "header_user_data", CV_NODE_SEQ + CV_NODE_FLOW ); |
| 4098 | cvWriteRawData( fs, (uchar*)seq + sizeof(CvSeq), 1, header_dt ); |
no test coverage detected