Commit 32b6ebb6 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #14989 from alalek:issue_14978

parents 1e9e2aa9 eedbd1ad
...@@ -748,24 +748,28 @@ bool imwrite( const String& filename, InputArray _img, ...@@ -748,24 +748,28 @@ bool imwrite( const String& filename, InputArray _img,
static void* static void*
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
{ {
CV_Assert(!buf.empty() && buf.isContinuous()); CV_Assert(!buf.empty());
CV_Assert(buf.isContinuous());
CV_Assert(buf.checkVector(1, CV_8U) > 0);
Mat buf_row = buf.reshape(1, 1); // decoders expects single row, avoid issues with vector columns
IplImage* image = 0; IplImage* image = 0;
CvMat *matrix = 0; CvMat *matrix = 0;
Mat temp, *data = &temp; Mat temp, *data = &temp;
String filename; String filename;
ImageDecoder decoder = findDecoder(buf); ImageDecoder decoder = findDecoder(buf_row);
if( !decoder ) if( !decoder )
return 0; return 0;
if( !decoder->setSource(buf) ) if( !decoder->setSource(buf_row) )
{ {
filename = tempfile(); filename = tempfile();
FILE* f = fopen( filename.c_str(), "wb" ); FILE* f = fopen( filename.c_str(), "wb" );
if( !f ) if( !f )
return 0; return 0;
size_t bufSize = buf.cols*buf.rows*buf.elemSize(); size_t bufSize = buf_row.total()*buf.elemSize();
if( fwrite( buf.ptr(), 1, bufSize, f ) != bufSize ) if (fwrite(buf_row.ptr(), 1, bufSize, f) != bufSize)
{ {
fclose( f ); fclose( f );
CV_Error( CV_StsError, "failed to write image data to temporary file" ); CV_Error( CV_StsError, "failed to write image data to temporary file" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment