From eb8ec27c861713f9001661f49f7d8f209971b23b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 13 Jun 2020 11:40:45 +0100 Subject: [PATCH] fix binary ppm read for some width --- configure.ac | 6 ++++-- libvips/foreign/ppmload.c | 17 ++++++++--------- libvips/foreign/ppmsave.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 790b5987..3d133a46 100644 --- a/configure.ac +++ b/configure.ac @@ -1322,8 +1322,9 @@ VIPS_CFLAGS="$VIPS_DEBUG_FLAGS $VIPS_CFLAGS" VIPS_INCLUDES="$ZLIB_INCLUDES $PNG_INCLUDES $TIFF_INCLUDES $JPEG_INCLUDES $NIFTI_INCLUDES" VIPS_LIBS="$ZLIB_LIBS $HEIF_LIBS $MAGICK_LIBS $SPNG_LIBS $PNG_LIBS $IMAGEQUANT_LIBS $TIFF_LIBS $JPEG_LIBS $GTHREAD_LIBS $GIO_LIBS $REQUIRED_LIBS $EXPAT_LIBS $PANGOFT2_LIBS $GSF_LIBS $FFTW_LIBS $ORC_LIBS $LCMS_LIBS $GIFLIB_LIBS $RSVG_LIBS $NIFTI_LIBS $PDFIUM_LIBS $POPPLER_LIBS $OPENEXR_LIBS $OPENSLIDE_LIBS $CFITSIO_LIBS $LIBWEBP_LIBS $LIBWEBPMUX_LIBS $MATIO_LIBS $EXIF_LIBS -lm" -# autoconf hates multi-line AC_SUBST -VIPS_CONFIG="native win32: $vips_os_win32, native OS X: $vips_os_darwin, open files in binary mode: $vips_binary_open, enable debug: $enable_debug, enable deprecated library components: $enable_deprecated, enable docs with gtkdoc: $enable_gtk_doc, gobject introspection: $found_introspection, enable radiance support: $with_radiance, enable analyze support: $with_analyze, enable PPM support: $with_ppm, use fftw3 for FFT: $with_fftw, Magick package: $with_magickpackage, Magick API version: $magick_version, load with libMagick: $enable_magickload, save with libMagick: $enable_magicksave, accelerate loops with orc: $with_orc, ICC profile support with lcms: $with_lcms, file import with niftiio: $with_nifti, file import with libheif: $with_heif, file import with OpenEXR: $with_OpenEXR, file import with OpenSlide: $with_openslide, file import with matio: $with_matio, PDF import with PDFium: $with_pdfium, PDF import with poppler-glib: $with_poppler, SVG import with librsvg-2.0: $with_rsvg, zlib: $with_zlib, file import with cfitsio: $with_cfitsio, file import/export with libwebp: $with_libwebp, text rendering with pangoft2: $with_pangoft2, file import/export with libpng: $with_png, support 8bpp PNG quantisation: $with_imagequant, file import/export with libtiff: $with_tiff, file import/export with giflib: $with_giflib, file import/export with libjpeg: $with_jpeg, image pyramid export: $with_gsf, use libexif to load/save JPEG metadata: $with_libexif" +# autoconf hates multi-line AC_SUBST so we have to have another copy of this +# thing +VIPS_CONFIG="native win32: $vips_os_win32, native OS X: $vips_os_darwin, open files in binary mode: $vips_binary_open, enable debug: $enable_debug, enable deprecated library components: $enable_deprecated, enable docs with gtkdoc: $enable_gtk_doc, gobject introspection: $found_introspection, enable radiance support: $with_radiance, enable analyze support: $with_analyze, enable PPM support: $with_ppm, use fftw3 for FFT: $with_fftw, Magick package: $with_magickpackage, Magick API version: $magick_version, load with libMagick: $enable_magickload, save with libMagick: $enable_magicksave, accelerate loops with orc: $with_orc, ICC profile support with lcms: $with_lcms, file import with niftiio: $with_nifti, file import with libheif: $with_heif, file import with OpenEXR: $with_OpenEXR, file import with OpenSlide: $with_openslide, file import with matio: $with_matio, PDF import with PDFium: $with_pdfium, PDF import with poppler-glib: $with_poppler, SVG import with librsvg-2.0: $with_rsvg, zlib: $with_zlib, file import with cfitsio: $with_cfitsio, file import/export with libwebp: $with_libwebp, text rendering with pangoft2: $with_pangoft2, file import/export with libpng: $with_png, support 8bpp PNG quantisation: $with_imagequant, file import/export with libtiff: $with_tiff, file import/export with giflib: $with_giflib, file import/export with libjpeg: $with_jpeg, image pyramid export: $with_gsf, use libexif to load/save JPEG metadata: $with_libexif, file import/export with libspng: $with_libspng" AC_SUBST(VIPS_LIBDIR) @@ -1382,6 +1383,7 @@ AC_OUTPUT([ fuzz/Makefile ]) +# also add any new items to VIPS_CONFIG above AC_MSG_RESULT([dnl * build options native win32: $vips_os_win32 diff --git a/libvips/foreign/ppmload.c b/libvips/foreign/ppmload.c index 6df91058..727536cb 100644 --- a/libvips/foreign/ppmload.c +++ b/libvips/foreign/ppmload.c @@ -492,23 +492,22 @@ vips_foreign_load_ppm_generate_1bit_binary( VipsRegion *or, VipsImage *image = or->im; int x, y; - int bits; - bits = VIPS_SBUF_GETC( ppm->sbuf ); for( y = 0; y < r->height; y++ ) { VipsPel *q = VIPS_REGION_ADDR( or, 0, r->top + y ); + int bits; + + /* Not needed, but stop a compiler warning. + */ + bits = 0; + for( x = 0; x < image->Xsize; x++ ) { + if( (x & 7) == 0 ) + bits = VIPS_SBUF_GETC( ppm->sbuf ); q[x] = (bits & 128) ? 0 : 255; bits = VIPS_LSHIFT_INT( bits, 1 ); - if( (x & 7) == 7 ) - bits = VIPS_SBUF_GETC( ppm->sbuf ); } - - /* Skip any unaligned bits at end of line. - */ - if( (x & 7) != 0 ) - bits = VIPS_SBUF_GETC( ppm->sbuf ); } return( 0 ); diff --git a/libvips/foreign/ppmsave.c b/libvips/foreign/ppmsave.c index 0f733777..22d6aebb 100644 --- a/libvips/foreign/ppmsave.c +++ b/libvips/foreign/ppmsave.c @@ -161,7 +161,7 @@ vips_foreign_save_ppm_line_binary_squash( VipsForeignSavePpm *ppm, for( x = 0; x < image->Xsize; x++ ) { bits = VIPS_LSHIFT_INT( bits, 1 ); n_bits += 1; - bits |= p[x] ? 0 : 1; + bits |= p[x] > 128 ? 0 : 1; if( n_bits == 8 ) { if( VIPS_TARGET_PUTC( ppm->target, bits ) )