Added patches to fix JPEG decoder and implement support for CMYK to BGR conversion.

This commit is contained in:
Sebastian Lackner 2017-08-22 03:19:04 +02:00
parent bab383452b
commit b6bab9758e
8 changed files with 419 additions and 1 deletions

View File

@ -427,6 +427,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"
@ -1556,6 +1557,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"
;;
@ -9331,6 +9335,29 @@ 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/0001-windowscodecs-Fix-IWICBitmapEncoder-SetPalette-for-a.patch
patch_apply windowscodecs-JPEG_Decoder/0002-windowscodecs-Fix-stride-calculation-in-JPEG-decoder.patch
patch_apply windowscodecs-JPEG_Decoder/0003-windowscodecs-Move-additional-processing-out-of-the-.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 IWICBitmapEncoder::SetPalette for a not initialized case in JPEG encoder.", 1 },';
printf '%s\n' '+ { "Dmitry Timoshkov", "windowscodecs: Fix stride calculation in JPEG decoder.", 1 },';
printf '%s\n' '+ { "Dmitry Timoshkov", "windowscodecs: Move additional processing out of the JPEG decoding loop.", 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:

View File

@ -39,7 +39,7 @@ index b7998be..9ec64e7 100644
+
+ EnterCriticalSection(&This->lock);
+
+ if (This->initialized)
+ if (This->frame_initialized)
+ hr = IWICPalette_GetColors(palette, 256, This->palette, &This->colors);
+ else
+ hr = WINCODEC_ERR_NOTINITIALIZED;

View File

@ -0,0 +1,37 @@
From 3a150ddeeb8cfc19bd93eb6484aad9e1d8f21658 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Fri, 18 Aug 2017 11:53:17 +0800
Subject: windowscodecs: Fix IWICBitmapEncoder::SetPalette for a not
initialized case in JPEG encoder.
---
dlls/windowscodecs/jpegformat.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c
index ae54b0f8009..abab36ab40a 100644
--- a/dlls/windowscodecs/jpegformat.c
+++ b/dlls/windowscodecs/jpegformat.c
@@ -1424,8 +1424,18 @@ static HRESULT WINAPI JpegEncoder_SetColorContexts(IWICBitmapEncoder *iface,
static HRESULT WINAPI JpegEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *pIPalette)
{
+ JpegEncoder *This = impl_from_IWICBitmapEncoder(iface);
+ HRESULT hr;
+
TRACE("(%p,%p)\n", iface, pIPalette);
- return WINCODEC_ERR_UNSUPPORTEDOPERATION;
+
+ EnterCriticalSection(&This->lock);
+
+ hr = This->initialized ? WINCODEC_ERR_UNSUPPORTEDOPERATION : WINCODEC_ERR_NOTINITIALIZED;
+
+ LeaveCriticalSection(&This->lock);
+
+ return hr;
}
static HRESULT WINAPI JpegEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *pIThumbnail)
--
2.14.1

View File

@ -0,0 +1,25 @@
From 271b0a51b2f1d70fcd7091e4829c77aacfdc0ba1 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Fri, 18 Aug 2017 12:03:50 +0800
Subject: windowscodecs: Fix stride calculation in JPEG decoder.
---
dlls/windowscodecs/jpegformat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c
index abab36ab40a..f31239b8d79 100644
--- a/dlls/windowscodecs/jpegformat.c
+++ b/dlls/windowscodecs/jpegformat.c
@@ -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;
- stride = bpp * This->cinfo.output_width;
+ stride = (bpp * This->cinfo.output_width + 7) / 8;
data_size = stride * This->cinfo.output_height;
max_row_needed = prc->Y + prc->Height;
--
2.14.1

View File

@ -0,0 +1,68 @@
From 799ae0c6a39c58423281ea5d8c46b1085a07bf48 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Fri, 18 Aug 2017 12:12:16 +0800
Subject: windowscodecs: Move additional processing out of the JPEG decoding
loop.
This avoids image corruption when libjpeg reuses existing pixel data.
---
dlls/windowscodecs/jpegformat.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c
index f31239b8d79..0023fd2bf32 100644
--- a/dlls/windowscodecs/jpegformat.c
+++ b/dlls/windowscodecs/jpegformat.c
@@ -603,7 +603,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
JpegDecoder *This = impl_from_IWICBitmapFrameDecode(iface);
UINT bpp;
UINT stride;
- UINT data_size;
+ UINT data_size, i;
UINT max_row_needed;
jmp_buf jmpbuf;
WICRect rect;
@@ -659,7 +659,6 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
UINT first_scanline = This->cinfo.output_scanline;
UINT max_rows;
JSAMPROW out_rows[4];
- UINT i;
JDIMENSION ret;
max_rows = min(This->cinfo.output_height-first_scanline, 4);
@@ -674,19 +673,21 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
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 + stride * first_scanline,
- This->cinfo.output_width, This->cinfo.output_scanline - first_scanline,
- stride);
- }
+ 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 (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
- /* Adobe JPEG's have inverted CMYK data. */
- for (i=0; i<data_size; i++)
- This->image_data[i] ^= 0xff;
+ if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
+ {
+ /* Adobe JPEG's have inverted CMYK data. */
+ for (i=0; i<data_size; i++)
+ This->image_data[i] ^= 0xff;
}
LeaveCriticalSection(&This->lock);
--
2.14.1

View File

@ -0,0 +1,195 @@
From 71de59213235b4e41531d0ecff43790cf172bf90 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Fri, 18 Aug 2017 12:17:52 +0800
Subject: windowscodecs: Move JPEG frame image data initialization from
Frame::CopyPixels to Decoder::Initialize. (v2)
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 | 146 +++++++++++++++-------------------------
1 file changed, 55 insertions(+), 91 deletions(-)
diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c
index 0023fd2bf32..296529cee73 100644
--- a/dlls/windowscodecs/jpegformat.c
+++ b/dlls/windowscodecs/jpegformat.c
@@ -155,6 +155,7 @@ typedef struct {
struct jpeg_error_mgr jerr;
struct jpeg_source_mgr source_mgr;
BYTE source_buffer[1024];
+ UINT bpp, stride;
BYTE *image_data;
CRITICAL_SECTION lock;
} JpegDecoder;
@@ -303,6 +304,8 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream *
int ret;
LARGE_INTEGER seek;
jmp_buf jmpbuf;
+ UINT data_size, i;
+
TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOptions);
EnterCriticalSection(&This->lock);
@@ -381,6 +384,55 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream *
return E_FAIL;
}
+ if (This->cinfo.out_color_space == JCS_GRAYSCALE) This->bpp = 8;
+ else if (This->cinfo.out_color_space == JCS_CMYK) This->bpp = 32;
+ else This->bpp = 24;
+
+ 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);
+ if (!This->image_data)
+ {
+ LeaveCriticalSection(&This->lock);
+ return E_OUTOFMEMORY;
+ }
+
+ 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;
+
+ max_rows = min(This->cinfo.output_height-first_scanline, 4);
+ for (i=0; i<max_rows; i++)
+ out_rows[i] = This->image_data + This->stride * (first_scanline+i);
+
+ ret = pjpeg_read_scanlines(&This->cinfo, out_rows, max_rows);
+ if (ret == 0)
+ {
+ ERR("read_scanlines failed\n");
+ LeaveCriticalSection(&This->lock);
+ return E_FAIL;
+ }
+ }
+
+ if (This->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,
+ This->stride);
+ }
+
+ if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
+ {
+ /* Adobe JPEG's have inverted CMYK data. */
+ for (i=0; i<data_size; i++)
+ This->image_data[i] ^= 0xff;
+ }
+
This->initialized = TRUE;
LeaveCriticalSection(&This->lock);
@@ -601,99 +653,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 max_row_needed;
- jmp_buf jmpbuf;
- WICRect rect;
- TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
-
- if (!prc)
- {
- rect.X = 0;
- rect.Y = 0;
- rect.Width = This->cinfo.output_width;
- rect.Height = This->cinfo.output_height;
- prc = &rect;
- }
- else
- {
- if (prc->X < 0 || prc->Y < 0 || prc->X+prc->Width > This->cinfo.output_width ||
- prc->Y+prc->Height > This->cinfo.output_height)
- return E_INVALIDARG;
- }
-
- if (This->cinfo.out_color_space == JCS_GRAYSCALE) bpp = 8;
- else if (This->cinfo.out_color_space == JCS_CMYK) bpp = 32;
- else bpp = 24;
-
- stride = (bpp * This->cinfo.output_width + 7) / 8;
- data_size = stride * This->cinfo.output_height;
-
- max_row_needed = prc->Y + prc->Height;
- 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);
- if (!This->image_data)
- {
- LeaveCriticalSection(&This->lock);
- return E_OUTOFMEMORY;
- }
- }
-
- This->cinfo.client_data = jmpbuf;
-
- if (setjmp(jmpbuf))
- {
- LeaveCriticalSection(&This->lock);
- return E_FAIL;
- }
-
- while (max_row_needed > This->cinfo.output_scanline)
- {
- UINT first_scanline = This->cinfo.output_scanline;
- UINT max_rows;
- JSAMPROW out_rows[4];
- JDIMENSION ret;
-
- max_rows = min(This->cinfo.output_height-first_scanline, 4);
- for (i=0; i<max_rows; i++)
- out_rows[i] = This->image_data + stride * (first_scanline+i);
-
- ret = pjpeg_read_scanlines(&This->cinfo, out_rows, max_rows);
-
- if (ret == 0)
- {
- ERR("read_scanlines failed\n");
- 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 (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
- {
- /* Adobe JPEG's have inverted CMYK data. */
- for (i=0; i<data_size; i++)
- This->image_data[i] ^= 0xff;
- }
-
- 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,
+ This->cinfo.output_width, This->cinfo.output_height, This->stride,
prc, cbStride, cbBufferSize, pbBuffer);
}
--
2.14.1

View File

@ -0,0 +1,65 @@
From 3a05eb9c499b348f3577cc7e7cb8ad23a261e5f0 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Thu, 17 Aug 2017 14:57:18 +0800
Subject: windowscodecs: Add support for CMYK to BGR conversion.
---
dlls/windowscodecs/converter.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c
index 5dccb70b1fb..525e1838b84 100644
--- a/dlls/windowscodecs/converter.c
+++ b/dlls/windowscodecs/converter.c
@@ -1085,6 +1085,48 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec
}
return S_OK;
+ case format_32bppCMYK:
+ if (prc)
+ {
+ BYTE *srcdata;
+ UINT srcstride, srcdatasize;
+
+ srcstride = 4 * prc->Width;
+ srcdatasize = srcstride * prc->Height;
+
+ srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
+ if (!srcdata) return E_OUTOFMEMORY;
+
+ hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
+ if (SUCCEEDED(hr))
+ {
+ INT x, y;
+ BYTE *src = srcdata, *dst = pbBuffer;
+
+ for (y = 0; y < prc->Height; y++)
+ {
+ BYTE *cmyk = src;
+ BYTE *bgr = dst;
+
+ for (x = 0; x < prc->Width; x++)
+ {
+ BYTE c = cmyk[0], m = cmyk[1], y = cmyk[2], k = cmyk[3];
+ bgr[0] = (255 - y) * (255 - k) / 255; /* B */
+ bgr[1] = (255 - m) * (255 - k) / 255; /* G */
+ bgr[2] = (255 - c) * (255 - k) / 255; /* R */
+ cmyk += 4;
+ bgr += 3;
+ }
+ src += srcstride;
+ dst += cbStride;
+ }
+ }
+
+ HeapFree(GetProcessHeap(), 0, srcdata);
+ return hr;
+ }
+ return S_OK;
+
default:
FIXME("Unimplemented conversion path!\n");
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
--
2.14.1

View File

@ -0,0 +1 @@
Fixes: [43520] Fix JPEG decoder and implement support for CMYK to BGR conversion