Skip to content

Commit 2a7d0b4

Browse files
committed
fix imdecode
1 parent ba164f6 commit 2a7d0b4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

highgui/src/highgui.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa
177177
return success;
178178
}
179179

180-
Mat imdecode(InputArray buf, int flags)
180+
Mat imdecode(InputArray _buf, int flags)
181181
{
182182
int desired_channels = 0;
183183
if (flags == IMREAD_UNCHANGED)
@@ -198,14 +198,19 @@ Mat imdecode(InputArray buf, int flags)
198198
return Mat();
199199
}
200200

201+
Mat buf = _buf.getMat();
202+
203+
if (!buf.isContinuous())
204+
{
205+
buf = buf.clone();
206+
}
207+
208+
size_t buf_size = buf.cols * buf.rows * buf.elemSize();
209+
201210
int w;
202211
int h;
203212
int c;
204-
#if CV_VERSION_EPOCH == 2
205-
unsigned char* pixeldata = stbi_load_from_memory((const unsigned char*)buf.obj, (int)buf.total(), &w, &h, &c, desired_channels);
206-
#else
207-
unsigned char* pixeldata = stbi_load_from_memory((const unsigned char*)buf.getObj(), (int)buf.total(), &w, &h, &c, desired_channels);
208-
#endif
213+
unsigned char* pixeldata = stbi_load_from_memory((const unsigned char*)buf.data, buf_size, &w, &h, &c, desired_channels);
209214
if (!pixeldata)
210215
{
211216
// load failed

0 commit comments

Comments
 (0)