mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 19:24:07 +08:00
core: fix FileStorage format detection in case of .gz archives
This commit is contained in:
parent
5bc291937f
commit
ec7ce81401
@ -4270,11 +4270,25 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
|
|||||||
|
|
||||||
if( fmt == CV_STORAGE_FORMAT_AUTO && filename )
|
if( fmt == CV_STORAGE_FORMAT_AUTO && filename )
|
||||||
{
|
{
|
||||||
const char* dot_pos = strrchr( filename, '.' );
|
const char* dot_pos = NULL;
|
||||||
|
const char* dot_pos2 = NULL;
|
||||||
|
// like strrchr() implementation, but save two last positions simultaneously
|
||||||
|
for (const char* pos = filename; pos[0] != 0; pos++)
|
||||||
|
{
|
||||||
|
if (pos[0] == '.')
|
||||||
|
{
|
||||||
|
dot_pos2 = dot_pos;
|
||||||
|
dot_pos = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cv_strcasecmp(dot_pos, ".gz") && dot_pos2 != NULL)
|
||||||
|
{
|
||||||
|
dot_pos = dot_pos2;
|
||||||
|
}
|
||||||
fs->fmt
|
fs->fmt
|
||||||
= cv_strcasecmp( dot_pos, ".xml" )
|
= (cv_strcasecmp(dot_pos, ".xml") || cv_strcasecmp(dot_pos, ".xml.gz"))
|
||||||
? CV_STORAGE_FORMAT_XML
|
? CV_STORAGE_FORMAT_XML
|
||||||
: cv_strcasecmp( dot_pos, ".json" )
|
: (cv_strcasecmp(dot_pos, ".json") || cv_strcasecmp(dot_pos, ".json.gz"))
|
||||||
? CV_STORAGE_FORMAT_JSON
|
? CV_STORAGE_FORMAT_JSON
|
||||||
: CV_STORAGE_FORMAT_YAML
|
: CV_STORAGE_FORMAT_YAML
|
||||||
;
|
;
|
||||||
|
Loading…
Reference in New Issue
Block a user