From de3298d69ea34317c044aaec68110ebfcedd478e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 31 Oct 2012 11:04:10 +0000 Subject: [PATCH] redo dEUCS as a class --- ChangeLog | 3 +- libvips/colour/Makefile.am | 4 +- libvips/colour/colour.h | 3 + libvips/colour/colour_funcs.c | 49 -------------- libvips/colour/dE76.c | 7 +- libvips/colour/dECMC.c | 100 +++++++++++++++++++++++++++++ libvips/colour/im_dECMC_fromLab.c | 84 ------------------------ libvips/deprecated/vips7compat.c | 17 +++++ libvips/include/vips/colour.h | 7 +- libvips/include/vips/vips7compat.h | 2 + 10 files changed, 132 insertions(+), 144 deletions(-) create mode 100644 libvips/colour/dECMC.c delete mode 100644 libvips/colour/im_dECMC_fromLab.c diff --git a/ChangeLog b/ChangeLog index 17ef851f..d0ad13a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ(), im_float2rad(), im_rad2float(), im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab(), im_LabQ2LabS(), im_LabS2LabQ(), im_LabQ2disp(), im_XYZ2disp(), im_disp2XYZ(), - im_icc_import*(), im_icc_export*(), im_icc_transform*(), im_dE_fromLab() + im_icc_import*(), im_icc_export*(), im_icc_transform*(), im_dE_fromLab(), + im_dECMC_fromLab(). as classes - added vips_colour_convert(), replaces all derived conversions - dzsave can write zoomify and google maps layout as well diff --git a/libvips/colour/Makefile.am b/libvips/colour/Makefile.am index 08f916b9..35652942 100644 --- a/libvips/colour/Makefile.am +++ b/libvips/colour/Makefile.am @@ -5,6 +5,7 @@ libcolour_la_SOURCES = \ colour_funcs.c \ colour_dispatch.c \ dE76.c \ + dECMC.c \ icc_transform.c \ Lab2XYZ.c \ Lab2LCh.c \ @@ -26,7 +27,6 @@ libcolour_la_SOURCES = \ XYZ2sRGB.c \ sRGB2XYZ.c \ im_lab_morph.c \ - im_dE00_fromLab.c \ - im_dECMC_fromLab.c + im_dE00_fromLab.c INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/colour/colour.h b/libvips/colour/colour.h index 2e977b53..cd639f73 100644 --- a/libvips/colour/colour.h +++ b/libvips/colour/colour.h @@ -200,6 +200,9 @@ typedef struct _VipsColourDifferenceClass { GType vips_colour_difference_get_type( void ); +void vips__pythagoras_line( VipsColour *colour, + VipsPel *out, VipsPel **in, int width ); + #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/colour/colour_funcs.c b/libvips/colour/colour_funcs.c index e8e64407..2e449680 100644 --- a/libvips/colour/colour_funcs.c +++ b/libvips/colour/colour_funcs.c @@ -91,55 +91,6 @@ vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ) /* Functions to convert from Lab to uniform colour space and back. */ -/** - * im_col_dECMC: - * @L1: Input coordinate 1 - * @a1: Input coordinate 1 - * @b1: Input coordinate 1 - * @L2: Input coordinate 2 - * @a2: Input coordinate 2 - * @b2: Input coordinate 2 - * - * CMC colour difference from a pair of Lab values. - * - * Returns: CMC(1:1) colour difference - */ -float -im_col_dECMC( float L1, float a1, float b1, - float L2, float a2, float b2 ) -{ - float h1, C1; - float h2, C2; - float Lucs1, Cucs1, hucs1; - float Lucs2, Cucs2, hucs2; - float aucs1, bucs1; - float aucs2, bucs2; - - /* Turn to LCh. - */ - im_col_ab2Ch( a1, b1, &C1, &h1 ); - im_col_ab2Ch( a2, b2, &C2, &h2 ); - - /* Turn to LCh in CMC space. - */ - Lucs1 = im_col_L2Lucs( L1 ); - Cucs1 = im_col_C2Cucs( C1 ); - hucs1 = im_col_Ch2hucs( C1, h1 ); - - Lucs2 = im_col_L2Lucs( L2 ); - Cucs2 = im_col_C2Cucs( C2 ); - hucs2 = im_col_Ch2hucs( C2, h2 ); - - /* Turn to Lab in CMC space. - */ - im_col_Ch2ab( Cucs1, hucs1, &aucs1, &bucs1 ); - im_col_Ch2ab( Cucs2, hucs2, &aucs2, &bucs2 ); - - /* Find difference. - */ - return( im_col_pythagoras( Lucs1, aucs1, bucs1, Lucs2, aucs2, bucs2 ) ); -} - /** * im_col_dE00: * @L1: Input coordinate 1 diff --git a/libvips/colour/dE76.c b/libvips/colour/dE76.c index e5e75dec..eccabc2e 100644 --- a/libvips/colour/dE76.c +++ b/libvips/colour/dE76.c @@ -57,8 +57,9 @@ G_DEFINE_TYPE( VipsdE76, vips_dE76, VIPS_TYPE_COLOUR_DIFFERENCE ); /* Find the difference between two buffers of LAB data. */ -static void -vips_dE76_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) +void +vips__pythagoras_line( VipsColour *colour, + VipsPel *out, VipsPel **in, int width ) { float *p1 = (float *) in[0]; float *p2 = (float *) in[1]; @@ -84,7 +85,7 @@ vips_dE76_class_init( VipsdE76Class *class ) object_class->nickname = "dE76"; object_class->description = _( "calculate dE76" ); - colour_class->process_line = vips_dE76_line; + colour_class->process_line = vips__pythagoras_line; } static void diff --git a/libvips/colour/dECMC.c b/libvips/colour/dECMC.c new file mode 100644 index 00000000..04e00d5b --- /dev/null +++ b/libvips/colour/dECMC.c @@ -0,0 +1,100 @@ +/* dECMC.c + * + * Modified: + * 31/10/12 + * - from dE76.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +/* + + These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk + + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /*HAVE_CONFIG_H*/ +#include + +#include +#include + +#include "colour.h" + +typedef struct _VipsdECMC { + VipsColourDifference parent_instance; + +} VipsdECMC; + +typedef VipsColourSpaceClass VipsdECMCClass; + +G_DEFINE_TYPE( VipsdECMC, vips_dECMC, VIPS_TYPE_COLOUR_DIFFERENCE ); + +static void +vips_dECMC_class_init( VipsdECMCClass *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class ); + + object_class->nickname = "dECMC"; + object_class->description = _( "calculate dECMC" ); + + colour_class->process_line = vips__pythagoras_line; +} + +static void +vips_dECMC_init( VipsdECMC *dECMC ) +{ + VipsColourDifference *difference = VIPS_COLOUR_DIFFERENCE( dECMC ); + + difference->interpretation = VIPS_INTERPRETATION_UCS; +} + +/** + * vips_dECMC: + * @in: input image + * @out: output image + * + * Calculate dE CMC. The input images are transformed to UCS colour space and + * the euclidean distance between corresponding pixels calculated. + * + * To calculate a colour difference with values for (l:c) other than (1:1), + * transform the two source images to UCS yourself, scale the channels + * appropriately, and call this function. + * + * See also: vips_colour_convert() + * + * Returns: 0 on success, -1 on error + */ +int +vips_dECMC( VipsImage *left, VipsImage *right, VipsImage **out, ... ) +{ + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "dECMC", ap, left, right, out ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/colour/im_dECMC_fromLab.c b/libvips/colour/im_dECMC_fromLab.c deleted file mode 100644 index f450a715..00000000 --- a/libvips/colour/im_dECMC_fromLab.c +++ /dev/null @@ -1,84 +0,0 @@ -/* im_dECMC_fromLab.c - * - * 5/8/98 JC - * - oops, wasn't testing input args correctly - * 30/10/09 - * - use im__colour_binary() - * - gtkdoc comment - */ - -/* - - 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include - -/* Process a buffer. - */ -void -imb_dECMC_fromLab( float **p, float *q, int n ) -{ - float *p1 = p[0]; - float *p2 = p[1]; - int x; - - for( x = 0; x < n; x++ ) { - float L1 = p1[0]; - float a1 = p1[1]; - float b1 = p1[2]; - float L2 = p2[0]; - float a2 = p2[1]; - float b2 = p2[2]; - - p1 += 3; - p2 += 3; - - q[x] = im_col_dECMC( L1, a1, b1, L2, a2, b2 ); - } -} - -/** - * im_dECMC_fromLab: - * @in1: first input image - * @in2: second input image - * @out: output image - * - * Calculate dE CMC from two Lab images. - * - * Returns: 0 on success, -1 on error. - */ -int -im_dECMC_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) -{ - return( im__colour_difference( "im_dECMC_fromLab", - in1, in2, out, - (im_wrapmany_fn) imb_dECMC_fromLab, NULL, NULL ) ); -} diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 073ccc47..967096d4 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -2790,3 +2790,20 @@ im_dE_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) return( 0 ); } + +int +im_dECMC_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) +{ + VipsImage *x; + + if( vips_dECMC( in1, in2, &x, + NULL ) ) + return( -1 ); + if( im_copy( x, out ) ) { + g_object_unref( x ); + return( -1 ); + } + g_object_unref( x ); + + return( 0 ); +} diff --git a/libvips/include/vips/colour.h b/libvips/include/vips/colour.h index 87e744b2..df0074ae 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -170,6 +170,8 @@ int vips_icc_ac2rc( VipsImage *in, VipsImage *out, int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); +int vips_dECMC( VipsImage *left, VipsImage *right, VipsImage **out, ... ) + __attribute__((sentinel)); void vips_col_Lab2XYZ( float L, float a, float b, float *X, float *Y, float *Z ); @@ -198,15 +200,10 @@ int vips_col_sRGB2XYZ( int r, int g, int b, float *X, float *Y, float *Z ); */ float vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ); - -float im_col_dECMC( - float L1, float a1, float b1, float L2, float a2, float b2 ); float im_col_dE00( float L1, float a1, float b1, float L2, float a2, float b2 ); -int im_dECMC_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_dE00_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); -int im_dE_fromXYZ( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_lab_morph( VipsImage *in, VipsImage *out, DOUBLEMASK *mask, diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index 41ecede3..ba8abd25 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -777,6 +777,8 @@ int im_Lab2UCS( VipsImage *in, VipsImage *out ); int im_XYZ2UCS( VipsImage *in, VipsImage *out ); int im_dE_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); +int im_dECMC_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); +int im_dE_fromXYZ( VipsImage *in1, VipsImage *in2, VipsImage *out ); /* ruby-vips uses this */