From 10f1352f6fd798b832d03f8fc1ac693d88b81cbd Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 1 May 2020 23:20:48 +0100 Subject: [PATCH] clean up, add benchmarks --- README.md | 27 ++++++++++++++++++++++++++- configure.ac | 10 +++++----- libvips/foreign/spngload.c | 17 +++++++++-------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1b4c4e6d..44b5d3ce 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Build libspng: ``` cd libspng -meson build --prefix=/home/john/vips --libdir=/home/john/vips/lib +meson build --prefix=/home/john/vips --libdir=/home/john/vips/lib \ + --buildtype=release cd build ninja ninja install @@ -26,6 +27,30 @@ Sample code: https://github.com/randy408/libspng/blob/master/examples/example.c +libspng benchmark: + +``` +$ time vips avg wtc.png +151.549325 + +real 0m3.167s +user 0m3.714s +sys 0m0.194s +``` + +And for libpng: + +``` +$ time vips avg wtc.png +117.065766 + +real 0m3.816s +user 0m4.177s +sys 0m0.221s +``` + +The avg is different since libspng is generating alpha 255. + # Introduction libvips is a [demand-driven, horizontally diff --git a/configure.ac b/configure.ac index e44866e9..90ca3d0a 100644 --- a/configure.ac +++ b/configure.ac @@ -1176,13 +1176,13 @@ FIND_GIFLIB( ) # Look for libspng first -AC_ARG_WITH([spng], - AS_HELP_STRING([--without-spng], [build without libspng (default: test)])) +AC_ARG_WITH([libspng], + AS_HELP_STRING([--without-libspng], [build without libspng (default: test)])) -if test x"$with_spng" != x"no"; then +if test x"$with_libspng" != x"no"; then PKG_CHECK_MODULES(SPNG, spng >= 0.6, [AC_DEFINE(HAVE_SPNG,1,[define if you have libspng installed.]) - with_spng=yes + with_libspng=yes PACKAGES_USED="$PACKAGES_USED spng" with_png=no ], @@ -1413,7 +1413,7 @@ file import with cfitsio: $with_cfitsio file import/export with libwebp: $with_libwebp (requires libwebp, libwebpmux, libwebpdemux 0.6.0 or later) text rendering with pangoft2: $with_pangoft2 -file import/export with libspng: $with_spng +file import/export with libspng: $with_libspng (requires libspng-0.6 or later) file import/export with libpng: $with_png (requires libpng-1.2.9 or later) diff --git a/libvips/foreign/spngload.c b/libvips/foreign/spngload.c index dad90fc0..7d9e36ab 100644 --- a/libvips/foreign/spngload.c +++ b/libvips/foreign/spngload.c @@ -36,6 +36,13 @@ * an enum for interlace_method would be nice ... ADAM7 == 1, * no interlace == 0. * an equivalent of png_sig_cmp() from libpng (is_a_png on a memory area) + * + * This always reads RGBA8 or RGBA16. Other formst G8/G16/GA8 etc. etc. are + * in the roadmap. + * + * Most metadata support (eg. XMP, ICC, etc. etc.) is missing. + * + * Load only, there's no save support for now. */ /* @@ -70,7 +77,6 @@ typedef struct _VipsForeignLoadPng { spng_ctx *ctx; struct spng_ihdr ihdr; - struct spng_trns trns; enum spng_format fmt; int bands; VipsInterpretation interpretation; @@ -96,9 +102,6 @@ vips_foreign_load_png_dispose( GObject *gobject ) dispose( gobject ); } -/* libspng read callbacks should copy length bytes to dest and return 0 - * or SPNG_IO_EOF/SPNG_IO_ERROR on error. - */ static int vips_foreign_load_png_stream( spng_ctx *ctx, void *user, void *dest, size_t length ) @@ -123,7 +126,7 @@ vips_foreign_load_png_get_flags_source( VipsSource *source ) struct spng_ihdr ihdr; VipsForeignFlags flags; - ctx = spng_ctx_new( 0 ); + ctx = spng_ctx_new( SPNG_CTX_IGNORE_ADLER32 ); spng_set_crc_action( ctx, SPNG_CRC_USE, SPNG_CRC_USE ); spng_set_png_stream( ctx, vips_foreign_load_png_stream, source ); @@ -317,9 +320,7 @@ vips_foreign_load_png_generate( VipsRegion *or, printf( " error %s\n", spng_strerror( error ) ); #endif /*DEBUG*/ - /* And bail if fail is on. We have to add an error - * message, since the handler we install just does - * g_warning(). + /* And bail if fail is on. */ if( load->fail ) { vips_error( class->nickname,