Merge branch 'master' into dzsave-skip-blanks

This commit is contained in:
John Cupitt 2019-01-02 11:00:42 +00:00
commit 020ff88f6a
21 changed files with 17429 additions and 27 deletions

View File

@ -13,10 +13,12 @@
- add vips_rect_overlapsrect()
- composite is much faster at positioning subimages
- dzsave has a new skip_blanks option
- add CMYK as a supported colourspace
21/11/18 started 8.7.3
- fix infinite loop for autofit with non-scaleable font
- mapim was not offsetting by window offset [erdmann]
- better rounding for scale [kleisauke]
21/11/18 started 8.7.2
- more info output for temp files to help diagnose problems

View File

@ -841,6 +841,14 @@ if test x"$with_lcms" != x"no"; then
)
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
AC_ARG_WITH([OpenEXR],
AS_HELP_STRING([--without-OpenEXR], [build without OpenEXR (default: test)]))

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

@ -0,0 +1,215 @@
/* 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>
#ifdef HAVE_LCMS2
#include <stdio.h>
#include <math.h>
#include <vips/vips.h>
#include <vips/internal.h>
#include "pcolour.h"
#include "profiles.h"
typedef struct _VipsCMYK2XYZ {
VipsOperation parent_instance;
VipsImage *in;
VipsImage *out;
} VipsCMYK2XYZ;
typedef VipsColourCodeClass VipsCMYK2XYZClass;
G_DEFINE_TYPE( VipsCMYK2XYZ, vips_CMYK2XYZ, VIPS_TYPE_OPERATION );
/* Created on first use from a base64 string in profiles.c.
*/
static void *vips_CMYK2XYZ_fallback_profile = NULL;
static size_t vips_CMYK2XYZ_fallback_profile_length = 0;
static void *
vips_CMYK2XYZ_get_fallback_profile_init( void )
{
size_t data_length;
unsigned char *data;
if( !(data = vips__b64_decode( vips__coded_cmyk, &data_length )) )
return( NULL );
vips_CMYK2XYZ_fallback_profile = data;
vips_CMYK2XYZ_fallback_profile_length = data_length;
return( NULL );
}
static void *
vips__CMYK2XYZ_get_fallback_profile( size_t *length )
{
GOnce once = G_ONCE_INIT;
VIPS_ONCE( &once,
(GThreadFunc) vips_CMYK2XYZ_get_fallback_profile_init, NULL );
*length = vips_CMYK2XYZ_fallback_profile_length;
return( vips_CMYK2XYZ_fallback_profile );
}
/* Shared with XYZ2CMYK.c.
*/
int
vips_CMYK2XYZ_set_fallback_profile( VipsImage *image )
{
size_t data_length;
unsigned char *data;
/* Already a profile? Do nothing. We could remove and replace non-CMYK
* profiles I guess.
*/
if( vips_image_get_typeof( image, VIPS_META_ICC_NAME ) )
return( 0 );
if( !(data = vips__CMYK2XYZ_get_fallback_profile( &data_length )) )
return( -1 );
vips_image_set_blob( image, VIPS_META_ICC_NAME,
NULL, data, data_length );
return( 0 );
}
/* 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_CMYK2XYZ_set_fallback_profile( t[0] ) ||
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,17 @@
noinst_LTLIBRARIES = libcolour.la
if ENABLE_LCMS
PROFILES = profiles.c profiles.h
else
PROFILES =
endif
libcolour_la_SOURCES = \
$(PROFILES) \
colour.c \
pcolour.h \
CMYK2XYZ.c \
XYZ2CMYK.c \
colourspace.c \
dE76.c \
dE00.c \
@ -33,4 +42,11 @@ libcolour_la_SOURCES = \
XYZ2scRGB.c \
scRGB2sRGB.c
profiles.c:
./wrap_profiles.sh profiles profiles
EXTRA_DIST = \
profiles \
wrap-profiles.sh
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@

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

@ -0,0 +1,159 @@
/* 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>
#ifdef HAVE_LCMS2
#include <stdio.h>
#include <math.h>
#include <vips/vips.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_CMYK2XYZ_set_fallback_profile( t[0] ) ||
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

@ -756,6 +756,8 @@ vips_colour_operation_init( void )
extern GType vips_icc_import_get_type( void );
extern GType vips_icc_export_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
extern GType vips_dE76_get_type( void );
extern GType vips_dE00_get_type( void );
@ -790,6 +792,8 @@ vips_colour_operation_init( void )
vips_icc_import_get_type();
vips_icc_export_get_type();
vips_icc_transform_get_type();
vips_CMYK2XYZ_get_type();
vips_XYZ2CMYK_get_type();
#endif
vips_dE76_get_type();
vips_dE00_get_type();

View File

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

View File

@ -38,6 +38,9 @@
* - more input profile sanity tests
* 8/3/18
* - 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
*/
/*
@ -1250,7 +1253,7 @@ vips_icc_ac2rc( VipsImage *in, VipsImage **out, const char *profile_filename )
return( 0 );
}
/* TRUE if a profile is compatible with an image.
/* TRUE if a profile is sane and is compatible with an image.
*/
gboolean
vips_icc_is_compatible_profile( VipsImage *image,
@ -1258,22 +1261,19 @@ vips_icc_is_compatible_profile( VipsImage *image,
{
cmsHPROFILE profile;
if( !(profile = cmsOpenProfileFromMem( data, data_length )) ) {
g_warning( "%s", _( "corrupt profile" ) );
if( !(profile = cmsOpenProfileFromMem( data, data_length )) )
/* Corrupt profile.
*/
return( FALSE );
}
if( vips_image_expected_bands( image ) !=
vips_icc_profile_needs_bands( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "profile incompatible with image" ) );
return( FALSE );
}
if( vips_image_expected_sig( image ) != cmsGetColorSpace( profile ) ) {
VIPS_FREEF( cmsCloseProfile, profile );
g_warning( "%s",
_( "profile colourspace differs from image" ) );
return( FALSE );
}

View File

@ -216,6 +216,15 @@ extern float vips_v2Y_16[65536];
void vips_col_make_tables_RGB_8( void );
void vips_col_make_tables_RGB_16( void );
int vips_CMYK2XYZ_set_fallback_profile( VipsImage *image );
/* 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
}
#endif /*__cplusplus*/

16875
libvips/colour/profiles.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
/* header for coded files, generated automatically */
extern char *vips__coded_cmyk ;

Binary file not shown.

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

@ -0,0 +1,27 @@
#!/bin/bash
# code up the binary files in $1 as a set of base64-encoded strings in $2
in=$1
out_c=$2.c
out_h=$2.h
echo "/* coded files, generated automatically */" > $out_c
echo "" >> $out_c
for file in $in/*; do
root=${file%.icm}
base=${root##*/}
echo char \*vips__coded_$base = >> $out_c
base64 $file | sed 's/\(.*\)/"\1"/g' >> $out_c
echo ';' >> $out_c
done
echo "/* header for coded files, generated automatically */" > $out_h
echo "" >> $out_h
for file in $in/*; do
root=${file%.icm}
base=${root##*/}
echo extern char \*vips__coded_$base ';' >> $out_h
done

View File

@ -22,6 +22,8 @@
* - use linear uchar mode
* 14/7/14
* - 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 ) ||
vips_linear1( t[2], &t[3], 1.0, 1.0, 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,
NULL ) ||
vips_image_write( t[5], conversion->out ) )

View File

@ -1515,7 +1515,7 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready,
/* Some format libraries, like libpng, will throw a hard error if the
* profile is inappropriate for this image type. With profiles inherited
* 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 ) ) {
void *data;

View File

@ -460,7 +460,7 @@ wtiff_embed_xmp( Wtiff *wtiff, TIFF *tif )
}
static int
wtiff_embed_ipct( Wtiff *wtiff, TIFF *tif )
wtiff_embed_iptc( Wtiff *wtiff, TIFF *tif )
{
void *data;
size_t data_length;
@ -581,7 +581,7 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer )
if( !wtiff->strip )
if( wtiff_embed_profile( wtiff, tif ) ||
wtiff_embed_xmp( wtiff, tif ) ||
wtiff_embed_ipct( wtiff, tif ) ||
wtiff_embed_iptc( wtiff, tif ) ||
wtiff_embed_photoshop( wtiff, tif ) ||
wtiff_embed_imagedescription( wtiff, tif ) )
return( -1 );
@ -1625,7 +1625,7 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in )
if( !wtiff->strip )
if( wtiff_embed_profile( wtiff, out ) ||
wtiff_embed_xmp( wtiff, out ) ||
wtiff_embed_ipct( wtiff, out ) ||
wtiff_embed_iptc( wtiff, out ) ||
wtiff_embed_photoshop( wtiff, out ) ||
wtiff_embed_imagedescription( wtiff, out ) )
return( -1 );

View File

@ -167,6 +167,11 @@ int vips_LabS2Lab( VipsImage *in, VipsImage **out, ... )
int vips_Lab2LabS( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_CMYK2XYZ( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_XYZ2CMYK( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_icc_present( void );
int vips_icc_transform( VipsImage *in, VipsImage **out,
const char *output_profile, ... )

View File

@ -233,7 +233,7 @@ VIPS_ARGUMENT_OPTIONAL_OUTPUT Eg. the x pos of the image minimum
\
pspec = g_param_spec_pointer( (NAME), (LONG), (DESC), \
(GParamFlags) (G_PARAM_READWRITE) ); \
g_object_class_install_property( gobject_class, \
g_object_class_install_property( G_OBJECT_CLASS( CLASS ), \
vips_argument_get_id(), pspec ); \
vips_object_class_install_argument( VIPS_OBJECT_CLASS( CLASS ), \
pspec, (VipsArgumentFlags) (FLAGS), (PRIORITY), (OFFSET) ); \

View File

@ -28,6 +28,8 @@
* - rename "field" as "name" in docs
* 21/11/18
* - 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 );
}
/* Deprecated header fields we hide from _map.
*/
static const char *vips_image_header_deprecated[] = {
"ipct-data"
};
static void *
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 ) );
}

View File

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

View File

@ -71,6 +71,19 @@ class TestColour:
# but 8-bit we should hit exactly
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:
# http://www.brucelindbloom.com
def test_dE00(self):