Merge branch 'master' into tiff-pyr-stop-at-1-pixel

This commit is contained in:
John Cupitt 2019-01-12 15:48:17 +00:00
commit bcc76c6edb
45 changed files with 18201 additions and 354 deletions

View File

@ -13,10 +13,19 @@
- add vips_rect_overlapsrect() - add vips_rect_overlapsrect()
- composite is much faster at positioning subimages - composite is much faster at positioning subimages
- stop tiff pyr layers if width or height drop to 1 [gvincke] - stop tiff pyr layers if width or height drop to 1 [gvincke]
- dzsave has a new skip_blanks option
- add vips_CMYK2XYZ() and vips_XYZ2CMYK(), plus associated routes
- include cmyk and srgb fallback profiles
- add vips_profile_load() and use it everywhere
4/1/19 started 8.7.4
- fix memory leak in magickload [kleisauke]
21/11/18 started 8.7.3 21/11/18 started 8.7.3
- fix infinite loop for autofit with non-scaleable font - fix infinite loop for autofit with non-scaleable font
- mapim was not offsetting by window offset [erdmann] - mapim was not offsetting by window offset [erdmann]
- better rounding for scale [kleisauke]
- fix a memleak in magick6load [kleisauke]
21/11/18 started 8.7.2 21/11/18 started 8.7.2
- more info output for temp files to help diagnose problems - more info output for temp files to help diagnose problems

View File

@ -762,6 +762,16 @@ if test x"$magick6" = x"yes"; then
LIBS="$save_LIBS" LIBS="$save_LIBS"
fi fi
if test x"$magick6" = x"yes"; then
# GM is missing AcquireExceptionInfo
save_LIBS="$LIBS"
LIBS="$LIBS $MAGICK_LIBS"
AC_CHECK_FUNCS(AcquireExceptionInfo,
AC_DEFINE(HAVE_ACQUIREEXCEPTIONINFO,1,
[define if your magick has AcquireExceptionInfo.]))
LIBS="$save_LIBS"
fi
# have flags to turn load and save off independently ... some people will want # have flags to turn load and save off independently ... some people will want
# save but not load, for example # save but not load, for example
AC_ARG_ENABLE([magickload], AC_ARG_ENABLE([magickload],
@ -841,6 +851,14 @@ if test x"$with_lcms" != x"no"; then
) )
fi fi
# we need a conditional for this to only compile in fallback profiles if lcms
# is detected
if test x"$with_lcms" != x"no"; then
AM_CONDITIONAL(ENABLE_LCMS, true)
else
AM_CONDITIONAL(ENABLE_LCMS, false)
fi
# OpenEXR # OpenEXR
AC_ARG_WITH([OpenEXR], AC_ARG_WITH([OpenEXR],
AS_HELP_STRING([--without-OpenEXR], [build without OpenEXR (default: test)])) AS_HELP_STRING([--without-OpenEXR], [build without OpenEXR (default: test)]))

View File

@ -32,8 +32,6 @@
#endif /*HAVE_CONFIG_H*/ #endif /*HAVE_CONFIG_H*/
#include <vips/intl.h> #include <vips/intl.h>
#include <iostream>
#include <vips/vips8> #include <vips/vips8>
VIPS_NAMESPACE_START VIPS_NAMESPACE_START

View File

@ -563,7 +563,7 @@ VImage::new_from_file( const char *name, VOption *options )
} }
VImage VImage
VImage::new_from_buffer( void *buf, size_t len, const char *option_string, VImage::new_from_buffer( const void *buf, size_t len, const char *option_string,
VOption *options ) VOption *options )
{ {
const char *operation_name; const char *operation_name;
@ -588,6 +588,13 @@ VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
return( out ); return( out );
} }
VImage
VImage::new_from_buffer( const std::string &buf, const char *option_string,
VOption *options )
{
return( new_from_buffer( buf.c_str(), buf.size(), option_string, options ) );
}
VImage VImage
VImage::new_matrix( int width, int height ) VImage::new_matrix( int width, int height )
{ {

View File

@ -31,8 +31,8 @@
#ifndef VIPS_VERROR_H #ifndef VIPS_VERROR_H
#define VIPS_VERROR_H #define VIPS_VERROR_H
#include <string> #include <cstring>
#include <iosfwd> #include <ostream>
#include <exception> #include <exception>
#include <vips/vips.h> #include <vips/vips.h>
@ -43,7 +43,7 @@ class VIPS_CPLUSPLUS_API VError : public std::exception {
std::string _what; std::string _what;
public: public:
VError( std::string what ) : _what( what ) {} VError( const std::string &what ) : _what( what ) {}
VError() : _what( vips_error_buffer() ) {} VError() : _what( vips_error_buffer() ) {}
virtual ~VError() throw() {} virtual ~VError() throw() {}

View File

@ -34,7 +34,7 @@
#include <complex> #include <complex>
#include <vector> #include <vector>
#include <string.h> #include <cstring>
#include <vips/vips.h> #include <vips/vips.h>
@ -327,6 +327,12 @@ public:
return( vips_image_get_yoffset( get_image() ) ); return( vips_image_get_yoffset( get_image() ) );
} }
bool
has_alpha() const
{
return( vips_image_hasalpha( get_image() ) );
}
const char * const char *
filename() const filename() const
{ {
@ -407,7 +413,7 @@ public:
const void * const void *
get_blob( const char *field, size_t *length ) const get_blob( const char *field, size_t *length ) const
{ {
void *value; const void *value;
if( vips_image_get_blob( this->get_image(), field, if( vips_image_get_blob( this->get_image(), field,
&value, length ) ) &value, length ) )
@ -416,6 +422,12 @@ public:
return( value ); return( value );
} }
bool
remove( const char *name ) const
{
return( vips_image_remove( get_image(), name ) );
}
static VOption * static VOption *
option() option()
{ {
@ -458,7 +470,10 @@ public:
return( VImage( image ) ); return( VImage( image ) );
} }
static VImage new_from_buffer( void *buf, size_t len, static VImage new_from_buffer( const void *buf, size_t len,
const char *option_string, VOption *options = 0 );
static VImage new_from_buffer( const std::string &buf,
const char *option_string, VOption *options = 0 ); const char *option_string, VOption *options = 0 );
static VImage new_matrix( int width, int height ); static VImage new_matrix( int width, int height );
@ -495,6 +510,17 @@ public:
return( new_from_image( to_vectorv( 1, pixel ) ) ); return( new_from_image( to_vectorv( 1, pixel ) ) );
} }
VImage
copy_memory() const
{
VipsImage *image;
if( !(image = vips_image_copy_memory( this->get_image() )) )
throw( VError() );
return( VImage( image ) );
}
VImage write( VImage out ) const; VImage write( VImage out ) const;
void write_to_file( const char *name, VOption *options = 0 ) const; void write_to_file( const char *name, VOption *options = 0 ) const;

View File

@ -34,7 +34,7 @@
#include <complex> #include <complex>
#include <vector> #include <vector>
#include <string.h> #include <cstring>
#include <vips/vips.h> #include <vips/vips.h>

161
libvips/colour/CMYK2XYZ.c Normal file
View File

@ -0,0 +1,161 @@
/* Use lcms to move from CMYK to XYZ, if we can. This needs a working
* vips_icc_import.
*
* 21/12/18
* - from scRGB2XYZ.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
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips.h>
#ifdef HAVE_LCMS2
#include <stdio.h>
#include <math.h>
#include <vips/internal.h>
#include "profiles.h"
#include "pcolour.h"
typedef struct _VipsCMYK2XYZ {
VipsOperation parent_instance;
VipsImage *in;
VipsImage *out;
} VipsCMYK2XYZ;
typedef VipsColourCodeClass VipsCMYK2XYZClass;
G_DEFINE_TYPE( VipsCMYK2XYZ, vips_CMYK2XYZ, VIPS_TYPE_OPERATION );
/* Our actual processing, as a VipsColourTransformFn.
*/
static int
vips_CMYK2XYZ_process( VipsImage *in, VipsImage **out, ... )
{
return( vips_icc_import( in, out,
"embedded", TRUE,
"pcs", VIPS_PCS_XYZ,
NULL ) );
}
static int
vips_CMYK2XYZ_build( VipsObject *object )
{
VipsCMYK2XYZ *CMYK2XYZ = (VipsCMYK2XYZ *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );
VipsImage *out;
if( VIPS_OBJECT_CLASS( vips_CMYK2XYZ_parent_class )->build( object ) )
return( -1 );
out = vips_image_new();
g_object_set( object, "out", out, NULL );
if( vips_copy( CMYK2XYZ->in, &t[0], NULL ) ||
vips__profile_set( t[0], "cmyk" ) ||
vips__colourspace_process_n( "CMYK2XYZ",
t[0], &t[1], 4, vips_CMYK2XYZ_process ) ||
vips_image_write( t[1], out ) )
return( -1 );
return( 0 );
}
static void
vips_CMYK2XYZ_class_init( VipsCMYK2XYZClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsOperationClass *operation_class = VIPS_OPERATION_CLASS( class );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
object_class->nickname = "CMYK2XYZ";
object_class->description = _( "transform CMYK to XYZ" );
object_class->build = vips_CMYK2XYZ_build;
operation_class->flags = VIPS_OPERATION_SEQUENTIAL;
VIPS_ARG_IMAGE( class, "in", 1,
_( "Input" ),
_( "Input image" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsCMYK2XYZ, in ) );
VIPS_ARG_IMAGE( class, "out", 100,
_( "Output" ),
_( "Output image" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsCMYK2XYZ, out ) );
}
static void
vips_CMYK2XYZ_init( VipsCMYK2XYZ *CMYK2XYZ )
{
}
#endif /*HAVE_LCMS2*/
/**
* vips_CMYK2XYZ: (method)
* @in: input image
* @out: (out): output image
* @...: %NULL-terminated list of optional named arguments
*
* Turn CMYK to XYZ. If the image has an embedded ICC profile this will be
* used for the conversion. If there is no embedded profile, a generic
* fallback profile will be used.
*
* Conversion is to D65 XYZ with relative intent. If you need more control
* over the process, use vips_icc_import() instead.
*
* Returns: 0 on success, -1 on error
*/
int
vips_CMYK2XYZ( VipsImage *in, VipsImage **out, ... )
{
va_list ap;
int result;
va_start( ap, out );
result = vips_call_split( "CMYK2XYZ", ap, in, out );
va_end( ap );
return( result );
}

View File

@ -1,8 +1,13 @@
noinst_LTLIBRARIES = libcolour.la noinst_LTLIBRARIES = libcolour.la
libcolour_la_SOURCES = \ libcolour_la_SOURCES = \
profiles.c \
profiles.h \
profile_load.c \
colour.c \ colour.c \
pcolour.h \ pcolour.h \
CMYK2XYZ.c \
XYZ2CMYK.c \
colourspace.c \ colourspace.c \
dE76.c \ dE76.c \
dE00.c \ dE00.c \
@ -33,4 +38,11 @@ libcolour_la_SOURCES = \
XYZ2scRGB.c \ XYZ2scRGB.c \
scRGB2sRGB.c scRGB2sRGB.c
profiles.c:
./wrap-profiles.sh profiles profiles.c
EXTRA_DIST = \
profiles \
wrap-profiles.sh
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@

160
libvips/colour/XYZ2CMYK.c Normal file
View File

@ -0,0 +1,160 @@
/* Use lcms to move from XYZ to CMYK, if we can. This needs a working
* vips_icc_export.
*
* 21/12/18
* - from CMYK2XYZ.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
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips.h>
#ifdef HAVE_LCMS2
#include <stdio.h>
#include <math.h>
#include <vips/internal.h>
#include "pcolour.h"
#include "profiles.h"
typedef struct _VipsXYZ2CMYK {
VipsOperation parent_instance;
VipsImage *in;
VipsImage *out;
} VipsXYZ2CMYK;
typedef VipsColourCodeClass VipsXYZ2CMYKClass;
G_DEFINE_TYPE( VipsXYZ2CMYK, vips_XYZ2CMYK, VIPS_TYPE_OPERATION );
/* Our actual processing, as a VipsColourTransformFn.
*/
static int
vips_XYZ2CMYK_process( VipsImage *in, VipsImage **out, ... )
{
return( vips_icc_export( in, out,
"pcs", VIPS_PCS_XYZ,
NULL ) );
}
static int
vips_XYZ2CMYK_build( VipsObject *object )
{
VipsXYZ2CMYK *XYZ2CMYK = (VipsXYZ2CMYK *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );
VipsImage *out;
if( VIPS_OBJECT_CLASS( vips_XYZ2CMYK_parent_class )->build( object ) )
return( -1 );
out = vips_image_new();
g_object_set( object, "out", out, NULL );
if( vips_copy( XYZ2CMYK->in, &t[0], NULL ) ||
vips__profile_set( t[0], "cmyk" ) ||
vips__colourspace_process_n( "XYZ2CMYK",
t[0], &t[1], 3, vips_XYZ2CMYK_process ) ||
vips_image_write( t[1], out ) )
return( -1 );
return( 0 );
}
static void
vips_XYZ2CMYK_class_init( VipsXYZ2CMYKClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsOperationClass *operation_class = VIPS_OPERATION_CLASS( class );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
object_class->nickname = "XYZ2CMYK";
object_class->description = _( "transform XYZ to CMYK" );
object_class->build = vips_XYZ2CMYK_build;
operation_class->flags = VIPS_OPERATION_SEQUENTIAL;
VIPS_ARG_IMAGE( class, "in", 1,
_( "Input" ),
_( "Input image" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsXYZ2CMYK, in ) );
VIPS_ARG_IMAGE( class, "out", 100,
_( "Output" ),
_( "Output image" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsXYZ2CMYK, out ) );
}
static void
vips_XYZ2CMYK_init( VipsXYZ2CMYK *XYZ2CMYK )
{
}
#endif /*HAVE_LCMS2*/
/**
* vips_XYZ2CMYK: (method)
* @in: input image
* @out: (out): output image
* @...: %NULL-terminated list of optional named arguments
*
* Turn XYZ to CMYK. If the image has an embedded ICC profile this will be
* used for the conversion. If there is no embedded profile, a generic
* fallback profile will be used.
*
* Conversion is from D65 XYZ with relative intent. If you need more control
* over the process, use vips_icc_export() instead.
*
* Returns: 0 on success, -1 on error
*/
int
vips_XYZ2CMYK( VipsImage *in, VipsImage **out, ... )
{
va_list ap;
int result;
va_start( ap, out );
result = vips_call_split( "XYZ2CMYK", ap, in, out );
va_end( ap );
return( result );
}

View File

@ -752,10 +752,13 @@ vips_colour_operation_init( void )
extern GType vips_scRGB2BW_get_type( void ); extern GType vips_scRGB2BW_get_type( void );
extern GType vips_XYZ2scRGB_get_type( void ); extern GType vips_XYZ2scRGB_get_type( void );
extern GType vips_scRGB2sRGB_get_type( void ); extern GType vips_scRGB2sRGB_get_type( void );
extern GType vips_profile_load_get_type( void );
#ifdef HAVE_LCMS2 #ifdef HAVE_LCMS2
extern GType vips_icc_import_get_type( void ); extern GType vips_icc_import_get_type( void );
extern GType vips_icc_export_get_type( void ); extern GType vips_icc_export_get_type( void );
extern GType vips_icc_transform_get_type( void ); extern GType vips_icc_transform_get_type( void );
extern GType vips_CMYK2XYZ_get_type( void );
extern GType vips_XYZ2CMYK_get_type( void );
#endif #endif
extern GType vips_dE76_get_type( void ); extern GType vips_dE76_get_type( void );
extern GType vips_dE00_get_type( void ); extern GType vips_dE00_get_type( void );
@ -786,10 +789,13 @@ vips_colour_operation_init( void )
vips_HSV2sRGB_get_type(); vips_HSV2sRGB_get_type();
vips_XYZ2scRGB_get_type(); vips_XYZ2scRGB_get_type();
vips_scRGB2sRGB_get_type(); vips_scRGB2sRGB_get_type();
vips_profile_load_get_type();
#ifdef HAVE_LCMS2 #ifdef HAVE_LCMS2
vips_icc_import_get_type(); vips_icc_import_get_type();
vips_icc_export_get_type(); vips_icc_export_get_type();
vips_icc_transform_get_type(); vips_icc_transform_get_type();
vips_CMYK2XYZ_get_type();
vips_XYZ2CMYK_get_type();
#endif #endif
vips_dE76_get_type(); vips_dE76_get_type();
vips_dE00_get_type(); vips_dE00_get_type();

View File

@ -19,6 +19,8 @@
* 17/4/15 * 17/4/15
* - better conversion to greyscale, see * - better conversion to greyscale, see
* https://github.com/lovell/sharp/issues/193 * https://github.com/lovell/sharp/issues/193
* 27/12/18
* - add CMYK conversions
*/ */
/* /*
@ -66,10 +68,6 @@
#include "pcolour.h" #include "pcolour.h"
/* A colour-transforming function.
*/
typedef int (*VipsColourTransformFn)( VipsImage *in, VipsImage **out, ... );
static int static int
vips_scRGB2RGB16( VipsImage *in, VipsImage **out, ... ) vips_scRGB2RGB16( VipsImage *in, VipsImage **out, ... )
{ {
@ -111,10 +109,12 @@ vips_sRGB2RGB16( VipsImage *in, VipsImage **out, ... )
} }
/* Process the first @n bands with @fn, detach and reattach remaining bands. /* Process the first @n bands with @fn, detach and reattach remaining bands.
*
* Also used by CMYK2XYZ and XYZ2CMYK.
*/ */
static int int
vips_process_n( const char *domain, VipsImage *in, VipsImage **out, vips__colourspace_process_n( const char *domain,
int n, VipsColourTransformFn fn ) VipsImage *in, VipsImage **out, int n, VipsColourTransformFn fn )
{ {
if( in->Bands > n ) { if( in->Bands > n ) {
VipsImage *scope = vips_image_new(); VipsImage *scope = vips_image_new();
@ -166,7 +166,8 @@ vips_BW2sRGB_op( VipsImage *in, VipsImage **out, ... )
static int static int
vips_BW2sRGB( VipsImage *in, VipsImage **out, ... ) vips_BW2sRGB( VipsImage *in, VipsImage **out, ... )
{ {
if( vips_process_n( "BW2sRGB", in, out, 1, vips_BW2sRGB_op ) ) if( vips__colourspace_process_n( "BW2sRGB",
in, out, 1, vips_BW2sRGB_op ) )
return( -1 ); return( -1 );
(*out)->Type = VIPS_INTERPRETATION_sRGB; (*out)->Type = VIPS_INTERPRETATION_sRGB;
@ -176,7 +177,8 @@ vips_BW2sRGB( VipsImage *in, VipsImage **out, ... )
static int static int
vips_GREY162RGB16( VipsImage *in, VipsImage **out, ... ) vips_GREY162RGB16( VipsImage *in, VipsImage **out, ... )
{ {
if( vips_process_n( "GREY162RGB16", in, out, 1, vips_BW2sRGB_op ) ) if( vips__colourspace_process_n( "GREY162RGB16",
in, out, 1, vips_BW2sRGB_op ) )
return( -1 ); return( -1 );
(*out)->Type = VIPS_INTERPRETATION_RGB16; (*out)->Type = VIPS_INTERPRETATION_RGB16;
@ -205,6 +207,7 @@ typedef struct _VipsColourRoute {
#define LCH VIPS_INTERPRETATION_LCH #define LCH VIPS_INTERPRETATION_LCH
#define CMC VIPS_INTERPRETATION_CMC #define CMC VIPS_INTERPRETATION_CMC
#define LABS VIPS_INTERPRETATION_LABS #define LABS VIPS_INTERPRETATION_LABS
#define CMYK VIPS_INTERPRETATION_CMYK
#define scRGB VIPS_INTERPRETATION_scRGB #define scRGB VIPS_INTERPRETATION_scRGB
#define sRGB VIPS_INTERPRETATION_sRGB #define sRGB VIPS_INTERPRETATION_sRGB
#define HSV VIPS_INTERPRETATION_HSV #define HSV VIPS_INTERPRETATION_HSV
@ -221,6 +224,7 @@ static VipsColourRoute vips_colour_routes[] = {
{ XYZ, LCH, { vips_XYZ2Lab, vips_Lab2LCh, NULL } }, { XYZ, LCH, { vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ XYZ, CMC, { vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, { XYZ, CMC, { vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ XYZ, LABS, { vips_XYZ2Lab, vips_Lab2LabS, NULL } }, { XYZ, LABS, { vips_XYZ2Lab, vips_Lab2LabS, NULL } },
{ XYZ, CMYK, { vips_XYZ2CMYK, NULL } },
{ XYZ, scRGB, { vips_XYZ2scRGB, NULL } }, { XYZ, scRGB, { vips_XYZ2scRGB, NULL } },
{ XYZ, sRGB, { vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } }, { XYZ, sRGB, { vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } },
{ XYZ, HSV, { vips_XYZ2scRGB, vips_scRGB2sRGB, vips_sRGB2HSV, NULL } }, { XYZ, HSV, { vips_XYZ2scRGB, vips_scRGB2sRGB, vips_sRGB2HSV, NULL } },
@ -234,9 +238,11 @@ static VipsColourRoute vips_colour_routes[] = {
{ LAB, LCH, { vips_Lab2LCh, NULL } }, { LAB, LCH, { vips_Lab2LCh, NULL } },
{ LAB, CMC, { vips_Lab2LCh, vips_LCh2CMC, NULL } }, { LAB, CMC, { vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ LAB, LABS, { vips_Lab2LabS, NULL } }, { LAB, LABS, { vips_Lab2LabS, NULL } },
{ LAB, CMYK, { vips_Lab2XYZ, vips_XYZ2CMYK, NULL } },
{ LAB, scRGB, { vips_Lab2XYZ, vips_XYZ2scRGB, NULL } }, { LAB, scRGB, { vips_Lab2XYZ, vips_XYZ2scRGB, NULL } },
{ LAB, sRGB, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } }, { LAB, sRGB, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } },
{ LAB, HSV, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, vips_sRGB2HSV, NULL } }, { LAB, HSV, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB,
vips_sRGB2HSV, NULL } },
{ LAB, BW, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2BW, NULL } }, { LAB, BW, { vips_Lab2XYZ, vips_XYZ2scRGB, vips_scRGB2BW, NULL } },
{ LAB, RGB16, { vips_Lab2XYZ, vips_XYZ2scRGB, { LAB, RGB16, { vips_Lab2XYZ, vips_XYZ2scRGB,
vips_scRGB2RGB16, NULL } }, vips_scRGB2RGB16, NULL } },
@ -249,6 +255,7 @@ static VipsColourRoute vips_colour_routes[] = {
{ LABQ, LCH, { vips_LabQ2Lab, vips_Lab2LCh, NULL } }, { LABQ, LCH, { vips_LabQ2Lab, vips_Lab2LCh, NULL } },
{ LABQ, CMC, { vips_LabQ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, { LABQ, CMC, { vips_LabQ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ LABQ, LABS, { vips_LabQ2LabS, NULL } }, { LABQ, LABS, { vips_LabQ2LabS, NULL } },
{ LABQ, CMYK, { vips_LabQ2Lab, vips_Lab2XYZ, vips_XYZ2CMYK } },
{ LABQ, scRGB, { vips_LabQ2Lab, vips_Lab2XYZ, vips_XYZ2scRGB } }, { LABQ, scRGB, { vips_LabQ2Lab, vips_Lab2XYZ, vips_XYZ2scRGB } },
{ LABQ, sRGB, { vips_LabQ2sRGB, NULL } }, { LABQ, sRGB, { vips_LabQ2sRGB, NULL } },
{ LABQ, HSV, { vips_LabQ2sRGB, vips_sRGB2HSV, NULL } }, { LABQ, HSV, { vips_LabQ2sRGB, vips_sRGB2HSV, NULL } },
@ -265,6 +272,7 @@ static VipsColourRoute vips_colour_routes[] = {
{ LCH, LABQ, { vips_LCh2Lab, vips_Lab2LabQ, NULL } }, { LCH, LABQ, { vips_LCh2Lab, vips_Lab2LabQ, NULL } },
{ LCH, CMC, { vips_LCh2CMC, NULL } }, { LCH, CMC, { vips_LCh2CMC, NULL } },
{ LCH, LABS, { vips_LCh2Lab, vips_Lab2LabS, NULL } }, { LCH, LABS, { vips_LCh2Lab, vips_Lab2LabS, NULL } },
{ LCH, CMYK, { vips_LCh2Lab, vips_Lab2XYZ, vips_XYZ2CMYK, NULL } },
{ LCH, scRGB, { vips_LCh2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, NULL } }, { LCH, scRGB, { vips_LCh2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, NULL } },
{ LCH, sRGB, { vips_LCh2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, { LCH, sRGB, { vips_LCh2Lab, vips_Lab2XYZ, vips_XYZ2scRGB,
vips_scRGB2sRGB, NULL } }, vips_scRGB2sRGB, NULL } },
@ -283,6 +291,8 @@ static VipsColourRoute vips_colour_routes[] = {
{ CMC, LABQ, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2LabQ, NULL } }, { CMC, LABQ, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2LabQ, NULL } },
{ CMC, LCH, { vips_CMC2LCh, NULL } }, { CMC, LCH, { vips_CMC2LCh, NULL } },
{ CMC, LABS, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2LabS, NULL } }, { CMC, LABS, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2LabS, NULL } },
{ CMC, CMYK, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2XYZ,
vips_XYZ2CMYK, NULL } },
{ CMC, scRGB, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2XYZ, { CMC, scRGB, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2XYZ,
vips_XYZ2scRGB, NULL } }, vips_XYZ2scRGB, NULL } },
{ CMC, sRGB, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2XYZ, { CMC, sRGB, { vips_CMC2LCh, vips_LCh2Lab, vips_Lab2XYZ,
@ -303,6 +313,7 @@ static VipsColourRoute vips_colour_routes[] = {
{ LABS, LABQ, { vips_LabS2LabQ, NULL } }, { LABS, LABQ, { vips_LabS2LabQ, NULL } },
{ LABS, LCH, { vips_LabS2Lab, vips_Lab2LCh, NULL } }, { LABS, LCH, { vips_LabS2Lab, vips_Lab2LCh, NULL } },
{ LABS, CMC, { vips_LabS2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, { LABS, CMC, { vips_LabS2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ LABS, CMYK, { vips_LabS2Lab, vips_Lab2XYZ, vips_XYZ2CMYK, NULL } },
{ LABS, scRGB, { vips_LabS2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, NULL } }, { LABS, scRGB, { vips_LabS2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, NULL } },
{ LABS, sRGB, { vips_LabS2Lab, vips_Lab2XYZ, vips_XYZ2scRGB, { LABS, sRGB, { vips_LabS2Lab, vips_Lab2XYZ, vips_XYZ2scRGB,
vips_scRGB2sRGB, NULL } }, vips_scRGB2sRGB, NULL } },
@ -322,6 +333,7 @@ static VipsColourRoute vips_colour_routes[] = {
{ scRGB, LCH, { vips_scRGB2XYZ, vips_XYZ2Lab, vips_Lab2LCh, NULL } }, { scRGB, LCH, { vips_scRGB2XYZ, vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ scRGB, CMC, { vips_scRGB2XYZ, vips_XYZ2Lab, { scRGB, CMC, { vips_scRGB2XYZ, vips_XYZ2Lab,
vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ scRGB, CMYK, { vips_scRGB2XYZ, vips_XYZ2CMYK, NULL } },
{ scRGB, sRGB, { vips_scRGB2sRGB, NULL } }, { scRGB, sRGB, { vips_scRGB2sRGB, NULL } },
{ scRGB, HSV, { vips_scRGB2sRGB, vips_sRGB2HSV, NULL } }, { scRGB, HSV, { vips_scRGB2sRGB, vips_sRGB2HSV, NULL } },
{ scRGB, BW, { vips_scRGB2BW, NULL } }, { scRGB, BW, { vips_scRGB2BW, NULL } },
@ -330,6 +342,25 @@ static VipsColourRoute vips_colour_routes[] = {
{ scRGB, GREY16, { vips_scRGB2BW16, NULL } }, { scRGB, GREY16, { vips_scRGB2BW16, NULL } },
{ scRGB, YXY, { vips_scRGB2XYZ, vips_XYZ2Yxy, NULL } }, { scRGB, YXY, { vips_scRGB2XYZ, vips_XYZ2Yxy, NULL } },
{ CMYK, XYZ, { vips_CMYK2XYZ, NULL } },
{ CMYK, LAB, { vips_CMYK2XYZ, vips_XYZ2Lab, NULL } },
{ CMYK, LABQ, { vips_CMYK2XYZ, vips_XYZ2Lab, vips_Lab2LabQ, NULL } },
{ CMYK, LCH, { vips_CMYK2XYZ, vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ CMYK, CMC, { vips_CMYK2XYZ, vips_XYZ2Lab,
vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ CMYK, scRGB, { vips_CMYK2XYZ, vips_XYZ2scRGB, NULL } },
{ CMYK, sRGB, { vips_CMYK2XYZ, vips_XYZ2scRGB,
vips_scRGB2sRGB, NULL } },
{ CMYK, HSV, { vips_CMYK2XYZ, vips_XYZ2scRGB,
vips_scRGB2sRGB, vips_sRGB2HSV, NULL } },
{ CMYK, BW, { vips_CMYK2XYZ, vips_XYZ2scRGB, vips_scRGB2BW, NULL } },
{ CMYK, LABS, { vips_CMYK2XYZ, vips_XYZ2Lab, vips_Lab2LabS, NULL } },
{ CMYK, RGB16, { vips_CMYK2XYZ, vips_XYZ2scRGB,
vips_scRGB2RGB16, NULL } },
{ CMYK, GREY16, { vips_CMYK2XYZ, vips_XYZ2scRGB,
vips_scRGB2BW16, NULL } },
{ CMYK, YXY, { vips_CMYK2XYZ, vips_XYZ2Yxy, NULL } },
{ sRGB, XYZ, { vips_sRGB2scRGB, vips_scRGB2XYZ, NULL } }, { sRGB, XYZ, { vips_sRGB2scRGB, vips_scRGB2XYZ, NULL } },
{ sRGB, LAB, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab, NULL } }, { sRGB, LAB, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab, NULL } },
{ sRGB, LABQ, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab, { sRGB, LABQ, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab,
@ -338,6 +369,8 @@ static VipsColourRoute vips_colour_routes[] = {
vips_Lab2LCh, NULL } }, vips_Lab2LCh, NULL } },
{ sRGB, CMC, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab, { sRGB, CMC, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab,
vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ sRGB, CMYK, { vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2CMYK, NULL } },
{ sRGB, scRGB, { vips_sRGB2scRGB, NULL } }, { sRGB, scRGB, { vips_sRGB2scRGB, NULL } },
{ sRGB, HSV, { vips_sRGB2HSV, NULL } }, { sRGB, HSV, { vips_sRGB2HSV, NULL } },
{ sRGB, BW, { vips_sRGB2scRGB, vips_scRGB2BW, NULL } }, { sRGB, BW, { vips_sRGB2scRGB, vips_scRGB2BW, NULL } },
@ -356,6 +389,8 @@ static VipsColourRoute vips_colour_routes[] = {
vips_XYZ2Lab, vips_Lab2LCh, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ HSV, CMC, { vips_HSV2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ, { HSV, CMC, { vips_HSV2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ HSV, CMYK, { vips_HSV2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2CMYK, NULL } },
{ HSV, scRGB, { vips_HSV2sRGB, vips_sRGB2scRGB, NULL } }, { HSV, scRGB, { vips_HSV2sRGB, vips_sRGB2scRGB, NULL } },
{ HSV, sRGB, { vips_HSV2sRGB, NULL } }, { HSV, sRGB, { vips_HSV2sRGB, NULL } },
{ HSV, BW, { vips_HSV2sRGB, vips_sRGB2scRGB, vips_scRGB2BW, NULL } }, { HSV, BW, { vips_HSV2sRGB, vips_sRGB2scRGB, vips_scRGB2BW, NULL } },
@ -375,6 +410,8 @@ static VipsColourRoute vips_colour_routes[] = {
vips_Lab2LCh, NULL } }, vips_Lab2LCh, NULL } },
{ RGB16, CMC, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab, { RGB16, CMC, { vips_sRGB2scRGB, vips_scRGB2XYZ, vips_XYZ2Lab,
vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ RGB16, CMYK, { vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2CMYK, NULL } },
{ RGB16, scRGB, { vips_sRGB2scRGB, NULL } }, { RGB16, scRGB, { vips_sRGB2scRGB, NULL } },
{ RGB16, sRGB, { vips_RGB162sRGB, NULL } }, { RGB16, sRGB, { vips_RGB162sRGB, NULL } },
{ RGB16, HSV, { vips_RGB162sRGB, vips_sRGB2HSV, NULL } }, { RGB16, HSV, { vips_RGB162sRGB, vips_sRGB2HSV, NULL } },
@ -394,9 +431,12 @@ static VipsColourRoute vips_colour_routes[] = {
vips_XYZ2Lab, vips_Lab2LCh, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ GREY16, CMC, { vips_GREY162RGB16, vips_sRGB2scRGB, vips_scRGB2XYZ, { GREY16, CMC, { vips_GREY162RGB16, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ GREY16, CMYK, { vips_GREY162RGB16, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2CMYK, NULL } },
{ GREY16, scRGB, { vips_GREY162RGB16, vips_sRGB2scRGB, NULL } }, { GREY16, scRGB, { vips_GREY162RGB16, vips_sRGB2scRGB, NULL } },
{ GREY16, sRGB, { vips_GREY162RGB16, vips_RGB162sRGB, NULL } }, { GREY16, sRGB, { vips_GREY162RGB16, vips_RGB162sRGB, NULL } },
{ GREY16, HSV, { vips_GREY162RGB16, vips_RGB162sRGB, vips_sRGB2HSV, NULL } }, { GREY16, HSV, { vips_GREY162RGB16, vips_RGB162sRGB,
vips_sRGB2HSV, NULL } },
{ GREY16, BW, { vips_GREY162RGB16, vips_sRGB2scRGB, { GREY16, BW, { vips_GREY162RGB16, vips_sRGB2scRGB,
vips_scRGB2BW, NULL } }, vips_scRGB2BW, NULL } },
{ GREY16, LABS, { vips_GREY162RGB16, vips_sRGB2scRGB, vips_scRGB2XYZ, { GREY16, LABS, { vips_GREY162RGB16, vips_sRGB2scRGB, vips_scRGB2XYZ,
@ -414,6 +454,8 @@ static VipsColourRoute vips_colour_routes[] = {
vips_XYZ2Lab, vips_Lab2LCh, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, NULL } },
{ BW, CMC, { vips_BW2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ, { BW, CMC, { vips_BW2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } }, vips_XYZ2Lab, vips_Lab2LCh, vips_LCh2CMC, NULL } },
{ BW, CMYK, { vips_BW2sRGB, vips_sRGB2scRGB, vips_scRGB2XYZ,
vips_XYZ2CMYK, NULL } },
{ BW, scRGB, { vips_BW2sRGB, vips_sRGB2scRGB, NULL } }, { BW, scRGB, { vips_BW2sRGB, vips_sRGB2scRGB, NULL } },
{ BW, sRGB, { vips_BW2sRGB, NULL } }, { BW, sRGB, { vips_BW2sRGB, NULL } },
{ BW, HSV, { vips_BW2sRGB, vips_sRGB2HSV, NULL } }, { BW, HSV, { vips_BW2sRGB, vips_sRGB2HSV, NULL } },
@ -432,9 +474,11 @@ static VipsColourRoute vips_colour_routes[] = {
{ YXY, CMC, { vips_Yxy2XYZ, vips_XYZ2Lab, vips_Lab2LCh, { YXY, CMC, { vips_Yxy2XYZ, vips_XYZ2Lab, vips_Lab2LCh,
vips_LCh2CMC, NULL } }, vips_LCh2CMC, NULL } },
{ YXY, LABS, { vips_Yxy2XYZ, vips_XYZ2Lab, vips_Lab2LabS, NULL } }, { YXY, LABS, { vips_Yxy2XYZ, vips_XYZ2Lab, vips_Lab2LabS, NULL } },
{ YXY, CMYK, { vips_Yxy2XYZ, vips_XYZ2CMYK, NULL } },
{ YXY, scRGB, { vips_Yxy2XYZ, vips_XYZ2scRGB, NULL } }, { YXY, scRGB, { vips_Yxy2XYZ, vips_XYZ2scRGB, NULL } },
{ YXY, sRGB, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } }, { YXY, sRGB, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, NULL } },
{ YXY, HSV, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB, vips_sRGB2HSV, NULL } }, { YXY, HSV, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2sRGB,
vips_sRGB2HSV, NULL } },
{ YXY, BW, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2BW, NULL } }, { YXY, BW, { vips_Yxy2XYZ, vips_XYZ2scRGB, vips_scRGB2BW, NULL } },
{ YXY, RGB16, { vips_Yxy2XYZ, vips_XYZ2scRGB, { YXY, RGB16, { vips_Yxy2XYZ, vips_XYZ2scRGB,
vips_scRGB2RGB16, NULL } }, vips_scRGB2RGB16, NULL } },

View File

@ -38,6 +38,9 @@
* - more input profile sanity tests * - more input profile sanity tests
* 8/3/18 * 8/3/18
* - attach fallback profile on import if we used it * - attach fallback profile on import if we used it
* 28/12/18
* - remove warning messages from vips_icc_is_compatible_profile() since
* they can be triggered under normal circumstances
*/ */
/* /*
@ -148,7 +151,9 @@ typedef struct _VipsIcc {
VipsPCS pcs; VipsPCS pcs;
int depth; int depth;
VipsBlob *in_blob;
cmsHPROFILE in_profile; cmsHPROFILE in_profile;
VipsBlob *out_blob;
cmsHPROFILE out_profile; cmsHPROFILE out_profile;
cmsUInt32Number in_icc_format; cmsUInt32Number in_icc_format;
cmsUInt32Number out_icc_format; cmsUInt32Number out_icc_format;
@ -178,6 +183,16 @@ vips_icc_dispose( GObject *gobject )
VIPS_FREEF( cmsCloseProfile, icc->in_profile ); VIPS_FREEF( cmsCloseProfile, icc->in_profile );
VIPS_FREEF( cmsCloseProfile, icc->out_profile ); VIPS_FREEF( cmsCloseProfile, icc->out_profile );
if( icc->in_blob ) {
vips_area_unref( (VipsArea *) icc->in_blob );
icc->in_blob = NULL;
}
if( icc->out_blob ) {
vips_area_unref( (VipsArea *) icc->out_blob );
icc->out_blob = NULL;
}
G_OBJECT_CLASS( vips_icc_parent_class )->dispose( gobject ); G_OBJECT_CLASS( vips_icc_parent_class )->dispose( gobject );
} }
@ -578,63 +593,50 @@ vips_image_expected_sig( VipsImage *image )
return( expected_sig ); return( expected_sig );
} }
static cmsHPROFILE /* Get from an image.
vips_icc_load_profile_image( VipsImage *image ) */
static VipsBlob *
vips_icc_get_profile_image( VipsImage *image )
{ {
void *data; const void *data;
size_t data_length; size_t size;
cmsHPROFILE profile;
if( !vips_image_get_typeof( image, VIPS_META_ICC_NAME ) ) if( !vips_image_get_typeof( image, VIPS_META_ICC_NAME ) )
return( NULL ); return( NULL );
if( vips_image_get_blob( image, VIPS_META_ICC_NAME, &data, &size ) )
if( vips_image_get_blob( image, VIPS_META_ICC_NAME,
&data, &data_length ) ||
!(profile = cmsOpenProfileFromMem( data, data_length )) ) {
g_warning( "%s", _( "corrupt embedded profile" ) );
return( NULL ); return( NULL );
return( vips_blob_new( NULL, data, size ) );
} }
if( vips_image_expected_bands( image ) != /* Load a profile from a blob and check compatibility.
vips_icc_profile_needs_bands( profile ) ) { */
VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "embedded profile incompatible with image" ) );
return( NULL );
}
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "embedded profile colourspace differs from image" ) );
return( NULL );
}
return( profile );
}
static cmsHPROFILE static cmsHPROFILE
vips_icc_load_profile_file( const char *domain, vips_icc_load_profile_blob( VipsBlob *blob, VipsImage *image )
VipsImage *image, const char *filename )
{ {
const void *data;
size_t size;
cmsHPROFILE profile; cmsHPROFILE profile;
if( !(profile = cmsOpenProfileFromFile( filename, "r" )) ) { data = vips_blob_get( blob, &size );
vips_error( domain, if( !(profile = cmsOpenProfileFromMem( data, size )) ) {
_( "unable to open profile \"%s\"" ), filename ); g_warning( "%s", _( "corrupt profile" ) );
return( NULL ); return( NULL );
} }
if( vips_image_expected_bands( image ) != if( image &&
vips_image_expected_bands( image ) !=
vips_icc_profile_needs_bands( profile ) ) { vips_icc_profile_needs_bands( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile ); VIPS_FREEF( cmsCloseProfile, profile );
g_warning( _( "profile \"%s\" incompatible with image" ), g_warning( "%s", _( "profile incompatible with image" ) );
filename );
return( NULL ); return( NULL );
} }
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) { if( image &&
vips_image_expected_sig( image ) !=
cmsGetColorSpace( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile ); VIPS_FREEF( cmsCloseProfile, profile );
g_warning( _( "profile \"%s\" colourspace " g_warning( "%s",
"differs from image" ), filename ); _( "profile colourspace differs from image" ) );
return( NULL ); return( NULL );
} }
@ -657,23 +659,26 @@ vips_icc_import_build( VipsObject *object )
* 1 0 image * 1 0 image
* 0 1 file * 0 1 file
* 1 1 image, then fall back to file * 1 1 image, then fall back to file
*
* see also import_build.
*/ */
if( code->in && if( code->in &&
(import->embedded || (import->embedded ||
!import->input_profile_filename) ) !import->input_profile_filename) )
icc->in_profile = vips_icc_load_profile_image( code->in ); icc->in_blob = vips_icc_get_profile_image( code->in );
if( !icc->in_profile && if( !icc->in_blob &&
code->in &&
import->input_profile_filename ) { import->input_profile_filename ) {
icc->in_profile = vips_icc_load_profile_file( class->nickname, if( vips_profile_load( import->input_profile_filename,
code->in, import->input_profile_filename ); &icc->in_blob, NULL ) )
return( -1 );
import->used_fallback = TRUE; import->used_fallback = TRUE;
} }
if( icc->in_blob &&
code->in )
icc->in_profile =
vips_icc_load_profile_blob( icc->in_blob, code->in );
if( !icc->in_profile ) { if( !icc->in_profile ) {
vips_error( class->nickname, "%s", _( "no input profile" ) ); vips_error( class->nickname, "%s", _( "no input profile" ) );
return( -1 ); return( -1 );
@ -695,23 +700,19 @@ vips_icc_import_build( VipsObject *object )
return( -1 ); return( -1 );
/* If we used the fallback profile, we need to attach it to the PCS /* If we used the fallback profile, we need to attach it to the PCS
* image since the PCS image needs to know about a route back to * image, since the PCS image needs a route back to device space.
* device space.
* *
* In the same way, we don't remove the embedded input profile on * In the same way, we don't remove the embedded input profile on
* import. * import.
*/ */
if( import->used_fallback ) { if( import->used_fallback &&
char *data; icc->in_blob ) {
size_t length; const void *data;
size_t size;
if( !(data = vips__file_read_name(
import->input_profile_filename,
vips__icc_dir(), &length )) )
return( -1 );
data = vips_blob_get( icc->in_blob, &size );
vips_image_set_blob( colour->out, VIPS_META_ICC_NAME, vips_image_set_blob( colour->out, VIPS_META_ICC_NAME,
(VipsCallbackFn) vips_free, data, length ); NULL, data, size );
} }
return( 0 ); return( 0 );
@ -859,36 +860,25 @@ vips_icc_export_build( VipsObject *object )
icc->in_profile = cmsCreateXYZProfile(); icc->in_profile = cmsCreateXYZProfile();
if( code->in && if( code->in &&
!export->output_profile_filename && !export->output_profile_filename )
vips_image_get_typeof( code->in, VIPS_META_ICC_NAME ) ) { icc->out_blob = vips_icc_get_profile_image( code->in );
void *data;
size_t data_length;
if( vips_image_get_blob( code->in, VIPS_META_ICC_NAME, if( !icc->out_blob &&
&data, &data_length ) || export->output_profile_filename ) {
!(icc->out_profile = cmsOpenProfileFromMem( if( vips_profile_load( export->output_profile_filename,
data, data_length )) ) { &icc->out_blob, NULL ) )
vips_error( class->nickname,
"%s", _( "unable to load embedded profile" ) );
return( -1 ); return( -1 );
}
}
else if( export->output_profile_filename ) {
if( !(icc->out_profile = cmsOpenProfileFromFile(
export->output_profile_filename, "r" )) ) {
vips_error( class->nickname,
_( "unable to open profile \"%s\"" ),
export->output_profile_filename );
return( -1 );
}
colour->profile_filename = export->output_profile_filename; colour->profile_filename = export->output_profile_filename;
} }
else {
if( icc->out_blob &&
!(icc->out_profile =
vips_icc_load_profile_blob( icc->out_blob, NULL )) ) {
vips_error( class->nickname, "%s", _( "no output profile" ) ); vips_error( class->nickname, "%s", _( "no output profile" ) );
return( -1 ); return( -1 );
} }
if( icc->out_profile )
vips_check_intent( class->nickname, vips_check_intent( class->nickname,
icc->out_profile, icc->intent, LCMS_USED_AS_OUTPUT ); icc->out_profile, icc->intent, LCMS_USED_AS_OUTPUT );
@ -1077,13 +1067,18 @@ vips_icc_transform_build( VipsObject *object )
if( code->in && if( code->in &&
(transform->embedded || (transform->embedded ||
!transform->input_profile_filename) ) !transform->input_profile_filename) )
icc->in_profile = vips_icc_load_profile_image( code->in ); icc->in_blob = vips_icc_get_profile_image( code->in );
if( !icc->in_profile && if( !icc->in_blob &&
code->in &&
transform->input_profile_filename ) transform->input_profile_filename )
icc->in_profile = vips_icc_load_profile_file( class->nickname, if( vips_profile_load( transform->input_profile_filename,
code->in, transform->input_profile_filename ); &icc->in_blob, NULL ) )
return( -1 );
if( icc->in_blob &&
code->in )
icc->in_profile =
vips_icc_load_profile_blob( icc->in_blob, code->in );
if( !icc->in_profile ) { if( !icc->in_profile ) {
vips_error( class->nickname, "%s", _( "no input profile" ) ); vips_error( class->nickname, "%s", _( "no input profile" ) );
@ -1091,15 +1086,19 @@ vips_icc_transform_build( VipsObject *object )
} }
if( transform->output_profile_filename ) { if( transform->output_profile_filename ) {
if( !(icc->out_profile = cmsOpenProfileFromFile( if( vips_profile_load( transform->output_profile_filename,
transform->output_profile_filename, "r" )) ) { &icc->out_blob, NULL ) )
vips_error( class->nickname,
_( "unable to open profile \"%s\"" ),
transform->output_profile_filename );
return( -1 ); return( -1 );
colour->profile_filename = transform->output_profile_filename;
} }
colour->profile_filename = transform->output_profile_filename; if( icc->out_blob )
icc->out_profile =
vips_icc_load_profile_blob( icc->out_blob, NULL );
if( !icc->out_profile ) {
vips_error( class->nickname, "%s", _( "no output profile" ) );
return( -1 );
} }
vips_check_intent( class->nickname, vips_check_intent( class->nickname,
@ -1250,30 +1249,27 @@ vips_icc_ac2rc( VipsImage *in, VipsImage **out, const char *profile_filename )
return( 0 ); return( 0 );
} }
/* TRUE if a profile is compatible with an image. /* TRUE if a profile is sane and is compatible with an image.
*/ */
gboolean gboolean
vips_icc_is_compatible_profile( VipsImage *image, vips_icc_is_compatible_profile( VipsImage *image,
void *data, size_t data_length ) const void *data, size_t data_length )
{ {
cmsHPROFILE profile; cmsHPROFILE profile;
if( !(profile = cmsOpenProfileFromMem( data, data_length )) ) { if( !(profile = cmsOpenProfileFromMem( data, data_length )) )
g_warning( "%s", _( "corrupt profile" ) ); /* Corrupt profile.
*/
return( FALSE ); return( FALSE );
}
if( vips_image_expected_bands( image ) != if( vips_image_expected_bands( image ) !=
vips_icc_profile_needs_bands( profile ) ) { vips_icc_profile_needs_bands( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile ); VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "profile incompatible with image" ) );
return( FALSE ); return( FALSE );
} }
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) { if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile ); VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "profile colourspace differs from image" ) );
return( FALSE ); return( FALSE );
} }

View File

@ -216,6 +216,13 @@ extern float vips_v2Y_16[65536];
void vips_col_make_tables_RGB_8( void ); void vips_col_make_tables_RGB_8( void );
void vips_col_make_tables_RGB_16( void ); void vips_col_make_tables_RGB_16( void );
/* A colour-transforming function.
*/
typedef int (*VipsColourTransformFn)( VipsImage *in, VipsImage **out, ... );
int vips__colourspace_process_n( const char *domain,
VipsImage *in, VipsImage **out, int n, VipsColourTransformFn fn );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -0,0 +1,254 @@
/* Load profiles as blobs.
*
* 10/1/19
* - from CMYK2XYZ.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
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips.h>
#include <stdio.h>
#include <math.h>
#include <vips/internal.h>
#include "profiles.h"
#include "pcolour.h"
typedef struct _VipsProfileLoad {
VipsOperation parent_instance;
const char *name;
VipsBlob *profile;
} VipsProfileLoad;
typedef VipsOperationClass VipsProfileLoadClass;
G_DEFINE_TYPE( VipsProfileLoad, vips_profile_load, VIPS_TYPE_OPERATION );
/* Created on first use from a base64 string in profiles.c.
*/
typedef struct _VipsFallbackProfile {
const char *name;
void *data;
size_t data_length;
} VipsFallbackProfile;
static GSList *vips_fallback_profile_list = NULL;
static void *
vips_fallback_profile_get_init( void )
{
int i;
for( i = 0; vips__coded_profiles[i].name; i++ ) {
size_t data_length;
unsigned char *data;
VipsFallbackProfile *fallback;
if( !(data = vips__b64_decode(
vips__coded_profiles[i].data, &data_length )) )
return( NULL );
fallback = g_new( VipsFallbackProfile,1 );
fallback->name = vips__coded_profiles[i].name;
fallback->data = data;
fallback->data_length = data_length;
vips_fallback_profile_list = g_slist_prepend(
vips_fallback_profile_list, fallback );
}
return( NULL );
}
static void *
vips_fallback_profile_get( const char *name, size_t *length )
{
GOnce once = G_ONCE_INIT;
GSList *p;
VIPS_ONCE( &once, (GThreadFunc) vips_fallback_profile_get_init, NULL );
for( p = vips_fallback_profile_list; p; p = p->next ) {
VipsFallbackProfile *fallback = (VipsFallbackProfile *) p->data;
if( strcasecmp( fallback->name, name ) == 0 ) {
*length = fallback->data_length;
return( fallback->data );
}
}
return( NULL );
}
static int
vips_profile_load_build( VipsObject *object )
{
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
VipsProfileLoad *load = (VipsProfileLoad *) object;
size_t length;
const void *data;
VipsBlob *profile;
if( VIPS_OBJECT_CLASS( vips_profile_load_parent_class )->
build( object ) )
return( -1 );
if( strcasecmp( load->name, "none" ) == 0 ) {
profile = NULL;
}
else if( (data = vips_fallback_profile_get( load->name, &length )) ) {
profile = vips_blob_new( NULL, data, length );
}
else if( (data = vips__file_read_name( load->name,
vips__icc_dir(), &length )) ) {
profile = vips_blob_new( NULL, data, length );
}
else {
vips_error( class->nickname,
_( "unable to load profile \"%s\"" ), load->name );
return( -1 );
}
g_object_set( object, "profile", profile, NULL );
if( profile ) {
vips_area_unref( (VipsArea *) profile );
profile = NULL;
}
return( 0 );
}
static void
vips_profile_load_class_init( VipsProfileLoadClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *object_class = (VipsObjectClass *) class;
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
object_class->nickname = "profile_load";
object_class->description = _( "load named ICC profile" );
object_class->build = vips_profile_load_build;
VIPS_ARG_STRING( class, "name", 1,
_( "Name" ),
_( "Profile name" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsProfileLoad, name ),
NULL );
VIPS_ARG_BOXED( class, "profile", 2,
_( "Profile" ),
_( "Loaded profile" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsProfileLoad, profile ),
VIPS_TYPE_BLOB );
}
static void
vips_profile_load_init( VipsProfileLoad *load )
{
}
/**
* vips_profile_load:
* @name: name of profile to load
* @profile: (out): loaded profile
* @...: %NULL-terminated list of optional named arguments
*
* Load a named profile.
*
* Profiles are loaded from four sources:
*
* - The special name `"none"` means no profile. @profile will be %NULL in this
* case.
*
* - @name can be the name of one of the ICC profiles embedded in libvips.
* These names can be at least `"cmyk"` and `"srgb"`.
*
* - @name can be the full path to a file.
*
* - @name can be the name of an ICC profile in the system profile directory
* for your platform.
*
* Returns: 0 on success, -1 on error
*/
int
vips_profile_load( const char *name, VipsBlob **profile, ... )
{
va_list ap;
int result;
va_start( ap, profile );
result = vips_call_split( "profile_load", ap, name, profile );
va_end( ap );
return( result );
}
/* Set (or remove) a named profile on an image.
*/
int
vips__profile_set( VipsImage *image, const char *name )
{
VipsBlob *profile;
void *data;
size_t length;
if( vips_profile_load( name, &profile, NULL ) )
return( -1 );
if( profile ) {
data = ((VipsArea *) profile)->data;
length = ((VipsArea *) profile)->length;
vips_image_set_blob( image, VIPS_META_ICC_NAME,
(VipsCallbackFn) NULL, data, length );
}
else
vips_image_remove( image, VIPS_META_ICC_NAME );
if( profile ) {
vips_area_unref( (VipsArea *) profile );
profile = NULL;
}
return( 0 );
}

17004
libvips/colour/profiles.c Normal file

File diff suppressed because it is too large Load Diff

10
libvips/colour/profiles.h Normal file
View File

@ -0,0 +1,10 @@
/* The fallback profiles, coded as a set of base64 strings, see
* wrap-profiles.sh
*/
typedef struct _VipsCodedProfile {
const char *name;
const char *data;
} VipsCodedProfile;
extern VipsCodedProfile vips__coded_profiles[];

Binary file not shown.

Binary file not shown.

22
libvips/colour/wrap-profiles.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# code up the binary files in $1 as a set of name / base64-encoded strings
# in $2
in=$1
out=$2
echo "/* coded files, generated automatically */" > $out
echo "" >> $out
echo "#include \"profiles.h\"" >> $out
echo "" >> $out
echo "VipsCodedProfile vips__coded_profiles[] = {" >> $out
for file in $in/*; do
root=${file%.icm}
base=${root##*/}
echo " { \"$base\"," >> $out
base64 $file | sed 's/\(.*\)/"\1"/g' >> $out
echo " }," >> $out
done
echo " { 0, 0 }" >> $out
echo "};" >> $out

View File

@ -194,11 +194,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION );
ITYPE * restrict p = (ITYPE *) in; \ ITYPE * restrict p = (ITYPE *) in; \
OTYPE * restrict q = (OTYPE *) out; \ OTYPE * restrict q = (OTYPE *) out; \
\ \
for( x = 0; x < sz; x++ ) { \ for( x = 0; x < sz; x++ ) \
TEMP v = VIPS_FLOOR( p[x] ); \ q[x] = CAST( p[x] ); \
\
q[x] = CAST( v ); \
} \
} }
/* Cast complex types to an int type. Just take the real part. /* Cast complex types to an int type. Just take the real part.
@ -208,10 +205,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION );
OTYPE * restrict q = (OTYPE *) out; \ OTYPE * restrict q = (OTYPE *) out; \
\ \
for( x = 0; x < sz; x++ ) { \ for( x = 0; x < sz; x++ ) { \
TEMP v = VIPS_FLOOR( p[0] ); \ q[x] = CAST( p[0] ); \
\
p += 2; \ p += 2; \
q[x] = CAST( v ); \
} \ } \
} }

View File

@ -22,6 +22,8 @@
* - use linear uchar mode * - use linear uchar mode
* 14/7/14 * 14/7/14
* - round to nearest on uchar output * - round to nearest on uchar output
* 29/12/18 kleisauke
* - ... and round to nearest in log mode too
*/ */
/* /*
@ -111,7 +113,9 @@ vips_scale_build( VipsObject *object )
if( vips_pow_const1( scale->in, &t[2], scale->exp, NULL ) || if( vips_pow_const1( scale->in, &t[2], scale->exp, NULL ) ||
vips_linear1( t[2], &t[3], 1.0, 1.0, NULL ) || vips_linear1( t[2], &t[3], 1.0, 1.0, NULL ) ||
vips_log10( t[3], &t[4], NULL ) || vips_log10( t[3], &t[4], NULL ) ||
vips_linear1( t[4], &t[5], f, 0.0, /* Add 0.5 to get round to nearest.
*/
vips_linear1( t[4], &t[5], f, 0.5,
"uchar", TRUE, "uchar", TRUE,
NULL ) || NULL ) ||
vips_image_write( t[5], conversion->out ) ) vips_image_write( t[5], conversion->out ) )

View File

@ -76,6 +76,8 @@
* 24/11/17 * 24/11/17
* - output overlap-only tiles on edges for better deepzoom spec * - output overlap-only tiles on edges for better deepzoom spec
* compliance * compliance
* 19/12/18
* - add @skip_blanks
*/ */
/* /*
@ -448,6 +450,7 @@ struct _VipsForeignSaveDz {
VipsForeignDzContainer container; VipsForeignDzContainer container;
int compression; int compression;
VipsRegionShrink region_shrink; VipsRegionShrink region_shrink;
int skip_blanks;
/* Tile and overlap geometry. The members above are the parameters we /* Tile and overlap geometry. The members above are the parameters we
* accept, this next set are the derived values which are actually * accept, this next set are the derived values which are actually
@ -1044,14 +1047,14 @@ tile_name( Layer *layer, int x, int y )
return( out ); return( out );
} }
/* Test for tile equal to background colour. In google maps mode, we skip /* Test for tile nearly equal to background colour. In google maps mode, we
* blank background tiles. * skip blank background tiles.
* *
* Don't use exactly equality, since compression artefacts or noise can upset * Don't use exactly equality since compression artefacts or noise can upset
* this. * this.
*/ */
static gboolean static gboolean
tile_equal( VipsImage *image, VipsPel * restrict ink ) tile_equal( VipsImage *image, int threshold, VipsPel * restrict ink )
{ {
const int bytes = VIPS_IMAGE_SIZEOF_PEL( image ); const int bytes = VIPS_IMAGE_SIZEOF_PEL( image );
@ -1077,7 +1080,7 @@ tile_equal( VipsImage *image, VipsPel * restrict ink )
for( x = 0; x < image->Xsize; x++ ) { for( x = 0; x < image->Xsize; x++ ) {
for( b = 0; b < bytes; b++ ) for( b = 0; b < bytes; b++ )
if( VIPS_ABS( p[b] - ink[b] ) > 5 ) { if( VIPS_ABS( p[b] - ink[b] ) > threshold ) {
g_object_unref( region ); g_object_unref( region );
return( FALSE ); return( FALSE );
} }
@ -1166,11 +1169,8 @@ strip_work( VipsThreadState *state, void *a )
state->pos.width, state->pos.height, NULL ) ) state->pos.width, state->pos.height, NULL ) )
return( -1 ); return( -1 );
/* If we are writing a google map pyramid and the tile is equal to the if( dz->skip_blanks >= 0 &&
* background, don't save. The viewer will display blank.png for us. tile_equal( x, dz->skip_blanks, dz->ink ) ) {
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE &&
tile_equal( x, dz->ink ) ) {
g_object_unref( x ); g_object_unref( x );
#ifdef DEBUG_VERBOSE #ifdef DEBUG_VERBOSE
@ -1631,6 +1631,12 @@ vips_foreign_save_dz_build( VipsObject *object )
dz->tile_size = 256; dz->tile_size = 256;
} }
/* skip_blanks defaults to 5 in google mode.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE &&
!vips_object_argument_isset( object, "skip_blanks" ) )
dz->skip_blanks = 5;
/* Our tile layout. /* Our tile layout.
*/ */
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_DZ ) { if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_DZ ) {
@ -1650,8 +1656,7 @@ vips_foreign_save_dz_build( VipsObject *object )
/* Default to white background. vips_foreign_save_init() defaults to /* Default to white background. vips_foreign_save_init() defaults to
* black. * black.
*/ */
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE && if( !vips_object_argument_isset( object, "background" ) ) {
!vips_object_argument_isset( object, "background" ) ) {
VipsArrayDouble *background; VipsArrayDouble *background;
/* Using g_object_set() to set an input param in build will /* Using g_object_set() to set an input param in build will
@ -1690,9 +1695,9 @@ vips_foreign_save_dz_build( VipsObject *object )
save->ready = z; save->ready = z;
} }
/* We use ink in google mode to check for blank tiles. /* We use ink to check for blank tiles.
*/ */
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE ) { if( dz->skip_blanks >= 0 ) {
if( !(dz->ink = vips__vector_to_ink( if( !(dz->ink = vips__vector_to_ink(
class->nickname, save->ready, class->nickname, save->ready,
VIPS_AREA( save->background )->data, NULL, VIPS_AREA( save->background )->data, NULL,
@ -2105,6 +2110,13 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
G_STRUCT_OFFSET( VipsForeignSaveDz, region_shrink ), G_STRUCT_OFFSET( VipsForeignSaveDz, region_shrink ),
VIPS_TYPE_REGION_SHRINK, VIPS_REGION_SHRINK_MEAN ); VIPS_TYPE_REGION_SHRINK, VIPS_REGION_SHRINK_MEAN );
VIPS_ARG_INT( class, "skip_blanks", 19,
_( "Skip blanks" ),
_( "Skip tiles which are nearly equal to the background" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, skip_blanks ),
-1, 65535, -1 );
/* How annoying. We stupidly had these in earlier versions. /* How annoying. We stupidly had these in earlier versions.
*/ */
@ -2144,6 +2156,7 @@ vips_foreign_save_dz_init( VipsForeignSaveDz *dz )
dz->container = VIPS_FOREIGN_DZ_CONTAINER_FS; dz->container = VIPS_FOREIGN_DZ_CONTAINER_FS;
dz->compression = 0; dz->compression = 0;
dz->region_shrink = VIPS_REGION_SHRINK_MEAN; dz->region_shrink = VIPS_REGION_SHRINK_MEAN;
dz->skip_blanks = -1;
} }
typedef struct _VipsForeignSaveDzFile { typedef struct _VipsForeignSaveDzFile {
@ -2340,7 +2353,8 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* * @container: #VipsForeignDzContainer set container type * * @container: #VipsForeignDzContainer set container type
* * @properties: %gboolean write a properties file * * @properties: %gboolean write a properties file
* * @compression: %gint zip deflate compression level * * @compression: %gint zip deflate compression level
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region. * * @region_shrink: #VipsRegionShrink how to shrink each 2x2 region
* * @skip_blanks: %gint skip tiles which are nearly equal to the background
* *
* Save an image as a set of tiles at various resolutions. By default dzsave * Save an image as a set of tiles at various resolutions. By default dzsave
* uses DeepZoom layout -- use @layout to pick other conventions. * uses DeepZoom layout -- use @layout to pick other conventions.
@ -2388,6 +2402,11 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* region. This defaults to using the average of the 4 input pixels but you can * region. This defaults to using the average of the 4 input pixels but you can
* also use the median in cases where you want to preserve the range of values. * also use the median in cases where you want to preserve the range of values.
* *
* If you set @skip_blanks to a value greater than or equal to zero, tiles
* which are all within that many pixel values to the background are skipped.
* This can save a lot of space for some image types. This option defaults to
* 5 in Google layout mode, -1 otherwise.
*
* See also: vips_tiffsave(). * See also: vips_tiffsave().
* *
* Returns: 0 on success, -1 on error. * Returns: 0 on success, -1 on error.
@ -2426,7 +2445,8 @@ vips_dzsave( VipsImage *in, const char *name, ... )
* * @container: #VipsForeignDzContainer set container type * * @container: #VipsForeignDzContainer set container type
* * @properties: %gboolean write a properties file * * @properties: %gboolean write a properties file
* * @compression: %gint zip deflate compression level * * @compression: %gint zip deflate compression level
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region. * * @region_shrink: #VipsRegionShrink how to shrink each 2x2 region.
* * @skip_blanks: %gint skip tiles which are nearly equal to the background
* *
* As vips_dzsave(), but save to a memory buffer. * As vips_dzsave(), but save to a memory buffer.
* *

View File

@ -158,7 +158,7 @@ show_values( ExifData *data )
* their default value and we won't know about it. * their default value and we won't know about it.
*/ */
static ExifData * static ExifData *
vips_exif_load_data_without_fix( void *data, int length ) vips_exif_load_data_without_fix( const void *data, int length )
{ {
ExifData *ed; ExifData *ed;
@ -458,17 +458,17 @@ vips_exif_resolution_from_image( ExifData *ed, VipsImage *image );
int int
vips__exif_parse( VipsImage *image ) vips__exif_parse( VipsImage *image )
{ {
void *data; const void *data;
size_t length; size_t size;
ExifData *ed; ExifData *ed;
VipsExifParams params; VipsExifParams params;
const char *str; const char *str;
if( !vips_image_get_typeof( image, VIPS_META_EXIF_NAME ) ) if( !vips_image_get_typeof( image, VIPS_META_EXIF_NAME ) )
return( 0 ); return( 0 );
if( vips_image_get_blob( image, VIPS_META_EXIF_NAME, &data, &length ) ) if( vips_image_get_blob( image, VIPS_META_EXIF_NAME, &data, &size ) )
return( -1 ); return( -1 );
if( !(ed = vips_exif_load_data_without_fix( data, length )) ) if( !(ed = vips_exif_load_data_without_fix( data, size )) )
return( -1 ); return( -1 );
#ifdef DEBUG_VERBOSE #ifdef DEBUG_VERBOSE
@ -1055,21 +1055,21 @@ vips_exif_set_thumbnail( ExifData *ed, VipsImage *im )
/* Update EXIF thumbnail from metadata, if any. /* Update EXIF thumbnail from metadata, if any.
*/ */
if( vips_image_get_typeof( im, "jpeg-thumbnail-data" ) ) { if( vips_image_get_typeof( im, "jpeg-thumbnail-data" ) ) {
void *data; const void *data;
size_t length; size_t size;
if( vips_image_get_blob( im, "jpeg-thumbnail-data", if( vips_image_get_blob( im, "jpeg-thumbnail-data",
&data, &length ) ) &data, &size ) )
return( -1 ); return( -1 );
/* Again, we should use the exif allocator attached to this /* Again, we should use the exif allocator attached to this
* entry, but it is not exposed! * entry, but it is not exposed!
*/ */
if( length > 0 && if( size > 0 &&
data ) { data ) {
ed->data = malloc( length ); ed->data = malloc( size );
memcpy( ed->data, data, length ); memcpy( ed->data, data, size );
ed->size = length; ed->size = size;
} }
} }

View File

@ -1259,15 +1259,6 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
g_object_unref( in ); g_object_unref( in );
in = out; in = out;
/* We've imported to PCS, we must remove the embedded profile,
* since it no longer matches the image.
*
* For example, when converting CMYK JPG to RGB PNG, we need
* to remove the CMYK profile on import, or the png writer will
* try to attach it when we write the image as RGB.
*/
vips_image_remove( in, VIPS_META_ICC_NAME );
} }
/* If this is something other than CMYK or RAD, eg. maybe a LAB image, /* If this is something other than CMYK or RAD, eg. maybe a LAB image,
@ -1515,10 +1506,10 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
/* Some format libraries, like libpng, will throw a hard error if the /* Some format libraries, like libpng, will throw a hard error if the
* profile is inappropriate for this image type. With profiles inherited * profile is inappropriate for this image type. With profiles inherited
* from a source image, this can happen all the time, so we * from a source image, this can happen all the time, so we
* want to just drop the profile in this case. * want to silently drop the profile in this case.
*/ */
if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) { if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
void *data; const void *data;
size_t length; size_t length;
if( !vips_image_get_blob( in, VIPS_META_ICC_NAME, if( !vips_image_get_blob( in, VIPS_META_ICC_NAME,

View File

@ -75,7 +75,7 @@ typedef struct _VipsForeignSaveJpeg {
*/ */
int Q; int Q;
/* Profile to embed .. "none" means don't attach a profile. /* Profile to embed.
*/ */
char *profile; char *profile;
@ -434,10 +434,9 @@ vips_foreign_save_jpeg_mime_init( VipsForeignSaveJpegMime *mime )
* *
* Use @Q to set the JPEG compression factor. Default 75. * Use @Q to set the JPEG compression factor. Default 75.
* *
* Use @profile to give the filename of a profile to be embedded in the JPEG. * Use @profile to give the name of a profile to be embedded in the JPEG.
* This does not affect the pixels which are written, just the way * This does not affect the pixels which are written, just the way
* they are tagged. You can use the special string "none" to mean * they are tagged. See vips_profile_load() for details on profile naming.
* "don't attach a profile".
* *
* If no profile is specified and the VIPS header * If no profile is specified and the VIPS header
* contains an ICC profile named #VIPS_META_ICC_NAME, the * contains an ICC profile named #VIPS_META_ICC_NAME, the

View File

@ -85,6 +85,18 @@ magick_set_property( Image *image, const char *property, const char *value,
(void) SetImageProperty( image, property, value, exception ); (void) SetImageProperty( image, property, value, exception );
} }
ExceptionInfo *
magick_acquire_exception( void )
{
return( AcquireExceptionInfo() );
}
void
magick_destroy_exception( ExceptionInfo *exception )
{
VIPS_FREEF( DestroyExceptionInfo, exception );
}
void void
magick_inherit_exception( ExceptionInfo *exception, Image *image ) magick_inherit_exception( ExceptionInfo *exception, Image *image )
{ {
@ -197,6 +209,42 @@ magick_set_property( Image *image, const char *property, const char *value,
#endif /*HAVE_SETIMAGEPROPERTY*/ #endif /*HAVE_SETIMAGEPROPERTY*/
} }
ExceptionInfo *
magick_acquire_exception( void )
{
ExceptionInfo *exception;
#ifdef HAVE_ACQUIREEXCEPTIONINFO
/* IM6+
*/
exception = AcquireExceptionInfo();
#else /*!HAVE_ACQUIREEXCEPTIONINFO*/
/* gm
*/
exception = g_new( ExceptionInfo, 1 );
GetExceptionInfo( exception );
#endif /*HAVE_ACQUIREEXCEPTIONINFO*/
return( exception );
}
void
magick_destroy_exception( ExceptionInfo *exception )
{
#ifdef HAVE_ACQUIREEXCEPTIONINFO
/* IM6+ will free the exception in destroy.
*/
VIPS_FREEF( DestroyExceptionInfo, exception );
#else /*!HAVE_ACQUIREEXCEPTIONINFO*/
/* gm and very old IM need to free the memory too.
*/
if( exception ) {
DestroyExceptionInfo( exception );
g_free( exception );
}
#endif /*HAVE_ACQUIREEXCEPTIONINFO*/
}
void void
magick_inherit_exception( ExceptionInfo *exception, Image *image ) magick_inherit_exception( ExceptionInfo *exception, Image *image )
{ {

View File

@ -58,7 +58,10 @@ void magick_set_image_option( ImageInfo *image_info,
void magick_set_number_scenes( ImageInfo *image_info, void magick_set_number_scenes( ImageInfo *image_info,
int scene, int number_scenes ); int scene, int number_scenes );
ExceptionInfo *magick_acquire_exception( void );
void magick_destroy_exception( ExceptionInfo *exception );
void magick_inherit_exception( ExceptionInfo *exception, Image *image ); void magick_inherit_exception( ExceptionInfo *exception, Image *image );
void magick_sniff_bytes( ImageInfo *image_info, void magick_sniff_bytes( ImageInfo *image_info,
const unsigned char *bytes, size_t length ); const unsigned char *bytes, size_t length );
void magick_sniff_file( ImageInfo *image_info, const char *filename ); void magick_sniff_file( ImageInfo *image_info, const char *filename );

View File

@ -59,6 +59,9 @@
* - don't use Ping, it's too unreliable * - don't use Ping, it's too unreliable
* 24/7/18 * 24/7/18
* - sniff extra filetypes * - sniff extra filetypes
* 4/1/19 kleisauke
* - we did not chain exceptions correctly, causing a memory leak
* - added wrapper funcs for exception handling
*/ */
/* /*
@ -137,7 +140,7 @@ typedef struct _Read {
Image *image; Image *image;
ImageInfo *image_info; ImageInfo *image_info;
ExceptionInfo exception; ExceptionInfo *exception;
/* Number of pages in image. /* Number of pages in image.
*/ */
@ -168,9 +171,7 @@ read_free( Read *read )
VIPS_FREEF( DestroyImageList, read->image ); VIPS_FREEF( DestroyImageList, read->image );
VIPS_FREEF( DestroyImageInfo, read->image_info ); VIPS_FREEF( DestroyImageInfo, read->image_info );
VIPS_FREE( read->frames ); VIPS_FREE( read->frames );
if ( (&read->exception)->signature == MagickSignature ) { VIPS_FREEF( magick_destroy_exception, read->exception );
DestroyExceptionInfo( &read->exception );
}
VIPS_FREEF( vips_g_mutex_free, read->lock ); VIPS_FREEF( vips_g_mutex_free, read->lock );
} }
@ -209,7 +210,7 @@ read_new( const char *filename, VipsImage *im,
read->im = im; read->im = im;
read->image = NULL; read->image = NULL;
read->image_info = CloneImageInfo( NULL ); read->image_info = CloneImageInfo( NULL );
GetExceptionInfo( &read->exception ); read->exception = magick_acquire_exception();
read->n_pages = 0; read->n_pages = 0;
read->n_frames = 0; read->n_frames = 0;
read->frames = NULL; read->frames = NULL;
@ -765,9 +766,9 @@ vips__magick_read( const char *filename,
printf( "magick2vips: calling ReadImage() ...\n" ); printf( "magick2vips: calling ReadImage() ...\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
read->image = ReadImage( read->image_info, &read->exception ); read->image = ReadImage( read->image_info, read->exception );
if( !read->image ) { if( !read->image ) {
magick_vips_error( "magick2vips", &read->exception ); magick_vips_error( "magick2vips", read->exception );
vips_error( "magick2vips", vips_error( "magick2vips",
_( "unable to read file \"%s\"" ), filename ); _( "unable to read file \"%s\"" ), filename );
return( -1 ); return( -1 );
@ -803,9 +804,9 @@ vips__magick_read_header( const char *filename,
* but sadly many IM coders do not support ping. The critical one for * but sadly many IM coders do not support ping. The critical one for
* us is DICOM. TGA also has issues. * us is DICOM. TGA also has issues.
*/ */
read->image = ReadImage( read->image_info, &read->exception ); read->image = ReadImage( read->image_info, read->exception );
if( !read->image ) { if( !read->image ) {
magick_vips_error( "magick2vips", &read->exception ); magick_vips_error( "magick2vips", read->exception );
vips_error( "magick2vips", vips_error( "magick2vips",
_( "unable to read file \"%s\"" ), filename ); _( "unable to read file \"%s\"" ), filename );
return( -1 ); return( -1 );
@ -845,9 +846,9 @@ vips__magick_read_buffer( const void *buf, const size_t len,
#endif /*DEBUG*/ #endif /*DEBUG*/
read->image = BlobToImage( read->image_info, read->image = BlobToImage( read->image_info,
buf, len, &read->exception ); buf, len, read->exception );
if( !read->image ) { if( !read->image ) {
magick_vips_error( "magick2vips", &read->exception ); magick_vips_error( "magick2vips", read->exception );
vips_error( "magick2vips", "%s", _( "unable to read buffer" ) ); vips_error( "magick2vips", "%s", _( "unable to read buffer" ) );
return( -1 ); return( -1 );
} }
@ -883,9 +884,9 @@ vips__magick_read_buffer_header( const void *buf, const size_t len,
* for us is DICOM. TGA also has issues. * for us is DICOM. TGA also has issues.
*/ */
read->image = BlobToImage( read->image_info, read->image = BlobToImage( read->image_info,
buf, len, &read->exception ); buf, len, read->exception );
if( !read->image ) { if( !read->image ) {
magick_vips_error( "magick2vips", &read->exception ); magick_vips_error( "magick2vips", read->exception );
vips_error( "magick2vips", "%s", _( "unable to ping blob" ) ); vips_error( "magick2vips", "%s", _( "unable to ping blob" ) );
return( -1 ); return( -1 );
} }

View File

@ -279,7 +279,7 @@ vips_foreign_load_magick7_dispose( GObject *gobject )
VIPS_FREEF( DestroyImageInfo, magick7->image_info ); VIPS_FREEF( DestroyImageInfo, magick7->image_info );
VIPS_FREE( magick7->frames ); VIPS_FREE( magick7->frames );
VIPS_FREE( magick7->cache_view ); VIPS_FREE( magick7->cache_view );
VIPS_FREEF( DestroyExceptionInfo, magick7->exception ); VIPS_FREEF( magick_destroy_exception, magick7->exception );
VIPS_FREEF( vips_g_mutex_free, magick7->lock ); VIPS_FREEF( vips_g_mutex_free, magick7->lock );
G_OBJECT_CLASS( vips_foreign_load_magick7_parent_class )-> G_OBJECT_CLASS( vips_foreign_load_magick7_parent_class )->
@ -298,7 +298,7 @@ vips_foreign_load_magick7_build( VipsObject *object )
magick_genesis(); magick_genesis();
magick7->image_info = CloneImageInfo( NULL ); magick7->image_info = CloneImageInfo( NULL );
magick7->exception = AcquireExceptionInfo(); magick7->exception = magick_acquire_exception();
magick7->lock = vips_g_mutex_new(); magick7->lock = vips_g_mutex_new();
if( !magick7->image_info ) if( !magick7->image_info )
@ -760,14 +760,14 @@ ismagick7( const char *filename )
/* Horribly slow :-( /* Horribly slow :-(
*/ */
image_info = CloneImageInfo( NULL ); image_info = CloneImageInfo( NULL );
exception = AcquireExceptionInfo(); exception = magick_acquire_exception();
vips_strncpy( image_info->filename, filename, MagickPathExtent ); vips_strncpy( image_info->filename, filename, MagickPathExtent );
magick_sniff_file( image_info, filename ); magick_sniff_file( image_info, filename );
image = PingImage( image_info, exception ); image = PingImage( image_info, exception );
result = image != NULL; result = image != NULL;
VIPS_FREEF( DestroyImageList, image ); VIPS_FREEF( DestroyImageList, image );
VIPS_FREEF( DestroyImageInfo, image_info ); VIPS_FREEF( DestroyImageInfo, image_info );
VIPS_FREEF( DestroyExceptionInfo, exception ); VIPS_FREEF( magick_destroy_exception, exception );
return( result ); return( result );
} }
@ -863,13 +863,13 @@ vips_foreign_load_magick7_buffer_is_a_buffer( const void *buf, size_t len )
/* Horribly slow :-( /* Horribly slow :-(
*/ */
image_info = CloneImageInfo( NULL ); image_info = CloneImageInfo( NULL );
exception = AcquireExceptionInfo(); exception = magick_acquire_exception();
magick_sniff_bytes( image_info, buf, len ); magick_sniff_bytes( image_info, buf, len );
image = PingBlob( image_info, buf, len, exception ); image = PingBlob( image_info, buf, len, exception );
result = image != NULL; result = image != NULL;
VIPS_FREEF( DestroyImageList, image ); VIPS_FREEF( DestroyImageList, image );
VIPS_FREEF( DestroyImageInfo, image_info ); VIPS_FREEF( DestroyImageInfo, image_info );
VIPS_FREEF( DestroyExceptionInfo, exception ); VIPS_FREEF( magick_destroy_exception, exception );
return( result ); return( result );
} }

View File

@ -81,7 +81,7 @@ vips_foreign_save_magick_dispose( GObject *gobject )
VIPS_FREE( magick->map ); VIPS_FREE( magick->map );
VIPS_FREEF( DestroyImageList, magick->images ); VIPS_FREEF( DestroyImageList, magick->images );
VIPS_FREEF( DestroyImageInfo, magick->image_info ); VIPS_FREEF( DestroyImageInfo, magick->image_info );
VIPS_FREEF( DestroyExceptionInfo, magick->exception ); VIPS_FREEF( magick_destroy_exception, magick->exception );
G_OBJECT_CLASS( vips_foreign_save_magick_parent_class )-> G_OBJECT_CLASS( vips_foreign_save_magick_parent_class )->
dispose( gobject ); dispose( gobject );
@ -218,7 +218,7 @@ vips_foreign_save_magick_build( VipsObject *object )
*/ */
im = save->ready; im = save->ready;
magick->exception = AcquireExceptionInfo(); magick->exception = magick_acquire_exception();
magick->image_info = CloneImageInfo( NULL ); magick->image_info = CloneImageInfo( NULL );
magick->storage_type = UndefinedPixel; magick->storage_type = UndefinedPixel;

View File

@ -332,8 +332,7 @@ vips_foreign_save_png_buffer_init( VipsForeignSavePngBuffer *buffer )
* *
* Use @profile to give the filename of a profile to be embedded in the PNG. * Use @profile to give the filename of a profile to be embedded in the PNG.
* This does not affect the pixels which are written, just the way * This does not affect the pixels which are written, just the way
* they are tagged. You can use the special string "none" to mean * they are tagged. See vips_profile_load() for details on profile naming.
* "don't attach a profile".
* *
* If @profile is specified and the VIPS header * If @profile is specified and the VIPS header
* contains an ICC profile named VIPS_META_ICC_NAME ("icc-profile-data"), the * contains an ICC profile named VIPS_META_ICC_NAME ("icc-profile-data"), the

View File

@ -509,8 +509,7 @@ vips_foreign_save_tiff_buffer_init( VipsForeignSaveTiffBuffer *buffer )
* *
* Use @profile to give the filename of a profile to be embedded in the TIFF. * Use @profile to give the filename of a profile to be embedded in the TIFF.
* This does not affect the pixels which are written, just the way * This does not affect the pixels which are written, just the way
* they are tagged. You can use the special string "none" to mean * they are tagged. See vips_profile_load() for details on profile naming.
* "don't attach a profile".
* *
* If no profile is specified and the VIPS header * If no profile is specified and the VIPS header
* contains an ICC profile named #VIPS_META_ICC_NAME, the * contains an ICC profile named #VIPS_META_ICC_NAME, the

View File

@ -196,8 +196,6 @@ typedef struct {
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
ErrorManager eman; ErrorManager eman;
JSAMPROW *row_pointer; JSAMPROW *row_pointer;
char *profile_bytes;
size_t profile_length;
VipsImage *inverted; VipsImage *inverted;
} Write; } Write;
@ -207,7 +205,6 @@ write_destroy( Write *write )
jpeg_destroy_compress( &write->cinfo ); jpeg_destroy_compress( &write->cinfo );
VIPS_FREEF( fclose, write->eman.fp ); VIPS_FREEF( fclose, write->eman.fp );
VIPS_FREE( write->row_pointer ); VIPS_FREE( write->row_pointer );
VIPS_FREE( write->profile_bytes );
VIPS_UNREF( write->inverted ); VIPS_UNREF( write->inverted );
g_free( write ); g_free( write );
@ -227,8 +224,6 @@ write_new( VipsImage *in )
write->eman.pub.error_exit = vips__new_error_exit; write->eman.pub.error_exit = vips__new_error_exit;
write->eman.pub.output_message = vips__new_output_message; write->eman.pub.output_message = vips__new_output_message;
write->eman.fp = NULL; write->eman.fp = NULL;
write->profile_bytes = NULL;
write->profile_length = 0;
write->inverted = NULL; write->inverted = NULL;
return( write ); return( write );
@ -358,35 +353,42 @@ write_profile_data (j_compress_ptr cinfo,
static int static int
write_profile_file( Write *write, const char *profile ) write_profile_file( Write *write, const char *profile )
{ {
if( !(write->profile_bytes = VipsBlob *blob;
vips__file_read_name( profile, vips__icc_dir(),
&write->profile_length )) ) if( vips_profile_load( profile, &blob, NULL ) )
return( -1 ); return( -1 );
write_profile_data( &write->cinfo,
(JOCTET *) write->profile_bytes, write->profile_length ); if( blob ) {
size_t length;
const void *data = vips_blob_get( blob, &length );
write_profile_data( &write->cinfo, (JOCTET *) data, length );
#ifdef DEBUG #ifdef DEBUG
printf( "write_profile_file: attached profile \"%s\"\n", profile ); printf( "write_profile_file: "
"attached profile \"%s\"\n", profile );
#endif /*DEBUG*/ #endif /*DEBUG*/
vips_area_unref( (VipsArea *) blob );
}
return( 0 ); return( 0 );
} }
static int static int
write_profile_meta( Write *write ) write_profile_meta( Write *write )
{ {
void *data; const void *data;
size_t data_length; size_t length;
if( vips_image_get_blob( write->in, VIPS_META_ICC_NAME, if( vips_image_get_blob( write->in,
&data, &data_length ) ) VIPS_META_ICC_NAME, &data, &length ) )
return( -1 ); return( -1 );
write_profile_data( &write->cinfo, data, length );
write_profile_data( &write->cinfo, data, data_length );
#ifdef DEBUG #ifdef DEBUG
printf( "write_profile_meta: attached %zd byte profile from header\n", printf( "write_profile_meta: attached %zd byte profile from header\n",
data_length ); length );
#endif /*DEBUG*/ #endif /*DEBUG*/
return( 0 ); return( 0 );
@ -598,10 +600,9 @@ write_vips( Write *write, int qfac, const char *profile,
return( -1 ); return( -1 );
/* A profile supplied as an argument overrides an embedded /* A profile supplied as an argument overrides an embedded
* profile. "none" means don't attach a profile. * profile.
*/ */
if( profile && if( profile &&
strcmp( profile, "none" ) != 0 &&
write_profile_file( write, profile ) ) write_profile_file( write, profile ) )
return( -1 ); return( -1 );
if( !profile && if( !profile &&

View File

@ -327,24 +327,29 @@ struct _Wtiff {
int image_height; int image_height;
}; };
/* Embed an ICC profile from a file. /* Write an ICC Profile from a file into the JPEG stream.
*/ */
static int static int
embed_profile_file( TIFF *tif, const char *profile ) embed_profile_file( TIFF *tif, const char *profile )
{ {
char *buffer; VipsBlob *blob;
size_t length;
if( !(buffer = vips__file_read_name( profile, if( vips_profile_load( profile, &blob, NULL ) )
vips__icc_dir(), &length )) )
return( -1 ); return( -1 );
TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, buffer );
vips_free( buffer ); if( blob ) {
size_t length;
const void *data = vips_blob_get( blob, &length );
TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, data );
#ifdef DEBUG #ifdef DEBUG
printf( "vips2tiff: attached profile \"%s\"\n", profile ); printf( "vips2tiff: attached profile \"%s\"\n", profile );
#endif /*DEBUG*/ #endif /*DEBUG*/
vips_area_unref( (VipsArea *) blob );
}
return( 0 ); return( 0 );
} }
@ -353,12 +358,12 @@ embed_profile_file( TIFF *tif, const char *profile )
static int static int
embed_profile_meta( TIFF *tif, VipsImage *im ) embed_profile_meta( TIFF *tif, VipsImage *im )
{ {
void *data; const void *data;
size_t data_length; size_t length;
if( vips_image_get_blob( im, VIPS_META_ICC_NAME, &data, &data_length ) ) if( vips_image_get_blob( im, VIPS_META_ICC_NAME, &data, &length ) )
return( -1 ); return( -1 );
TIFFSetField( tif, TIFFTAG_ICCPROFILE, data_length, data ); TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, data );
#ifdef DEBUG #ifdef DEBUG
printf( "vips2tiff: attached profile from meta\n" ); printf( "vips2tiff: attached profile from meta\n" );
@ -442,7 +447,6 @@ static int
wtiff_embed_profile( Wtiff *wtiff, TIFF *tif ) wtiff_embed_profile( Wtiff *wtiff, TIFF *tif )
{ {
if( wtiff->icc_profile && if( wtiff->icc_profile &&
strcmp( wtiff->icc_profile, "none" ) != 0 &&
embed_profile_file( tif, wtiff->icc_profile ) ) embed_profile_file( tif, wtiff->icc_profile ) )
return( -1 ); return( -1 );
@ -457,15 +461,14 @@ wtiff_embed_profile( Wtiff *wtiff, TIFF *tif )
static int static int
wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif ) wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif )
{ {
void *data; const void *data;
size_t data_length; size_t size;
if( !vips_image_get_typeof( wtiff->im, VIPS_META_XMP_NAME ) ) if( !vips_image_get_typeof( wtiff->im, VIPS_META_XMP_NAME ) )
return( 0 ); return( 0 );
if( vips_image_get_blob( wtiff->im, VIPS_META_XMP_NAME, if( vips_image_get_blob( wtiff->im, VIPS_META_XMP_NAME, &data, &size ) )
&data, &data_length ) )
return( -1 ); return( -1 );
TIFFSetField( tif, TIFFTAG_XMLPACKET, data_length, data ); TIFFSetField( tif, TIFFTAG_XMLPACKET, size, data );
#ifdef DEBUG #ifdef DEBUG
printf( "vips2tiff: attached XMP from meta\n" ); printf( "vips2tiff: attached XMP from meta\n" );
@ -475,29 +478,29 @@ wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif )
} }
static int static int
wtiff_embed_ipct( Wtiff *wtiff, TIFF *tif ) wtiff_embed_iptc( Wtiff *wtiff, TIFF *tif )
{ {
void *data; const void *data;
size_t data_length; size_t size;
if( !vips_image_get_typeof( wtiff->im, VIPS_META_IPTC_NAME ) ) if( !vips_image_get_typeof( wtiff->im, VIPS_META_IPTC_NAME ) )
return( 0 ); return( 0 );
if( vips_image_get_blob( wtiff->im, VIPS_META_IPTC_NAME, if( vips_image_get_blob( wtiff->im, VIPS_META_IPTC_NAME,
&data, &data_length ) ) &data, &size ) )
return( -1 ); return( -1 );
/* For no very good reason, libtiff stores IPTC as an array of /* For no very good reason, libtiff stores IPTC as an array of
* long, not byte. * long, not byte.
*/ */
if( data_length & 3 ) { if( size & 3 ) {
g_warning( "%s", _( "rounding up IPTC data length" ) ); g_warning( "%s", _( "rounding up IPTC data length" ) );
data_length /= 4; size /= 4;
data_length += 1; size += 1;
} }
else else
data_length /= 4; size /= 4;
TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, data_length, data ); TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, size, data );
#ifdef DEBUG #ifdef DEBUG
printf( "vips2tiff: attached IPTC from meta\n" ); printf( "vips2tiff: attached IPTC from meta\n" );
@ -509,15 +512,15 @@ wtiff_embed_ipct( Wtiff *wtiff, TIFF *tif )
static int static int
wtiff_embed_photoshop( Wtiff *wtiff, TIFF *tif ) wtiff_embed_photoshop( Wtiff *wtiff, TIFF *tif )
{ {
void *data; const void *data;
size_t data_length; size_t size;
if( !vips_image_get_typeof( wtiff->im, VIPS_META_PHOTOSHOP_NAME ) ) if( !vips_image_get_typeof( wtiff->im, VIPS_META_PHOTOSHOP_NAME ) )
return( 0 ); return( 0 );
if( vips_image_get_blob( wtiff->im, if( vips_image_get_blob( wtiff->im,
VIPS_META_PHOTOSHOP_NAME, &data, &data_length ) ) VIPS_META_PHOTOSHOP_NAME, &data, &size ) )
return( -1 ); return( -1 );
TIFFSetField( tif, TIFFTAG_PHOTOSHOP, data_length, data ); TIFFSetField( tif, TIFFTAG_PHOTOSHOP, size, data );
#ifdef DEBUG #ifdef DEBUG
printf( "vips2tiff: attached photoshop data from meta\n" ); printf( "vips2tiff: attached photoshop data from meta\n" );
@ -596,7 +599,7 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer )
if( !wtiff->strip ) if( !wtiff->strip )
if( wtiff_embed_profile( wtiff, tif ) || if( wtiff_embed_profile( wtiff, tif ) ||
wtiff_embed_xmp( wtiff, tif ) || wtiff_embed_xmp( wtiff, tif ) ||
wtiff_embed_ipct( wtiff, tif ) || wtiff_embed_iptc( wtiff, tif ) ||
wtiff_embed_photoshop( wtiff, tif ) || wtiff_embed_photoshop( wtiff, tif ) ||
wtiff_embed_imagedescription( wtiff, tif ) ) wtiff_embed_imagedescription( wtiff, tif ) )
return( -1 ); return( -1 );
@ -1640,7 +1643,7 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in )
if( !wtiff->strip ) if( !wtiff->strip )
if( wtiff_embed_profile( wtiff, out ) || if( wtiff_embed_profile( wtiff, out ) ||
wtiff_embed_xmp( wtiff, out ) || wtiff_embed_xmp( wtiff, out ) ||
wtiff_embed_ipct( wtiff, out ) || wtiff_embed_iptc( wtiff, out ) ||
wtiff_embed_photoshop( wtiff, out ) || wtiff_embed_photoshop( wtiff, out ) ||
wtiff_embed_imagedescription( wtiff, out ) ) wtiff_embed_imagedescription( wtiff, out ) )
return( -1 ); return( -1 );

View File

@ -410,7 +410,7 @@ vips_webp_set_count( VipsWebPWrite *write, int loop_count )
static int static int
vips_webp_set_chunk( VipsWebPWrite *write, vips_webp_set_chunk( VipsWebPWrite *write,
const char *webp_name, void *data, size_t length ) const char *webp_name, const void *data, size_t length )
{ {
WebPData chunk; WebPData chunk;
@ -440,7 +440,7 @@ vips_webp_add_chunks( VipsWebPWrite *write, VipsImage *image )
const char *webp_name = vips__webp_names[i].webp; const char *webp_name = vips__webp_names[i].webp;
if( vips_image_get_typeof( image, vips_name ) ) { if( vips_image_get_typeof( image, vips_name ) ) {
void *data; const void *data;
size_t length; size_t length;
if( vips_image_get_blob( image, if( vips_image_get_blob( image,

View File

@ -490,6 +490,11 @@ png2vips_header( Read *read, VipsImage *out )
return( -1 ); return( -1 );
} }
/* Attach original palette bit depth, if any, as metadata.
*/
if( color_type == PNG_COLOR_TYPE_PALETTE )
vips_image_set_int( out, "palette-bit-depth", bit_depth );
return( 0 ); return( 0 );
} }
@ -1062,31 +1067,32 @@ write_vips( Write *write,
VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ), VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ),
PNG_RESOLUTION_METER ); PNG_RESOLUTION_METER );
/* Set ICC Profile. /* Metadata
*/ */
if( profile && if( !strip ) {
!strip ) { if( profile ) {
if( strcmp( profile, "none" ) != 0 ) { VipsBlob *blob;
void *data;
size_t length;
if( !(data = vips__file_read_name( profile, if( vips_profile_load( profile, &blob, NULL ) )
vips__icc_dir(), &length )) )
return( -1 ); return( -1 );
if( blob ) {
size_t length;
const void *data = vips_blob_get( blob, &length );
#ifdef DEBUG #ifdef DEBUG
printf( "write_vips: " printf( "write_vips: attaching %zd bytes "
"attaching %zd bytes of ICC profile\n", "of ICC profile\n", length );
length );
#endif /*DEBUG*/ #endif /*DEBUG*/
png_set_iCCP( write->pPng, write->pInfo, "icc", png_set_iCCP( write->pPng, write->pInfo,
PNG_COMPRESSION_TYPE_BASE, data, length ); "icc", PNG_COMPRESSION_TYPE_BASE,
data, length );
vips_area_unref( (VipsArea *) blob );
} }
} }
else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) && else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
!strip ) { const void *data;
void *data;
size_t length; size_t length;
if( vips_image_get_blob( in, VIPS_META_ICC_NAME, if( vips_image_get_blob( in, VIPS_META_ICC_NAME,
@ -1094,21 +1100,22 @@ write_vips( Write *write,
return( -1 ); return( -1 );
#ifdef DEBUG #ifdef DEBUG
printf( "write_vips: attaching %zd bytes of ICC profile\n", printf( "write_vips: attaching %zd bytes "
length ); "of ICC profile\n", length );
#endif /*DEBUG*/ #endif /*DEBUG*/
png_set_iCCP( write->pPng, write->pInfo, "icc", png_set_iCCP( write->pPng, write->pInfo, "icc",
PNG_COMPRESSION_TYPE_BASE, data, length ); PNG_COMPRESSION_TYPE_BASE, data, length );
} }
if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) { if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) {
void *data; const void *data;
size_t length; size_t length;
char *str; char *str;
/* XMP is attached as a BLOB with no null-termination. We /* XMP is attached as a BLOB with no null-termination.
* must re-add this. * We must re-add this.
*/ */
if( vips_image_get_blob( in, if( vips_image_get_blob( in,
VIPS_META_XMP_NAME, &data, &length ) ) VIPS_META_XMP_NAME, &data, &length ) )
@ -1121,11 +1128,10 @@ write_vips( Write *write,
g_free( str ); g_free( str );
} }
/* Set any "png-comment-xx-yyy" metadata items.
*/
if( vips_image_map( in, if( vips_image_map( in,
write_png_comment, write ) ) write_png_comment, write ) )
return( -1 ); return( -1 );
}
#ifdef HAVE_IMAGEQUANT #ifdef HAVE_IMAGEQUANT
if( palette ) { if( palette ) {

View File

@ -167,6 +167,13 @@ int vips_LabS2Lab( VipsImage *in, VipsImage **out, ... )
int vips_Lab2LabS( VipsImage *in, VipsImage **out, ... ) int vips_Lab2LabS( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_CMYK2XYZ( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_XYZ2CMYK( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_profile_load( const char *name, VipsBlob **profile, ... )
__attribute__((sentinel));
int vips_icc_present( void ); int vips_icc_present( void );
int vips_icc_transform( VipsImage *in, VipsImage **out, int vips_icc_transform( VipsImage *in, VipsImage **out,
const char *output_profile, ... ) const char *output_profile, ... )
@ -178,7 +185,7 @@ int vips_icc_export( VipsImage *in, VipsImage **out, ... )
int vips_icc_ac2rc( VipsImage *in, VipsImage **out, int vips_icc_ac2rc( VipsImage *in, VipsImage **out,
const char *profile_filename ); const char *profile_filename );
gboolean vips_icc_is_compatible_profile( VipsImage *image, gboolean vips_icc_is_compatible_profile( VipsImage *image,
void *data, size_t data_length ); const void *data, size_t data_length );
int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... ) int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));

View File

@ -194,11 +194,12 @@ void vips_image_set_area( VipsImage *image,
int vips_image_get_area( const VipsImage *image, int vips_image_get_area( const VipsImage *image,
const char *name, void **data ); const char *name, void **data );
void vips_image_set_blob( VipsImage *image, void vips_image_set_blob( VipsImage *image,
const char *name, VipsCallbackFn free_fn, void *data, size_t length ); const char *name,
VipsCallbackFn free_fn, const void *data, size_t length );
void vips_image_set_blob_copy( VipsImage *image, void vips_image_set_blob_copy( VipsImage *image,
const char *name, const void *data, size_t length ); const char *name, const void *data, size_t length );
int vips_image_get_blob( const VipsImage *image, const char *name, int vips_image_get_blob( const VipsImage *image,
void **data, size_t *length ); const char *name, const void **data, size_t *length );
int vips_image_get_int( const VipsImage *image, const char *name, int *out ); int vips_image_get_int( const VipsImage *image, const char *name, int *out );
void vips_image_set_int( VipsImage *image, const char *name, int i ); void vips_image_set_int( VipsImage *image, const char *name, int i );

View File

@ -269,6 +269,8 @@ void vips__reorder_clear( VipsImage *image );
VipsWindow *vips_window_take( VipsWindow *window, VipsWindow *vips_window_take( VipsWindow *window,
VipsImage *im, int top, int height ); VipsImage *im, int top, int height );
int vips__profile_set( VipsImage *image, const char *name );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -158,9 +158,9 @@ typedef struct _VipsBlob {
} VipsBlob; } VipsBlob;
VipsBlob *vips_blob_new( VipsCallbackFn free_fn, VipsBlob *vips_blob_new( VipsCallbackFn free_fn,
const void *data, size_t size ); const void *data, size_t length );
VipsBlob *vips_blob_copy( const void *data, size_t size ); VipsBlob *vips_blob_copy( const void *data, size_t length );
const void *vips_blob_get( VipsBlob *blob, size_t *size ); const void *vips_blob_get( VipsBlob *blob, size_t *length );
GType vips_blob_get_type(void); GType vips_blob_get_type(void);
/** /**
@ -224,7 +224,7 @@ void vips_value_set_ref_string( GValue *value, const char *str );
void *vips_value_get_blob( const GValue *value, size_t *length ); void *vips_value_get_blob( const GValue *value, size_t *length );
void vips_value_set_blob( GValue *value, void vips_value_set_blob( GValue *value,
VipsCallbackFn free_fn, void *data, size_t length ); VipsCallbackFn free_fn, const void *data, size_t length );
void vips_value_set_blob_free( GValue *value, void *data, size_t length ); void vips_value_set_blob_free( GValue *value, void *data, size_t length );
void vips_value_set_array( GValue *value, void vips_value_set_array( GValue *value,

View File

@ -28,6 +28,8 @@
* - rename "field" as "name" in docs * - rename "field" as "name" in docs
* 21/11/18 * 21/11/18
* - get_string will allow G_STRING and REF_STRING * - get_string will allow G_STRING and REF_STRING
* 28/12/18
* - hide deprecated header fields from _map
*/ */
/* /*
@ -1160,9 +1162,23 @@ vips_image_remove( VipsImage *image, const char *name )
return( FALSE ); return( FALSE );
} }
/* Deprecated header fields we hide from _map.
*/
static const char *vips_image_header_deprecated[] = {
"ipct-data"
};
static void * static void *
vips_image_map_fn( VipsMeta *meta, VipsImageMapFn fn, void *a ) vips_image_map_fn( VipsMeta *meta, VipsImageMapFn fn, void *a )
{ {
int i;
/* Hide deprecated fields.
*/
for( i = 0; i < VIPS_NUMBER( vips_image_header_deprecated ); i++ )
if( strcmp( meta->name, vips_image_header_deprecated[i] ) == 0 )
return( NULL );
return( fn( meta->im, meta->name, &meta->value, a ) ); return( fn( meta->im, meta->name, &meta->value, a ) );
} }
@ -1349,13 +1365,13 @@ vips_image_get_area( const VipsImage *image, const char *name, void **data )
* See also: vips_image_get_blob(), vips_image_set(). * See also: vips_image_get_blob(), vips_image_set().
*/ */
void void
vips_image_set_blob( VipsImage *image, vips_image_set_blob( VipsImage *image, const char *name,
const char *name, VipsCallbackFn free_fn, void *data, size_t length ) VipsCallbackFn free_fn, const void *data, size_t size )
{ {
GValue value = { 0 }; GValue value = { 0 };
g_value_init( &value, VIPS_TYPE_BLOB ); g_value_init( &value, VIPS_TYPE_BLOB );
vips_value_set_blob( &value, free_fn, data, length ); vips_value_set_blob( &value, free_fn, data, size );
vips_image_set( image, name, &value ); vips_image_set( image, name, &value );
g_value_unset( &value ); g_value_unset( &value );
} }
@ -1415,7 +1431,7 @@ vips_image_set_blob_copy( VipsImage *image,
*/ */
int int
vips_image_get_blob( const VipsImage *image, const char *name, vips_image_get_blob( const VipsImage *image, const char *name,
void **data, size_t *length ) const void **data, size_t *length )
{ {
GValue value_copy = { 0 }; GValue value_copy = { 0 };

View File

@ -376,6 +376,9 @@ void *
vips_area_get_data( VipsArea *area, vips_area_get_data( VipsArea *area,
size_t *length, int *n, GType *type, size_t *sizeof_type ) size_t *length, int *n, GType *type, size_t *sizeof_type )
{ {
if( !area )
return( NULL );
if( length ) if( length )
*length = area->length; *length = area->length;
if( n ) if( n )
@ -599,8 +602,8 @@ vips_ref_string_get_type( void )
/** /**
* vips_blob_new: * vips_blob_new:
* @free_fn: (scope async) (allow-none): @data will be freed with this function * @free_fn: (scope async) (allow-none): @data will be freed with this function
* @data: (array length=size) (element-type guint8) (transfer full): data to store * @data: (array length=length) (element-type guint8) (transfer full): data to store
* @size: number of bytes in @data * @length: number of bytes in @data
* *
* Like vips_area_new(), but track a length as well. The returned #VipsBlob * Like vips_area_new(), but track a length as well. The returned #VipsBlob
* takes ownership of @data and will free it with @free_fn. Pass NULL for * takes ownership of @data and will free it with @free_fn. Pass NULL for
@ -614,20 +617,20 @@ vips_ref_string_get_type( void )
* Returns: (transfer full): the new #VipsBlob. * Returns: (transfer full): the new #VipsBlob.
*/ */
VipsBlob * VipsBlob *
vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t size ) vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t length )
{ {
VipsArea *area; VipsArea *area;
area = vips_area_new( free_fn, (void *) data ); area = vips_area_new( free_fn, (void *) data );
area->length = size; area->length = length;
return( (VipsBlob *) area ); return( (VipsBlob *) area );
} }
/** /**
* vips_blob_copy: * vips_blob_copy:
* @data: (array length=size) (element-type guint8) (transfer none): data to store * @data: (array length=length) (element-type guint8) (transfer none): data to store
* @size: number of bytes in @data * @length: number of bytes in @data
* *
* Like vips_blob_new(), but take a copy of the data. Useful for bindings * Like vips_blob_new(), but take a copy of the data. Useful for bindings
* which strugle with callbacks. * which strugle with callbacks.
@ -637,15 +640,15 @@ vips_blob_new( VipsCallbackFn free_fn, const void *data, size_t size )
* Returns: (transfer full): the new #VipsBlob. * Returns: (transfer full): the new #VipsBlob.
*/ */
VipsBlob * VipsBlob *
vips_blob_copy( const void *data, size_t size ) vips_blob_copy( const void *data, size_t length )
{ {
void *data_copy; void *data_copy;
VipsArea *area; VipsArea *area;
data_copy = vips_malloc( NULL, size ); data_copy = vips_malloc( NULL, length );
memcpy( data_copy, data, size ); memcpy( data_copy, data, length );
area = vips_area_new( (VipsCallbackFn) g_free, data_copy ); area = vips_area_new( (VipsCallbackFn) g_free, data_copy );
area->length = size; area->length = length;
return( (VipsBlob *) area ); return( (VipsBlob *) area );
} }
@ -653,19 +656,19 @@ vips_blob_copy( const void *data, size_t size )
/** /**
* vips_blob_get: * vips_blob_get:
* @blob: #VipsBlob to fetch from * @blob: #VipsBlob to fetch from
* @size: return number of bytes of data * @length: return number of bytes of data
* *
* Get the data from a #VipsBlob. * Get the data from a #VipsBlob.
* *
* See also: vips_blob_new(). * See also: vips_blob_new().
* *
* Returns: (array length=size) (element-type guint8) (transfer none): the data * Returns: (array length=length) (element-type guint8) (transfer none): the data
*/ */
const void * const void *
vips_blob_get( VipsBlob *blob, size_t *size ) vips_blob_get( VipsBlob *blob, size_t *length )
{ {
return( vips_area_get_data( VIPS_AREA( blob ), return( vips_area_get_data( VIPS_AREA( blob ),
size, NULL, NULL, NULL ) ); length, NULL, NULL, NULL ) );
} }
/* Transform a blob to a G_TYPE_STRING. /* Transform a blob to a G_TYPE_STRING.
@ -674,12 +677,12 @@ static void
transform_blob_g_string( const GValue *src_value, GValue *dest_value ) transform_blob_g_string( const GValue *src_value, GValue *dest_value )
{ {
void *blob; void *blob;
size_t blob_length; size_t length;
char buf[256]; char buf[256];
blob = vips_value_get_blob( src_value, &blob_length ); blob = vips_value_get_blob( src_value, &length );
vips_snprintf( buf, 256, "VIPS_TYPE_BLOB, data = %p, length = %zd", vips_snprintf( buf, 256, "VIPS_TYPE_BLOB, data = %p, length = %zd",
blob, blob_length ); blob, length );
g_value_set_string( dest_value, buf ); g_value_set_string( dest_value, buf );
} }
@ -689,11 +692,11 @@ static void
transform_blob_save_string( const GValue *src_value, GValue *dest_value ) transform_blob_save_string( const GValue *src_value, GValue *dest_value )
{ {
void *blob; void *blob;
size_t blob_length; size_t length;
char *b64; char *b64;
blob = vips_value_get_blob( src_value, &blob_length ); blob = vips_value_get_blob( src_value, &length );
if( (b64 = vips__b64_encode( blob, blob_length )) ) { if( (b64 = vips__b64_encode( blob, length )) ) {
vips_value_set_save_string( dest_value, b64 ); vips_value_set_save_string( dest_value, b64 );
vips_free( b64 ); vips_free( b64 );
} }
@ -709,12 +712,12 @@ transform_save_string_blob( const GValue *src_value, GValue *dest_value )
{ {
const char *b64; const char *b64;
void *blob; void *blob;
size_t blob_length; size_t length;
b64 = vips_value_get_save_string( src_value ); b64 = vips_value_get_save_string( src_value );
if( (blob = vips__b64_decode( b64, &blob_length )) ) if( (blob = vips__b64_decode( b64, &length )) )
vips_value_set_blob( dest_value, vips_value_set_blob( dest_value,
(VipsCallbackFn) vips_free, blob, blob_length ); (VipsCallbackFn) vips_free, blob, length );
else else
/* No error return from transform, but we should set it to /* No error return from transform, but we should set it to
* something. * something.
@ -1556,7 +1559,7 @@ vips_value_set_ref_string( GValue *value, const char *str )
* @length: length of memory area * @length: length of memory area
* *
* Sets @value to hold a @data. When @value is freed, @data will be * Sets @value to hold a @data. When @value is freed, @data will be
* freed with @free_fn. @value also holds a note of the length of the memory * freed with @free_fn. @value also holds a note of the size of the memory
* area. * area.
* *
* blobs are things like ICC profiles or EXIF data. They are relocatable, and * blobs are things like ICC profiles or EXIF data. They are relocatable, and
@ -1567,7 +1570,7 @@ vips_value_set_ref_string( GValue *value, const char *str )
*/ */
void void
vips_value_set_blob( GValue *value, vips_value_set_blob( GValue *value,
VipsCallbackFn free_fn, void *data, size_t length ) VipsCallbackFn free_fn, const void *data, size_t length )
{ {
VipsBlob *blob; VipsBlob *blob;

View File

@ -53,12 +53,14 @@ colour_colourspaces = [pyvips.Interpretation.XYZ,
pyvips.Interpretation.HSV, pyvips.Interpretation.HSV,
pyvips.Interpretation.SRGB, pyvips.Interpretation.SRGB,
pyvips.Interpretation.YXY] pyvips.Interpretation.YXY]
cmyk_colourspaces = [pyvips.Interpretation.CMYK]
coded_colourspaces = [pyvips.Interpretation.LABQ] coded_colourspaces = [pyvips.Interpretation.LABQ]
mono_colourspaces = [pyvips.Interpretation.B_W] mono_colourspaces = [pyvips.Interpretation.B_W]
sixteenbit_colourspaces = [pyvips.Interpretation.GREY16, sixteenbit_colourspaces = [pyvips.Interpretation.GREY16,
pyvips.Interpretation.RGB16] pyvips.Interpretation.RGB16]
all_colourspaces = colour_colourspaces + mono_colourspaces + \ all_colourspaces = colour_colourspaces + mono_colourspaces + \
coded_colourspaces + sixteenbit_colourspaces coded_colourspaces + sixteenbit_colourspaces + \
cmyk_colourspaces
max_value = {pyvips.BandFormat.UCHAR: 0xff, max_value = {pyvips.BandFormat.UCHAR: 0xff,
pyvips.BandFormat.USHORT: 0xffff, pyvips.BandFormat.USHORT: 0xffff,

View File

@ -71,6 +71,19 @@ class TestColour:
# but 8-bit we should hit exactly # but 8-bit we should hit exactly
assert abs(after - before) < 1 assert abs(after - before) < 1
# we should be able to go from cmyk to any 3-band space and back again,
# approximately
cmyk = test.colourspace(pyvips.Interpretation.CMYK)
for end in colour_colourspaces:
im = cmyk.colourspace(end)
im2 = im.colourspace(pyvips.Interpretation.CMYK)
before = cmyk(10, 10)
after = im2(10, 10)
assert_almost_equal_objects(before, after, threshold=10)
# test results from Bruce Lindbloom's calculator: # test results from Bruce Lindbloom's calculator:
# http://www.brucelindbloom.com # http://www.brucelindbloom.com
def test_dE00(self): def test_dE00(self):