From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/decoder.c | 28 ++++++++++++++++++++++---- dlls/windowscodecs/libjpeg.c | 7 +++++++ dlls/windowscodecs/libpng.c | 7 +++++++ dlls/windowscodecs/libtiff.c | 7 +++++++ dlls/windowscodecs/wincodecs_common.h | 5 +++++ dlls/windowscodecs/wincodecs_private.h | 2 ++ dlls/wmphoto/jxrlib.c | 6 ++++++ 7 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/dlls/windowscodecs/decoder.c b/dlls/windowscodecs/decoder.c index 37ad8c10007..a287d79b8fd 100644 --- a/dlls/windowscodecs/decoder.c +++ b/dlls/windowscodecs/decoder.c @@ -47,6 +47,7 @@ typedef struct CommonDecoder { LONG ref; CRITICAL_SECTION lock; /* must be held when stream or decoder is accessed */ IStream *stream; + UINT frame; struct decoder *decoder; struct decoder_info decoder_info; struct decoder_stat file_info; @@ -338,8 +339,26 @@ static HRESULT WINAPI CommonDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, static HRESULT WINAPI CommonDecoder_CopyPalette(IWICBitmapDecoder *iface, IWICPalette *palette) { + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + WICColor colors[256]; + UINT num_colors; + HRESULT hr; + TRACE("(%p,%p)\n", iface, palette); - return WINCODEC_ERR_PALETTEUNAVAILABLE; + + if (FAILED(hr = decoder_get_decoder_palette(This->decoder, This->frame, colors, &num_colors))) + return hr; + + if (num_colors) + { + hr = IWICPalette_InitializeCustom(palette, colors, num_colors); + } + else + { + hr = WINCODEC_ERR_PALETTEUNAVAILABLE; + } + + return hr; }
static HRESULT common_decoder_create_query_reader(IWICMetadataBlockReader *block_reader, IWICMetadataQueryReader **query_reader) @@ -880,6 +899,9 @@ static HRESULT WINAPI CommonDecoder_GetFrame(IWICBitmapDecoder *iface, if (SUCCEEDED(hr) && This->cache_options == WICDecodeMetadataCacheOnLoad) hr = metadata_block_reader_initialize_metadata(&result->block_reader);
+ if (SUCCEEDED(hr)) + This->frame = result->frame; + if (FAILED(hr)) free(result); } @@ -912,8 +934,7 @@ HRESULT CommonDecoder_CreateInstance(struct decoder *decoder,
TRACE("(%s,%s,%p)\n", debugstr_guid(&decoder_info->clsid), debugstr_guid(iid), ppv);
- This = malloc(sizeof(*This)); - if (!This) + if (!(This = calloc(1, sizeof(*This)))) { decoder_destroy(decoder); return E_OUTOFMEMORY; @@ -922,7 +943,6 @@ HRESULT CommonDecoder_CreateInstance(struct decoder *decoder, This->IWICBitmapDecoder_iface.lpVtbl = &CommonDecoder_Vtbl; This->IWICMetadataBlockReader_iface.lpVtbl = &CommonDecoder_BlockVtbl; This->ref = 1; - This->stream = NULL; This->decoder = decoder; This->decoder_info = *decoder_info; metadata_block_reader_initialize(&This->block_reader, This, ~0u); diff --git a/dlls/windowscodecs/libjpeg.c b/dlls/windowscodecs/libjpeg.c index 22903ae4340..ad6f58e3f02 100644 --- a/dlls/windowscodecs/libjpeg.c +++ b/dlls/windowscodecs/libjpeg.c @@ -305,6 +305,12 @@ static HRESULT CDECL jpeg_decoder_get_frame_info(struct decoder* iface, UINT fra return S_OK; }
+static HRESULT CDECL jpeg_decoder_get_decoder_palette(struct decoder *iface, UINT frame, WICColor *colors, + UINT *num_colors) +{ + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + static HRESULT CDECL jpeg_decoder_copy_pixels(struct decoder* iface, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer) { @@ -334,6 +340,7 @@ static HRESULT CDECL jpeg_decoder_get_color_context(struct decoder* This, UINT f static const struct decoder_funcs jpeg_decoder_vtable = { jpeg_decoder_initialize, jpeg_decoder_get_frame_info, + jpeg_decoder_get_decoder_palette, jpeg_decoder_copy_pixels, jpeg_decoder_get_metadata_blocks, jpeg_decoder_get_color_context, diff --git a/dlls/windowscodecs/libpng.c b/dlls/windowscodecs/libpng.c index 2c660b83e72..e4ef74f185b 100644 --- a/dlls/windowscodecs/libpng.c +++ b/dlls/windowscodecs/libpng.c @@ -349,6 +349,12 @@ static HRESULT CDECL png_decoder_get_frame_info(struct decoder *iface, UINT fram return S_OK; }
+static HRESULT CDECL png_decoder_get_decoder_palette(struct decoder *iface, UINT frame, WICColor *colors, + UINT *num_colors) +{ + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + static HRESULT CDECL png_decoder_copy_pixels(struct decoder *iface, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer) { @@ -454,6 +460,7 @@ static void CDECL png_decoder_destroy(struct decoder* iface) static const struct decoder_funcs png_decoder_vtable = { png_decoder_initialize, png_decoder_get_frame_info, + png_decoder_get_decoder_palette, png_decoder_copy_pixels, png_decoder_get_metadata_blocks, png_decoder_get_color_context, diff --git a/dlls/windowscodecs/libtiff.c b/dlls/windowscodecs/libtiff.c index 16701a258f9..b88ccb68b62 100644 --- a/dlls/windowscodecs/libtiff.c +++ b/dlls/windowscodecs/libtiff.c @@ -650,6 +650,12 @@ static HRESULT CDECL tiff_decoder_get_frame_info(struct decoder* iface, UINT fra return hr; }
+static HRESULT CDECL tiff_decoder_get_decoder_palette(struct decoder *iface, UINT frame, WICColor *colors, + UINT *num_colors) +{ + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + static HRESULT tiff_decoder_read_tile(struct tiff_decoder *This, UINT tile_x, UINT tile_y) { tsize_t ret; @@ -1069,6 +1075,7 @@ static void CDECL tiff_decoder_destroy(struct decoder* iface) static const struct decoder_funcs tiff_decoder_vtable = { tiff_decoder_initialize, tiff_decoder_get_frame_info, + tiff_decoder_get_decoder_palette, tiff_decoder_copy_pixels, tiff_decoder_get_metadata_blocks, tiff_decoder_get_color_context, diff --git a/dlls/windowscodecs/wincodecs_common.h b/dlls/windowscodecs/wincodecs_common.h index dcccdc2e5f1..e369c7e6d97 100644 --- a/dlls/windowscodecs/wincodecs_common.h +++ b/dlls/windowscodecs/wincodecs_common.h @@ -26,6 +26,11 @@ HRESULT CDECL decoder_get_frame_info(struct decoder *decoder, UINT frame, struct return decoder->vtable->get_frame_info(decoder, frame, info); }
+HRESULT CDECL decoder_get_decoder_palette(struct decoder *decoder, UINT frame, WICColor *colors, UINT *num_colors) +{ + return decoder->vtable->get_decoder_palette(decoder, frame, colors, num_colors); +} + HRESULT CDECL decoder_copy_pixels(struct decoder *decoder, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer) { diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index 648ebf4305a..acc7909e7a8 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -319,6 +319,7 @@ struct decoder_funcs { HRESULT (CDECL *initialize)(struct decoder* This, IStream *stream, struct decoder_stat *st); HRESULT (CDECL *get_frame_info)(struct decoder* This, UINT frame, struct decoder_frame *info); + HRESULT (CDECL *get_decoder_palette)(struct decoder* This, UINT frame, WICColor *colors, UINT *num_colors); HRESULT (CDECL *copy_pixels)(struct decoder* This, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer); HRESULT (CDECL *get_metadata_blocks)(struct decoder* This, UINT frame, UINT *count, @@ -336,6 +337,7 @@ HRESULT CDECL stream_write(IStream *stream, const void *buffer, ULONG write, ULO HRESULT CDECL decoder_create(const CLSID *decoder_clsid, struct decoder_info *info, struct decoder **result); HRESULT CDECL decoder_initialize(struct decoder *This, IStream *stream, struct decoder_stat *st); HRESULT CDECL decoder_get_frame_info(struct decoder* This, UINT frame, struct decoder_frame *info); +HRESULT CDECL decoder_get_decoder_palette(struct decoder* This, UINT frame, WICColor *colors, UINT *num_colors); HRESULT CDECL decoder_copy_pixels(struct decoder* This, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer); HRESULT CDECL decoder_get_metadata_blocks(struct decoder* This, UINT frame, UINT *count, diff --git a/dlls/wmphoto/jxrlib.c b/dlls/wmphoto/jxrlib.c index c5ce59b454e..d26a8baffca 100644 --- a/dlls/wmphoto/jxrlib.c +++ b/dlls/wmphoto/jxrlib.c @@ -249,6 +249,11 @@ static HRESULT CDECL wmp_decoder_get_frame_info(struct decoder *iface, UINT fram return S_OK; }
+static HRESULT CDECL wmp_decoder_get_decoder_palette(struct decoder *iface, UINT frame, WICColor *colors, UINT *num_colors) +{ + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + static HRESULT CDECL wmp_decoder_copy_pixels(struct decoder *iface, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer) { struct wmp_decoder *This = impl_from_decoder(iface); @@ -343,6 +348,7 @@ static void CDECL wmp_decoder_destroy(struct decoder* iface) static const struct decoder_funcs wmp_decoder_vtable = { wmp_decoder_initialize, wmp_decoder_get_frame_info, + wmp_decoder_get_decoder_palette, wmp_decoder_copy_pixels, wmp_decoder_get_metadata_blocks, wmp_decoder_get_color_context,