From 00569d49c7a310959e7b03afdb4b27078b076d9c Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Thu, 27 Aug 2009 13:17:06 -0500 Subject: [PATCH] windowscodecs: implement CopyPalette for the PNG decoder --- dlls/windowscodecs/pngformat.c | 45 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 2 deletions(-) diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c index 5c73f40..96873d2 100644 --- a/dlls/windowscodecs/pngformat.c +++ b/dlls/windowscodecs/pngformat.c @@ -52,6 +52,8 @@ MAKE_FUNCPTR(png_get_color_type); MAKE_FUNCPTR(png_get_image_height); MAKE_FUNCPTR(png_get_image_width); MAKE_FUNCPTR(png_get_io_ptr); +MAKE_FUNCPTR(png_get_PLTE); +MAKE_FUNCPTR(png_get_tRNS); MAKE_FUNCPTR(png_set_bgr); MAKE_FUNCPTR(png_set_gray_to_rgb); MAKE_FUNCPTR(png_set_read_fn); @@ -78,6 +80,8 @@ static void *load_libpng(void) LOAD_FUNCPTR(png_get_image_height); LOAD_FUNCPTR(png_get_image_width); LOAD_FUNCPTR(png_get_io_ptr); + LOAD_FUNCPTR(png_get_PLTE); + LOAD_FUNCPTR(png_get_tRNS); LOAD_FUNCPTR(png_set_bgr); LOAD_FUNCPTR(png_set_gray_to_rgb); LOAD_FUNCPTR(png_set_read_fn); @@ -484,8 +488,45 @@ static HRESULT WINAPI PngDecoder_Frame_GetResolution(IWICBitmapFrameDecode *ifac static HRESULT WINAPI PngDecoder_Frame_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette) { - FIXME("(%p,%p): stub\n", iface, pIPalette); - return E_NOTIMPL; + PngDecoder *This = impl_from_frame(iface); + png_uint_32 ret; + png_colorp png_palette; + int num_palette; + WICColor palette[256]; + png_bytep trans; + int num_trans; + png_color_16p trans_values; + int i; + + TRACE("(%p,%p)\n", iface, pIPalette); + + ret = ppng_get_PLTE(This->png_ptr, This->info_ptr, &png_palette, &num_palette); + if (!ret) return WINCODEC_ERR_PALETTEUNAVAILABLE; + + if (num_palette > 256) + { + ERR("palette has %i colors?!\n", num_palette); + return E_FAIL; + } + + for (i=0; ipng_ptr, This->info_ptr, &trans, &num_trans, &trans_values); + if (ret) + { + for (i=0; i