diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 75ca291d..568109af 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -387,6 +387,7 @@ patch_enable_all () enable_windowscodecs_GIF_Encoder="$1" enable_windowscodecs_IMILBitmapSource="$1" enable_windowscodecs_IWICPalette_InitializeFromBitmap="$1" + enable_windowscodecs_JPEG_Decoder="$1" enable_windowscodecs_Palette_Images="$1" enable_windowscodecs_TIFF_Support="$1" enable_windowscodecs_WICCreateBitmapFromSection="$1" @@ -1384,6 +1385,9 @@ patch_enable () windowscodecs-IWICPalette_InitializeFromBitmap) enable_windowscodecs_IWICPalette_InitializeFromBitmap="$2" ;; + windowscodecs-JPEG_Decoder) + enable_windowscodecs_JPEG_Decoder="$2" + ;; windowscodecs-Palette_Images) enable_windowscodecs_Palette_Images="$2" ;; @@ -8336,6 +8340,25 @@ if test "$enable_windowscodecs_IMILBitmapSource" -eq 1; then ) >> "$patchlist" fi +# Patchset windowscodecs-JPEG_Decoder +# | +# | This patchset fixes the following Wine bugs: +# | * [#43520] Fix JPEG decoder and implement support for CMYK to BGR conversion +# | +# | Modified files: +# | * dlls/windowscodecs/converter.c, dlls/windowscodecs/jpegformat.c +# | +if test "$enable_windowscodecs_JPEG_Decoder" -eq 1; then + patch_apply windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch + patch_apply windowscodecs-JPEG_Decoder/0004-windowscodecs-Move-JPEG-frame-image-data-initializat.patch + patch_apply windowscodecs-JPEG_Decoder/0005-windowscodecs-Add-support-for-CMYK-to-BGR-conversion.patch + ( + printf '%s\n' '+ { "Dmitry Timoshkov", "windowscodecs: Fix stride calculation in JPEG decoder.", 1 },'; + printf '%s\n' '+ { "Dmitry Timoshkov", "windowscodecs: Move JPEG frame image data initialization from Frame::CopyPixels to Decoder::Initialize.", 2 },'; + printf '%s\n' '+ { "Dmitry Timoshkov", "windowscodecs: Add support for CMYK to BGR conversion.", 1 },'; + ) >> "$patchlist" +fi + # Patchset windowscodecs-WICCreateBitmapFromSection # | # | This patchset fixes the following Wine bugs: diff --git a/patches/windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch b/patches/windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch index 65a4fe3d..ef1953bb 100644 --- a/patches/windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch +++ b/patches/windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch @@ -1,4 +1,4 @@ -From 77ec3e3c1f2346c5b70647ed2e99102a41bad353 Mon Sep 17 00:00:00 2001 +From 140717936cf4b769bd09d7890290597597bcc131 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Fri, 18 Aug 2017 12:03:50 +0800 Subject: [PATCH] windowscodecs: Fix stride calculation in JPEG decoder. @@ -8,10 +8,10 @@ Subject: [PATCH] windowscodecs: Fix stride calculation in JPEG decoder. 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c -index 08f1ee7..27cd880 100644 +index 0069bdfd89..4636e30a6f 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c -@@ -624,7 +624,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, +@@ -628,7 +628,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, else if (This->cinfo.out_color_space == JCS_CMYK) bpp = 32; else bpp = 24; @@ -21,5 +21,5 @@ index 08f1ee7..27cd880 100644 max_row_needed = prc->Y + prc->Height; -- -1.9.1 +2.16.2 diff --git a/patches/windowscodecs-JPEG_Decoder/0004-windowscodecs-Move-JPEG-frame-image-data-initializat.patch b/patches/windowscodecs-JPEG_Decoder/0004-windowscodecs-Move-JPEG-frame-image-data-initializat.patch index 5494d7c3..b8cac1e5 100644 --- a/patches/windowscodecs-JPEG_Decoder/0004-windowscodecs-Move-JPEG-frame-image-data-initializat.patch +++ b/patches/windowscodecs-JPEG_Decoder/0004-windowscodecs-Move-JPEG-frame-image-data-initializat.patch @@ -1,4 +1,4 @@ -From c91028da31f4578f90c19396c37bac0e898f566a Mon Sep 17 00:00:00 2001 +From 6599895d37972742aa9a5709972af934e9c0800f Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Fri, 18 Aug 2017 12:17:52 +0800 Subject: [PATCH] windowscodecs: Move JPEG frame image data initialization from @@ -7,14 +7,35 @@ Subject: [PATCH] windowscodecs: Move JPEG frame image data initialization from This is how PNG decoder does things, and it avoids image data corruption in some cases (presumably when libjpeg reuses existing scanline data). --- - dlls/windowscodecs/jpegformat.c | 156 +++++++++++++++------------------------- - 1 file changed, 59 insertions(+), 97 deletions(-) + dlls/windowscodecs/converter.c | 1 + + dlls/windowscodecs/jpegformat.c | 152 +++++++++++++++------------------------- + 2 files changed, 57 insertions(+), 96 deletions(-) +diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c +index 42ba260..ad2b3de 100644 +--- a/dlls/windowscodecs/converter.c ++++ b/dlls/windowscodecs/converter.c +@@ -30,6 +30,7 @@ + + #include "wincodecs_private.h" + ++#include "wine/heap.h" + #include "wine/debug.h" + + WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c -index 97899a7..df5da36 100644 +index 27cd880..1feff69 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c -@@ -155,6 +155,7 @@ typedef struct { +@@ -50,6 +50,7 @@ + + #include "wincodecs_private.h" + ++#include "wine/heap.h" + #include "wine/debug.h" + #include "wine/library.h" + +@@ -155,6 +156,7 @@ typedef struct { struct jpeg_error_mgr jerr; struct jpeg_source_mgr source_mgr; BYTE source_buffer[1024]; @@ -22,17 +43,16 @@ index 97899a7..df5da36 100644 BYTE *image_data; CRITICAL_SECTION lock; } JpegDecoder; -@@ -303,6 +304,9 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * +@@ -303,6 +305,8 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * int ret; LARGE_INTEGER seek; jmp_buf jmpbuf; + UINT data_size, i; -+ UINT first_scanline = 0; + TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOptions); EnterCriticalSection(&This->lock); -@@ -381,6 +385,59 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * +@@ -381,6 +385,55 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * return E_FAIL; } @@ -43,7 +63,7 @@ index 97899a7..df5da36 100644 + This->stride = (This->bpp * This->cinfo.output_width + 7) / 8; + data_size = This->stride * This->cinfo.output_height; + -+ This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size); ++ This->image_data = heap_alloc(data_size); + if (!This->image_data) + { + LeaveCriticalSection(&This->lock); @@ -52,12 +72,11 @@ index 97899a7..df5da36 100644 + + while (This->cinfo.output_scanline < This->cinfo.output_height) + { ++ UINT first_scanline = This->cinfo.output_scanline; + UINT max_rows; + JSAMPROW out_rows[4]; + JDIMENSION ret; + -+ first_scanline = This->cinfo.output_scanline; -+ + max_rows = min(This->cinfo.output_height-first_scanline, 4); + for (i=0; iimage_data + This->stride * (first_scanline+i); @@ -81,31 +100,26 @@ index 97899a7..df5da36 100644 + + if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) + { -+ DWORD *pDwordData = (DWORD*) (This->image_data + This->stride * first_scanline); -+ DWORD *pDwordDataEnd = (DWORD*) (This->image_data + This->cinfo.output_scanline * This->stride); -+ + /* Adobe JPEG's have inverted CMYK data. */ -+ while(pDwordData < pDwordDataEnd) -+ *pDwordData++ ^= 0xffffffff; ++ for (i=0; iimage_data[i] ^= 0xff; + } + This->initialized = TRUE; LeaveCriticalSection(&This->lock); -@@ -597,106 +654,11 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, +@@ -597,104 +650,11 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer) { JpegDecoder *This = impl_from_IWICBitmapFrameDecode(iface); - UINT bpp; - UINT stride; -- UINT data_size, i; +- UINT data_size; - UINT max_row_needed; - jmp_buf jmpbuf; - WICRect rect; -- UINT first_scanline = 0; - - TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer); - +- TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer); +- - if (!prc) - { - rect.X = 0; @@ -132,7 +146,7 @@ index 97899a7..df5da36 100644 - if (max_row_needed > This->cinfo.output_height) return E_INVALIDARG; - - EnterCriticalSection(&This->lock); -- + - if (!This->image_data) - { - This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size); @@ -153,12 +167,12 @@ index 97899a7..df5da36 100644 - - while (max_row_needed > This->cinfo.output_scanline) - { +- UINT first_scanline = This->cinfo.output_scanline; - UINT max_rows; - JSAMPROW out_rows[4]; +- UINT i; - JDIMENSION ret; - -- first_scanline = This->cinfo.output_scanline; -- - max_rows = min(This->cinfo.output_height-first_scanline, 4); - for (i=0; iimage_data + stride * (first_scanline+i); @@ -171,29 +185,30 @@ index 97899a7..df5da36 100644 - LeaveCriticalSection(&This->lock); - return E_FAIL; - } -- } - -- if (bpp == 24) -- { -- /* libjpeg gives us RGB data and we want BGR, so byteswap the data */ -- reverse_bgr8(3, This->image_data, -- This->cinfo.output_width, This->cinfo.output_height, -- stride); -- } +- if (bpp == 24) +- { +- /* libjpeg gives us RGB data and we want BGR, so byteswap the data */ +- reverse_bgr8(3, This->image_data + stride * first_scanline, +- This->cinfo.output_width, This->cinfo.output_scanline - first_scanline, +- stride); +- } - +- if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) +- { +- DWORD *pDwordData = (DWORD*) (This->image_data + stride * first_scanline); +- DWORD *pDwordDataEnd = (DWORD*) (This->image_data + This->cinfo.output_scanline * stride); - -- if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) -- { -- DWORD *pDwordData = (DWORD*) (This->image_data + stride * first_scanline); -- DWORD *pDwordDataEnd = (DWORD*) (This->image_data + This->cinfo.output_scanline * stride); +- /* Adobe JPEG's have inverted CMYK data. */ +- while(pDwordData < pDwordDataEnd) +- *pDwordData++ ^= 0xffffffff; +- } - -- /* Adobe JPEG's have inverted CMYK data. */ -- while(pDwordData < pDwordDataEnd) -- *pDwordData++ ^= 0xffffffff; - } - - LeaveCriticalSection(&This->lock); -- ++ TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer); + - return copy_pixels(bpp, This->image_data, - This->cinfo.output_width, This->cinfo.output_height, stride, + return copy_pixels(This->bpp, This->image_data, diff --git a/patches/windowscodecs-JPEG_Decoder/0005-windowscodecs-Add-support-for-CMYK-to-BGR-conversion.patch b/patches/windowscodecs-JPEG_Decoder/0005-windowscodecs-Add-support-for-CMYK-to-BGR-conversion.patch index 406750bb..d0705524 100644 --- a/patches/windowscodecs-JPEG_Decoder/0005-windowscodecs-Add-support-for-CMYK-to-BGR-conversion.patch +++ b/patches/windowscodecs-JPEG_Decoder/0005-windowscodecs-Add-support-for-CMYK-to-BGR-conversion.patch @@ -1,17 +1,18 @@ -From f26102e49cdff5e0afbb3132b02b9f4fe2d93dd5 Mon Sep 17 00:00:00 2001 +From 042ed16cde1e29daecdeead7bbfbe876a2b5a067 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Thu, 17 Aug 2017 14:57:18 +0800 Subject: [PATCH] windowscodecs: Add support for CMYK to BGR conversion. +Content-Type: text/plain; charset=UTF-8 --- dlls/windowscodecs/converter.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c -index 42ba260..54731ab 100644 +index 5dccb70b1f..525e1838b8 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c -@@ -1012,6 +1012,48 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec +@@ -1085,6 +1085,48 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec } return S_OK; @@ -24,7 +25,7 @@ index 42ba260..54731ab 100644 + srcstride = 4 * prc->Width; + srcdatasize = srcstride * prc->Height; + -+ srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); ++ srcdata = heap_alloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -52,7 +53,7 @@ index 42ba260..54731ab 100644 + } + } + -+ HeapFree(GetProcessHeap(), 0, srcdata); ++ heap_free(srcdata); + return hr; + } + return S_OK; @@ -61,5 +62,5 @@ index 42ba260..54731ab 100644 FIXME("Unimplemented conversion path!\n"); return WINCODEC_ERR_UNSUPPORTEDOPERATION; -- -1.9.1 +2.16.2 diff --git a/patches/windowscodecs-JPEG_Decoder/definition b/patches/windowscodecs-JPEG_Decoder/definition index 9f031045..3014ef11 100644 --- a/patches/windowscodecs-JPEG_Decoder/definition +++ b/patches/windowscodecs-JPEG_Decoder/definition @@ -1,2 +1 @@ Fixes: [43520] Fix JPEG decoder and implement support for CMYK to BGR conversion -Disabled: true