Gentoo Archives: gentoo-commits

From: Amy Liffey <amynka@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: media-libs/opencv/, media-libs/opencv/files/
Date: Fri, 01 Sep 2017 11:39:05
Message-Id: 1504265833.a900af241376ab156509ae9a3832dfeb332d95b7.amynka@gentoo
1 commit: a900af241376ab156509ae9a3832dfeb332d95b7
2 Author: Amy Liffey <amynka <AT> gentoo <DOT> org>
3 AuthorDate: Fri Sep 1 11:34:13 2017 +0000
4 Commit: Amy Liffey <amynka <AT> gentoo <DOT> org>
5 CommitDate: Fri Sep 1 11:37:13 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a900af24
7
8 media-libs/opencv: 2.4.13 add imgcodecs patch bug #627958
9
10 Package-Manager: Portage-2.3.6, Repoman-2.3.1
11
12 .../opencv-2.4.13-imgcodecs-refactoring.patch | 580 +++++++++++++++++++++
13 ...cv-2.4.13-r1.ebuild => opencv-2.4.13-r2.ebuild} | 2 +-
14 2 files changed, 581 insertions(+), 1 deletion(-)
15
16 diff --git a/media-libs/opencv/files/opencv-2.4.13-imgcodecs-refactoring.patch b/media-libs/opencv/files/opencv-2.4.13-imgcodecs-refactoring.patch
17 new file mode 100644
18 index 00000000000..d1bea36580f
19 --- /dev/null
20 +++ b/media-libs/opencv/files/opencv-2.4.13-imgcodecs-refactoring.patch
21 @@ -0,0 +1,580 @@
22 +From 72d29259ca741950527c8cca7fb649030c01f658 Mon Sep 17 00:00:00 2001
23 +From: Alexander Alekhin <alexander.a.alekhin@×××××.com>
24 +Date: Tue, 15 Aug 2017 22:04:55 +0000
25 +Subject: [PATCH] imgcodecs: refactoring, improve code quality
26 +
27 +---
28 + modules/core/include/opencv2/core/core.hpp | 3 +
29 + modules/core/include/opencv2/core/operations.hpp | 3 +
30 + modules/highgui/src/bitstrm.cpp | 2 +
31 + modules/highgui/src/bitstrm.hpp | 19 ++--
32 + modules/highgui/src/grfmt_bmp.cpp | 13 ++-
33 + modules/highgui/src/grfmt_pxm.cpp | 119 +++++++++++++---------
34 + modules/highgui/src/loadsave.cpp | 120 +++++++++++++++++++----
35 + 7 files changed, 207 insertions(+), 72 deletions(-)
36 +
37 +diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp
38 +index 6bb295f5c73..86f4eb182b2 100644
39 +--- a/modules/core/include/opencv2/core/core.hpp
40 ++++ b/modules/core/include/opencv2/core/core.hpp
41 +@@ -3248,6 +3248,9 @@ template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class AutoBuffer
42 + //! returns read-only pointer to the real buffer, stack-allocated or head-allocated
43 + operator const _Tp* () const;
44 +
45 ++ //! returns number of allocated elements
46 ++ size_t getSize() const;
47 ++
48 + protected:
49 + //! pointer to the real buffer, can point to buf if the buffer is small enough
50 + _Tp* ptr;
51 +diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp
52 +index 1b7484aded2..37fd3d97c7a 100644
53 +--- a/modules/core/include/opencv2/core/operations.hpp
54 ++++ b/modules/core/include/opencv2/core/operations.hpp
55 +@@ -2581,6 +2581,9 @@ template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::op
56 + template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
57 + { return ptr; }
58 +
59 ++template<typename _Tp, size_t fixed_size> inline size_t AutoBuffer<_Tp, fixed_size>::getSize() const
60 ++{ return size; }
61 ++
62 +
63 + /////////////////////////////////// Ptr ////////////////////////////////////////
64 +
65 +diff --git a/modules/highgui/src/bitstrm.cpp b/modules/highgui/src/bitstrm.cpp
66 +index dd8bec87cca..67792a27f28 100644
67 +--- a/modules/highgui/src/bitstrm.cpp
68 ++++ b/modules/highgui/src/bitstrm.cpp
69 +@@ -208,6 +208,8 @@ int RLByteStream::getByte()
70 + current = m_current;
71 + }
72 +
73 ++ CV_Assert(current < m_end);
74 ++
75 + val = *((uchar*)current);
76 + m_current = current + 1;
77 + return val;
78 +diff --git a/modules/highgui/src/bitstrm.hpp b/modules/highgui/src/bitstrm.hpp
79 +index 57956beb539..b22987bc911 100644
80 +--- a/modules/highgui/src/bitstrm.hpp
81 ++++ b/modules/highgui/src/bitstrm.hpp
82 +@@ -48,13 +48,20 @@
83 + namespace cv
84 + {
85 +
86 +-enum
87 +-{
88 +- RBS_THROW_EOS=-123, // <end of stream> exception code
89 +- RBS_THROW_FORB=-124, // <forrbidden huffman code> exception code
90 +- RBS_HUFF_FORB=2047, // forrbidden huffman code "value"
91 +- RBS_BAD_HEADER=-125 // invalid header
92 ++#define DECLARE_RBS_EXCEPTION(name) \
93 ++class RBS_ ## name ## _Exception : public cv::Exception \
94 ++{ \
95 ++public: \
96 ++ RBS_ ## name ## _Exception(int code_, const String& err_, const String& func_, const String& file_, int line_) : \
97 ++ cv::Exception(code_, err_, func_, file_, line_) \
98 ++ {} \
99 + };
100 ++DECLARE_RBS_EXCEPTION(THROW_EOS)
101 ++#define RBS_THROW_EOS RBS_THROW_EOS_Exception(CV_StsError, "Unexpected end of input stream", CV_Func, __FILE__, __LINE__)
102 ++DECLARE_RBS_EXCEPTION(THROW_FORB)
103 ++#define RBS_THROW_FORB RBS_THROW_FORB_Exception(CV_StsError, "Forrbidden huffman code", CV_Func, __FILE__, __LINE__)
104 ++DECLARE_RBS_EXCEPTION(BAD_HEADER)
105 ++#define RBS_BAD_HEADER RBS_BAD_HEADER_Exception(CV_StsError, "Invalid header", CV_Func, __FILE__, __LINE__)
106 +
107 + typedef unsigned long ulong;
108 +
109 +diff --git a/modules/highgui/src/grfmt_bmp.cpp b/modules/highgui/src/grfmt_bmp.cpp
110 +index c8f8218cd3b..026b317467d 100644
111 +--- a/modules/highgui/src/grfmt_bmp.cpp
112 ++++ b/modules/highgui/src/grfmt_bmp.cpp
113 +@@ -115,8 +115,9 @@ bool BmpDecoder::readHeader()
114 +
115 + if( m_bpp <= 8 )
116 + {
117 +- memset( m_palette, 0, sizeof(m_palette));
118 +- m_strm.getBytes( m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
119 ++ CV_Assert(clrused < 256);
120 ++ memset(m_palette, 0, sizeof(m_palette));
121 ++ m_strm.getBytes(m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
122 + iscolor = IsColorPalette( m_palette, m_bpp );
123 + }
124 + else if( m_bpp == 16 && m_rle_code == BMP_BITFIELDS )
125 +@@ -282,7 +283,9 @@ bool BmpDecoder::readData( Mat& img )
126 + else if( code > 2 ) // absolute mode
127 + {
128 + if( data + code*nch > line_end ) goto decode_rle4_bad;
129 +- m_strm.getBytes( src, (((code + 1)>>1) + 1) & -2 );
130 ++ int sz = (((code + 1)>>1) + 1) & (~1);
131 ++ CV_Assert((size_t)sz < _src.getSize());
132 ++ m_strm.getBytes(src, sz);
133 + if( color )
134 + data = FillColorRow4( data, src, code, m_palette );
135 + else
136 +@@ -371,7 +374,9 @@ decode_rle4_bad: ;
137 +
138 + if( data + code3 > line_end )
139 + goto decode_rle8_bad;
140 +- m_strm.getBytes( src, (code + 1) & -2 );
141 ++ int sz = (code + 1) & (~1);
142 ++ CV_Assert((size_t)sz < _src.getSize());
143 ++ m_strm.getBytes(src, sz);
144 + if( color )
145 + data = FillColorRow8( data, src, code, m_palette );
146 + else
147 +diff --git a/modules/highgui/src/grfmt_pxm.cpp b/modules/highgui/src/grfmt_pxm.cpp
148 +index f73bbb1bf6b..e609d165966 100644
149 +--- a/modules/highgui/src/grfmt_pxm.cpp
150 ++++ b/modules/highgui/src/grfmt_pxm.cpp
151 +@@ -43,50 +43,58 @@
152 + #include "precomp.hpp"
153 + #include "utils.hpp"
154 + #include "grfmt_pxm.hpp"
155 ++#include <iostream>
156 +
157 + namespace cv
158 + {
159 +
160 + ///////////////////////// P?M reader //////////////////////////////
161 +
162 +-static int ReadNumber( RLByteStream& strm, int maxdigits )
163 ++static int ReadNumber(RLByteStream& strm, int maxdigits = 0)
164 + {
165 + int code;
166 +- int val = 0;
167 ++ int64 val = 0;
168 + int digits = 0;
169 +
170 + code = strm.getByte();
171 +
172 +- if( !isdigit(code))
173 ++ while (!isdigit(code))
174 + {
175 +- do
176 ++ if (code == '#' )
177 + {
178 +- if( code == '#' )
179 ++ do
180 + {
181 +- do
182 +- {
183 +- code = strm.getByte();
184 +- }
185 +- while( code != '\n' && code != '\r' );
186 ++ code = strm.getByte();
187 + }
188 +-
189 ++ while (code != '\n' && code != '\r');
190 + code = strm.getByte();
191 +-
192 +- while( isspace(code))
193 ++ }
194 ++ else if (isspace(code))
195 ++ {
196 ++ while (isspace(code))
197 + code = strm.getByte();
198 + }
199 +- while( !isdigit( code ));
200 ++ else
201 ++ {
202 ++#if 1
203 ++ CV_Error_(CV_StsError, ("PXM: Unexpected code in ReadNumber(): 0x%x (%d)", code, code));
204 ++#else
205 ++ code = strm.getByte();
206 ++#endif
207 ++ }
208 + }
209 +
210 + do
211 + {
212 +- val = val*10 + code - '0';
213 +- if( ++digits >= maxdigits ) break;
214 ++ val = val*10 + (code - '0');
215 ++ CV_Assert(val <= INT_MAX && "PXM: ReadNumber(): result is too large");
216 ++ digits++;
217 ++ if (maxdigits != 0 && digits >= maxdigits) break;
218 + code = strm.getByte();
219 + }
220 +- while( isdigit(code));
221 ++ while (isdigit(code));
222 +
223 +- return val;
224 ++ return (int)val;
225 + }
226 +
227 +
228 +@@ -119,13 +127,13 @@ ImageDecoder PxMDecoder::newDecoder() const
229 + return new PxMDecoder;
230 + }
231 +
232 +-void PxMDecoder::close()
233 ++void PxMDecoder::close()
234 + {
235 + m_strm.close();
236 + }
237 +
238 +
239 +-bool PxMDecoder::readHeader()
240 ++bool PxMDecoder::readHeader()
241 + {
242 + bool result = false;
243 +
244 +@@ -155,10 +163,10 @@ bool PxMDecoder::readHeader()
245 + m_binary = code >= '4';
246 + m_type = m_bpp > 8 ? CV_8UC3 : CV_8UC1;
247 +
248 +- m_width = ReadNumber( m_strm, INT_MAX );
249 +- m_height = ReadNumber( m_strm, INT_MAX );
250 ++ m_width = ReadNumber(m_strm);
251 ++ m_height = ReadNumber(m_strm);
252 +
253 +- m_maxval = m_bpp == 1 ? 1 : ReadNumber( m_strm, INT_MAX );
254 ++ m_maxval = m_bpp == 1 ? 1 : ReadNumber(m_strm);
255 + if( m_maxval > 65535 )
256 + throw RBS_BAD_HEADER;
257 +
258 +@@ -172,8 +180,14 @@ bool PxMDecoder::readHeader()
259 + result = true;
260 + }
261 + }
262 +- catch(...)
263 ++ catch (const cv::Exception&)
264 + {
265 ++ throw;
266 ++ }
267 ++ catch (...)
268 ++ {
269 ++ std::cerr << "PXM::readHeader(): unknown C++ exception" << std::endl << std::flush;
270 ++ throw;
271 + }
272 +
273 + if( !result )
274 +@@ -193,27 +207,23 @@ bool PxMDecoder::readData( Mat& img )
275 + int step = (int)img.step;
276 + PaletteEntry palette[256];
277 + bool result = false;
278 +- int bit_depth = CV_ELEM_SIZE1(m_type)*8;
279 +- int src_pitch = (m_width*m_bpp*bit_depth/8 + 7)/8;
280 ++ const int bit_depth = CV_ELEM_SIZE1(m_type)*8;
281 ++ const int src_pitch = (m_width*m_bpp*(bit_depth/8) + 7) / 8;
282 ++
283 + int nch = CV_MAT_CN(m_type);
284 + int width3 = m_width*nch;
285 +- int i, x, y;
286 +
287 + if( m_offset < 0 || !m_strm.isOpened())
288 + return false;
289 +
290 +- AutoBuffer<uchar,1024> _src(src_pitch + 32);
291 +- uchar* src = _src;
292 +- AutoBuffer<uchar,1024> _gray_palette;
293 +- uchar* gray_palette = _gray_palette;
294 ++ uchar gray_palette[256] = {0};
295 +
296 + // create LUT for converting colors
297 + if( bit_depth == 8 )
298 + {
299 +- _gray_palette.allocate(m_maxval + 1);
300 +- gray_palette = _gray_palette;
301 ++ CV_Assert(m_maxval < 256);
302 +
303 +- for( i = 0; i <= m_maxval; i++ )
304 ++ for (int i = 0; i <= m_maxval; i++)
305 + gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
306 +
307 + FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 );
308 +@@ -227,12 +237,16 @@ bool PxMDecoder::readData( Mat& img )
309 + {
310 + ////////////////////////// 1 BPP /////////////////////////
311 + case 1:
312 ++ CV_Assert(CV_MAT_DEPTH(m_type) == CV_8U);
313 + if( !m_binary )
314 + {
315 +- for( y = 0; y < m_height; y++, data += step )
316 ++ AutoBuffer<uchar> _src(m_width);
317 ++ uchar* src = _src;
318 ++
319 ++ for (int y = 0; y < m_height; y++, data += step)
320 + {
321 +- for( x = 0; x < m_width; x++ )
322 +- src[x] = ReadNumber( m_strm, 1 ) != 0;
323 ++ for (int x = 0; x < m_width; x++)
324 ++ src[x] = ReadNumber(m_strm, 1) != 0;
325 +
326 + if( color )
327 + FillColorRow8( data, src, m_width, palette );
328 +@@ -242,7 +256,10 @@ bool PxMDecoder::readData( Mat& img )
329 + }
330 + else
331 + {
332 +- for( y = 0; y < m_height; y++, data += step )
333 ++ AutoBuffer<uchar> _src(src_pitch);
334 ++ uchar* src = _src;
335 ++
336 ++ for (int y = 0; y < m_height; y++, data += step)
337 + {
338 + m_strm.getBytes( src, src_pitch );
339 +
340 +@@ -258,11 +275,15 @@ bool PxMDecoder::readData( Mat& img )
341 + ////////////////////////// 8 BPP /////////////////////////
342 + case 8:
343 + case 24:
344 +- for( y = 0; y < m_height; y++, data += step )
345 ++ {
346 ++ AutoBuffer<uchar> _src(std::max<size_t>(width3*2, src_pitch));
347 ++ uchar* src = _src;
348 ++
349 ++ for (int y = 0; y < m_height; y++, data += step)
350 + {
351 + if( !m_binary )
352 + {
353 +- for( x = 0; x < width3; x++ )
354 ++ for (int x = 0; x < width3; x++)
355 + {
356 + int code = ReadNumber( m_strm, INT_MAX );
357 + if( (unsigned)code > (unsigned)m_maxval ) code = m_maxval;
358 +@@ -277,7 +298,7 @@ bool PxMDecoder::readData( Mat& img )
359 + m_strm.getBytes( src, src_pitch );
360 + if( bit_depth == 16 && !isBigEndian() )
361 + {
362 +- for( x = 0; x < width3; x++ )
363 ++ for (int x = 0; x < width3; x++)
364 + {
365 + uchar v = src[x * 2];
366 + src[x * 2] = src[x * 2 + 1];
367 +@@ -288,7 +309,7 @@ bool PxMDecoder::readData( Mat& img )
368 +
369 + if( img.depth() == CV_8U && bit_depth == 16 )
370 + {
371 +- for( x = 0; x < width3; x++ )
372 ++ for (int x = 0; x < width3; x++)
373 + {
374 + int v = ((ushort *)src)[x];
375 + src[x] = (uchar)(v >> 8);
376 +@@ -329,12 +350,19 @@ bool PxMDecoder::readData( Mat& img )
377 + }
378 + result = true;
379 + break;
380 ++ }
381 + default:
382 +- assert(0);
383 ++ CV_Error(CV_StsError, "m_bpp is not supported");
384 + }
385 + }
386 +- catch(...)
387 ++ catch (const cv::Exception&)
388 ++ {
389 ++ throw;
390 ++ }
391 ++ catch (...)
392 + {
393 ++ std::cerr << "PXM::readData(): unknown exception" << std::endl << std::flush;
394 ++ throw;
395 + }
396 +
397 + return result;
398 +@@ -410,8 +438,9 @@ bool PxMEncoder::write( const Mat& img, const vector<int>& params )
399 + char* buffer = _buffer;
400 +
401 + // write header;
402 +- sprintf( buffer, "P%c\n%d %d\n%d\n",
403 ++ sprintf( buffer, "P%c\n# Generated by OpenCV %s\n%d %d\n%d\n",
404 + '2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0),
405 ++ CV_VERSION,
406 + width, height, (1 << depth) - 1 );
407 +
408 + strm.putBytes( buffer, (int)strlen(buffer) );
409 +diff --git a/modules/highgui/src/loadsave.cpp b/modules/highgui/src/loadsave.cpp
410 +index 81c708acdd4..9b270c900f7 100644
411 +--- a/modules/highgui/src/loadsave.cpp
412 ++++ b/modules/highgui/src/loadsave.cpp
413 +@@ -48,12 +48,32 @@
414 + #undef min
415 + #undef max
416 +
417 ++#include <iostream>
418 ++
419 + /****************************************************************************************\
420 + * Image Codecs *
421 + \****************************************************************************************/
422 + namespace cv
423 + {
424 +
425 ++// TODO Add runtime configuration
426 ++#define CV_IO_MAX_IMAGE_PARAMS (50)
427 ++#define CV_IO_MAX_IMAGE_WIDTH (1<<20)
428 ++#define CV_IO_MAX_IMAGE_HEIGHT (1<<20)
429 ++#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel
430 ++
431 ++static Size validateInputImageSize(const Size& size)
432 ++{
433 ++ CV_Assert(size.width > 0);
434 ++ CV_Assert(size.width <= CV_IO_MAX_IMAGE_WIDTH);
435 ++ CV_Assert(size.height > 0);
436 ++ CV_Assert(size.height <= CV_IO_MAX_IMAGE_HEIGHT);
437 ++ uint64 pixels = (uint64)size.width * (uint64)size.height;
438 ++ CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
439 ++ return size;
440 ++}
441 ++
442 ++
443 + struct ImageCodecInitializer
444 + {
445 + ImageCodecInitializer()
446 +@@ -203,12 +223,26 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
447 + if( decoder.empty() )
448 + return 0;
449 + decoder->setSource(filename);
450 +- if( !decoder->readHeader() )
451 ++
452 ++ try
453 ++ {
454 ++ // read the header to make sure it succeeds
455 ++ if (!decoder->readHeader())
456 ++ return 0;
457 ++ }
458 ++ catch (const cv::Exception& e)
459 ++ {
460 ++ std::cerr << "imread_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
461 + return 0;
462 ++ }
463 ++ catch (...)
464 ++ {
465 ++ std::cerr << "imread_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
466 ++ return 0;
467 ++ }
468 +
469 +- CvSize size;
470 +- size.width = decoder->width();
471 +- size.height = decoder->height();
472 ++
473 ++ Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
474 +
475 + int type = decoder->type();
476 + if( flags != -1 )
477 +@@ -242,7 +276,21 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
478 + temp = cvarrToMat(image);
479 + }
480 +
481 +- if( !decoder->readData( *data ))
482 ++ bool success = false;
483 ++ try
484 ++ {
485 ++ if (decoder->readData(*data))
486 ++ success = true;
487 ++ }
488 ++ catch (const cv::Exception& e)
489 ++ {
490 ++ std::cerr << "imread_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
491 ++ }
492 ++ catch (...)
493 ++ {
494 ++ std::cerr << "imread_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
495 ++ }
496 ++ if (!success)
497 + {
498 + cvReleaseImage( &image );
499 + cvReleaseMat( &matrix );
500 +@@ -288,6 +336,7 @@ static bool imwrite_( const string& filename, const Mat& image,
501 + }
502 +
503 + encoder->setDestination( filename );
504 ++ CV_Assert(params.size() <= CV_IO_MAX_IMAGE_PARAMS*2);
505 + bool code = encoder->write( *pimage, params );
506 +
507 + // CV_Assert( code );
508 +@@ -326,16 +375,34 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
509 + decoder->setSource(filename);
510 + }
511 +
512 +- if( !decoder->readHeader() )
513 ++ bool success = false;
514 ++ try
515 + {
516 +- if( !filename.empty() )
517 +- remove(filename.c_str());
518 ++ if (decoder->readHeader())
519 ++ success = true;
520 ++ }
521 ++ catch (const cv::Exception& e)
522 ++ {
523 ++ std::cerr << "imdecode_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
524 ++ }
525 ++ catch (...)
526 ++ {
527 ++ std::cerr << "imdecode_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
528 ++ }
529 ++ if (!success)
530 ++ {
531 ++ if (!filename.empty())
532 ++ {
533 ++ if (0 != remove(filename.c_str()))
534 ++ {
535 ++ std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
536 ++ }
537 ++ }
538 + return 0;
539 + }
540 +
541 +- CvSize size;
542 +- size.width = decoder->width();
543 +- size.height = decoder->height();
544 ++ // established the required input image size
545 ++ Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
546 +
547 + int type = decoder->type();
548 + if( flags != -1 )
549 +@@ -369,11 +436,30 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
550 + temp = cvarrToMat(image);
551 + }
552 +
553 +- bool code = decoder->readData( *data );
554 +- if( !filename.empty() )
555 +- remove(filename.c_str());
556 ++ success = false;
557 ++ try
558 ++ {
559 ++ if (decoder->readData(*data))
560 ++ success = true;
561 ++ }
562 ++ catch (const cv::Exception& e)
563 ++ {
564 ++ std::cerr << "imdecode_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
565 ++ }
566 ++ catch (...)
567 ++ {
568 ++ std::cerr << "imdecode_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
569 ++ }
570 +
571 +- if( !code )
572 ++ if (!filename.empty())
573 ++ {
574 ++ if (0 != remove(filename.c_str()))
575 ++ {
576 ++ std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
577 ++ }
578 ++ }
579 ++
580 ++ if (!success)
581 + {
582 + cvReleaseImage( &image );
583 + cvReleaseMat( &matrix );
584 +@@ -490,7 +576,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
585 + if( _params )
586 + {
587 + for( ; _params[i] > 0; i += 2 )
588 +- ;
589 ++ CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
590 + }
591 + return cv::imwrite_(filename, cv::cvarrToMat(arr),
592 + i > 0 ? cv::vector<int>(_params, _params+i) : cv::vector<int>(),
593 +@@ -521,7 +607,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
594 + if( _params )
595 + {
596 + for( ; _params[i] > 0; i += 2 )
597 +- ;
598 ++ CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
599 + }
600 + cv::Mat img = cv::cvarrToMat(arr);
601 + if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
602
603 diff --git a/media-libs/opencv/opencv-2.4.13-r1.ebuild b/media-libs/opencv/opencv-2.4.13-r2.ebuild
604 similarity index 99%
605 rename from media-libs/opencv/opencv-2.4.13-r1.ebuild
606 rename to media-libs/opencv/opencv-2.4.13-r2.ebuild
607 index b57b2652493..4158e701ea4 100644
608 --- a/media-libs/opencv/opencv-2.4.13-r1.ebuild
609 +++ b/media-libs/opencv/opencv-2.4.13-r2.ebuild
610 @@ -87,8 +87,8 @@ PATCHES=(
611 "${FILESDIR}/${PN}-2.4.9-cuda-pkg-config.patch"
612 "${FILESDIR}/${PN}-3.0.0-gles.patch"
613 "${FILESDIR}/${P}-gcc-6.0.patch"
614 + "${FILESDIR}/${P}-imgcodecs-refactoring.patch" #bug 627958
615 )
616 -#"${FILESDIR}/${P}-git-autodetect.patch
617
618 pkg_setup() {
619 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp