add svgload
load from bubffer is not working though, strange ... it seems to be generating a 16-biit image?
This commit is contained in:
parent
625e0fbd9e
commit
153886d2eb
@ -2,8 +2,8 @@
|
|||||||
- add vips_reduce*() ... a fast path for bicubic downsize
|
- add vips_reduce*() ... a fast path for bicubic downsize
|
||||||
- vips_resize() and vips_similarity() use it when they can
|
- vips_resize() and vips_similarity() use it when they can
|
||||||
- bicubic is better on 32-bit int images
|
- bicubic is better on 32-bit int images
|
||||||
- add pdfload for PDF rendering ... file and buffer input are supported
|
- add pdfload and svgload for PDF and SVG rendering
|
||||||
- vipsthumbnail knows about pdfload
|
- vipsthumbnail knows about pdfload and svgload
|
||||||
|
|
||||||
27/1/16 started 8.2.3
|
27/1/16 started 8.2.3
|
||||||
- fix a crash with SPARC byte-order labq vips images
|
- fix a crash with SPARC byte-order labq vips images
|
||||||
|
2
TODO
2
TODO
@ -1,4 +1,4 @@
|
|||||||
- svg loader?
|
- test suite is failing for svg load from buffer, strange
|
||||||
|
|
||||||
- gif loader?
|
- gif loader?
|
||||||
|
|
||||||
|
22
configure.ac
22
configure.ac
@ -561,6 +561,22 @@ if test x"$with_poppler" != x"no"; then
|
|||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# librsvg
|
||||||
|
AC_ARG_WITH([rsvg],
|
||||||
|
AS_HELP_STRING([--without-rsvg], [build without rsvg (default: test)]))
|
||||||
|
|
||||||
|
if test x"$with_rsvg" != x"no"; then
|
||||||
|
PKG_CHECK_MODULES(RSVG, [librsvg-2.0 >= 2.40 cairo >= 1.2],
|
||||||
|
[AC_DEFINE(HAVE_RSVG,1,[define if you have librsvg-2.0 >= 2.40.0 and cairo >= 1.2 installed.])
|
||||||
|
with_rsvg=yes
|
||||||
|
PACKAGES_USED="$PACKAGES_USED librsvg-2.0 cairo"
|
||||||
|
],
|
||||||
|
[AC_MSG_WARN([librsvg-2.0 >= 2.40.0 or cairo >= 1.2 not found; disabling SVG load via rsvg])
|
||||||
|
with_rsvg=no
|
||||||
|
]
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
# OpenSlide
|
# OpenSlide
|
||||||
AC_ARG_WITH([openslide],
|
AC_ARG_WITH([openslide],
|
||||||
AS_HELP_STRING([--without-openslide],
|
AS_HELP_STRING([--without-openslide],
|
||||||
@ -806,14 +822,14 @@ fi
|
|||||||
# Gather all up for VIPS_CFLAGS, VIPS_INCLUDES, VIPS_LIBS
|
# Gather all up for VIPS_CFLAGS, VIPS_INCLUDES, VIPS_LIBS
|
||||||
# sort includes to get longer, more specific dirs first
|
# sort includes to get longer, more specific dirs first
|
||||||
# helps, for example, selecting graphicsmagick over imagemagick
|
# helps, for example, selecting graphicsmagick over imagemagick
|
||||||
VIPS_CFLAGS=`for i in $VIPS_CFLAGS $GTHREAD_CFLAGS $REQUIRED_CFLAGS $PANGOFT2_CFLAGS $GSF_CFLAGS $FFTW_CFLAGS $MAGICK_CFLAGS $PNG_CFLAGS $EXIF_CFLAGS $MATIO_CFLAGS $CFITSIO_CFLAGS $LIBWEBP_CFLAGS $POPPLER_CFLAGS $OPENEXR_CFLAGS $OPENSLIDE_CFLAGS $ORC_CFLAGS $TIFF_CFLAGS $LCMS_CFLAGS
|
VIPS_CFLAGS=`for i in $VIPS_CFLAGS $GTHREAD_CFLAGS $REQUIRED_CFLAGS $PANGOFT2_CFLAGS $GSF_CFLAGS $FFTW_CFLAGS $MAGICK_CFLAGS $PNG_CFLAGS $EXIF_CFLAGS $MATIO_CFLAGS $CFITSIO_CFLAGS $LIBWEBP_CFLAGS $RSVG_CFLAGS $POPPLER_CFLAGS $OPENEXR_CFLAGS $OPENSLIDE_CFLAGS $ORC_CFLAGS $TIFF_CFLAGS $LCMS_CFLAGS
|
||||||
do
|
do
|
||||||
echo $i
|
echo $i
|
||||||
done | sort -ru`
|
done | sort -ru`
|
||||||
VIPS_CFLAGS=`echo $VIPS_CFLAGS`
|
VIPS_CFLAGS=`echo $VIPS_CFLAGS`
|
||||||
VIPS_CFLAGS="$VIPS_DEBUG_FLAGS $VIPS_CFLAGS"
|
VIPS_CFLAGS="$VIPS_DEBUG_FLAGS $VIPS_CFLAGS"
|
||||||
VIPS_INCLUDES="$PNG_INCLUDES $TIFF_INCLUDES $ZIP_INCLUDES $JPEG_INCLUDES"
|
VIPS_INCLUDES="$PNG_INCLUDES $TIFF_INCLUDES $ZIP_INCLUDES $JPEG_INCLUDES"
|
||||||
VIPS_LIBS="$MAGICK_LIBS $PNG_LIBS $TIFF_LIBS $ZIP_LIBS $JPEG_LIBS $GTHREAD_LIBS $REQUIRED_LIBS $PANGOFT2_LIBS $GSF_LIBS $FFTW_LIBS $ORC_LIBS $LCMS_LIBS $POPPLER_LIBS $OPENEXR_LIBS $OPENSLIDE_LIBS $CFITSIO_LIBS $LIBWEBP_LIBS $MATIO_LIBS $EXIF_LIBS -lm"
|
VIPS_LIBS="$MAGICK_LIBS $PNG_LIBS $TIFF_LIBS $ZIP_LIBS $JPEG_LIBS $GTHREAD_LIBS $REQUIRED_LIBS $PANGOFT2_LIBS $GSF_LIBS $FFTW_LIBS $ORC_LIBS $LCMS_LIBS $RSVG_LIBS $POPPLER_LIBS $OPENEXR_LIBS $OPENSLIDE_LIBS $CFITSIO_LIBS $LIBWEBP_LIBS $MATIO_LIBS $EXIF_LIBS -lm"
|
||||||
|
|
||||||
AC_SUBST(VIPS_LIBDIR)
|
AC_SUBST(VIPS_LIBDIR)
|
||||||
|
|
||||||
@ -901,6 +917,8 @@ file import with OpenSlide: $with_openslide
|
|||||||
file import with matio: $with_matio
|
file import with matio: $with_matio
|
||||||
PDF import with poppler-glib: $with_poppler
|
PDF import with poppler-glib: $with_poppler
|
||||||
(requires poppler-glib 0.30.0 or later)
|
(requires poppler-glib 0.30.0 or later)
|
||||||
|
SVG import with librsvg-2.0: $with_rsvg
|
||||||
|
(requires librsvg-2.0 2.40.0 or later)
|
||||||
file import with cfitsio: $with_cfitsio
|
file import with cfitsio: $with_cfitsio
|
||||||
file import/export with libwebp: $with_libwebp
|
file import/export with libwebp: $with_libwebp
|
||||||
text rendering with pangoft2: $with_pangoft2
|
text rendering with pangoft2: $with_pangoft2
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// headers for vips operations
|
// headers for vips operations
|
||||||
// Mon Feb 8 20:26:08 GMT 2016
|
// Tue Feb 9 10:43:17 GMT 2016
|
||||||
// this file is generated automatically, do not edit!
|
// this file is generated automatically, do not edit!
|
||||||
|
|
||||||
static void system( char * cmd_format , VOption *options = 0 );
|
static void system( char * cmd_format , VOption *options = 0 );
|
||||||
@ -112,6 +112,8 @@ static VImage rawload( char * filename , int width , int height , int bands , VO
|
|||||||
static VImage vipsload( char * filename , VOption *options = 0 );
|
static VImage vipsload( char * filename , VOption *options = 0 );
|
||||||
static VImage pdfload( char * filename , VOption *options = 0 );
|
static VImage pdfload( char * filename , VOption *options = 0 );
|
||||||
static VImage pdfload_buffer( VipsBlob * buffer , VOption *options = 0 );
|
static VImage pdfload_buffer( VipsBlob * buffer , VOption *options = 0 );
|
||||||
|
static VImage svgload( char * filename , VOption *options = 0 );
|
||||||
|
static VImage svgload_buffer( VipsBlob * buffer , VOption *options = 0 );
|
||||||
static VImage pngload( char * filename , VOption *options = 0 );
|
static VImage pngload( char * filename , VOption *options = 0 );
|
||||||
static VImage pngload_buffer( VipsBlob * buffer , VOption *options = 0 );
|
static VImage pngload_buffer( VipsBlob * buffer , VOption *options = 0 );
|
||||||
static VImage matload( char * filename , VOption *options = 0 );
|
static VImage matload( char * filename , VOption *options = 0 );
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// bodies for vips operations
|
// bodies for vips operations
|
||||||
// Mon Feb 8 20:25:58 GMT 2016
|
// Tue Feb 9 10:43:09 GMT 2016
|
||||||
// this file is generated automatically, do not edit!
|
// this file is generated automatically, do not edit!
|
||||||
|
|
||||||
void VImage::system( char * cmd_format , VOption *options )
|
void VImage::system( char * cmd_format , VOption *options )
|
||||||
@ -1432,6 +1432,30 @@ VImage VImage::pdfload_buffer( VipsBlob * buffer , VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::svgload( char * filename , VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "svgload" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "filename", filename ) ->
|
||||||
|
set( "out", &out ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage VImage::svgload_buffer( VipsBlob * buffer , VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "svgload_buffer" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "buffer", buffer ) ->
|
||||||
|
set( "out", &out ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::pngload( char * filename , VOption *options )
|
VImage VImage::pngload( char * filename , VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
|
@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libforeign.la
|
|||||||
|
|
||||||
libforeign_la_SOURCES = \
|
libforeign_la_SOURCES = \
|
||||||
pdfload.c \
|
pdfload.c \
|
||||||
|
svgload.c \
|
||||||
radiance.h \
|
radiance.h \
|
||||||
radiance.c \
|
radiance.c \
|
||||||
radload.c \
|
radload.c \
|
||||||
|
@ -1657,6 +1657,9 @@ vips_foreign_operation_init( void )
|
|||||||
extern GType vips_foreign_load_pdf_get_type( void );
|
extern GType vips_foreign_load_pdf_get_type( void );
|
||||||
extern GType vips_foreign_load_pdf_file_get_type( void );
|
extern GType vips_foreign_load_pdf_file_get_type( void );
|
||||||
extern GType vips_foreign_load_pdf_buffer_get_type( void );
|
extern GType vips_foreign_load_pdf_buffer_get_type( void );
|
||||||
|
extern GType vips_foreign_load_svg_get_type( void );
|
||||||
|
extern GType vips_foreign_load_svg_file_get_type( void );
|
||||||
|
extern GType vips_foreign_load_svg_buffer_get_type( void );
|
||||||
|
|
||||||
vips_foreign_load_rad_get_type();
|
vips_foreign_load_rad_get_type();
|
||||||
vips_foreign_save_rad_get_type();
|
vips_foreign_save_rad_get_type();
|
||||||
@ -1680,6 +1683,12 @@ vips_foreign_operation_init( void )
|
|||||||
vips_foreign_load_pdf_buffer_get_type();
|
vips_foreign_load_pdf_buffer_get_type();
|
||||||
#endif /*HAVE_POPPLER*/
|
#endif /*HAVE_POPPLER*/
|
||||||
|
|
||||||
|
#ifdef HAVE_RSVG
|
||||||
|
vips_foreign_load_svg_get_type();
|
||||||
|
vips_foreign_load_svg_file_get_type();
|
||||||
|
vips_foreign_load_svg_buffer_get_type();
|
||||||
|
#endif /*HAVE_RSVG*/
|
||||||
|
|
||||||
#ifdef HAVE_GSF
|
#ifdef HAVE_GSF
|
||||||
vips_foreign_save_dz_get_type();
|
vips_foreign_save_dz_get_type();
|
||||||
#endif /*HAVE_GSF*/
|
#endif /*HAVE_GSF*/
|
||||||
@ -2936,3 +2945,82 @@ vips_pdfload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
|||||||
|
|
||||||
return( result );
|
return( result );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vips_svgload:
|
||||||
|
* @filename: file to load
|
||||||
|
* @out: output image
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
|
*
|
||||||
|
* Optional arguments:
|
||||||
|
*
|
||||||
|
* @dpi: %gdouble, render at this DPI
|
||||||
|
* @scale: %gdouble, scale render by this factor
|
||||||
|
*
|
||||||
|
* Render a SVG file into a VIPS image. Rendering uses the librsvg library
|
||||||
|
* and should be fast.
|
||||||
|
*
|
||||||
|
* Use @dpi to set the rendering resolution. The default is 72. Alternatively,
|
||||||
|
* you can scale the rendering from the default 1 point == 1 pixel by @scale.
|
||||||
|
*
|
||||||
|
* This function only reads the image header and does not render any pixel
|
||||||
|
* data. Rendering occurs when pixels are accessed.
|
||||||
|
*
|
||||||
|
* See also: vips_image_new_from_file().
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vips_svgload( const char *filename, VipsImage **out, ... )
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
va_start( ap, out );
|
||||||
|
result = vips_call_split( "svgload", ap, filename, out );
|
||||||
|
va_end( ap );
|
||||||
|
|
||||||
|
return( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vips_svgload_buffer:
|
||||||
|
* @buf: memory area to load
|
||||||
|
* @len: size of memory area
|
||||||
|
* @out: image to write
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
|
*
|
||||||
|
* Optional arguments:
|
||||||
|
*
|
||||||
|
* @dpi: %gdouble, render at this DPI
|
||||||
|
* @scale: %gdouble, scale render by this factor
|
||||||
|
*
|
||||||
|
* Read a SVG-formatted memory block into a VIPS image. Exactly as
|
||||||
|
* vips_svgload(), but read from a memory buffer.
|
||||||
|
*
|
||||||
|
* You must not free the buffer while @out is active. The
|
||||||
|
* #VipsObject::postclose signal on @out is a good place to free.
|
||||||
|
*
|
||||||
|
* See also: vips_svgload().
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vips_svgload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
VipsBlob *blob;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
/* We don't take a copy of the data or free it.
|
||||||
|
*/
|
||||||
|
blob = vips_blob_new( NULL, buf, len );
|
||||||
|
|
||||||
|
va_start( ap, out );
|
||||||
|
result = vips_call_split( "svgload_buffer", ap, blob, out );
|
||||||
|
va_end( ap );
|
||||||
|
|
||||||
|
vips_area_unref( VIPS_AREA( blob ) );
|
||||||
|
|
||||||
|
return( result );
|
||||||
|
}
|
||||||
|
@ -263,7 +263,7 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
|
|||||||
* but I have no way of testing this :(
|
* but I have no way of testing this :(
|
||||||
*/
|
*/
|
||||||
for( y = 0; y < r->height; y++ ) {
|
for( y = 0; y < r->height; y++ ) {
|
||||||
VipsPel *q;
|
VipsPel * restrict q;
|
||||||
|
|
||||||
q = VIPS_REGION_ADDR( or, r->left, r->top + y );
|
q = VIPS_REGION_ADDR( or, r->left, r->top + y );
|
||||||
for( x = 0; x < r->width; x++ ) {
|
for( x = 0; x < r->width; x++ ) {
|
||||||
@ -511,7 +511,7 @@ vips_foreign_load_pdf_buffer_class_init(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vips_foreign_load_pdf_buffer_init( VipsForeignLoadPdfBuffer *file )
|
vips_foreign_load_pdf_buffer_init( VipsForeignLoadPdfBuffer *buffer )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
408
libvips/foreign/svgload.c
Normal file
408
libvips/foreign/svgload.c
Normal file
@ -0,0 +1,408 @@
|
|||||||
|
/* load SVG with librsvg
|
||||||
|
*
|
||||||
|
* 7/2/16
|
||||||
|
* - from svgload.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
This file is part of VIPS.
|
||||||
|
|
||||||
|
VIPS is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
02110-1301 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define DEBUG
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif /*HAVE_CONFIG_H*/
|
||||||
|
#include <vips/intl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_RSVG
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <vips/vips.h>
|
||||||
|
#include <vips/buf.h>
|
||||||
|
#include <vips/internal.h>
|
||||||
|
|
||||||
|
#include <cairo.h>
|
||||||
|
#include <librsvg/rsvg.h>
|
||||||
|
|
||||||
|
typedef struct _VipsForeignLoadSvg {
|
||||||
|
VipsForeignLoad parent_object;
|
||||||
|
|
||||||
|
/* Render at this DPI.
|
||||||
|
*/
|
||||||
|
double dpi;
|
||||||
|
|
||||||
|
/* Calculate this from DPI. At 72 DPI, we render 1:1 with cairo.
|
||||||
|
*/
|
||||||
|
double scale;
|
||||||
|
|
||||||
|
RsvgHandle *page;
|
||||||
|
|
||||||
|
} VipsForeignLoadSvg;
|
||||||
|
|
||||||
|
typedef VipsForeignLoadClass VipsForeignLoadSvgClass;
|
||||||
|
|
||||||
|
G_DEFINE_ABSTRACT_TYPE( VipsForeignLoadSvg, vips_foreign_load_svg,
|
||||||
|
VIPS_TYPE_FOREIGN_LOAD );
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_dispose( GObject *gobject )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) gobject;
|
||||||
|
|
||||||
|
VIPS_UNREF( svg->page );
|
||||||
|
|
||||||
|
G_OBJECT_CLASS( vips_foreign_load_svg_parent_class )->
|
||||||
|
dispose( gobject );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_build( VipsObject *object )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) object;
|
||||||
|
|
||||||
|
if( !vips_object_argument_isset( object, "scale" ) )
|
||||||
|
svg->scale = svg->dpi / 72.0;
|
||||||
|
|
||||||
|
if( VIPS_OBJECT_CLASS( vips_foreign_load_svg_parent_class )->
|
||||||
|
build( object ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static VipsForeignFlags
|
||||||
|
vips_foreign_load_svg_get_flags_filename( const char *filename )
|
||||||
|
{
|
||||||
|
/* We can render any part of the page on demand.
|
||||||
|
*/
|
||||||
|
return( VIPS_FOREIGN_PARTIAL );
|
||||||
|
}
|
||||||
|
|
||||||
|
static VipsForeignFlags
|
||||||
|
vips_foreign_load_svg_get_flags( VipsForeignLoad *load )
|
||||||
|
{
|
||||||
|
return( VIPS_FOREIGN_PARTIAL );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg,
|
||||||
|
VipsImage *out )
|
||||||
|
{
|
||||||
|
RsvgDimensionData dimensions;
|
||||||
|
double res;
|
||||||
|
|
||||||
|
rsvg_handle_get_dimensions( svg->page, &dimensions );
|
||||||
|
|
||||||
|
/* We need pixels/mm for vips.
|
||||||
|
*/
|
||||||
|
res = svg->dpi / 25.4;
|
||||||
|
|
||||||
|
vips_image_init_fields( out,
|
||||||
|
dimensions.width * svg->scale, dimensions.height * svg->scale,
|
||||||
|
4, VIPS_FORMAT_UCHAR,
|
||||||
|
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res );
|
||||||
|
|
||||||
|
/* We render to a linecache, so fat strips work well.
|
||||||
|
*/
|
||||||
|
vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_header( VipsForeignLoad *load )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) load;
|
||||||
|
|
||||||
|
vips_foreign_load_svg_parse( svg, load->out );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_generate( VipsRegion *or,
|
||||||
|
void *seq, void *a, void *b, gboolean *stop )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) a;
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( svg );
|
||||||
|
VipsRect *r = &or->valid;
|
||||||
|
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
cairo_t *cr;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
surface = cairo_image_surface_create_for_data(
|
||||||
|
VIPS_REGION_ADDR( or, r->left, r->top ),
|
||||||
|
CAIRO_FORMAT_ARGB32,
|
||||||
|
r->width, r->height,
|
||||||
|
VIPS_REGION_LSKIP( or ) );
|
||||||
|
cr = cairo_create( surface );
|
||||||
|
cairo_surface_destroy( surface );
|
||||||
|
|
||||||
|
cairo_scale( cr, svg->scale, svg->scale );
|
||||||
|
cairo_translate( cr,
|
||||||
|
-r->left / svg->scale, -r->top / svg->scale );
|
||||||
|
|
||||||
|
/* rsvg is single-threaded, but we don't need to lock since we're
|
||||||
|
* running inside a non-threaded tilecache.
|
||||||
|
*/
|
||||||
|
if( !rsvg_handle_render_cairo( svg->page, cr ) ) {
|
||||||
|
vips_error( class->nickname,
|
||||||
|
"%s", _( "SVG rendering failed" ) );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_destroy( cr );
|
||||||
|
|
||||||
|
/* Cairo makes BRGA, we must byteswap. We might not need to on SPARC,
|
||||||
|
* but I have no way of testing this :(
|
||||||
|
*/
|
||||||
|
for( y = 0; y < r->height; y++ ) {
|
||||||
|
VipsPel * restrict q;
|
||||||
|
|
||||||
|
q = VIPS_REGION_ADDR( or, r->left, r->top + y );
|
||||||
|
for( x = 0; x < r->width; x++ ) {
|
||||||
|
VIPS_SWAP( VipsPel, q[0], q[2] );
|
||||||
|
|
||||||
|
q += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_load( VipsForeignLoad *load )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) load;
|
||||||
|
VipsImage **t = (VipsImage **)
|
||||||
|
vips_object_local_array( (VipsObject *) load, 2 );
|
||||||
|
|
||||||
|
/* Read to this image, then cache to out, see below.
|
||||||
|
*/
|
||||||
|
t[0] = vips_image_new();
|
||||||
|
|
||||||
|
vips_foreign_load_svg_parse( svg, t[0] );
|
||||||
|
if( vips_image_generate( t[0],
|
||||||
|
NULL, vips_foreign_load_svg_generate, NULL, svg, NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
/* Don't use tilecache to keep the number of calls to
|
||||||
|
* svg_page_render() low. Don't thread the cache, we rely on
|
||||||
|
* locking to keep svg single-threaded.
|
||||||
|
*/
|
||||||
|
if( vips_linecache( t[0], &t[1],
|
||||||
|
"tile_height", 128,
|
||||||
|
NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
if( vips_image_write( t[1], load->real ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_class_init( VipsForeignLoadSvgClass *class )
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
|
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||||
|
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
||||||
|
|
||||||
|
gobject_class->dispose = vips_foreign_load_svg_dispose;
|
||||||
|
gobject_class->set_property = vips_object_set_property;
|
||||||
|
gobject_class->get_property = vips_object_get_property;
|
||||||
|
|
||||||
|
object_class->nickname = "svgload";
|
||||||
|
object_class->description = _( "load SVG with rsvg" );
|
||||||
|
object_class->build = vips_foreign_load_svg_build;
|
||||||
|
|
||||||
|
load_class->get_flags_filename =
|
||||||
|
vips_foreign_load_svg_get_flags_filename;
|
||||||
|
load_class->get_flags = vips_foreign_load_svg_get_flags;
|
||||||
|
load_class->load = vips_foreign_load_svg_load;
|
||||||
|
|
||||||
|
VIPS_ARG_DOUBLE( class, "dpi", 11,
|
||||||
|
_( "DPI" ),
|
||||||
|
_( "Render at this DPI" ),
|
||||||
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignLoadSvg, dpi ),
|
||||||
|
0.001, 100000.0, 72.0 );
|
||||||
|
|
||||||
|
VIPS_ARG_DOUBLE( class, "scale", 12,
|
||||||
|
_( "Scale" ),
|
||||||
|
_( "Scale output by this factor" ),
|
||||||
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignLoadSvg, scale ),
|
||||||
|
0.001, 100000.0, 1.0 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_init( VipsForeignLoadSvg *svg )
|
||||||
|
{
|
||||||
|
svg->dpi = 72.0;
|
||||||
|
svg->scale = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct _VipsForeignLoadSvgFile {
|
||||||
|
VipsForeignLoadSvg parent_object;
|
||||||
|
|
||||||
|
/* Filename for load.
|
||||||
|
*/
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
} VipsForeignLoadSvgFile;
|
||||||
|
|
||||||
|
typedef VipsForeignLoadSvgClass VipsForeignLoadSvgFileClass;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE( VipsForeignLoadSvgFile, vips_foreign_load_svg_file,
|
||||||
|
vips_foreign_load_svg_get_type() );
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_file_header( VipsForeignLoad *load )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) load;
|
||||||
|
VipsForeignLoadSvgFile *file = (VipsForeignLoadSvgFile *) load;
|
||||||
|
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if( !(svg->page = rsvg_handle_new_from_file(
|
||||||
|
file->filename, &error )) ) {
|
||||||
|
vips_g_error( &error );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( vips_foreign_load_svg_header( load ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *vips_foreign_svg_suffs[] = {
|
||||||
|
".svg",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_file_class_init(
|
||||||
|
VipsForeignLoadSvgFileClass *class )
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
|
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||||
|
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
|
||||||
|
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
||||||
|
|
||||||
|
gobject_class->set_property = vips_object_set_property;
|
||||||
|
gobject_class->get_property = vips_object_get_property;
|
||||||
|
|
||||||
|
object_class->nickname = "svgload";
|
||||||
|
object_class->description = _( "load PDF with rsvg" );
|
||||||
|
|
||||||
|
foreign_class->suffs = vips_foreign_svg_suffs;
|
||||||
|
|
||||||
|
load_class->header = vips_foreign_load_svg_file_header;
|
||||||
|
|
||||||
|
VIPS_ARG_STRING( class, "filename", 1,
|
||||||
|
_( "Filename" ),
|
||||||
|
_( "Filename to load from" ),
|
||||||
|
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignLoadSvgFile, filename ),
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_file_init( VipsForeignLoadSvgFile *file )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct _VipsForeignLoadSvgBuffer {
|
||||||
|
VipsForeignLoadSvg parent_object;
|
||||||
|
|
||||||
|
/* Load from a buffer.
|
||||||
|
*/
|
||||||
|
VipsArea *buf;
|
||||||
|
|
||||||
|
} VipsForeignLoadSvgBuffer;
|
||||||
|
|
||||||
|
typedef VipsForeignLoadSvgClass VipsForeignLoadSvgBufferClass;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE( VipsForeignLoadSvgBuffer, vips_foreign_load_svg_buffer,
|
||||||
|
vips_foreign_load_svg_get_type() );
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_foreign_load_svg_buffer_header( VipsForeignLoad *load )
|
||||||
|
{
|
||||||
|
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) load;
|
||||||
|
VipsForeignLoadSvgBuffer *buffer =
|
||||||
|
(VipsForeignLoadSvgBuffer *) load;
|
||||||
|
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if( !(svg->page = rsvg_handle_new_from_data(
|
||||||
|
buffer->buf->data, buffer->buf->length, &error )) ) {
|
||||||
|
vips_g_error( &error );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( vips_foreign_load_svg_header( load ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_buffer_class_init(
|
||||||
|
VipsForeignLoadSvgBufferClass *class )
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
|
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||||
|
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
||||||
|
|
||||||
|
gobject_class->set_property = vips_object_set_property;
|
||||||
|
gobject_class->get_property = vips_object_get_property;
|
||||||
|
|
||||||
|
object_class->nickname = "svgload_buffer";
|
||||||
|
object_class->description = _( "load SVG with rsvg" );
|
||||||
|
|
||||||
|
load_class->header = vips_foreign_load_svg_buffer_header;
|
||||||
|
|
||||||
|
VIPS_ARG_BOXED( class, "buffer", 1,
|
||||||
|
_( "Buffer" ),
|
||||||
|
_( "Buffer to load from" ),
|
||||||
|
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignLoadSvgBuffer, buf ),
|
||||||
|
VIPS_TYPE_BLOB );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_foreign_load_svg_buffer_init( VipsForeignLoadSvgBuffer *buffer )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*HAVE_RSVG*/
|
||||||
|
|
@ -495,6 +495,11 @@ int vips_pdfload( const char *filename, VipsImage **out, ... )
|
|||||||
int vips_pdfload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
int vips_pdfload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
|
||||||
|
int vips_svgload( const char *filename, VipsImage **out, ... )
|
||||||
|
__attribute__((sentinel));
|
||||||
|
int vips_svgload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||||
|
__attribute__((sentinel));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VipsForeignDzLayout:
|
* VipsForeignDzLayout:
|
||||||
* @VIPS_FOREIGN_DZ_LAYOUT_DZ: use DeepZoom directory layout
|
* @VIPS_FOREIGN_DZ_LAYOUT_DZ: use DeepZoom directory layout
|
||||||
|
@ -1093,6 +1093,10 @@ class_methods = [
|
|||||||
"webpload_buffer",
|
"webpload_buffer",
|
||||||
"tiffload",
|
"tiffload",
|
||||||
"tiffload_buffer",
|
"tiffload_buffer",
|
||||||
|
"pdfload",
|
||||||
|
"pdfload_buffer",
|
||||||
|
"svgload",
|
||||||
|
"svgload_buffer",
|
||||||
"openslideload",
|
"openslideload",
|
||||||
"magickload",
|
"magickload",
|
||||||
"magickload_buffer",
|
"magickload_buffer",
|
||||||
|
2011
test/images/vips-profile.svg
Normal file
2011
test/images/vips-profile.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 297 KiB |
@ -45,6 +45,7 @@ class TestForeign(unittest.TestCase):
|
|||||||
self.fits_file = "images/WFPC2u5780205r_c0fx.fits"
|
self.fits_file = "images/WFPC2u5780205r_c0fx.fits"
|
||||||
self.openslide_file = "images/CMU-1-Small-Region.svs"
|
self.openslide_file = "images/CMU-1-Small-Region.svs"
|
||||||
self.pdf_file = "images/ISO_12233-reschart.pdf"
|
self.pdf_file = "images/ISO_12233-reschart.pdf"
|
||||||
|
self.svg_file = "images/vips-profile.svg"
|
||||||
|
|
||||||
self.colour = Vips.Image.jpegload(self.jpeg_file)
|
self.colour = Vips.Image.jpegload(self.jpeg_file)
|
||||||
self.mono = self.colour.extract_band(1)
|
self.mono = self.colour.extract_band(1)
|
||||||
@ -363,6 +364,33 @@ class TestForeign(unittest.TestCase):
|
|||||||
self.assertLess(abs(im.width * 2 - x.width), 2)
|
self.assertLess(abs(im.width * 2 - x.width), 2)
|
||||||
self.assertLess(abs(im.height * 2 - x.height), 2)
|
self.assertLess(abs(im.height * 2 - x.height), 2)
|
||||||
|
|
||||||
|
def test_svgload(self):
|
||||||
|
x = Vips.type_find("VipsForeign", "svgload")
|
||||||
|
if not x.is_instantiatable():
|
||||||
|
print("no svg support in this vips, skipping test")
|
||||||
|
return
|
||||||
|
|
||||||
|
def svg_valid(self, im):
|
||||||
|
im.write_to_file("x.v")
|
||||||
|
a = im(10, 10)
|
||||||
|
self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
|
||||||
|
self.assertEqual(im.width, 360)
|
||||||
|
self.assertEqual(im.height, 588)
|
||||||
|
self.assertEqual(im.bands, 4)
|
||||||
|
|
||||||
|
self.file_loader("svgload", self.svg_file, svg_valid)
|
||||||
|
self.buffer_loader("svgload_buffer", self.svg_file, svg_valid)
|
||||||
|
|
||||||
|
im = Vips.Image.new_from_file(self.svg_file)
|
||||||
|
x = Vips.Image.new_from_file(self.svg_file, scale = 2)
|
||||||
|
self.assertLess(abs(im.width * 2 - x.width), 2)
|
||||||
|
self.assertLess(abs(im.height * 2 - x.height), 2)
|
||||||
|
|
||||||
|
im = Vips.Image.new_from_file(self.svg_file)
|
||||||
|
x = Vips.Image.new_from_file(self.svg_file, dpi = 144)
|
||||||
|
self.assertLess(abs(im.width * 2 - x.width), 2)
|
||||||
|
self.assertLess(abs(im.height * 2 - x.height), 2)
|
||||||
|
|
||||||
def test_csv(self):
|
def test_csv(self):
|
||||||
self.save_load("%s.csv", self.mono)
|
self.save_load("%s.csv", self.mono)
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
* - warn if you autorot and there's no exif support
|
* - warn if you autorot and there's no exif support
|
||||||
* 9/2/16
|
* 9/2/16
|
||||||
* - add PDF --size support
|
* - add PDF --size support
|
||||||
|
* - add SVG --size support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -300,6 +301,31 @@ thumbnail_open( VipsObject *process, const char *filename )
|
|||||||
NULL )) )
|
NULL )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
|
||||||
|
}
|
||||||
|
else if( strcmp( loader, "VipsForeignLoadSvgFile" ) == 0 ) {
|
||||||
|
double shrink;
|
||||||
|
|
||||||
|
/* This will just read in the header and is quick.
|
||||||
|
*/
|
||||||
|
if( !(im = vips_image_new_from_file( filename, NULL )) )
|
||||||
|
return( NULL );
|
||||||
|
|
||||||
|
shrink = calculate_shrink( im );
|
||||||
|
|
||||||
|
g_object_unref( im );
|
||||||
|
|
||||||
|
vips_info( "vipsthumbnail",
|
||||||
|
"loading SVG with factor %g pre-shrink",
|
||||||
|
shrink );
|
||||||
|
|
||||||
|
/* We can't use UNBUFERRED safely on very-many-core systems.
|
||||||
|
*/
|
||||||
|
if( !(im = vips_image_new_from_file( filename,
|
||||||
|
"access", VIPS_ACCESS_SEQUENTIAL,
|
||||||
|
"scale", 1.0 / shrink,
|
||||||
|
NULL )) )
|
||||||
|
return( NULL );
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* All other formats. We can't use UNBUFERRED safely on
|
/* All other formats. We can't use UNBUFERRED safely on
|
||||||
|
Loading…
Reference in New Issue
Block a user