Repository: opencv
Issue: Failed tests perf_features2d, perf_stitching, sanity_features2d, sanity_stitching when compiled with bundled libjpeg
Labels: category: imgcodecs

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV and testdata => 3.4.1
- Operating System / Platform => Windows 10 x64 1803
- Compiler => mingw-w64 8.1.0
- CMake:                       3.11.4
- CMake generator:             MinGW Makefiles
- CMake build tool:            C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe
- Configuration:               Release

##### Detailed description

When compiled with bundled libjpeg, tests perf_features2d, perf_stitching, sanity_features2d, sanity_stitching fail. The reason is s1.jpg and s2.jpg images located in testdata/stitching are not read properly.

##### Steps to reproduce

Compilation:

> set PrefixDir=C:
> cd %PrefixDir%\libs\opencv-3.4.1-build
> cmake -DWITH_VTK:BOOL="0" -DWITH_FFMPEG:BOOL="0" -DBUILD_opencv_cudaimgproc:BOOL="0" -DBUILD_PERF_TESTS:BOOL="1" -DWITH_GTK:BOOL="0" -DWITH_CUFFT:BOOL="0" -DCMAKE_BUILD_TYPE:STRING="Release" -DWITH_EIGEN:BOOL="0" -DBUILD_TESTS:BOOL="1" -DBUILD_IPP_IW:BOOL="0" -DCMAKE_INSTALL_PREFIX:PATH="%PrefixDir%\libs\opencv-3.4.1-release-x64" -DWITH_OPENCL:BOOL="0" -DBUILD_opencv_python_bindings_generator:BOOL="0" -DBUILD_opencv_python3:BOOL="0" -DBUILD_PROTOBUF:BOOL="0" -DBUILD_opencv_cudabgsegm:BOOL="0" -DBUILD_opencv_dnn:BOOL="0" -DWITH_MATLAB:BOOL="0" -DWITH_WEBP:BOOL="0" -DBUILD_opencv_cudaarithm:BOOL="0" -DBUILD_opencv_cudastereo:BOOL="0" -DWITH_PROTOBUF:BOOL="0" -DBUILD_opencv_cudawarping:BOOL="0" -DWITH_GPHOTO2:BOOL="0" -DWITH_OPENCLAMDFFT:BOOL="0" -DWITH_NVCUVID:BOOL="0" -DWITH_GSTREAMER:BOOL="0" -DWITH_CUDA:BOOL="0" -DWITH_1394:BOOL="0" -DBUILD_opencv_cudafeatures2d:BOOL="0" -DBUILD_opencv_cudalegacy:BOOL="0" -DBUILD_opencv_cudaobjdetect:BOOL="0" -DBUILD_opencv_cudaoptflow:BOOL="0" -DWITH_IPP:BOOL="0" -DWITH_OPENMP:BOOL="1" -DWITH_ITT:BOOL="0" -DBUILD_opencv_cudev:BOOL="0" -DBUILD_JAVA:BOOL="0" -DBUILD_ITT:BOOL="0" -DWITH_OPENCLAMDBLAS:BOOL="0" -DBUILD_opencv_python2:BOOL="0" -DWITH_LAPACK:BOOL="0" -DBUILD_opencv_cudafilters:BOOL="0" -DBUILD_opencv_cudacodec:BOOL="0" -DBUILD_opencv_java_bindings_generator:BOOL="0" -DWITH_CUBLAS:BOOL="0" -G "MinGW Makefiles" ..\opencv-3.4.1
> mingw32-make -j4
> set OPENCV_TEST_DATA_PATH=C:\libs\testdata\
> mingw32-make test

##### Which does not help
Updating libjpeg to recent version 9c

##### Which helps
Resaving these images into jpeg simply with Paint, or...
1. Compiling libjpeg-turbo version 1.5.3 with default settings using cmake and mingw.
2. Compiling opencv with libjpeg-turbo (static variant). Configuration with cmake parameters:
-DBUILD_JPEG:BOOL="0" -DJPEG_LIBRARY:PATH=C:\libs\libjpeg-turbo-gcc64\lib\libturbojpeg.a -DJPEG_INCLUDE_DIR:PATH=C:\libs\libjpeg-turbo-gcc64\include\

Media I/O:
ZLib:                        build (ver 1.2.11)
JPEG:                        C:/libs/libjpeg-turbo-gcc64/lib/libturbojpeg.a (ver )
PNG:                         build (ver 1.6.34)
TIFF:                        build (ver 42 - 4.0.9)
JPEG 2000:                   build (ver 1.900.1)
OpenEXR:                     build (ver 1.7.1)