windowscodecs: Use the bundled libpng.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-10-18 14:36:33 +02:00
parent 9f9441c9cf
commit c3d8a29a04
7 changed files with 54 additions and 384 deletions

120
configure vendored
View File

@ -641,8 +641,6 @@ MPG123_LIBS
MPG123_CFLAGS
TIFF_LIBS
TIFF_CFLAGS
PNG_LIBS
PNG_CFLAGS
JXRLIB_LIBS
JXRLIB_CFLAGS
JPEG_LIBS
@ -881,7 +879,6 @@ with_opengl
with_osmesa
with_oss
with_pcap
with_png
with_pthread
with_pulse
with_quicktime
@ -1978,8 +1975,6 @@ JPEG_CFLAGS
JPEG_LIBS
JXRLIB_CFLAGS
JXRLIB_LIBS
PNG_CFLAGS
PNG_LIBS
TIFF_CFLAGS
TIFF_LIBS
MPG123_CFLAGS
@ -2666,7 +2661,6 @@ Optional Packages:
--without-osmesa do not use the OSMesa library
--without-oss do not use the OSS sound support
--without-pcap do not use the Packet Capture library
--without-png do not use PNG
--without-pthread do not use the pthread library
--without-pulse do not use PulseAudio sound support
--without-quicktime do not use QuickTime support
@ -2791,8 +2785,6 @@ Some influential environment variables:
JXRLIB_CFLAGS
C compiler flags for jxrlib, overriding pkg-config
JXRLIB_LIBS Linker flags for jxrlib, overriding pkg-config
PNG_CFLAGS C compiler flags for libpng, overriding pkg-config
PNG_LIBS Linker flags for libpng, overriding pkg-config
TIFF_CFLAGS C compiler flags for libtiff-4, overriding pkg-config
TIFF_LIBS Linker flags for libtiff-4, overriding pkg-config
MPG123_CFLAGS
@ -4176,12 +4168,6 @@ if test "${with_pcap+set}" = set; then :
fi
# Check whether --with-png was given.
if test "${with_png+set}" = set; then :
withval=$with_png;
fi
# Check whether --with-pthread was given.
if test "${with_pthread+set}" = set; then :
withval=$with_pthread; if test "x$withval" = "xno"; then ac_cv_header_pthread_h=no; fi
@ -16022,110 +16008,6 @@ esac
fi
if test "x$with_png" != "xno"
then
if ${PNG_CFLAGS:+false} :; then :
if ${PKG_CONFIG+:} false; then :
PNG_CFLAGS=`$PKG_CONFIG --cflags libpng 2>/dev/null`
fi
fi
test "$cross_compiling" = yes || PNG_CFLAGS=${PNG_CFLAGS:-$X_CFLAGS}
if ${PNG_LIBS:+false} :; then :
if ${PKG_CONFIG+:} false; then :
PNG_LIBS=`$PKG_CONFIG --libs libpng 2>/dev/null`
fi
fi
test "$cross_compiling" = yes || PNG_LIBS=${PNG_LIBS:-$X_LIBS}
$as_echo "$as_me:${as_lineno-$LINENO}: libpng cflags: $PNG_CFLAGS" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: libpng libs: $PNG_LIBS" >&5
ac_save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $PNG_CFLAGS"
for ac_header in png.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "png.h" "ac_cv_header_png_h" "$ac_includes_default"
if test "x$ac_cv_header_png_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_PNG_H 1
_ACEOF
fi
done
if test "$ac_cv_header_png_h" = "yes"
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -lpng" >&5
$as_echo_n "checking for -lpng... " >&6; }
if ${ac_cv_lib_soname_png+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_soname_save_LIBS=$LIBS
LIBS="-lpng $PNG_LIBS -lm -lz $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char png_create_read_struct ();
int
main ()
{
return png_create_read_struct ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
case "$LIBEXT" in
dll) ac_cv_lib_soname_png=`$ac_cv_path_LDD conftest.exe | grep "png" | sed -e "s/dll.*/dll/"';2,$d'` ;;
dylib) ac_cv_lib_soname_png=`$OTOOL -L conftest$ac_exeext | grep "libpng[0-9]*\\.[0-9A-Za-z.]*dylib" | sed -e "s/^.*\/\(libpng[0-9]*\.[0-9A-Za-z.]*dylib\).*$/\1/"';2,$d'` ;;
*) ac_cv_lib_soname_png=`$READELF -d conftest$ac_exeext | grep "NEEDED.*libpng[0-9]*\\.$LIBEXT" | sed -e "s/^.*\\[\\(libpng[0-9]*\\.$LIBEXT[^ ]*\\)\\].*$/\1/"';2,$d'`
if ${ac_cv_lib_soname_png:+false} :; then :
ac_cv_lib_soname_png=`$LDD conftest$ac_exeext | grep "libpng[0-9]*\\.$LIBEXT" | sed -e "s/^.*\(libpng[0-9]*\.$LIBEXT[^ ]*\).*$/\1/"';2,$d'`
fi ;;
esac
else
ac_cv_lib_soname_png=
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_soname_save_LIBS
fi
if ${ac_cv_lib_soname_png:+false} :; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
PNG_CFLAGS=""
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_soname_png" >&5
$as_echo "$ac_cv_lib_soname_png" >&6; }
cat >>confdefs.h <<_ACEOF
#define SONAME_LIBPNG "$ac_cv_lib_soname_png"
_ACEOF
fi
else
PNG_CFLAGS=""
fi
CPPFLAGS=$ac_save_CPPFLAGS
fi
if test "x$ac_cv_lib_soname_png" = "x"; then :
case "x$with_png" in
x) as_fn_append wine_warnings "|libpng ${notice_platform}development files not found, PNG won't be supported." ;;
xno) ;;
*) as_fn_error $? "libpng ${notice_platform}development files not found, PNG won't be supported.
This is an error since --with-png was requested." "$LINENO" 5 ;;
esac
fi
if test "x$with_tiff" != "xno"
then
if ${TIFF_CFLAGS:+false} :; then :
@ -19739,8 +19621,6 @@ JPEG_CFLAGS = $JPEG_CFLAGS
JPEG_LIBS = $JPEG_LIBS
JXRLIB_CFLAGS = $JXRLIB_CFLAGS
JXRLIB_LIBS = $JXRLIB_LIBS
PNG_CFLAGS = $PNG_CFLAGS
PNG_LIBS = $PNG_LIBS
TIFF_CFLAGS = $TIFF_CFLAGS
TIFF_LIBS = $TIFF_LIBS
MPG123_CFLAGS = $MPG123_CFLAGS

View File

@ -75,7 +75,6 @@ AC_ARG_WITH(osmesa, AS_HELP_STRING([--without-osmesa],[do not use the OSMesa
AC_ARG_WITH(oss, AS_HELP_STRING([--without-oss],[do not use the OSS sound support]))
AC_ARG_WITH(pcap, AS_HELP_STRING([--without-pcap],[do not use the Packet Capture library]),
[if test "x$withval" = "xno"; then ac_cv_header_pcap_pcap_h=no; fi])
AC_ARG_WITH(png, AS_HELP_STRING([--without-png],[do not use PNG]))
AC_ARG_WITH(pthread, AS_HELP_STRING([--without-pthread],[do not use the pthread library]),
[if test "x$withval" = "xno"; then ac_cv_header_pthread_h=no; fi])
AC_ARG_WITH(pulse, AS_HELP_STRING([--without-pulse],[do not use PulseAudio sound support]))
@ -1813,22 +1812,6 @@ fi
WINE_NOTICE_WITH(jxrlib,[test "x$ac_cv_lib_soname_jxrglue" = "x"],
[jxrlib ${notice_platform}development files not found, JPEG-XR won't be supported.])
dnl **** Check for libpng ****
if test "x$with_png" != "xno"
then
WINE_PACKAGE_FLAGS(PNG,[libpng],,[$X_CFLAGS],[$X_LIBS],
[AC_CHECK_HEADERS([png.h])
if test "$ac_cv_header_png_h" = "yes"
then
WINE_CHECK_SONAME(png,png_create_read_struct,,
[PNG_CFLAGS=""],[$PNG_LIBS -lm -lz],[[libpng[[0-9]]*]])
else
PNG_CFLAGS=""
fi])
fi
WINE_WARNING_WITH(png,[test "x$ac_cv_lib_soname_png" = "x"],
[libpng ${notice_platform}development files not found, PNG won't be supported.])
dnl **** Check for libtiff ****
if test "x$with_tiff" != "xno"
then

View File

@ -1,7 +1,7 @@
MODULE = windowscodecs.dll
IMPORTLIB = windowscodecs
IMPORTS = windowscodecs uuid ole32 oleaut32 propsys rpcrt4 shlwapi user32 gdi32 advapi32
EXTRAINCL = $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS)
IMPORTS = $(PNG_PE_LIBS) windowscodecs uuid ole32 oleaut32 propsys rpcrt4 shlwapi user32 gdi32 advapi32
EXTRAINCL = $(PNG_PE_CFLAGS) $(JPEG_CFLAGS) $(TIFF_CFLAGS)
EXTRALIBS = $(APPLICATIONSERVICES_LIBS)
C_SRCS = \

View File

@ -17,17 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if 0
#pragma makedep unix
#endif
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#ifdef SONAME_LIBPNG
#include <png.h>
#endif
#define NONAMELESSUNION
@ -44,119 +35,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
#ifdef SONAME_LIBPNG
static void *libpng_handle;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR(png_create_info_struct);
MAKE_FUNCPTR(png_create_read_struct);
MAKE_FUNCPTR(png_create_write_struct);
MAKE_FUNCPTR(png_destroy_read_struct);
MAKE_FUNCPTR(png_destroy_write_struct);
MAKE_FUNCPTR(png_error);
MAKE_FUNCPTR(png_get_bit_depth);
MAKE_FUNCPTR(png_get_color_type);
MAKE_FUNCPTR(png_get_error_ptr);
MAKE_FUNCPTR(png_get_iCCP);
MAKE_FUNCPTR(png_get_image_height);
MAKE_FUNCPTR(png_get_image_width);
MAKE_FUNCPTR(png_get_io_ptr);
MAKE_FUNCPTR(png_get_pHYs);
MAKE_FUNCPTR(png_get_PLTE);
MAKE_FUNCPTR(png_get_tRNS);
MAKE_FUNCPTR(png_read_image);
MAKE_FUNCPTR(png_read_info);
MAKE_FUNCPTR(png_set_bgr);
MAKE_FUNCPTR(png_set_crc_action);
MAKE_FUNCPTR(png_set_error_fn);
MAKE_FUNCPTR(png_set_filler);
MAKE_FUNCPTR(png_set_filter);
MAKE_FUNCPTR(png_set_gray_to_rgb);
MAKE_FUNCPTR(png_set_IHDR);
MAKE_FUNCPTR(png_set_interlace_handling);
MAKE_FUNCPTR(png_set_pHYs);
MAKE_FUNCPTR(png_set_PLTE);
MAKE_FUNCPTR(png_set_read_fn);
MAKE_FUNCPTR(png_set_swap);
MAKE_FUNCPTR(png_set_tRNS);
MAKE_FUNCPTR(png_set_tRNS_to_alpha);
MAKE_FUNCPTR(png_set_write_fn);
MAKE_FUNCPTR(png_write_end);
MAKE_FUNCPTR(png_write_info);
MAKE_FUNCPTR(png_write_rows);
#undef MAKE_FUNCPTR
static CRITICAL_SECTION init_png_cs;
static CRITICAL_SECTION_DEBUG init_png_cs_debug =
{
0, 0, &init_png_cs,
{ &init_png_cs_debug.ProcessLocksList,
&init_png_cs_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": init_png_cs") }
};
static CRITICAL_SECTION init_png_cs = { &init_png_cs_debug, -1, 0, 0, 0, 0 };
static void *load_libpng(void)
{
void *result;
RtlEnterCriticalSection(&init_png_cs);
if(!libpng_handle && (libpng_handle = dlopen(SONAME_LIBPNG, RTLD_NOW)) != NULL) {
#define LOAD_FUNCPTR(f) \
if((p##f = dlsym(libpng_handle, #f)) == NULL) { \
libpng_handle = NULL; \
RtlLeaveCriticalSection(&init_png_cs); \
return NULL; \
}
LOAD_FUNCPTR(png_create_info_struct);
LOAD_FUNCPTR(png_create_read_struct);
LOAD_FUNCPTR(png_create_write_struct);
LOAD_FUNCPTR(png_destroy_read_struct);
LOAD_FUNCPTR(png_destroy_write_struct);
LOAD_FUNCPTR(png_error);
LOAD_FUNCPTR(png_get_bit_depth);
LOAD_FUNCPTR(png_get_color_type);
LOAD_FUNCPTR(png_get_error_ptr);
LOAD_FUNCPTR(png_get_image_height);
LOAD_FUNCPTR(png_get_image_width);
LOAD_FUNCPTR(png_get_iCCP);
LOAD_FUNCPTR(png_get_io_ptr);
LOAD_FUNCPTR(png_get_pHYs);
LOAD_FUNCPTR(png_get_PLTE);
LOAD_FUNCPTR(png_get_tRNS);
LOAD_FUNCPTR(png_read_image);
LOAD_FUNCPTR(png_read_info);
LOAD_FUNCPTR(png_set_bgr);
LOAD_FUNCPTR(png_set_crc_action);
LOAD_FUNCPTR(png_set_error_fn);
LOAD_FUNCPTR(png_set_filler);
LOAD_FUNCPTR(png_set_filter);
LOAD_FUNCPTR(png_set_gray_to_rgb);
LOAD_FUNCPTR(png_set_IHDR);
LOAD_FUNCPTR(png_set_interlace_handling);
LOAD_FUNCPTR(png_set_pHYs);
LOAD_FUNCPTR(png_set_PLTE);
LOAD_FUNCPTR(png_set_read_fn);
LOAD_FUNCPTR(png_set_swap);
LOAD_FUNCPTR(png_set_tRNS);
LOAD_FUNCPTR(png_set_tRNS_to_alpha);
LOAD_FUNCPTR(png_set_write_fn);
LOAD_FUNCPTR(png_write_end);
LOAD_FUNCPTR(png_write_info);
LOAD_FUNCPTR(png_write_rows);
#undef LOAD_FUNCPTR
}
result = libpng_handle;
RtlLeaveCriticalSection(&init_png_cs);
return result;
}
struct png_decoder
{
struct decoder decoder;
@ -173,33 +51,16 @@ static inline struct png_decoder *impl_from_decoder(struct decoder* iface)
return CONTAINING_RECORD(iface, struct png_decoder, decoder);
}
static void user_error_fn(png_structp png_ptr, png_const_charp error_message)
{
jmp_buf *pjmpbuf;
/* This uses setjmp/longjmp just like the default. We can't use the
* default because there's no way to access the jmp buffer in the png_struct
* that works in 1.2 and 1.4 and allows us to dynamically load libpng. */
WARN("PNG error: %s\n", debugstr_a(error_message));
pjmpbuf = ppng_get_error_ptr(png_ptr);
longjmp(*pjmpbuf, 1);
}
static void user_warning_fn(png_structp png_ptr, png_const_charp warning_message)
{
WARN("PNG warning: %s\n", debugstr_a(warning_message));
}
static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
IStream *stream = ppng_get_io_ptr(png_ptr);
IStream *stream = png_get_io_ptr(png_ptr);
HRESULT hr;
ULONG bytesread;
hr = stream_read(stream, data, length, &bytesread);
if (FAILED(hr) || bytesread != length)
{
ppng_error(png_ptr, "failed reading data");
png_error(png_ptr, "failed reading data");
}
}
@ -208,7 +69,6 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
struct png_decoder *This = impl_from_decoder(iface);
png_structp png_ptr;
png_infop info_ptr;
jmp_buf jmpbuf;
HRESULT hr = E_FAIL;
int color_type, bit_depth;
png_bytep trans;
@ -227,27 +87,26 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
png_uint_32 cp_len;
int cp_compression;
png_ptr = ppng_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
return E_FAIL;
}
info_ptr = ppng_create_info_struct(png_ptr);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
ppng_destroy_read_struct(&png_ptr, NULL, NULL);
png_destroy_read_struct(&png_ptr, NULL, NULL);
return E_FAIL;
}
/* set up setjmp/longjmp error handling */
if (setjmp(jmpbuf))
if (setjmp(png_jmpbuf(png_ptr)))
{
hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT;
goto end;
}
ppng_set_error_fn(png_ptr, jmpbuf, user_error_fn, user_warning_fn);
ppng_set_crc_action(png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
png_set_crc_action(png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
/* seek to the start of the stream */
hr = stream_seek(stream, 0, STREAM_SEEK_SET, NULL);
@ -257,21 +116,21 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
}
/* set up custom i/o handling */
ppng_set_read_fn(png_ptr, stream, user_read_data);
png_set_read_fn(png_ptr, stream, user_read_data);
/* read the header */
ppng_read_info(png_ptr, info_ptr);
png_read_info(png_ptr, info_ptr);
/* choose a pixel format */
color_type = ppng_get_color_type(png_ptr, info_ptr);
bit_depth = ppng_get_bit_depth(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
/* PNGs with bit-depth greater than 8 are network byte order. Windows does not expect this. */
if (bit_depth > 8)
ppng_set_swap(png_ptr);
png_set_swap(png_ptr);
/* check for color-keyed alpha */
transparency = ppng_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values);
transparency = png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values);
if (!transparency)
num_trans = 0;
@ -280,8 +139,8 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
{
/* expand to RGBA */
if (color_type == PNG_COLOR_TYPE_GRAY)
ppng_set_gray_to_rgb(png_ptr);
ppng_set_tRNS_to_alpha(png_ptr);
png_set_gray_to_rgb(png_ptr);
png_set_tRNS_to_alpha(png_ptr);
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
@ -289,14 +148,14 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
{
case PNG_COLOR_TYPE_GRAY_ALPHA:
/* WIC does not support grayscale alpha formats so use RGBA */
ppng_set_gray_to_rgb(png_ptr);
png_set_gray_to_rgb(png_ptr);
/* fall through */
case PNG_COLOR_TYPE_RGB_ALPHA:
This->decoder_frame.bpp = bit_depth * 4;
switch (bit_depth)
{
case 8:
ppng_set_bgr(png_ptr);
png_set_bgr(png_ptr);
This->decoder_frame.pixel_format = GUID_WICPixelFormat32bppBGRA;
break;
case 16: This->decoder_frame.pixel_format = GUID_WICPixelFormat64bppRGBA; break;
@ -344,7 +203,7 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
switch (bit_depth)
{
case 8:
ppng_set_bgr(png_ptr);
png_set_bgr(png_ptr);
This->decoder_frame.pixel_format = GUID_WICPixelFormat24bppBGR;
break;
case 16: This->decoder_frame.pixel_format = GUID_WICPixelFormat48bppRGB; break;
@ -360,10 +219,10 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
goto end;
}
This->decoder_frame.width = ppng_get_image_width(png_ptr, info_ptr);
This->decoder_frame.height = ppng_get_image_height(png_ptr, info_ptr);
This->decoder_frame.width = png_get_image_width(png_ptr, info_ptr);
This->decoder_frame.height = png_get_image_height(png_ptr, info_ptr);
ret = ppng_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type);
ret = png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type);
if (ret && unit_type == PNG_RESOLUTION_METER)
{
@ -376,7 +235,7 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
This->decoder_frame.dpix = This->decoder_frame.dpiy = 96.0;
}
ret = ppng_get_iCCP(png_ptr, info_ptr, &cp_name, &cp_compression, &cp_profile, &cp_len);
ret = png_get_iCCP(png_ptr, info_ptr, &cp_name, &cp_compression, &cp_profile, &cp_len);
if (ret)
{
This->decoder_frame.num_color_contexts = 1;
@ -394,7 +253,7 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
ret = ppng_get_PLTE(png_ptr, info_ptr, &png_palette, &num_palette);
ret = png_get_PLTE(png_ptr, info_ptr, &png_palette, &num_palette);
if (!ret)
{
ERR("paletted image with no PLTE chunk\n");
@ -455,7 +314,7 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
for (i=0; i<This->decoder_frame.height; i++)
row_pointers[i] = This->image_bits + i * This->stride;
ppng_read_image(png_ptr, row_pointers);
png_read_image(png_ptr, row_pointers);
free(row_pointers);
row_pointers = NULL;
@ -472,7 +331,7 @@ static HRESULT CDECL png_decoder_initialize(struct decoder *iface, IStream *stre
hr = S_OK;
end:
ppng_destroy_read_struct(&png_ptr, &info_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
free(row_pointers);
if (FAILED(hr))
{
@ -612,12 +471,6 @@ HRESULT CDECL png_decoder_create(struct decoder_info *info, struct decoder **res
{
struct png_decoder *This;
if (!load_libpng())
{
ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG);
return E_FAIL;
}
This = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*This));
if (!This)
@ -685,14 +538,14 @@ static inline struct png_encoder *impl_from_encoder(struct encoder* iface)
static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
struct png_encoder *This = ppng_get_io_ptr(png_ptr);
struct png_encoder *This = png_get_io_ptr(png_ptr);
HRESULT hr;
ULONG byteswritten;
hr = stream_write(This->stream, data, length, &byteswritten);
if (FAILED(hr) || byteswritten != length)
{
ppng_error(png_ptr, "failed writing data");
png_error(png_ptr, "failed writing data");
}
}
@ -703,19 +556,18 @@ static void user_flush(png_structp png_ptr)
static HRESULT CDECL png_encoder_initialize(struct encoder *encoder, IStream *stream)
{
struct png_encoder *This = impl_from_encoder(encoder);
jmp_buf jmpbuf;
TRACE("(%p,%p)\n", encoder, stream);
/* initialize libpng */
This->png_ptr = ppng_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
This->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!This->png_ptr)
return E_FAIL;
This->info_ptr = ppng_create_info_struct(This->png_ptr);
This->info_ptr = png_create_info_struct(This->png_ptr);
if (!This->info_ptr)
{
ppng_destroy_write_struct(&This->png_ptr, NULL);
png_destroy_write_struct(&This->png_ptr, NULL);
This->png_ptr = NULL;
return E_FAIL;
}
@ -723,17 +575,16 @@ static HRESULT CDECL png_encoder_initialize(struct encoder *encoder, IStream *st
This->stream = stream;
/* set up setjmp/longjmp error handling */
if (setjmp(jmpbuf))
if (setjmp(png_jmpbuf(This->png_ptr)))
{
ppng_destroy_write_struct(&This->png_ptr, &This->info_ptr);
png_destroy_write_struct(&This->png_ptr, &This->info_ptr);
This->png_ptr = NULL;
This->stream = NULL;
return E_FAIL;
}
ppng_set_error_fn(This->png_ptr, jmpbuf, user_error_fn, user_warning_fn);
/* set up custom i/o handling */
ppng_set_write_fn(This->png_ptr, This, user_write_data, user_flush);
png_set_write_fn(This->png_ptr, This, user_write_data, user_flush);
return S_OK;
}
@ -761,7 +612,6 @@ static HRESULT CDECL png_encoder_get_supported_format(struct encoder* iface, GUI
static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const struct encoder_frame *encoder_frame)
{
struct png_encoder *This = impl_from_encoder(encoder);
jmp_buf jmpbuf;
int i;
for (i=0; formats[i].guid; i++)
@ -780,11 +630,9 @@ static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const str
}
/* set up setjmp/longjmp error handling */
if (setjmp(jmpbuf))
if (setjmp(png_jmpbuf(This->png_ptr)))
return E_FAIL;
ppng_set_error_fn(This->png_ptr, jmpbuf, user_error_fn, user_warning_fn);
This->encoder_frame = *encoder_frame;
This->lines_written = 0;
@ -799,16 +647,16 @@ static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const str
/* Tell PNG we need to byte swap if writing a >8-bpp image */
if (This->format->bit_depth > 8)
ppng_set_swap(This->png_ptr);
png_set_swap(This->png_ptr);
ppng_set_IHDR(This->png_ptr, This->info_ptr, encoder_frame->width, encoder_frame->height,
png_set_IHDR(This->png_ptr, This->info_ptr, encoder_frame->width, encoder_frame->height,
This->format->bit_depth, This->format->color_type,
encoder_frame->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if (encoder_frame->dpix != 0.0 && encoder_frame->dpiy != 0.0)
{
ppng_set_pHYs(This->png_ptr, This->info_ptr, (encoder_frame->dpix+0.0127) / 0.0254,
png_set_pHYs(This->png_ptr, This->info_ptr, (encoder_frame->dpix+0.0127) / 0.0254,
(encoder_frame->dpiy+0.0127) / 0.0254, PNG_RESOLUTION_METER);
}
@ -833,22 +681,22 @@ static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const str
num_trans = i+1;
}
ppng_set_PLTE(This->png_ptr, This->info_ptr, png_palette, colors);
png_set_PLTE(This->png_ptr, This->info_ptr, png_palette, colors);
if (num_trans)
ppng_set_tRNS(This->png_ptr, This->info_ptr, trans, num_trans, NULL);
png_set_tRNS(This->png_ptr, This->info_ptr, trans, num_trans, NULL);
}
ppng_write_info(This->png_ptr, This->info_ptr);
png_write_info(This->png_ptr, This->info_ptr);
if (This->format->remove_filler)
ppng_set_filler(This->png_ptr, 0, PNG_FILLER_AFTER);
png_set_filler(This->png_ptr, 0, PNG_FILLER_AFTER);
if (This->format->swap_rgb)
ppng_set_bgr(This->png_ptr);
png_set_bgr(This->png_ptr);
if (encoder_frame->interlace)
This->passes = ppng_set_interlace_handling(This->png_ptr);
This->passes = png_set_interlace_handling(This->png_ptr);
if (encoder_frame->filter != WICPngFilterUnspecified)
{
@ -863,7 +711,7 @@ static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const str
/* WICPngFilterAdaptive */ PNG_ALL_FILTERS,
};
ppng_set_filter(This->png_ptr, 0, png_filter_map[encoder_frame->filter]);
png_set_filter(This->png_ptr, 0, png_filter_map[encoder_frame->filter]);
}
return S_OK;
@ -872,7 +720,6 @@ static HRESULT CDECL png_encoder_create_frame(struct encoder *encoder, const str
static HRESULT CDECL png_encoder_write_lines(struct encoder* encoder, BYTE *data, DWORD line_count, DWORD stride)
{
struct png_encoder *This = impl_from_encoder(encoder);
jmp_buf jmpbuf;
png_byte **row_pointers=NULL;
UINT i;
@ -890,14 +737,12 @@ static HRESULT CDECL png_encoder_write_lines(struct encoder* encoder, BYTE *data
}
/* set up setjmp/longjmp error handling */
if (setjmp(jmpbuf))
if (setjmp(png_jmpbuf(This->png_ptr)))
{
free(row_pointers);
return E_FAIL;
}
ppng_set_error_fn(This->png_ptr, jmpbuf, user_error_fn, user_warning_fn);
row_pointers = malloc(line_count * sizeof(png_byte*));
if (!row_pointers)
return E_OUTOFMEMORY;
@ -905,7 +750,7 @@ static HRESULT CDECL png_encoder_write_lines(struct encoder* encoder, BYTE *data
for (i=0; i<line_count; i++)
row_pointers[i] = data + stride * i;
ppng_write_rows(This->png_ptr, row_pointers, line_count);
png_write_rows(This->png_ptr, row_pointers, line_count);
This->lines_written += line_count;
free(row_pointers);
@ -916,18 +761,15 @@ static HRESULT CDECL png_encoder_write_lines(struct encoder* encoder, BYTE *data
static HRESULT CDECL png_encoder_commit_frame(struct encoder *encoder)
{
struct png_encoder *This = impl_from_encoder(encoder);
jmp_buf jmpbuf;
png_byte **row_pointers=NULL;
/* set up setjmp/longjmp error handling */
if (setjmp(jmpbuf))
if (setjmp(png_jmpbuf(This->png_ptr)))
{
free(row_pointers);
return E_FAIL;
}
ppng_set_error_fn(This->png_ptr, jmpbuf, user_error_fn, user_warning_fn);
if (This->encoder_frame.interlace)
{
int i;
@ -940,10 +782,10 @@ static HRESULT CDECL png_encoder_commit_frame(struct encoder *encoder)
row_pointers[i] = This->data + This->stride * i;
for (i=0; i<This->passes; i++)
ppng_write_rows(This->png_ptr, row_pointers, This->encoder_frame.height);
png_write_rows(This->png_ptr, row_pointers, This->encoder_frame.height);
}
ppng_write_end(This->png_ptr, This->info_ptr);
png_write_end(This->png_ptr, This->info_ptr);
free(row_pointers);
@ -959,7 +801,7 @@ static void CDECL png_encoder_destroy(struct encoder *encoder)
{
struct png_encoder *This = impl_from_encoder(encoder);
if (This->png_ptr)
ppng_destroy_write_struct(&This->png_ptr, &This->info_ptr);
png_destroy_write_struct(&This->png_ptr, &This->info_ptr);
free(This->data);
RtlFreeHeap(GetProcessHeap(), 0, This);
}
@ -978,12 +820,6 @@ HRESULT CDECL png_encoder_create(struct encoder_info *info, struct encoder **res
{
struct png_encoder *This;
if (!load_libpng())
{
ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG);
return E_FAIL;
}
This = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*This));
if (!This)
@ -1006,19 +842,3 @@ HRESULT CDECL png_encoder_create(struct encoder_info *info, struct encoder **res
return S_OK;
}
#else
HRESULT CDECL png_decoder_create(struct decoder_info *info, struct decoder **result)
{
ERR("Trying to load PNG picture, but PNG support is not compiled in.\n");
return E_FAIL;
}
HRESULT CDECL png_encoder_create(struct encoder_info *info, struct encoder **result)
{
ERR("Trying to save PNG picture, but PNG support is not compiled in.\n");
return E_FAIL;
}
#endif

View File

@ -251,7 +251,7 @@ HRESULT PngDecoder_CreateInstance(REFIID iid, void** ppv)
struct decoder *decoder;
struct decoder_info decoder_info;
hr = get_unix_decoder(&CLSID_WICPngDecoder, &decoder_info, &decoder);
hr = png_decoder_create(&decoder_info, &decoder);
if (SUCCEEDED(hr))
hr = CommonDecoder_CreateInstance(decoder, &decoder_info, iid, ppv);
@ -265,7 +265,7 @@ HRESULT PngEncoder_CreateInstance(REFIID iid, void** ppv)
struct encoder *encoder;
struct encoder_info encoder_info;
hr = get_unix_encoder(&CLSID_WICPngEncoder, &encoder_info, &encoder);
hr = png_encoder_create(&encoder_info, &encoder);
if (SUCCEEDED(hr))
hr = CommonEncoder_CreateInstance(encoder, &encoder_info, iid, ppv);

View File

@ -69,10 +69,6 @@ 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)
{
if (IsEqualGUID(decoder_clsid, &CLSID_WICPngDecoder)||
IsEqualGUID(decoder_clsid, &CLSID_WICPngDecoder2))
return png_decoder_create(info, result);
if (IsEqualGUID(decoder_clsid, &CLSID_WICTiffDecoder))
return tiff_decoder_create(info, result);
@ -84,9 +80,6 @@ HRESULT CDECL decoder_create(const CLSID *decoder_clsid, struct decoder_info *in
HRESULT CDECL encoder_create(const CLSID *encoder_clsid, struct encoder_info *info, struct encoder **result)
{
if (IsEqualGUID(encoder_clsid, &CLSID_WICPngEncoder))
return png_encoder_create(info, result);
if (IsEqualGUID(encoder_clsid, &CLSID_WICTiffEncoder))
return tiff_encoder_create(info, result);

View File

@ -450,9 +450,6 @@
/* Define to 1 if you have the `pipe2' function. */
#undef HAVE_PIPE2
/* Define to 1 if you have the <png.h> header file. */
#undef HAVE_PNG_H
/* Define to 1 if you have the <poll.h> header file. */
#undef HAVE_POLL_H
@ -1025,9 +1022,6 @@
/* Define to the soname of the libOSMesa library. */
#undef SONAME_LIBOSMESA
/* Define to the soname of the libpng library. */
#undef SONAME_LIBPNG
/* Define to the soname of the libsane library. */
#undef SONAME_LIBSANE