summaryrefslogtreecommitdiff
path: root/media-libs/opencv/files
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
committerV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
commit4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch)
treeba5f07bf3f9d22d82e54a462313f5d244036c768 /media-libs/opencv/files
reinit the tree, so we can have metadata
Diffstat (limited to 'media-libs/opencv/files')
-rw-r--r--media-libs/opencv/files/opencv-2.3.1a-libav-0.7.patch10
-rw-r--r--media-libs/opencv/files/opencv-2.4.13-gcc-6.0.patch23
-rw-r--r--media-libs/opencv/files/opencv-2.4.13-imgcodecs-refactoring.patch580
-rw-r--r--media-libs/opencv/files/opencv-2.4.2-cflags.patch21
-rw-r--r--media-libs/opencv/files/opencv-2.4.3-gcc47.patch22
-rw-r--r--media-libs/opencv/files/opencv-2.4.8-javamagic.patch32
-rw-r--r--media-libs/opencv/files/opencv-2.4.9-cuda-pkg-config.patch12
-rw-r--r--media-libs/opencv/files/opencv-3.0.0-gles.patch14
-rw-r--r--media-libs/opencv/files/opencv-3.1.0-cmake-no-opengl.patch22
-rw-r--r--media-libs/opencv/files/opencv-3.1.0-find-libraries-fix.patch48
-rw-r--r--media-libs/opencv/files/opencv-3.1.0-git-autodetect.patch42
-rw-r--r--media-libs/opencv/files/opencv-3.1.0-java-magic.patch47
-rw-r--r--media-libs/opencv/files/opencv-3.1.0-remove-graphcut-for-cuda-8.patch23
-rw-r--r--media-libs/opencv/files/opencv-3.2.0-contrib_xfeatures2d-autodownload.patch10
-rw-r--r--media-libs/opencv/files/opencv-3.2.0-cpu-mno-sse2.patch11
-rw-r--r--media-libs/opencv/files/opencv-3.2.0-fix_ussage_cpu_instructions.patch64
-rw-r--r--media-libs/opencv/files/opencv-3.2.0-gcc-6.0.patch11
-rw-r--r--media-libs/opencv/files/opencv-3.2.0-vtk.patch11
-rw-r--r--media-libs/opencv/files/opencv-3.3.0-contrib-xfeatures2d.patch19
19 files changed, 1022 insertions, 0 deletions
diff --git a/media-libs/opencv/files/opencv-2.3.1a-libav-0.7.patch b/media-libs/opencv/files/opencv-2.3.1a-libav-0.7.patch
new file mode 100644
index 000000000000..59090703d149
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.3.1a-libav-0.7.patch
@@ -0,0 +1,10 @@
+--- OpenCV-2.3.1.orig/modules/highgui/src/cap_ffmpeg_impl.hpp 2011-11-14 05:33:37.000000000 +0100
++++ OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp 2011-11-14 05:33:18.000000000 +0100
+@@ -104,6 +104,7 @@
+ #endif
+ #if defined(HAVE_LIBAVCODEC_AVCODEC_H)
+ #include <libavcodec/avcodec.h>
++ #include <libavutil/mathematics.h>
+ #endif
+ #if defined(HAVE_LIBSWSCALE_SWSCALE_H)
+ #include <libswscale/swscale.h>
diff --git a/media-libs/opencv/files/opencv-2.4.13-gcc-6.0.patch b/media-libs/opencv/files/opencv-2.4.13-gcc-6.0.patch
new file mode 100644
index 000000000000..b0a5084752ca
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.13-gcc-6.0.patch
@@ -0,0 +1,23 @@
+From fb598bb76a0431aa3a880ecfa45054c996a070fb Mon Sep 17 00:00:00 2001
+From: Maksim Shabunin <maksim.shabunin@itseez.com>
+Date: Fri, 13 May 2016 13:28:09 +0300
+Subject: [PATCH] Disabled PCH support for gcc >= 6.0.0
+
+Command line generation routine uses "-isystem" to include headers outside of "<opencv>/modules" folder, but GCC 6 does not work when passed "-isystem /usr/include" option.
+---
+ cmake/OpenCVPCHSupport.cmake | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake
+index 13619daf27e..e6585cae020 100644
+--- a/cmake/OpenCVPCHSupport.cmake
++++ b/cmake/OpenCVPCHSupport.cmake
+@@ -19,7 +19,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
+ ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
+ OUTPUT_VARIABLE gcc_compiler_version)
+ #MESSAGE("GCC Version: ${gcc_compiler_version}")
+- IF(gcc_compiler_version VERSION_GREATER "4.2.-1")
++ IF(gcc_compiler_version VERSION_GREATER "4.2.-1" AND gcc_compiler_version VERSION_LESS "6.0.0")
+ SET(PCHSupport_FOUND TRUE)
+ ENDIF()
+
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
new file mode 100644
index 000000000000..d1bea36580fe
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.13-imgcodecs-refactoring.patch
@@ -0,0 +1,580 @@
+From 72d29259ca741950527c8cca7fb649030c01f658 Mon Sep 17 00:00:00 2001
+From: Alexander Alekhin <alexander.a.alekhin@gmail.com>
+Date: Tue, 15 Aug 2017 22:04:55 +0000
+Subject: [PATCH] imgcodecs: refactoring, improve code quality
+
+---
+ modules/core/include/opencv2/core/core.hpp | 3 +
+ modules/core/include/opencv2/core/operations.hpp | 3 +
+ modules/highgui/src/bitstrm.cpp | 2 +
+ modules/highgui/src/bitstrm.hpp | 19 ++--
+ modules/highgui/src/grfmt_bmp.cpp | 13 ++-
+ modules/highgui/src/grfmt_pxm.cpp | 119 +++++++++++++---------
+ modules/highgui/src/loadsave.cpp | 120 +++++++++++++++++++----
+ 7 files changed, 207 insertions(+), 72 deletions(-)
+
+diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp
+index 6bb295f5c73..86f4eb182b2 100644
+--- a/modules/core/include/opencv2/core/core.hpp
++++ b/modules/core/include/opencv2/core/core.hpp
+@@ -3248,6 +3248,9 @@ template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class AutoBuffer
+ //! returns read-only pointer to the real buffer, stack-allocated or head-allocated
+ operator const _Tp* () const;
+
++ //! returns number of allocated elements
++ size_t getSize() const;
++
+ protected:
+ //! pointer to the real buffer, can point to buf if the buffer is small enough
+ _Tp* ptr;
+diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp
+index 1b7484aded2..37fd3d97c7a 100644
+--- a/modules/core/include/opencv2/core/operations.hpp
++++ b/modules/core/include/opencv2/core/operations.hpp
+@@ -2581,6 +2581,9 @@ template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::op
+ template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
+ { return ptr; }
+
++template<typename _Tp, size_t fixed_size> inline size_t AutoBuffer<_Tp, fixed_size>::getSize() const
++{ return size; }
++
+
+ /////////////////////////////////// Ptr ////////////////////////////////////////
+
+diff --git a/modules/highgui/src/bitstrm.cpp b/modules/highgui/src/bitstrm.cpp
+index dd8bec87cca..67792a27f28 100644
+--- a/modules/highgui/src/bitstrm.cpp
++++ b/modules/highgui/src/bitstrm.cpp
+@@ -208,6 +208,8 @@ int RLByteStream::getByte()
+ current = m_current;
+ }
+
++ CV_Assert(current < m_end);
++
+ val = *((uchar*)current);
+ m_current = current + 1;
+ return val;
+diff --git a/modules/highgui/src/bitstrm.hpp b/modules/highgui/src/bitstrm.hpp
+index 57956beb539..b22987bc911 100644
+--- a/modules/highgui/src/bitstrm.hpp
++++ b/modules/highgui/src/bitstrm.hpp
+@@ -48,13 +48,20 @@
+ namespace cv
+ {
+
+-enum
+-{
+- RBS_THROW_EOS=-123, // <end of stream> exception code
+- RBS_THROW_FORB=-124, // <forrbidden huffman code> exception code
+- RBS_HUFF_FORB=2047, // forrbidden huffman code "value"
+- RBS_BAD_HEADER=-125 // invalid header
++#define DECLARE_RBS_EXCEPTION(name) \
++class RBS_ ## name ## _Exception : public cv::Exception \
++{ \
++public: \
++ RBS_ ## name ## _Exception(int code_, const String& err_, const String& func_, const String& file_, int line_) : \
++ cv::Exception(code_, err_, func_, file_, line_) \
++ {} \
+ };
++DECLARE_RBS_EXCEPTION(THROW_EOS)
++#define RBS_THROW_EOS RBS_THROW_EOS_Exception(CV_StsError, "Unexpected end of input stream", CV_Func, __FILE__, __LINE__)
++DECLARE_RBS_EXCEPTION(THROW_FORB)
++#define RBS_THROW_FORB RBS_THROW_FORB_Exception(CV_StsError, "Forrbidden huffman code", CV_Func, __FILE__, __LINE__)
++DECLARE_RBS_EXCEPTION(BAD_HEADER)
++#define RBS_BAD_HEADER RBS_BAD_HEADER_Exception(CV_StsError, "Invalid header", CV_Func, __FILE__, __LINE__)
+
+ typedef unsigned long ulong;
+
+diff --git a/modules/highgui/src/grfmt_bmp.cpp b/modules/highgui/src/grfmt_bmp.cpp
+index c8f8218cd3b..026b317467d 100644
+--- a/modules/highgui/src/grfmt_bmp.cpp
++++ b/modules/highgui/src/grfmt_bmp.cpp
+@@ -115,8 +115,9 @@ bool BmpDecoder::readHeader()
+
+ if( m_bpp <= 8 )
+ {
+- memset( m_palette, 0, sizeof(m_palette));
+- m_strm.getBytes( m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
++ CV_Assert(clrused < 256);
++ memset(m_palette, 0, sizeof(m_palette));
++ m_strm.getBytes(m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
+ iscolor = IsColorPalette( m_palette, m_bpp );
+ }
+ else if( m_bpp == 16 && m_rle_code == BMP_BITFIELDS )
+@@ -282,7 +283,9 @@ bool BmpDecoder::readData( Mat& img )
+ else if( code > 2 ) // absolute mode
+ {
+ if( data + code*nch > line_end ) goto decode_rle4_bad;
+- m_strm.getBytes( src, (((code + 1)>>1) + 1) & -2 );
++ int sz = (((code + 1)>>1) + 1) & (~1);
++ CV_Assert((size_t)sz < _src.getSize());
++ m_strm.getBytes(src, sz);
+ if( color )
+ data = FillColorRow4( data, src, code, m_palette );
+ else
+@@ -371,7 +374,9 @@ decode_rle4_bad: ;
+
+ if( data + code3 > line_end )
+ goto decode_rle8_bad;
+- m_strm.getBytes( src, (code + 1) & -2 );
++ int sz = (code + 1) & (~1);
++ CV_Assert((size_t)sz < _src.getSize());
++ m_strm.getBytes(src, sz);
+ if( color )
+ data = FillColorRow8( data, src, code, m_palette );
+ else
+diff --git a/modules/highgui/src/grfmt_pxm.cpp b/modules/highgui/src/grfmt_pxm.cpp
+index f73bbb1bf6b..e609d165966 100644
+--- a/modules/highgui/src/grfmt_pxm.cpp
++++ b/modules/highgui/src/grfmt_pxm.cpp
+@@ -43,50 +43,58 @@
+ #include "precomp.hpp"
+ #include "utils.hpp"
+ #include "grfmt_pxm.hpp"
++#include <iostream>
+
+ namespace cv
+ {
+
+ ///////////////////////// P?M reader //////////////////////////////
+
+-static int ReadNumber( RLByteStream& strm, int maxdigits )
++static int ReadNumber(RLByteStream& strm, int maxdigits = 0)
+ {
+ int code;
+- int val = 0;
++ int64 val = 0;
+ int digits = 0;
+
+ code = strm.getByte();
+
+- if( !isdigit(code))
++ while (!isdigit(code))
+ {
+- do
++ if (code == '#' )
+ {
+- if( code == '#' )
++ do
+ {
+- do
+- {
+- code = strm.getByte();
+- }
+- while( code != '\n' && code != '\r' );
++ code = strm.getByte();
+ }
+-
++ while (code != '\n' && code != '\r');
+ code = strm.getByte();
+-
+- while( isspace(code))
++ }
++ else if (isspace(code))
++ {
++ while (isspace(code))
+ code = strm.getByte();
+ }
+- while( !isdigit( code ));
++ else
++ {
++#if 1
++ CV_Error_(CV_StsError, ("PXM: Unexpected code in ReadNumber(): 0x%x (%d)", code, code));
++#else
++ code = strm.getByte();
++#endif
++ }
+ }
+
+ do
+ {
+- val = val*10 + code - '0';
+- if( ++digits >= maxdigits ) break;
++ val = val*10 + (code - '0');
++ CV_Assert(val <= INT_MAX && "PXM: ReadNumber(): result is too large");
++ digits++;
++ if (maxdigits != 0 && digits >= maxdigits) break;
+ code = strm.getByte();
+ }
+- while( isdigit(code));
++ while (isdigit(code));
+
+- return val;
++ return (int)val;
+ }
+
+
+@@ -119,13 +127,13 @@ ImageDecoder PxMDecoder::newDecoder() const
+ return new PxMDecoder;
+ }
+
+-void PxMDecoder::close()
++void PxMDecoder::close()
+ {
+ m_strm.close();
+ }
+
+
+-bool PxMDecoder::readHeader()
++bool PxMDecoder::readHeader()
+ {
+ bool result = false;
+
+@@ -155,10 +163,10 @@ bool PxMDecoder::readHeader()
+ m_binary = code >= '4';
+ m_type = m_bpp > 8 ? CV_8UC3 : CV_8UC1;
+
+- m_width = ReadNumber( m_strm, INT_MAX );
+- m_height = ReadNumber( m_strm, INT_MAX );
++ m_width = ReadNumber(m_strm);
++ m_height = ReadNumber(m_strm);
+
+- m_maxval = m_bpp == 1 ? 1 : ReadNumber( m_strm, INT_MAX );
++ m_maxval = m_bpp == 1 ? 1 : ReadNumber(m_strm);
+ if( m_maxval > 65535 )
+ throw RBS_BAD_HEADER;
+
+@@ -172,8 +180,14 @@ bool PxMDecoder::readHeader()
+ result = true;
+ }
+ }
+- catch(...)
++ catch (const cv::Exception&)
+ {
++ throw;
++ }
++ catch (...)
++ {
++ std::cerr << "PXM::readHeader(): unknown C++ exception" << std::endl << std::flush;
++ throw;
+ }
+
+ if( !result )
+@@ -193,27 +207,23 @@ bool PxMDecoder::readData( Mat& img )
+ int step = (int)img.step;
+ PaletteEntry palette[256];
+ bool result = false;
+- int bit_depth = CV_ELEM_SIZE1(m_type)*8;
+- int src_pitch = (m_width*m_bpp*bit_depth/8 + 7)/8;
++ const int bit_depth = CV_ELEM_SIZE1(m_type)*8;
++ const int src_pitch = (m_width*m_bpp*(bit_depth/8) + 7) / 8;
++
+ int nch = CV_MAT_CN(m_type);
+ int width3 = m_width*nch;
+- int i, x, y;
+
+ if( m_offset < 0 || !m_strm.isOpened())
+ return false;
+
+- AutoBuffer<uchar,1024> _src(src_pitch + 32);
+- uchar* src = _src;
+- AutoBuffer<uchar,1024> _gray_palette;
+- uchar* gray_palette = _gray_palette;
++ uchar gray_palette[256] = {0};
+
+ // create LUT for converting colors
+ if( bit_depth == 8 )
+ {
+- _gray_palette.allocate(m_maxval + 1);
+- gray_palette = _gray_palette;
++ CV_Assert(m_maxval < 256);
+
+- for( i = 0; i <= m_maxval; i++ )
++ for (int i = 0; i <= m_maxval; i++)
+ gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
+
+ FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 );
+@@ -227,12 +237,16 @@ bool PxMDecoder::readData( Mat& img )
+ {
+ ////////////////////////// 1 BPP /////////////////////////
+ case 1:
++ CV_Assert(CV_MAT_DEPTH(m_type) == CV_8U);
+ if( !m_binary )
+ {
+- for( y = 0; y < m_height; y++, data += step )
++ AutoBuffer<uchar> _src(m_width);
++ uchar* src = _src;
++
++ for (int y = 0; y < m_height; y++, data += step)
+ {
+- for( x = 0; x < m_width; x++ )
+- src[x] = ReadNumber( m_strm, 1 ) != 0;
++ for (int x = 0; x < m_width; x++)
++ src[x] = ReadNumber(m_strm, 1) != 0;
+
+ if( color )
+ FillColorRow8( data, src, m_width, palette );
+@@ -242,7 +256,10 @@ bool PxMDecoder::readData( Mat& img )
+ }
+ else
+ {
+- for( y = 0; y < m_height; y++, data += step )
++ AutoBuffer<uchar> _src(src_pitch);
++ uchar* src = _src;
++
++ for (int y = 0; y < m_height; y++, data += step)
+ {
+ m_strm.getBytes( src, src_pitch );
+
+@@ -258,11 +275,15 @@ bool PxMDecoder::readData( Mat& img )
+ ////////////////////////// 8 BPP /////////////////////////
+ case 8:
+ case 24:
+- for( y = 0; y < m_height; y++, data += step )
++ {
++ AutoBuffer<uchar> _src(std::max<size_t>(width3*2, src_pitch));
++ uchar* src = _src;
++
++ for (int y = 0; y < m_height; y++, data += step)
+ {
+ if( !m_binary )
+ {
+- for( x = 0; x < width3; x++ )
++ for (int x = 0; x < width3; x++)
+ {
+ int code = ReadNumber( m_strm, INT_MAX );
+ if( (unsigned)code > (unsigned)m_maxval ) code = m_maxval;
+@@ -277,7 +298,7 @@ bool PxMDecoder::readData( Mat& img )
+ m_strm.getBytes( src, src_pitch );
+ if( bit_depth == 16 && !isBigEndian() )
+ {
+- for( x = 0; x < width3; x++ )
++ for (int x = 0; x < width3; x++)
+ {
+ uchar v = src[x * 2];
+ src[x * 2] = src[x * 2 + 1];
+@@ -288,7 +309,7 @@ bool PxMDecoder::readData( Mat& img )
+
+ if( img.depth() == CV_8U && bit_depth == 16 )
+ {
+- for( x = 0; x < width3; x++ )
++ for (int x = 0; x < width3; x++)
+ {
+ int v = ((ushort *)src)[x];
+ src[x] = (uchar)(v >> 8);
+@@ -329,12 +350,19 @@ bool PxMDecoder::readData( Mat& img )
+ }
+ result = true;
+ break;
++ }
+ default:
+- assert(0);
++ CV_Error(CV_StsError, "m_bpp is not supported");
+ }
+ }
+- catch(...)
++ catch (const cv::Exception&)
++ {
++ throw;
++ }
++ catch (...)
+ {
++ std::cerr << "PXM::readData(): unknown exception" << std::endl << std::flush;
++ throw;
+ }
+
+ return result;
+@@ -410,8 +438,9 @@ bool PxMEncoder::write( const Mat& img, const vector<int>& params )
+ char* buffer = _buffer;
+
+ // write header;
+- sprintf( buffer, "P%c\n%d %d\n%d\n",
++ sprintf( buffer, "P%c\n# Generated by OpenCV %s\n%d %d\n%d\n",
+ '2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0),
++ CV_VERSION,
+ width, height, (1 << depth) - 1 );
+
+ strm.putBytes( buffer, (int)strlen(buffer) );
+diff --git a/modules/highgui/src/loadsave.cpp b/modules/highgui/src/loadsave.cpp
+index 81c708acdd4..9b270c900f7 100644
+--- a/modules/highgui/src/loadsave.cpp
++++ b/modules/highgui/src/loadsave.cpp
+@@ -48,12 +48,32 @@
+ #undef min
+ #undef max
+
++#include <iostream>
++
+ /****************************************************************************************\
+ * Image Codecs *
+ \****************************************************************************************/
+ namespace cv
+ {
+
++// TODO Add runtime configuration
++#define CV_IO_MAX_IMAGE_PARAMS (50)
++#define CV_IO_MAX_IMAGE_WIDTH (1<<20)
++#define CV_IO_MAX_IMAGE_HEIGHT (1<<20)
++#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel
++
++static Size validateInputImageSize(const Size& size)
++{
++ CV_Assert(size.width > 0);
++ CV_Assert(size.width <= CV_IO_MAX_IMAGE_WIDTH);
++ CV_Assert(size.height > 0);
++ CV_Assert(size.height <= CV_IO_MAX_IMAGE_HEIGHT);
++ uint64 pixels = (uint64)size.width * (uint64)size.height;
++ CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
++ return size;
++}
++
++
+ struct ImageCodecInitializer
+ {
+ ImageCodecInitializer()
+@@ -203,12 +223,26 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
+ if( decoder.empty() )
+ return 0;
+ decoder->setSource(filename);
+- if( !decoder->readHeader() )
++
++ try
++ {
++ // read the header to make sure it succeeds
++ if (!decoder->readHeader())
++ return 0;
++ }
++ catch (const cv::Exception& e)
++ {
++ std::cerr << "imread_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
+ return 0;
++ }
++ catch (...)
++ {
++ std::cerr << "imread_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
++ return 0;
++ }
+
+- CvSize size;
+- size.width = decoder->width();
+- size.height = decoder->height();
++
++ Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
+
+ int type = decoder->type();
+ if( flags != -1 )
+@@ -242,7 +276,21 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
+ temp = cvarrToMat(image);
+ }
+
+- if( !decoder->readData( *data ))
++ bool success = false;
++ try
++ {
++ if (decoder->readData(*data))
++ success = true;
++ }
++ catch (const cv::Exception& e)
++ {
++ std::cerr << "imread_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
++ }
++ catch (...)
++ {
++ std::cerr << "imread_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
++ }
++ if (!success)
+ {
+ cvReleaseImage( &image );
+ cvReleaseMat( &matrix );
+@@ -288,6 +336,7 @@ static bool imwrite_( const string& filename, const Mat& image,
+ }
+
+ encoder->setDestination( filename );
++ CV_Assert(params.size() <= CV_IO_MAX_IMAGE_PARAMS*2);
+ bool code = encoder->write( *pimage, params );
+
+ // CV_Assert( code );
+@@ -326,16 +375,34 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
+ decoder->setSource(filename);
+ }
+
+- if( !decoder->readHeader() )
++ bool success = false;
++ try
+ {
+- if( !filename.empty() )
+- remove(filename.c_str());
++ if (decoder->readHeader())
++ success = true;
++ }
++ catch (const cv::Exception& e)
++ {
++ std::cerr << "imdecode_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
++ }
++ catch (...)
++ {
++ std::cerr << "imdecode_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
++ }
++ if (!success)
++ {
++ if (!filename.empty())
++ {
++ if (0 != remove(filename.c_str()))
++ {
++ std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
++ }
++ }
+ return 0;
+ }
+
+- CvSize size;
+- size.width = decoder->width();
+- size.height = decoder->height();
++ // established the required input image size
++ Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
+
+ int type = decoder->type();
+ if( flags != -1 )
+@@ -369,11 +436,30 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
+ temp = cvarrToMat(image);
+ }
+
+- bool code = decoder->readData( *data );
+- if( !filename.empty() )
+- remove(filename.c_str());
++ success = false;
++ try
++ {
++ if (decoder->readData(*data))
++ success = true;
++ }
++ catch (const cv::Exception& e)
++ {
++ std::cerr << "imdecode_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
++ }
++ catch (...)
++ {
++ std::cerr << "imdecode_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
++ }
+
+- if( !code )
++ if (!filename.empty())
++ {
++ if (0 != remove(filename.c_str()))
++ {
++ std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
++ }
++ }
++
++ if (!success)
+ {
+ cvReleaseImage( &image );
+ cvReleaseMat( &matrix );
+@@ -490,7 +576,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
+ if( _params )
+ {
+ for( ; _params[i] > 0; i += 2 )
+- ;
++ CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
+ }
+ return cv::imwrite_(filename, cv::cvarrToMat(arr),
+ i > 0 ? cv::vector<int>(_params, _params+i) : cv::vector<int>(),
+@@ -521,7 +607,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
+ if( _params )
+ {
+ for( ; _params[i] > 0; i += 2 )
+- ;
++ CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
+ }
+ cv::Mat img = cv::cvarrToMat(arr);
+ if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
diff --git a/media-libs/opencv/files/opencv-2.4.2-cflags.patch b/media-libs/opencv/files/opencv-2.4.2-cflags.patch
new file mode 100644
index 000000000000..d52e6b6a39f4
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.2-cflags.patch
@@ -0,0 +1,21 @@
+diff -ruN OpenCV-2.4.2.orig/cmake/OpenCVCompilerOptions.cmake OpenCV-2.4.2/cmake/OpenCVCompilerOptions.cmake
+--- OpenCV-2.4.2.orig/cmake/OpenCVCompilerOptions.cmake 2012-06-29 00:55:15.000000000 +0200
++++ OpenCV-2.4.2/cmake/OpenCVCompilerOptions.cmake 2012-07-16 23:51:24.244907235 +0200
+@@ -110,17 +110,6 @@
+ endif()
+
+ # Other optimizations
+- if(ENABLE_OMIT_FRAME_POINTER)
+- add_extra_compiler_option(-fomit-frame-pointer)
+- else()
+- add_extra_compiler_option(-fno-omit-frame-pointer)
+- endif()
+- if(ENABLE_FAST_MATH)
+- add_extra_compiler_option(-ffast-math)
+- endif()
+- if(ENABLE_POWERPC)
+- add_extra_compiler_option("-mcpu=G3 -mtune=G5")
+- endif()
+ if(ENABLE_SSE)
+ add_extra_compiler_option(-msse)
+ endif()
diff --git a/media-libs/opencv/files/opencv-2.4.3-gcc47.patch b/media-libs/opencv/files/opencv-2.4.3-gcc47.patch
new file mode 100644
index 000000000000..13ac8f8fb58f
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.3-gcc47.patch
@@ -0,0 +1,22 @@
+diff -ruN OpenCV-2.4.3.orig/modules/highgui/src/grfmt_tiff.cpp OpenCV-2.4.3/modules/highgui/src/grfmt_tiff.cpp
+--- OpenCV-2.4.3.orig/modules/highgui/src/grfmt_tiff.cpp 2012-10-12 00:55:12.000000000 +0200
++++ OpenCV-2.4.3/modules/highgui/src/grfmt_tiff.cpp 2012-11-05 21:37:40.000000000 +0100
+@@ -47,6 +47,7 @@
+
+ #include "precomp.hpp"
+ #include "grfmt_tiff.hpp"
++#include "unistd.h"
+
+ namespace cv
+ {
+diff -ruN OpenCV-2.4.3.orig/modules/highgui/src/window_QT.h OpenCV-2.4.3/modules/highgui/src/window_QT.h
+--- OpenCV-2.4.3.orig/modules/highgui/src/window_QT.h 2012-10-18 00:55:38.000000000 +0200
++++ OpenCV-2.4.3/modules/highgui/src/window_QT.h 2012-11-05 21:38:41.000000000 +0100
+@@ -41,6 +41,7 @@
+ #define __OPENCV_HIGHGUI_QT_H__
+
+ #include "precomp.hpp"
++#include "unistd.h"
+
+ #if defined( HAVE_QT_OPENGL )
+ #include <QtOpenGL>
diff --git a/media-libs/opencv/files/opencv-2.4.8-javamagic.patch b/media-libs/opencv/files/opencv-2.4.8-javamagic.patch
new file mode 100644
index 000000000000..766abc1e0941
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.8-javamagic.patch
@@ -0,0 +1,32 @@
+diff -ruN opencv-2.4.8.orig/CMakeLists.txt opencv-2.4.8/CMakeLists.txt
+--- opencv-2.4.8.orig/CMakeLists.txt 2013-12-27 18:09:18.000000000 +0100
++++ opencv-2.4.8/CMakeLists.txt 2014-01-24 22:06:12.000000000 +0100
+@@ -164,6 +164,7 @@
+ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS) )
+ OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
+ OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 )
++OCV_OPTION(WITH_JAVA "Include Java support" ON)
+
+ # OpenCV build components
+ # ===================================================
+@@ -449,6 +450,8 @@
+ include(cmake/OpenCVDetectPython.cmake)
+
+ # --- Java Support ---
++if(WITH_JAVA)
++
+ include(cmake/OpenCVDetectApacheAnt.cmake)
+ if(ANDROID)
+ include(cmake/OpenCVDetectAndroidSDK.cmake)
+@@ -466,6 +469,11 @@
+ SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
+ endif()
+
++else()
++ SET(ANT_EXECUTABLE "")
++ SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
++endif()
++
+ # --- OpenCL ---
+ if(WITH_OPENCL)
+ include(cmake/OpenCVDetectOpenCL.cmake)
diff --git a/media-libs/opencv/files/opencv-2.4.9-cuda-pkg-config.patch b/media-libs/opencv/files/opencv-2.4.9-cuda-pkg-config.patch
new file mode 100644
index 000000000000..d7ff3c7eaf67
--- /dev/null
+++ b/media-libs/opencv/files/opencv-2.4.9-cuda-pkg-config.patch
@@ -0,0 +1,12 @@
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -528,6 +528,9 @@
+ if(HAVE_CUFFT)
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY})
+ endif()
++ foreach(p ${CUDA_LIBS_PATH})
++ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} -L${p})
++ endforeach()
+ endif()
+
+ # ----------------------------------------------------------------------------
diff --git a/media-libs/opencv/files/opencv-3.0.0-gles.patch b/media-libs/opencv/files/opencv-3.0.0-gles.patch
new file mode 100644
index 000000000000..a2629d928e82
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.0.0-gles.patch
@@ -0,0 +1,14 @@
+Index: opencv-2.4.11/modules/highgui/src/window_QT.cpp
+===================================================================
+--- opencv-2.4.11.orig/modules/highgui/src/window_QT.cpp
++++ opencv-2.4.11/modules/highgui/src/window_QT.cpp
+@@ -3118,7 +3118,9 @@ void OpenGlViewPort::updateGl()
+
+ void OpenGlViewPort::initializeGL()
+ {
++#ifdef GL_PERSPECTIVE_CORRECTION_HINT
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
++#endif
+ }
+
+ void OpenGlViewPort::resizeGL(int w, int h)
diff --git a/media-libs/opencv/files/opencv-3.1.0-cmake-no-opengl.patch b/media-libs/opencv/files/opencv-3.1.0-cmake-no-opengl.patch
new file mode 100644
index 000000000000..d6d70d717d3b
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.1.0-cmake-no-opengl.patch
@@ -0,0 +1,22 @@
+From cdb9c60dcb65e04e7c0bd6bef9b86841191c785a Mon Sep 17 00:00:00 2001
+From: Alexander Alekhin <alexander.alekhin@itseez.com>
+Date: Thu, 31 Dec 2015 02:24:54 +0300
+Subject: [PATCH] gpu samples: fix REMOVE_ITEM error
+
+---
+ samples/gpu/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt
+index 6085cac..852a8c2 100644
+--- a/samples/gpu/CMakeLists.txt
++++ b/samples/gpu/CMakeLists.txt
+@@ -97,7 +97,7 @@ endif()
+ if(INSTALL_C_EXAMPLES AND NOT WIN32)
+ file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
+ if(NOT WITH_OPENGL)
+- list(REMOVE_ITEM all_samples "opengl.cpp")
++ list(REMOVE_ITEM install_list "opengl.cpp")
+ endif(NOT WITH_OPENGL)
+ install(FILES ${install_list}
+ DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu
diff --git a/media-libs/opencv/files/opencv-3.1.0-find-libraries-fix.patch b/media-libs/opencv/files/opencv-3.1.0-find-libraries-fix.patch
new file mode 100644
index 000000000000..52f4db6b3113
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.1.0-find-libraries-fix.patch
@@ -0,0 +1,48 @@
+diff -purN a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake
+--- a/cmake/OpenCVFindLibsGrfmt.cmake 2015-12-18 15:02:16.000000000 +0000
++++ b/cmake/OpenCVFindLibsGrfmt.cmake 2016-11-07 13:18:04.567340791 +0000
+@@ -18,7 +18,7 @@ endif()
+ if(NOT ZLIB_FOUND)
+ ocv_clear_vars(ZLIB_LIBRARY ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS)
+
+- set(ZLIB_LIBRARY zlib)
++ set(ZLIB_LIBRARY z)
+ add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/zlib")
+ set(ZLIB_INCLUDE_DIRS "${${ZLIB_LIBRARY}_SOURCE_DIR}" "${${ZLIB_LIBRARY}_BINARY_DIR}")
+ set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+@@ -40,7 +40,7 @@ if(WITH_TIFF)
+ if(NOT TIFF_FOUND)
+ ocv_clear_vars(TIFF_LIBRARY TIFF_LIBRARIES TIFF_INCLUDE_DIR)
+
+- set(TIFF_LIBRARY libtiff)
++ set(TIFF_LIBRARY tiff)
+ set(TIFF_LIBRARIES ${TIFF_LIBRARY})
+ add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libtiff")
+ set(TIFF_INCLUDE_DIR "${${TIFF_LIBRARY}_SOURCE_DIR}" "${${TIFF_LIBRARY}_BINARY_DIR}")
+@@ -79,7 +79,7 @@ if(WITH_JPEG)
+ if(NOT JPEG_FOUND)
+ ocv_clear_vars(JPEG_LIBRARY JPEG_LIBRARIES JPEG_INCLUDE_DIR)
+
+- set(JPEG_LIBRARY libjpeg)
++ set(JPEG_LIBRARY jpeg)
+ set(JPEG_LIBRARIES ${JPEG_LIBRARY})
+ add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libjpeg")
+ set(JPEG_INCLUDE_DIR "${${JPEG_LIBRARY}_SOURCE_DIR}")
+@@ -136,7 +136,7 @@ if(WITH_JASPER)
+ if(NOT JASPER_FOUND)
+ ocv_clear_vars(JASPER_LIBRARY JASPER_LIBRARIES JASPER_INCLUDE_DIR)
+
+- set(JASPER_LIBRARY libjasper)
++ set(JASPER_LIBRARY jasper)
+ set(JASPER_LIBRARIES ${JASPER_LIBRARY})
+ add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libjasper")
+ set(JASPER_INCLUDE_DIR "${${JASPER_LIBRARY}_SOURCE_DIR}")
+@@ -169,7 +169,7 @@ if(WITH_PNG)
+ if(NOT PNG_FOUND)
+ ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_PNG_INCLUDE_DIR HAVE_LIBPNG_PNG_H PNG_DEFINITIONS)
+
+- set(PNG_LIBRARY libpng)
++ set(PNG_LIBRARY png)
+ set(PNG_LIBRARIES ${PNG_LIBRARY})
+ add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libpng")
+ set(PNG_INCLUDE_DIR "${${PNG_LIBRARY}_SOURCE_DIR}")
diff --git a/media-libs/opencv/files/opencv-3.1.0-git-autodetect.patch b/media-libs/opencv/files/opencv-3.1.0-git-autodetect.patch
new file mode 100644
index 000000000000..f4bf0da2cc92
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.1.0-git-autodetect.patch
@@ -0,0 +1,42 @@
+--- a/CMakeLists.txt 2016-04-07 14:34:35.090937125 +0200
++++ b/CMakeLists.txt 2016-04-07 14:35:18.492935300 +0200
+@@ -444,23 +444,23 @@
+ # ----------------------------------------------------------------------------
+ # Autodetect if we are in a GIT repository
+ # ----------------------------------------------------------------------------
+-find_host_package(Git QUIET)
++#find_host_package(Git QUIET)
+
+-if(GIT_FOUND)
+- execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*"
+- WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
+- OUTPUT_VARIABLE OPENCV_VCSVERSION
+- RESULT_VARIABLE GIT_RESULT
+- ERROR_QUIET
+- OUTPUT_STRIP_TRAILING_WHITESPACE
+- )
+- if(NOT GIT_RESULT EQUAL 0)
+- set(OPENCV_VCSVERSION "unknown")
+- endif()
+-else()
+- # We don't have git:
+- set(OPENCV_VCSVERSION "unknown")
+-endif()
++#if(GIT_FOUND)
++# execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*"
++# WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
++# OUTPUT_VARIABLE OPENCV_VCSVERSION
++# RESULT_VARIABLE GIT_RESULT
++# ERROR_QUIET
++# OUTPUT_STRIP_TRAILING_WHITESPACE
++# )
++# if(NOT GIT_RESULT EQUAL 0)
++# set(OPENCV_VCSVERSION "unknown")
++# endif()
++#else()
++# # We don't have git:
++# set(OPENCV_VCSVERSION "unknown")
++#endif()
+
+
+ # ----------------------------------------------------------------------------
diff --git a/media-libs/opencv/files/opencv-3.1.0-java-magic.patch b/media-libs/opencv/files/opencv-3.1.0-java-magic.patch
new file mode 100644
index 000000000000..96a0e7e7053f
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.1.0-java-magic.patch
@@ -0,0 +1,47 @@
+diff -purN a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt 2015-12-18 15:02:16.000000000 +0000
++++ b/CMakeLists.txt 2016-06-06 17:15:48.006020666 +0100
+@@ -209,6 +209,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include
+ OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
+ OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) )
+ OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
++OCV_OPTION(WITH_JAVA "Include Java support" ON)
+ OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
+ OCV_OPTION(WITH_MATLAB "Include Matlab support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT))
+ OCV_OPTION(WITH_VA "Include VA support" OFF IF (UNIX AND NOT ANDROID) )
+@@ -562,20 +563,25 @@ endif(BUILD_DOCS)
+ include(cmake/OpenCVDetectPython.cmake)
+
+ # --- Java Support ---
+-include(cmake/OpenCVDetectApacheAnt.cmake)
+-if(ANDROID)
+- include(cmake/OpenCVDetectAndroidSDK.cmake)
++If(WITH_JAVA)
++ include(cmake/OpenCVDetectApacheAnt.cmake)
++ if(ANDROID)
++ include(cmake/OpenCVDetectAndroidSDK.cmake)
+
+- if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
+- message(WARNING "OpenCV requires Android SDK tools revision 14 or newer. Otherwise tests and samples will no be compiled.")
++ if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
++ message(WARNING "OpenCV requires Android SDK tools revision 14 or newer. Otherwise tests and samples will no be compiled.")
++ endif()
++ else()
++ find_package(JNI)
+ endif()
+-else()
+- find_package(JNI)
+-endif()
+
+-if(ANDROID AND ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13))
+- SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
++ if(ANDROID AND ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13))
++ SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
++ else()
++ SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
++ endif()
+ else()
++ SET(ANT_EXECUTABLE "")
+ SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
+ endif()
+
diff --git a/media-libs/opencv/files/opencv-3.1.0-remove-graphcut-for-cuda-8.patch b/media-libs/opencv/files/opencv-3.1.0-remove-graphcut-for-cuda-8.patch
new file mode 100644
index 000000000000..64761a263a17
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.1.0-remove-graphcut-for-cuda-8.patch
@@ -0,0 +1,23 @@
+From 10896129b39655e19e4e7c529153cb5c2191a1db Mon Sep 17 00:00:00 2001
+From: Vladislav Vinogradov <vlad.vinogradov@itseez.com>
+Date: Fri, 6 May 2016 11:37:32 +0300
+Subject: [PATCH] GraphCut deprecated in CUDA 7.5 and removed in 8.0
+
+---
+ modules/cudalegacy/src/graphcuts.cpp | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/modules/cudalegacy/src/graphcuts.cpp b/modules/cudalegacy/src/graphcuts.cpp
+index eb08c3c..1a1eb85 100644
+--- a/modules/cudalegacy/src/graphcuts.cpp
++++ b/modules/cudalegacy/src/graphcuts.cpp
+@@ -42,7 +42,8 @@
+
+ #include "precomp.hpp"
+
+-#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
++// GraphCut has been removed in NPP 8.0
++#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
+
+ void cv::cuda::graphcut(GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
+ void cv::cuda::graphcut(GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
diff --git a/media-libs/opencv/files/opencv-3.2.0-contrib_xfeatures2d-autodownload.patch b/media-libs/opencv/files/opencv-3.2.0-contrib_xfeatures2d-autodownload.patch
new file mode 100644
index 000000000000..f03c57d425cc
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.2.0-contrib_xfeatures2d-autodownload.patch
@@ -0,0 +1,10 @@
+--- a/modules/xfeatures2d/CMakeLists.txt 2017-02-28 13:10:56.470000000 +0100
++++ b/modules/xfeatures2d/CMakeLists.txt 2017-02-28 13:11:03.970000000 +0100
+@@ -1,5 +1,5 @@
+ set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection")
+ ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml
+ OPTIONAL opencv_cudaarithm WRAP python java)
+-include(cmake/download_vgg.cmake)
+-include(cmake/download_boostdesc.cmake)
++#include(cmake/download_vgg.cmake)
++#include(cmake/download_boostdesc.cmake)
diff --git a/media-libs/opencv/files/opencv-3.2.0-cpu-mno-sse2.patch b/media-libs/opencv/files/opencv-3.2.0-cpu-mno-sse2.patch
new file mode 100644
index 000000000000..a73456411f27
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.2.0-cpu-mno-sse2.patch
@@ -0,0 +1,11 @@
+--- a/cmake/OpenCVCompilerOptions.cmake 2017-07-22 13:26:51.178960091 +0200
++++ b/cmake/OpenCVCompilerOptions.cmake 2017-07-22 13:27:47.238961469 +0200
+@@ -176,8 +176,6 @@
+ endif()
+ if(ENABLE_SSE2)
+ add_extra_compiler_option(-msse2)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-sse2)
+ endif()
+ if(ARM)
+ add_extra_compiler_option("-mfp16-format=ieee")
diff --git a/media-libs/opencv/files/opencv-3.2.0-fix_ussage_cpu_instructions.patch b/media-libs/opencv/files/opencv-3.2.0-fix_ussage_cpu_instructions.patch
new file mode 100644
index 000000000000..7b88216f329a
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.2.0-fix_ussage_cpu_instructions.patch
@@ -0,0 +1,64 @@
+--- a/cmake/OpenCVCompilerOptions.cmake
++++ b/cmake/OpenCVCompilerOptions.cmake
+@@ -164,8 +164,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
+ # Other optimizations
+ if(ENABLE_OMIT_FRAME_POINTER)
+ add_extra_compiler_option(-fomit-frame-pointer)
+- else()
+- add_extra_compiler_option(-fno-omit-frame-pointer)
+ endif()
+ if(ENABLE_FAST_MATH)
+ add_extra_compiler_option(-ffast-math)
+@@ -195,8 +193,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
+ if(NOT MINGW)
+ if(ENABLE_AVX)
+ add_extra_compiler_option(-mavx)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-avx)
+ endif()
+ if(ENABLE_AVX2)
+ add_extra_compiler_option(-mavx2)
+@@ -210,26 +206,18 @@ if(CMAKE_COMPILER_IS_GNUCXX)
+ if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-mavx")
+ if(ENABLE_SSE3)
+ add_extra_compiler_option(-msse3)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-sse3)
+ endif()
+
+ if(ENABLE_SSSE3)
+ add_extra_compiler_option(-mssse3)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-ssse3)
+ endif()
+
+ if(ENABLE_SSE41)
+ add_extra_compiler_option(-msse4.1)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-sse4.1)
+ endif()
+
+ if(ENABLE_SSE42)
+ add_extra_compiler_option(-msse4.2)
+- elseif(X86 OR X86_64)
+- add_extra_compiler_option(-mno-sse4.2)
+ endif()
+
+ if(ENABLE_POPCNT)
+@@ -238,16 +226,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
+ endif()
+ endif(NOT MINGW)
+
+- if(X86 OR X86_64)
+- if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+- if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)")
+- add_extra_compiler_option(-mfpmath=sse)# !! important - be on the same wave with x64 compilers
+- else()
+- add_extra_compiler_option(-mfpmath=387)
+- endif()
+- endif()
+- endif()
+-
+ # Profiling?
+ if(ENABLE_PROFILING)
+ add_extra_compiler_option("-pg -g"
diff --git a/media-libs/opencv/files/opencv-3.2.0-gcc-6.0.patch b/media-libs/opencv/files/opencv-3.2.0-gcc-6.0.patch
new file mode 100644
index 000000000000..457d3595e49b
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.2.0-gcc-6.0.patch
@@ -0,0 +1,11 @@
+--- a/cmake/OpenCVPCHSupport.cmake 2017-06-06 15:05:09.180022719 +0200
++++ b/cmake/OpenCVPCHSupport.cmake 2017-06-06 15:05:50.775022684 +0200
+@@ -14,7 +14,7 @@
+
+ IF(CMAKE_COMPILER_IS_GNUCXX)
+
+- IF(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2.0")
++ IF(gcc_compiler_version VERSION_GREATER "4.2.-1" AND gcc_compiler_version VERSION_LESS "6.0.0")
+ SET(PCHSupport_FOUND TRUE)
+ ENDIF()
+
diff --git a/media-libs/opencv/files/opencv-3.2.0-vtk.patch b/media-libs/opencv/files/opencv-3.2.0-vtk.patch
new file mode 100644
index 000000000000..1e3daec8aa30
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.2.0-vtk.patch
@@ -0,0 +1,11 @@
+--- a/cmake/OpenCVDetectVTK.cmake 2017-03-20 10:43:28.401962910 +0100
++++ b/cmake/OpenCVDetectVTK.cmake 2017-03-20 10:43:09.127963906 +0100
+@@ -8,7 +8,7 @@
+ IF(VTK_RENDERING_BACKEND) #in vtk 7, the rendering backend is exported as a var.
+ find_package(VTK QUIET COMPONENTS vtkRendering${VTK_RENDERING_BACKEND} vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport vtkIOGeometry NO_MODULE)
+ ELSE(VTK_RENDERING_BACKEND)
+- find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
++ find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL2 vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
+ ENDIF(VTK_RENDERING_BACKEND)
+ ENDIF(VTK_FOUND)
+
diff --git a/media-libs/opencv/files/opencv-3.3.0-contrib-xfeatures2d.patch b/media-libs/opencv/files/opencv-3.3.0-contrib-xfeatures2d.patch
new file mode 100644
index 000000000000..26e4ac767c37
--- /dev/null
+++ b/media-libs/opencv/files/opencv-3.3.0-contrib-xfeatures2d.patch
@@ -0,0 +1,19 @@
+--- a/modules/xfeatures2d/CMakeLists.txt 2017-09-16 14:28:38.440000000 +0200
++++ b/modules/xfeatures2d/CMakeLists.txt 2017-09-16 14:27:21.350000000 +0200
+@@ -2,11 +2,11 @@
+
+ ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_shape opencv_cudaarithm WRAP python java)
+
++#include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
++#include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
++#set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
++#download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
++#download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
+-include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
+-include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
+-set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
+-download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
+-download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
+ if(NOT boost_status OR NOT vgg_status)
+ ocv_module_disable(xfeatures2d)
+ endif()