From 5d9d4659ad25c29b854cf8fd3dace2c79ac40b17 Mon Sep 17 00:00:00 2001 From: Roy Reapor Date: Wed, 3 Oct 2012 23:06:59 -0700 Subject: [PATCH] Fixed issue 2404 - imdecode_() only creates a temporary file when needed. - Use the string's empty() function to flag if the temporary file needs to be deleted. --- modules/highgui/src/loadsave.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/loadsave.cpp b/modules/highgui/src/loadsave.cpp index 3d20c83..0691e15 100644 --- a/modules/highgui/src/loadsave.cpp +++ b/modules/highgui/src/loadsave.cpp @@ -308,8 +308,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) IplImage* image = 0; CvMat *matrix = 0; Mat temp, *data = &temp; - string filename = tempfile(); - bool removeTempFile = false; + string filename; ImageDecoder decoder = findDecoder(buf); if( decoder.empty() ) @@ -317,10 +316,10 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) if( !decoder->setSource(buf) ) { + filename = tempfile(); FILE* f = fopen( filename.c_str(), "wb" ); if( !f ) return 0; - removeTempFile = true; size_t bufSize = buf.cols*buf.rows*buf.elemSize(); fwrite( &buf.data[0], 1, bufSize, f ); fclose(f); @@ -329,7 +328,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) if( !decoder->readHeader() ) { - if( removeTempFile ) + if( !filename.empty() ) remove(filename.c_str()); return 0; } @@ -371,7 +370,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) } bool code = decoder->readData( *data ); - if( removeTempFile ) + if( !filename.empty() ) remove(filename.c_str()); if( !code ) -- 2.7.4