Merge pull request #34 from roynos/master

This commit is contained in:
Andrey Kamaev 2012-10-11 16:30:47 +04:00
commit f41ab3a330
2 changed files with 6 additions and 5 deletions

View File

@ -487,6 +487,8 @@ string tempfile( const char* suffix )
if(0 == ::GetTempFileNameA(temp_dir, "ocv", 0, temp_file)) if(0 == ::GetTempFileNameA(temp_dir, "ocv", 0, temp_file))
return string(); return string();
DeleteFileA(temp_file);
string name = temp_file; string name = temp_file;
if(suffix) if(suffix)
{ {

View File

@ -308,8 +308,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
IplImage* image = 0; IplImage* image = 0;
CvMat *matrix = 0; CvMat *matrix = 0;
Mat temp, *data = &temp; Mat temp, *data = &temp;
string filename = tempfile(); string filename;
bool removeTempFile = false;
ImageDecoder decoder = findDecoder(buf); ImageDecoder decoder = findDecoder(buf);
if( decoder.empty() ) if( decoder.empty() )
@ -317,10 +316,10 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if( !decoder->setSource(buf) ) if( !decoder->setSource(buf) )
{ {
filename = tempfile();
FILE* f = fopen( filename.c_str(), "wb" ); FILE* f = fopen( filename.c_str(), "wb" );
if( !f ) if( !f )
return 0; return 0;
removeTempFile = true;
size_t bufSize = buf.cols*buf.rows*buf.elemSize(); size_t bufSize = buf.cols*buf.rows*buf.elemSize();
fwrite( &buf.data[0], 1, bufSize, f ); fwrite( &buf.data[0], 1, bufSize, f );
fclose(f); fclose(f);
@ -329,7 +328,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if( !decoder->readHeader() ) if( !decoder->readHeader() )
{ {
if( removeTempFile ) if( !filename.empty() )
remove(filename.c_str()); remove(filename.c_str());
return 0; return 0;
} }
@ -371,7 +370,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
} }
bool code = decoder->readData( *data ); bool code = decoder->readData( *data );
if( removeTempFile ) if( !filename.empty() )
remove(filename.c_str()); remove(filename.c_str());
if( !code ) if( !code )