| 3944 | |
| 3945 | |
| 3946 | static void* |
| 3947 | icvReadImage( CvFileStorage* fs, CvFileNode* node ) |
| 3948 | { |
| 3949 | void* ptr = 0; |
| 3950 | IplImage* image; |
| 3951 | const char* dt; |
| 3952 | CvFileNode* data; |
| 3953 | CvFileNode* roi_node; |
| 3954 | CvSeqReader reader; |
| 3955 | CvRect roi; |
| 3956 | int y, width, height, elem_type, coi, depth; |
| 3957 | const char* origin, *data_order; |
| 3958 | |
| 3959 | width = cvReadIntByName( fs, node, "width", 0 ); |
| 3960 | height = cvReadIntByName( fs, node, "height", 0 ); |
| 3961 | dt = cvReadStringByName( fs, node, "dt", 0 ); |
| 3962 | origin = cvReadStringByName( fs, node, "origin", 0 ); |
| 3963 | |
| 3964 | if( width == 0 || height == 0 || dt == 0 || origin == 0 ) |
| 3965 | CV_Error( CV_StsError, "Some of essential image attributes are absent" ); |
| 3966 | |
| 3967 | elem_type = icvDecodeSimpleFormat( dt ); |
| 3968 | data_order = cvReadStringByName( fs, node, "layout", "interleaved" ); |
| 3969 | if( strcmp( data_order, "interleaved" ) != 0 ) |
| 3970 | CV_Error( CV_StsError, "Only interleaved images can be read" ); |
| 3971 | |
| 3972 | data = cvGetFileNodeByName( fs, node, "data" ); |
| 3973 | if( !data ) |
| 3974 | CV_Error( CV_StsError, "The image data is not found in file storage" ); |
| 3975 | |
| 3976 | if( icvFileNodeSeqLen( data ) != width*height*CV_MAT_CN(elem_type) ) |
| 3977 | CV_Error( CV_StsUnmatchedSizes, |
| 3978 | "The matrix size does not match to the number of stored elements" ); |
| 3979 | |
| 3980 | depth = cvIplDepth(elem_type); |
| 3981 | image = cvCreateImage( cvSize(width,height), depth, CV_MAT_CN(elem_type) ); |
| 3982 | |
| 3983 | roi_node = cvGetFileNodeByName( fs, node, "roi" ); |
| 3984 | if( roi_node ) |
| 3985 | { |
| 3986 | roi.x = cvReadIntByName( fs, roi_node, "x", 0 ); |
| 3987 | roi.y = cvReadIntByName( fs, roi_node, "y", 0 ); |
| 3988 | roi.width = cvReadIntByName( fs, roi_node, "width", 0 ); |
| 3989 | roi.height = cvReadIntByName( fs, roi_node, "height", 0 ); |
| 3990 | coi = cvReadIntByName( fs, roi_node, "coi", 0 ); |
| 3991 | |
| 3992 | cvSetImageROI( image, roi ); |
| 3993 | cvSetImageCOI( image, coi ); |
| 3994 | } |
| 3995 | |
| 3996 | if( width*CV_ELEM_SIZE(elem_type) == image->widthStep ) |
| 3997 | { |
| 3998 | width *= height; |
| 3999 | height = 1; |
| 4000 | } |
| 4001 | |
| 4002 | width *= CV_MAT_CN(elem_type); |
| 4003 | cvStartReadRawData( fs, data, &reader ); |
nothing calls this directly
no test coverage detected