From 9bdf5e8cda3e0c63584984282b1e36d97c50bb1a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 1 Apr 2021 12:53:57 +0100 Subject: [PATCH 01/16] try delaying libnsgif alloc until read frame gives the caller a chance to detect memory bombs --- libvips/foreign/libnsgif/libnsgif.c | 41 +++++++++++------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/libvips/foreign/libnsgif/libnsgif.c b/libvips/foreign/libnsgif/libnsgif.c index 55c25999..679522bd 100644 --- a/libvips/foreign/libnsgif/libnsgif.c +++ b/libvips/foreign/libnsgif/libnsgif.c @@ -79,34 +79,17 @@ gif_initialise_sprite(gif_animation *gif, unsigned int width, unsigned int height) { - unsigned int max_width; - unsigned int max_height; - struct bitmap *buffer; - - /* Check if we've changed */ - if ((width <= gif->width) && (height <= gif->height)) { + /* Already allocated? */ + if (gif->frame_image) { return GIF_OK; } - /* Get our maximum values */ - max_width = (width > gif->width) ? width : gif->width; - max_height = (height > gif->height) ? height : gif->height; - - /* Allocate some more memory */ assert(gif->bitmap_callbacks.bitmap_create); - buffer = gif->bitmap_callbacks.bitmap_create(max_width, max_height); - if (buffer == NULL) { + gif->frame_image = gif->bitmap_callbacks.bitmap_create(width, height); + if (gif->frame_image == NULL) { return GIF_INSUFFICIENT_MEMORY; } - assert(gif->bitmap_callbacks.bitmap_destroy); - gif->bitmap_callbacks.bitmap_destroy(gif->frame_image); - gif->frame_image = buffer; - gif->width = max_width; - gif->height = max_height; - - /* Invalidate our currently decoded image */ - gif->decoded_frame = GIF_INVALID_FRAME; return GIF_OK; } @@ -392,10 +375,12 @@ static gif_result gif_initialise_frame(gif_animation *gif) gif->frames[frame].redraw_required = ((gif->frames[frame].disposal_method == GIF_FRAME_CLEAR) || (gif->frames[frame].disposal_method == GIF_FRAME_RESTORE)); - /* Boundary checking - shouldn't ever happen except with junk data */ - if (gif_initialise_sprite(gif, (offset_x + width), (offset_y + height))) { - return GIF_INSUFFICIENT_MEMORY; - } + /* Frame size may have grown. + */ + gif->width = (offset_x + width > gif->width) ? + offset_x + width : gif->width; + gif->height = (offset_y + height > gif->height) ? + offset_y + height : gif->height; /* Decode the flags */ flags = gif_data[9]; @@ -739,6 +724,12 @@ gif_internal_decode_frame(gif_animation *gif, goto gif_decode_frame_exit; } + /* Make sure we have a buffer to decode to. + */ + if (gif_initialise_sprite(gif, gif->width, gif->height)) { + return GIF_INSUFFICIENT_MEMORY; + } + /* Decode the flags */ flags = gif_data[9]; colour_table_size = 2 << (flags & GIF_COLOUR_TABLE_SIZE_MASK); From 701dcc750043d5207cd48e4e993e0534a265df5e Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 1 Apr 2021 19:18:56 +0100 Subject: [PATCH 02/16] nsgifload: enforce maximum GIF dimensions of 16383 The GIF spec allows dimensions up to 65535 (16-bit unsigned), but this equates to 17GB/frame. A common task is to convert animated GIF to animated WebP, and the latter supports dimensions up to 16383 (14-bit unsigned), so that seems like a sensible limit and equates to 1GB/frame. Also makes the error message consistent with other loaders. --- libvips/foreign/nsgifload.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libvips/foreign/nsgifload.c b/libvips/foreign/nsgifload.c index 4b449e80..99c9234b 100644 --- a/libvips/foreign/nsgifload.c +++ b/libvips/foreign/nsgifload.c @@ -534,17 +534,17 @@ vips_foreign_load_nsgif_class_init( VipsForeignLoadNsgifClass *class ) static void * vips_foreign_load_nsgif_bitmap_create( int width, int height ) { - /* Check GIF dimensions fit within 16-bit unsigned. + /* Enforce max GIF dimensions of 16383 (0x7FFF). */ if( width <= 0 || - width > 65535 || + width > 16383 || height <= 0 || - height > 65535 ) { + height > 16383 ) { vips_error( "gifload", - "%s", _( "dimensions out of range ") ); + "%s", _( "bad image dimensions") ); return( NULL ); } - return g_malloc0( width * height * 4 ); + return g_malloc0( (gsize) width * height * 4 ); } static void From 07e73475c18e129e18825426b3071b99f6b6871a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 2 Apr 2021 12:00:50 +0100 Subject: [PATCH 03/16] make a patch for the libnsgif alloc delay --- .../libnsgif/patches/delay-alloc.patch | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 libvips/foreign/libnsgif/patches/delay-alloc.patch diff --git a/libvips/foreign/libnsgif/patches/delay-alloc.patch b/libvips/foreign/libnsgif/patches/delay-alloc.patch new file mode 100644 index 00000000..d7d5f97d --- /dev/null +++ b/libvips/foreign/libnsgif/patches/delay-alloc.patch @@ -0,0 +1,71 @@ +--- libnsgif-orig.c 2021-04-02 11:59:38.120048459 +0100 ++++ libnsgif.c 2021-04-02 11:59:44.439972362 +0100 +@@ -79,34 +79,17 @@ + unsigned int width, + unsigned int height) + { +- unsigned int max_width; +- unsigned int max_height; +- struct bitmap *buffer; +- +- /* Check if we've changed */ +- if ((width <= gif->width) && (height <= gif->height)) { ++ /* Already allocated? */ ++ if (gif->frame_image) { + return GIF_OK; + } + +- /* Get our maximum values */ +- max_width = (width > gif->width) ? width : gif->width; +- max_height = (height > gif->height) ? height : gif->height; +- +- /* Allocate some more memory */ + assert(gif->bitmap_callbacks.bitmap_create); +- buffer = gif->bitmap_callbacks.bitmap_create(max_width, max_height); +- if (buffer == NULL) { ++ gif->frame_image = gif->bitmap_callbacks.bitmap_create(width, height); ++ if (gif->frame_image == NULL) { + return GIF_INSUFFICIENT_MEMORY; + } + +- assert(gif->bitmap_callbacks.bitmap_destroy); +- gif->bitmap_callbacks.bitmap_destroy(gif->frame_image); +- gif->frame_image = buffer; +- gif->width = max_width; +- gif->height = max_height; +- +- /* Invalidate our currently decoded image */ +- gif->decoded_frame = GIF_INVALID_FRAME; + return GIF_OK; + } + +@@ -392,10 +375,12 @@ + gif->frames[frame].redraw_required = ((gif->frames[frame].disposal_method == GIF_FRAME_CLEAR) || + (gif->frames[frame].disposal_method == GIF_FRAME_RESTORE)); + +- /* Boundary checking - shouldn't ever happen except with junk data */ +- if (gif_initialise_sprite(gif, (offset_x + width), (offset_y + height))) { +- return GIF_INSUFFICIENT_MEMORY; +- } ++ /* Frame size may have grown. ++ */ ++ gif->width = (offset_x + width > gif->width) ? ++ offset_x + width : gif->width; ++ gif->height = (offset_y + height > gif->height) ? ++ offset_y + height : gif->height; + + /* Decode the flags */ + flags = gif_data[9]; +@@ -739,6 +724,12 @@ + goto gif_decode_frame_exit; + } + ++ /* Make sure we have a buffer to decode to. ++ */ ++ if (gif_initialise_sprite(gif, gif->width, gif->height)) { ++ return GIF_INSUFFICIENT_MEMORY; ++ } ++ + /* Decode the flags */ + flags = gif_data[9]; + colour_table_size = 2 << (flags & GIF_COLOUR_TABLE_SIZE_MASK); From f726edb7f71f05f2af6f08a7442354c1b70e9383 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 3 Apr 2021 12:28:41 +0100 Subject: [PATCH 04/16] remove stray bitmap_create call missed this one in the delay gif alloc patch --- libvips/foreign/libnsgif/libnsgif.c | 8 -------- .../libnsgif/patches/delay-alloc.patch | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libvips/foreign/libnsgif/libnsgif.c b/libvips/foreign/libnsgif/libnsgif.c index 679522bd..1c4bd00e 100644 --- a/libvips/foreign/libnsgif/libnsgif.c +++ b/libvips/foreign/libnsgif/libnsgif.c @@ -1106,14 +1106,6 @@ gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data) } gif->frame_holders = 1; - /* Initialise the bitmap header */ - assert(gif->bitmap_callbacks.bitmap_create); - gif->frame_image = gif->bitmap_callbacks.bitmap_create(gif->width, gif->height); - if (gif->frame_image == NULL) { - gif_finalise(gif); - return GIF_INSUFFICIENT_MEMORY; - } - /* Remember we've done this now */ gif->buffer_position = gif_data - gif->gif_data; } diff --git a/libvips/foreign/libnsgif/patches/delay-alloc.patch b/libvips/foreign/libnsgif/patches/delay-alloc.patch index d7d5f97d..21630f2b 100644 --- a/libvips/foreign/libnsgif/patches/delay-alloc.patch +++ b/libvips/foreign/libnsgif/patches/delay-alloc.patch @@ -1,5 +1,5 @@ ---- libnsgif-orig.c 2021-04-02 11:59:38.120048459 +0100 -+++ libnsgif.c 2021-04-02 11:59:44.439972362 +0100 +--- libnsgif-orig.c 2021-04-03 12:23:43.700260070 +0100 ++++ libnsgif.c 2021-04-03 12:24:44.079567702 +0100 @@ -79,34 +79,17 @@ unsigned int width, unsigned int height) @@ -69,3 +69,18 @@ /* Decode the flags */ flags = gif_data[9]; colour_table_size = 2 << (flags & GIF_COLOUR_TABLE_SIZE_MASK); +@@ -1115,14 +1106,6 @@ + } + gif->frame_holders = 1; + +- /* Initialise the bitmap header */ +- assert(gif->bitmap_callbacks.bitmap_create); +- gif->frame_image = gif->bitmap_callbacks.bitmap_create(gif->width, gif->height); +- if (gif->frame_image == NULL) { +- gif_finalise(gif); +- return GIF_INSUFFICIENT_MEMORY; +- } +- + /* Remember we've done this now */ + gif->buffer_position = gif_data - gif->gif_data; + } From 234c4684894adca556071d6aebcfeb47db9e967a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 3 Apr 2021 16:32:23 +0100 Subject: [PATCH 05/16] comment fix --- libvips/foreign/tiffsave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/foreign/tiffsave.c b/libvips/foreign/tiffsave.c index 57eda43b..f9a4db2e 100644 --- a/libvips/foreign/tiffsave.c +++ b/libvips/foreign/tiffsave.c @@ -115,7 +115,7 @@ G_DEFINE_ABSTRACT_TYPE( VipsForeignSaveTiff, vips_foreign_save_tiff, #define UC VIPS_FORMAT_UCHAR -/* Type promotion for save ... just always go to uchar. +/* Type promotion for jpeg-in-tiff save ... just always go to uchar. */ static int bandfmt_jpeg[10] = { /* UC C US S UI I F X D DX */ From 930078a6f971ccc4abf5568d384975c36fbad54c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 3 Apr 2021 18:50:18 +0100 Subject: [PATCH 06/16] note jp2k support in README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e7cc567..0c512df1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ operations, frequency filtering, colour, resampling, statistics and others. It supports a large range of [numeric types](https://libvips.github.io/libvips/API/current/VipsImage.html#VipsBandFormat), from 8-bit int to 128-bit complex. Images can have any number of bands. -It supports a good range of image formats, including JPEG, TIFF, PNG, +It supports a good range of image formats, including JPEG, JPEG2000, TIFF, PNG, WebP, HEIC, AVIF, FITS, Matlab, OpenEXR, PDF, SVG, HDR, PPM / PGM / PFM, CSV, GIF, Analyze, NIfTI, DeepZoom, and OpenSlide. It can also load images via ImageMagick or GraphicsMagick, letting it work with formats like DICOM. @@ -274,6 +274,10 @@ If available, vips can load and save NIfTI images. If available, libvips will directly read (but not write, sadly) OpenEXR images. +### OpenJPEG + +If available, libvips will read and write JPEG2000 images. + ### OpenSlide If available, libvips can load OpenSlide-supported virtual slide From d56a47829b2180558ed9a913030053e110f37394 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 7 Apr 2021 21:44:31 +0100 Subject: [PATCH 07/16] colour: add a fallback for the increasingly-common P3 profile Uses the CC0-licensed 'magic' compatibility profile from https://github.com/saucecontrol/Compact-ICC-Profiles#display-p3 --- libvips/colour/profiles.c | 59 +++++++++++++++++++++++++++++++++ libvips/colour/profiles/p3.icm | Bin 0 -> 736 bytes 2 files changed, 59 insertions(+) create mode 100644 libvips/colour/profiles/p3.icm diff --git a/libvips/colour/profiles.c b/libvips/colour/profiles.c index 521faa98..76b5d62f 100644 --- a/libvips/colour/profiles.c +++ b/libvips/colour/profiles.c @@ -32143,6 +32143,64 @@ static VipsProfileFallback vips__profile_fallback_cmyk = { } }; +static VipsProfileFallback vips__profile_fallback_p3 = { + "p3", + 736, + { + 0x78, 0xDA, 0x7D, 0xD0, 0x03, 0xA0, 0xE4, 0x30, 0x14, 0x05, 0xD0, 0x57, + 0x7C, 0xDB, 0xB6, 0x6D, 0xDB, 0xB6, 0x8D, 0xB1, 0xD1, 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D, 0x77, 0xA7, 0xE1, 0xEE, 0x33, 0xFB, + 0xE6, 0x1E, 0xEC, 0x78, 0xA4, 0xF6, 0x78, 0xDC, 0x29, 0xD7, 0xB3, 0xC6, + 0x17, 0xC8, 0x4B, 0x1F, 0xAE, 0xBE, 0xBB, 0x89, 0xDD, 0xD1, 0xBD, 0x6F, + 0xFB, 0x28, 0xF4, 0x69, 0xE1, 0x0B, 0xEA, 0xF5, 0xD8, 0x77, 0x7B, 0x3E, + 0x7E, 0xFC, 0x04, 0xD4, 0xCA, 0xD2, 0x46, + } +}; + static VipsProfileFallback vips__profile_fallback_sRGB = { "sRGB", 6922, @@ -32348,6 +32406,7 @@ static VipsProfileFallback vips__profile_fallback_sRGB = { VipsProfileFallback *vips__profile_fallback_table[] = { &vips__profile_fallback_cmyk, + &vips__profile_fallback_p3, &vips__profile_fallback_sRGB, NULL }; diff --git a/libvips/colour/profiles/p3.icm b/libvips/colour/profiles/p3.icm new file mode 100644 index 0000000000000000000000000000000000000000..cfe315d39333cd92c907dafdeeb1350b780ac182 GIT binary patch literal 736 zcmZQzV0w^~oLkH!z`&53S5g$@?xYYA8KuDfh=G|wgn^TRk3lvuxwybL*e!$s2#OQS zi<3)=azJbZ_;!tf5yZQ!n~|88Qk~C#`hlyXnZ3V@>1nApNrXDAEY6hF;$)!A2Oy41 zE+{HtU|{3{vU$o&3P5ZLAX}se=qMmt2gFW?upL0`BnTViHj$!`AZMVO3?QyZM`9-- zv7vSWl{2sw2N(m@BS1-N1<*bQ24`mj22dD4WIhLi{l+ME1|imbpMk-4KS&-S<^|+$ zG-qJo+KLd|Z#NIj(Yg zavtWg=i1Nh#C?({gy$h|2_GllB7O({2Li2vx`MZax`ge7zlm%TEfg~o`zwA*Vy0xC zl$*4Y471F0*$Z-e<<}`JQJkkVM|r-=Qq_%W2h^`>yw&2;*47Est4ssH~0)XLIE literal 0 HcmV?d00001 From db22eb4d4f867e4eccf6374d1640160fb152fd67 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 8 Apr 2021 10:53:15 +0100 Subject: [PATCH 08/16] add p3.icm to makefile.am and fix make dist --- libvips/colour/profiles/Makefile.am | 1 + po/POTFILES.in | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/colour/profiles/Makefile.am b/libvips/colour/profiles/Makefile.am index fc8f9734..b9d87a46 100644 --- a/libvips/colour/profiles/Makefile.am +++ b/libvips/colour/profiles/Makefile.am @@ -1,3 +1,4 @@ EXTRA_DIST = \ + p3.icm \ cmyk.icm \ sRGB.icm diff --git a/po/POTFILES.in b/po/POTFILES.in index 6152da50..87cbcb90 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -2,7 +2,6 @@ cplusplus/include/vips/VConnection8.h cplusplus/include/vips/VError8.h cplusplus/include/vips/VImage8.h cplusplus/include/vips/VInterpolate8.h -cplusplus/include/vips/vips-operators.h libvips/include/vips/arithmetic.h libvips/include/vips/basic.h libvips/include/vips/buf.h From 8412b8233c8f37ab00dc85f4e9976df191da242c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 10:59:50 +0100 Subject: [PATCH 09/16] start adding colour text rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit try eg. vips text x.png 😀 --rgba --dpi 300 But it's not working :( need to tyweak something else? --- libvips/create/text.c | 57 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/libvips/create/text.c b/libvips/create/text.c index a750c8ec..bfa6dd4d 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -94,6 +94,7 @@ typedef struct _VipsText { gboolean justify; int dpi; char *fontfile; + gboolean rgba; FT_Bitmap bitmap; PangoContext *context; @@ -342,6 +343,9 @@ vips_text_build( VipsObject *object ) VipsText *text = (VipsText *) object; VipsRect extents; + int bands; + VipsInterpretation interpretation; + FT_Pixel_Mode pixel_mode; int y; if( VIPS_OBJECT_CLASS( vips_text_parent_class )->build( object ) ) @@ -399,8 +403,19 @@ vips_text_build( VipsObject *object ) return( -1 ); } + if( text->rgba ) { + interpretation = VIPS_INTERPRETATION_sRGB; + bands = 4; + pixel_mode = FT_PIXEL_MODE_BGRA; + } + else { + interpretation = VIPS_INTERPRETATION_MULTIBAND; + bands = 1; + pixel_mode = FT_PIXEL_MODE_GRAY; + } + text->bitmap.width = extents.width; - text->bitmap.pitch = (text->bitmap.width + 3) & ~3; + text->bitmap.pitch = (bands * text->bitmap.width + 3) & ~3; text->bitmap.rows = extents.height; if( !(text->bitmap.buffer = VIPS_ARRAY( NULL, @@ -409,25 +424,31 @@ vips_text_build( VipsObject *object ) return( -1 ); } text->bitmap.num_grays = 256; - text->bitmap.pixel_mode = ft_pixel_mode_grays; + text->bitmap.pixel_mode = pixel_mode; memset( text->bitmap.buffer, 0x00, text->bitmap.pitch * text->bitmap.rows ); pango_ft2_render_layout( &text->bitmap, text->layout, -extents.left, -extents.top ); + /* Set DPI as pixels/mm. + */ + vips_image_init_fields( create->out, + text->bitmap.width, text->bitmap.rows, bands, + VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, + interpretation, text->dpi / 25.4, text->dpi / 25.4 ); + g_mutex_unlock( vips_text_lock ); - vips_image_init_fields( create->out, - text->bitmap.width, text->bitmap.rows, 1, - VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, - VIPS_INTERPRETATION_MULTIBAND, - 1.0, 1.0 ); - vips_image_pipelinev( create->out, - VIPS_DEMAND_STYLE_ANY, NULL ); + vips_image_pipelinev( create->out, VIPS_DEMAND_STYLE_ANY, NULL ); create->out->Xoffset = extents.left; create->out->Yoffset = extents.top; + if( text->rgba ) { + /* Convert premultiplied BGRA to RGBA. + */ + } + for( y = 0; y < text->bitmap.rows; y++ ) if( vips_image_write_line( create->out, y, (VipsPel *) text->bitmap.buffer + @@ -534,6 +555,13 @@ vips_text_class_init( VipsTextClass *class ) G_STRUCT_OFFSET( VipsText, fontfile ), NULL ); + VIPS_ARG_BOOL( class, "rgba", 9, + _( "RGBA" ), + _( "Enable RGBA output" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsText, rgba ), + FALSE ); + } static void @@ -563,17 +591,22 @@ vips_text_init( VipsText *text ) * * @justify: %gboolean, justify lines * * @dpi: %gint, render at this resolution * * @autofit_dpi: %gint, read out auto-fitted DPI + * * @rgba: %gboolean, enable RGBA output * * @spacing: %gint, space lines by this in points * - * Draw the string @text to an image. @out is a one-band 8-bit + * Draw the string @text to an image. @out is normally a one-band 8-bit * unsigned char image, with 0 for no text and 255 for text. Values between * are used for anti-aliasing. * + * Set @rgba to enable RGBA output. This is useful for colour emoji rendering, + * or support for pango markup features like `Red!`. + * * @text is the text to render as a UTF-8 string. It can contain Pango markup, - * for example "<i>The</i>Guardian". + * for example `TheGuardian`. * * @font is the font to render with, as a fontconfig name. Examples might be - * "sans 12" or perhaps "bitstream charter bold 10". + * `sans 12` or perhaps `bitstream charter bold 10`. * * You can specify a font to load with @fontfile. You'll need to also set the * name of the font with @font. From f53959b82475946a3f9b29d0ac98d34a9b906d5f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 15:11:18 +0100 Subject: [PATCH 10/16] switch font rendering to pangocairo to make colour font rendering work --- ChangeLog | 1 + configure.ac | 30 +++++++------- libvips/create/create.c | 8 ++-- libvips/create/text.c | 88 ++++++++++++++++++++++------------------- 4 files changed, 67 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67264ff7..ef45770b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,7 @@ - add vips_image_[set|get]_array_double() - add GIF load with libnsgif - add JPEG2000 load and save +- add "rgba" flag to vips_text() to enable full colour text rendering 22/12/20 start 8.10.6 - don't seek on bad file descriptors [kleisauke] diff --git a/configure.ac b/configure.ac index 9f906b8c..1a7c5ace 100644 --- a/configure.ac +++ b/configure.ac @@ -1083,25 +1083,25 @@ fi VIPS_CFLAGS="$VIPS_CFLAGS $LIBWEBP_CFLAGS" VIPS_LIBS="$VIPS_LIBS $LIBWEBP_LIBS" -# pangoft2 -AC_ARG_WITH([pangoft2], - AS_HELP_STRING([--without-pangoft2], - [build without pangoft2 (default: test)])) +# pangocairo for text rendering +AC_ARG_WITH([pangocairo], + AS_HELP_STRING([--without-pangocairo], + [build without pangocairo (default: test)])) -if test x"$with_pangoft2" != x"no"; then - PKG_CHECK_MODULES(PANGOFT2, pangoft2, - [AC_DEFINE(HAVE_PANGOFT2,1,[define if you have pangoft2 installed.]) - with_pangoft2=yes - PACKAGES_USED="$PACKAGES_USED pangoft2" +if test x"$with_pangocairo" != x"no"; then + PKG_CHECK_MODULES(PANGOCAIRO, pangocairo, + [AC_DEFINE(HAVE_PANGOCAIRO,1,[define if you have pangocairo installed.]) + with_pangocairo=yes + PACKAGES_USED="$PACKAGES_USED pangocairo" ], - [AC_MSG_WARN([pangoft2 not found; disabling pangoft2 support]) - with_pangoft2=no + [AC_MSG_WARN([pangocairo not found; disabling pangocairo support]) + with_pangocairo=no ] ) fi -VIPS_CFLAGS="$VIPS_CFLAGS $PANGOFT2_CFLAGS" -VIPS_LIBS="$VIPS_LIBS $PANGOFT2_LIBS" +VIPS_CFLAGS="$VIPS_CFLAGS $PANGOCAIRO_CFLAGS" +VIPS_LIBS="$VIPS_LIBS $PANGOCAIRO_LIBS" # look for TIFF with pkg-config ... fall back to our tester # pkgconfig support for libtiff starts with libtiff-4 @@ -1325,7 +1325,7 @@ use fftw3 for FFT: $with_fftw, \ accelerate loops with orc: $with_orc, \ ICC profile support with lcms: $with_lcms, \ zlib: $with_zlib, \ -text rendering with pangoft2: $with_pangoft2, \ +text rendering with pangocairo: $with_pangocairo, \ EXIF metadata support with libexif: $with_libexif, \ JPEG load/save with libjpeg: $with_jpeg, \ PNG load with libspng: $with_libspng, \ @@ -1427,7 +1427,7 @@ accelerate loops with orc: $with_orc (requires orc-0.4.11 or later) ICC profile support with lcms: $with_lcms zlib: $with_zlib -text rendering with pangoft2: $with_pangoft2 +text rendering with pangocairo: $with_pangocairo EXIF metadata support with libexif: $with_libexif ## File format support diff --git a/libvips/create/create.c b/libvips/create/create.c index 93c35796..de1da74c 100644 --- a/libvips/create/create.c +++ b/libvips/create/create.c @@ -116,9 +116,9 @@ vips_create_operation_init( void ) extern GType vips_gaussmat_get_type( void ); extern GType vips_logmat_get_type( void ); extern GType vips_gaussnoise_get_type( void ); -#ifdef HAVE_PANGOFT2 +#ifdef HAVE_PANGOCAIRO extern GType vips_text_get_type( void ); -#endif /*HAVE_PANGOFT2*/ +#endif /*HAVE_PANGOCAIRO*/ extern GType vips_xyz_get_type( void ); extern GType vips_eye_get_type( void ); extern GType vips_grey_get_type( void ); @@ -146,9 +146,9 @@ vips_create_operation_init( void ) vips_gaussmat_get_type(); vips_logmat_get_type(); vips_gaussnoise_get_type(); -#ifdef HAVE_PANGOFT2 +#ifdef HAVE_PANGOCAIRO vips_text_get_type(); -#endif /*HAVE_PANGOFT2*/ +#endif /*HAVE_PANGOCAIRO*/ vips_xyz_get_type(); vips_eye_get_type(); vips_grey_get_type(); diff --git a/libvips/create/text.c b/libvips/create/text.c index bfa6dd4d..71dd9786 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -32,6 +32,9 @@ * - fitting could occasionally terminate early [levmorozov] * 16/5/20 [keiviv] * - don't add fontfiles repeatedly + * 12/4/21 + * - switch to cairo for text rendering + * - add rgba flag */ /* @@ -74,11 +77,13 @@ #include #include +#include -#ifdef HAVE_PANGOFT2 +#ifdef HAVE_PANGOCAIRO +#include #include -#include +#include #include "pcreate.h" @@ -96,7 +101,6 @@ typedef struct _VipsText { char *fontfile; gboolean rgba; - FT_Bitmap bitmap; PangoContext *context; PangoLayout *layout; @@ -130,7 +134,6 @@ vips_text_dispose( GObject *gobject ) VIPS_UNREF( text->layout ); VIPS_UNREF( text->context ); - VIPS_FREE( text->bitmap.buffer ); G_OBJECT_CLASS( vips_text_parent_class )->dispose( gobject ); } @@ -187,8 +190,8 @@ vips_text_get_extents( VipsText *text, VipsRect *extents ) PangoRectangle ink_rect; PangoRectangle logical_rect; - pango_ft2_font_map_set_resolution( - PANGO_FT2_FONT_MAP( vips_text_fontmap ), text->dpi, text->dpi ); + pango_cairo_font_map_set_resolution( + PANGO_CAIRO_FONT_MAP( vips_text_fontmap ), text->dpi ); VIPS_UNREF( text->layout ); if( !(text->layout = text_layout_new( text->context, @@ -345,8 +348,8 @@ vips_text_build( VipsObject *object ) VipsRect extents; int bands; VipsInterpretation interpretation; - FT_Pixel_Mode pixel_mode; - int y; + cairo_surface_t *surface; + cairo_t *cr; if( VIPS_OBJECT_CLASS( vips_text_parent_class )->build( object ) ) return( -1 ); @@ -360,7 +363,7 @@ vips_text_build( VipsObject *object ) g_mutex_lock( vips_text_lock ); if( !vips_text_fontmap ) - vips_text_fontmap = pango_ft2_font_map_new(); + vips_text_fontmap = pango_cairo_font_map_new(); if( !vips_text_fontfiles ) vips_text_fontfiles = g_hash_table_new( g_str_hash, g_str_equal ); @@ -368,6 +371,7 @@ vips_text_build( VipsObject *object ) text->context = pango_font_map_create_context( PANGO_FONT_MAP( vips_text_fontmap ) ); + /* if( text->fontfile && !g_hash_table_lookup( vips_text_fontfiles, text->fontfile ) ) { if( !FcConfigAppFontAddFile( NULL, @@ -382,6 +386,7 @@ vips_text_build( VipsObject *object ) text->fontfile, g_strdup( text->fontfile ) ); } + */ /* If our caller set height and not dpi, we adjust dpi until * we get a fit. @@ -406,54 +411,56 @@ vips_text_build( VipsObject *object ) if( text->rgba ) { interpretation = VIPS_INTERPRETATION_sRGB; bands = 4; - pixel_mode = FT_PIXEL_MODE_BGRA; } else { interpretation = VIPS_INTERPRETATION_MULTIBAND; bands = 1; - pixel_mode = FT_PIXEL_MODE_GRAY; } - text->bitmap.width = extents.width; - text->bitmap.pitch = (bands * text->bitmap.width + 3) & ~3; - text->bitmap.rows = extents.height; - if( !(text->bitmap.buffer = - VIPS_ARRAY( NULL, - text->bitmap.pitch * text->bitmap.rows, VipsPel )) ) { - g_mutex_unlock( vips_text_lock ); - return( -1 ); - } - text->bitmap.num_grays = 256; - text->bitmap.pixel_mode = pixel_mode; - memset( text->bitmap.buffer, 0x00, - text->bitmap.pitch * text->bitmap.rows ); - - pango_ft2_render_layout( &text->bitmap, text->layout, - -extents.left, -extents.top ); - /* Set DPI as pixels/mm. */ vips_image_init_fields( create->out, - text->bitmap.width, text->bitmap.rows, bands, + extents.width, extents.height, bands, VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, interpretation, text->dpi / 25.4, text->dpi / 25.4 ); - g_mutex_unlock( vips_text_lock ); - vips_image_pipelinev( create->out, VIPS_DEMAND_STYLE_ANY, NULL ); create->out->Xoffset = extents.left; create->out->Yoffset = extents.top; - if( text->rgba ) { - /* Convert premultiplied BGRA to RGBA. - */ + if( vips_image_write_prepare( create->out ) ) { + g_mutex_unlock( vips_text_lock ); + return( -1 ); } - for( y = 0; y < text->bitmap.rows; y++ ) - if( vips_image_write_line( create->out, y, - (VipsPel *) text->bitmap.buffer + - y * text->bitmap.pitch ) ) - return( -1 ); + surface = cairo_image_surface_create_for_data( + VIPS_IMAGE_ADDR( create->out, 0, 0 ), + text->rgba ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A8, + create->out->Xsize, create->out->Ysize, + VIPS_IMAGE_SIZEOF_LINE( create->out ) ); + cr = cairo_create( surface ); + cairo_surface_destroy( surface ); + + cairo_translate( cr, -extents.left, -extents.top ); + + pango_cairo_show_layout( cr, text->layout ); + + cairo_destroy( cr ); + + g_mutex_unlock( vips_text_lock ); + + if( text->rgba ) { + int y; + + /* Cairo makes pre-multipled BRGA -- we must byteswap and + * unpremultiply. + */ + for( y = 0; y < create->out->Ysize; y++ ) + vips__premultiplied_bgra2rgba( + (guint32 *) + VIPS_IMAGE_ADDR( create->out, 0, y ), + create->out->Xsize ); + } return( 0 ); } @@ -569,11 +576,10 @@ vips_text_init( VipsText *text ) { text->align = VIPS_ALIGN_LOW; text->dpi = 72; - text->bitmap.buffer = NULL; VIPS_SETSTR( text->font, "sans 12" ); } -#endif /*HAVE_PANGOFT2*/ +#endif /*HAVE_PANGOCAIRO*/ /** * vips_text: From 985a3e2282e635f336f036e6206ca9238b7dfd37 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 15:46:56 +0100 Subject: [PATCH 11/16] reenable fontfile --- libvips/create/text.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libvips/create/text.c b/libvips/create/text.c index 71dd9786..26c4d177 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -84,6 +84,7 @@ #include #include #include +#include #include "pcreate.h" @@ -371,7 +372,6 @@ vips_text_build( VipsObject *object ) text->context = pango_font_map_create_context( PANGO_FONT_MAP( vips_text_fontmap ) ); - /* if( text->fontfile && !g_hash_table_lookup( vips_text_fontfiles, text->fontfile ) ) { if( !FcConfigAppFontAddFile( NULL, @@ -386,7 +386,6 @@ vips_text_build( VipsObject *object ) text->fontfile, g_strdup( text->fontfile ) ); } - */ /* If our caller set height and not dpi, we adjust dpi until * we get a fit. From b4fe2c7b8b01994e0a59479bbc8d65f88166192e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 16:52:14 +0100 Subject: [PATCH 12/16] Note pagocairo dep in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c512df1..45c05f9e 100644 --- a/README.md +++ b/README.md @@ -243,10 +243,10 @@ If you are going to be using libvips with untrusted images, perhaps in a web server, for example, you should consider the security implications of enabling a package with such a large attack surface. -### pangoft2 +### pangocairo If available, libvips adds support for text rendering. You need the -package pangoft2 in `pkg-config --list-all`. +package pangocairo in `pkg-config --list-all`. ### orc-0.4 From b27a10c54727d080e8d51f8d70e7b9c4701689eb Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 16:55:01 +0100 Subject: [PATCH 13/16] ask brew to update/upgrade might help CI failures on macOS --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32d8c34a..67a166f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,9 @@ jobs: - name: Install macOS dependencies if: contains(matrix.os, 'macos') - run: + run: | + brew update + brew upgrade brew install autoconf automake libtool gtk-doc gobject-introspection From 31fe2746266b1f2da457be778b49b8b2f0a6943f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 17:29:54 +0100 Subject: [PATCH 14/16] fix mono rendering always render RGBA, then in mono mode just use the alpha --- libvips/create/text.c | 56 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/libvips/create/text.c b/libvips/create/text.c index 26c4d177..d09f5e5b 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -345,10 +345,10 @@ vips_text_build( VipsObject *object ) VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsCreate *create = VIPS_CREATE( object ); VipsText *text = (VipsText *) object; + VipsImage **t = (VipsImage **) vips_object_local_array( object, 3 ); VipsRect extents; - int bands; - VipsInterpretation interpretation; + VipsImage *image; cairo_surface_t *surface; cairo_t *cr; @@ -407,36 +407,29 @@ vips_text_build( VipsObject *object ) return( -1 ); } - if( text->rgba ) { - interpretation = VIPS_INTERPRETATION_sRGB; - bands = 4; - } - else { - interpretation = VIPS_INTERPRETATION_MULTIBAND; - bands = 1; - } - /* Set DPI as pixels/mm. */ - vips_image_init_fields( create->out, - extents.width, extents.height, bands, + image = t[0] = vips_image_new_memory(); + vips_image_init_fields( image, + extents.width, extents.height, 4, VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, - interpretation, text->dpi / 25.4, text->dpi / 25.4 ); + VIPS_INTERPRETATION_sRGB, + text->dpi / 25.4, text->dpi / 25.4 ); - vips_image_pipelinev( create->out, VIPS_DEMAND_STYLE_ANY, NULL ); - create->out->Xoffset = extents.left; - create->out->Yoffset = extents.top; + vips_image_pipelinev( image, VIPS_DEMAND_STYLE_ANY, NULL ); + image->Xoffset = extents.left; + image->Yoffset = extents.top; - if( vips_image_write_prepare( create->out ) ) { + if( vips_image_write_prepare( image ) ) { g_mutex_unlock( vips_text_lock ); return( -1 ); } surface = cairo_image_surface_create_for_data( - VIPS_IMAGE_ADDR( create->out, 0, 0 ), - text->rgba ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A8, - create->out->Xsize, create->out->Ysize, - VIPS_IMAGE_SIZEOF_LINE( create->out ) ); + VIPS_IMAGE_ADDR( image, 0, 0 ), + CAIRO_FORMAT_ARGB32, + image->Xsize, image->Ysize, + VIPS_IMAGE_SIZEOF_LINE( image ) ); cr = cairo_create( surface ); cairo_surface_destroy( surface ); @@ -454,12 +447,25 @@ vips_text_build( VipsObject *object ) /* Cairo makes pre-multipled BRGA -- we must byteswap and * unpremultiply. */ - for( y = 0; y < create->out->Ysize; y++ ) + for( y = 0; y < image->Ysize; y++ ) vips__premultiplied_bgra2rgba( (guint32 *) - VIPS_IMAGE_ADDR( create->out, 0, y ), - create->out->Xsize ); + VIPS_IMAGE_ADDR( image, 0, y ), + image->Xsize ); } + else { + /* We just want the alpha channel. + */ + if( vips_extract_band( image, &t[1], 3, NULL ) || + vips_copy( t[1], &t[2], + "interpretation", VIPS_INTERPRETATION_MULTIBAND, + NULL ) ) + return( -1 ); + image = t[2]; + } + + if( vips_image_write( image, create->out ) ) + return( -1 ); return( 0 ); } From cc04449dc5d455964809c16d5df088568728eaa0 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 12 Apr 2021 20:40:00 +0100 Subject: [PATCH 15/16] remove extraeous "brew upgrade" --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67a166f7..c038210e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,6 @@ jobs: if: contains(matrix.os, 'macos') run: | brew update - brew upgrade brew install autoconf automake libtool gtk-doc gobject-introspection From 21c565d5d620d7b032066901bcb1b11f6424e504 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 14 Apr 2021 11:32:08 +0100 Subject: [PATCH 16/16] improve comment --- libvips/foreign/nsgifload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libvips/foreign/nsgifload.c b/libvips/foreign/nsgifload.c index 99c9234b..06c5215a 100644 --- a/libvips/foreign/nsgifload.c +++ b/libvips/foreign/nsgifload.c @@ -534,7 +534,8 @@ vips_foreign_load_nsgif_class_init( VipsForeignLoadNsgifClass *class ) static void * vips_foreign_load_nsgif_bitmap_create( int width, int height ) { - /* Enforce max GIF dimensions of 16383 (0x7FFF). + /* Enforce max GIF dimensions of 16383 (0x7FFF). This should be enough + * for anyone, and will prevent the worst GIF bombs. */ if( width <= 0 || width > 16383 || @@ -544,6 +545,7 @@ vips_foreign_load_nsgif_bitmap_create( int width, int height ) "%s", _( "bad image dimensions") ); return( NULL ); } + return g_malloc0( (gsize) width * height * 4 ); }