mirror of
https://github.com/opencv/opencv.git
synced 2025-07-31 09:57:28 +08:00
Merge pull request #14989 from alalek:issue_14978
This commit is contained in:
commit
32b6ebb670
@ -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" );
|
||||||
|
Loading…
Reference in New Issue
Block a user