From a2d4c150499cfb78b905e7bbfe7b456ce1d1c024 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 31 Oct 2012 11:22:28 +0000 Subject: [PATCH] move dE00 to a class --- ChangeLog | 2 +- TODO | 1 - libvips/colour/Makefile.am | 6 +- libvips/colour/colour.c | 4 + libvips/colour/{colour_funcs.c => dE00.c} | 139 +++++++++++------- libvips/colour/dE76.c | 33 ++++- libvips/colour/dECMC.c | 3 +- libvips/colour/im_dE00_fromLab.c | 115 --------------- libvips/deprecated/Makefile.am | 1 + libvips/{colour => deprecated}/im_lab_morph.c | 0 libvips/deprecated/vips7compat.c | 17 +++ libvips/include/vips/colour.h | 14 +- libvips/include/vips/vips7compat.h | 8 + 13 files changed, 150 insertions(+), 193 deletions(-) rename libvips/colour/{colour_funcs.c => dE00.c} (74%) delete mode 100644 libvips/colour/im_dE00_fromLab.c rename libvips/{colour => deprecated}/im_lab_morph.c (100%) diff --git a/ChangeLog b/ChangeLog index d0ad13a8..421d94a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ 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_dECMC_fromLab(). + im_dECMC_fromLab(), im_dE00_from_Lab() as classes - added vips_colour_convert(), replaces all derived conversions - dzsave can write zoomify and google maps layout as well diff --git a/TODO b/TODO index 98919efc..05e580d4 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ trim this down! - - add mono as a colourspace? also rad? - something to test if an image is in a supported colourspace? diff --git a/libvips/colour/Makefile.am b/libvips/colour/Makefile.am index 35652942..29982c46 100644 --- a/libvips/colour/Makefile.am +++ b/libvips/colour/Makefile.am @@ -2,9 +2,9 @@ noinst_LTLIBRARIES = libcolour.la libcolour_la_SOURCES = \ colour.c \ - colour_funcs.c \ colour_dispatch.c \ dE76.c \ + dE00.c \ dECMC.c \ icc_transform.c \ Lab2XYZ.c \ @@ -25,8 +25,6 @@ libcolour_la_SOURCES = \ LabQ2LabS.c \ LabQ2sRGB.c \ XYZ2sRGB.c \ - sRGB2XYZ.c \ - im_lab_morph.c \ - im_dE00_fromLab.c + sRGB2XYZ.c INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index ae855c12..8b77fdaa 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -849,6 +849,8 @@ vips_colour_operation_init( void ) extern GType vips_icc_transform_get_type( void ); #endif extern GType vips_dE76_get_type( void ); + extern GType vips_dE00_get_type( void ); + extern GType vips_dECMC_get_type( void ); vips_colour_convert_get_type(); vips_Lab2XYZ_get_type(); @@ -876,4 +878,6 @@ vips_colour_operation_init( void ) vips_icc_transform_get_type(); #endif vips_dE76_get_type(); + vips_dE00_get_type(); + vips_dECMC_get_type(); } diff --git a/libvips/colour/colour_funcs.c b/libvips/colour/dE00.c similarity index 74% rename from libvips/colour/colour_funcs.c rename to libvips/colour/dE00.c index 2e449680..7cbd435c 100644 --- a/libvips/colour/colour_funcs.c +++ b/libvips/colour/dE00.c @@ -1,31 +1,8 @@ -/* Convert colours in various ways. +/* dE00.c * - * Written: January 1990 - * Modified .. innumerable times - * Code by: DS, JC, J-Ph.L. - * 18/7/93 JC - * - final tidies before v7 release - * - ANSIfied - * - code for samples removed - * 5/5/94 JC - * - nint() -> rint() to make ANSI easier - * 14/3/96 JC - * - new display characterisation - * - speed-up to im_col_XYZ2rgb() and im_col_rgb2XYZ() - * 4/3/98 JC - * - new display profile for ultra2 - * - new sRGB profile - * 17/8/98 JC - * - error_exit() removed, now clips - * 26/11/03 Andrey Kiselev - * - tiny clean-up for calcul_tables() - * - some reformatting - * 23/7/07 - * - tiny cleanup for make_hI() prevents cond jump on ui in valgrind - * 14/3/08 - * - more tiny cond jump valgrind fixes - * 23/10/09 - * - gtkdoc comments + * Modified: + * 31/10/12 + * - from dE76.c */ /* @@ -59,40 +36,24 @@ #endif /*HAVE_CONFIG_H*/ #include -#include -#include -#include #include #include -#include +#include + +#include "colour.h" + +typedef struct _VipsdE00 { + VipsColourDifference parent_instance; + +} VipsdE00; + +typedef VipsColourSpaceClass VipsdE00Class; + +G_DEFINE_TYPE( VipsdE00, vips_dE00, VIPS_TYPE_COLOUR_DIFFERENCE ); /** - * vips_pythagoras: - * @L1: Input coordinate 1 - * @a1: Input coordinate 1 - * @b1: Input coordinate 1 - * @L2: Input coordinate 2 - * @a2: Input coordinate 2 - * @b2: Input coordinate 2 - * - * Pythagorean distance between two points in colour space. Lab/XYZ/UCS etc. - */ -float -vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ) -{ - float dL = L1 - L2; - float da = a1 - a2; - float db = b1 - b2; - - return( sqrt( dL * dL + da * da + db * db ) ); -} - -/* Functions to convert from Lab to uniform colour space and back. - */ - -/** - * im_col_dE00: + * vips_col_dE00: * @L1: Input coordinate 1 * @a1: Input coordinate 1 * @b1: Input coordinate 1 @@ -108,7 +69,7 @@ vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ) * Returns: CIE dE2000 colour difference. */ float -im_col_dE00( float L1, float a1, float b1, +vips_col_dE00( float L1, float a1, float b1, float L2, float a2, float b2 ) { /* Code if you want XYZ params and the colour temp used in the reference @@ -241,3 +202,67 @@ im_col_dE00( float L1, float a1, float b1, return( dE00 ); } + +/* Find the difference between two buffers of LAB data. + */ +void +vips_dE00_line( VipsColour *colour, + VipsPel *out, VipsPel **in, int width ) +{ + float *p1 = (float *) in[0]; + float *p2 = (float *) in[1]; + float *q = (float *) out; + + int x; + + for( x = 0; x < width; x++ ) { + q[x] = vips_col_dE00( p1[0], p1[1], p1[2], + p2[0], p2[1], p2[2] ); + + p1 += 3; + p2 += 3; + } +} + +static void +vips_dE00_class_init( VipsdE00Class *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class ); + + object_class->nickname = "dE00"; + object_class->description = _( "calculate dE00" ); + + colour_class->process_line = vips_dE00_line; +} + +static void +vips_dE00_init( VipsdE00 *dE00 ) +{ + VipsColourDifference *difference = VIPS_COLOUR_DIFFERENCE( dE00 ); + + difference->interpretation = VIPS_INTERPRETATION_LAB; +} + +/** + * vips_dE00: + * @left: first input image + * @right: second input image + * @out: output image + * + * Calculate dE 00. + * + * Returns: 0 on success, -1 on error + */ +int +vips_dE00( VipsImage *left, VipsImage *right, VipsImage **out, ... ) +{ + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "dE00", ap, left, right, out ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/colour/dE76.c b/libvips/colour/dE76.c index eccabc2e..6df79b51 100644 --- a/libvips/colour/dE76.c +++ b/libvips/colour/dE76.c @@ -41,6 +41,8 @@ #endif /*HAVE_CONFIG_H*/ #include +#include + #include #include @@ -55,6 +57,27 @@ typedef VipsColourSpaceClass VipsdE76Class; G_DEFINE_TYPE( VipsdE76, vips_dE76, VIPS_TYPE_COLOUR_DIFFERENCE ); +/** + * vips_pythagoras: + * @L1: Input coordinate 1 + * @a1: Input coordinate 1 + * @b1: Input coordinate 1 + * @L2: Input coordinate 2 + * @a2: Input coordinate 2 + * @b2: Input coordinate 2 + * + * Pythagorean distance between two points in colour space. Lab/XYZ/UCS etc. + */ +float +vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ) +{ + float dL = L1 - L2; + float da = a1 - a2; + float db = b1 - b2; + + return( sqrt( dL * dL + da * da + db * db ) ); +} + /* Find the difference between two buffers of LAB data. */ void @@ -68,8 +91,11 @@ vips__pythagoras_line( VipsColour *colour, int x; for( x = 0; x < width; x++ ) { - q[x] = vips_pythagoras( - p1[0], p1[1], p1[2], p2[0], p2[1], p2[2] ); + float dL = p1[0] - p2[0]; + float da = p1[1] - p2[1]; + float db = p1[2] - p2[2]; + + q[x] = sqrt( dL * dL + da * da + db * db ); p1 += 3; p2 += 3; @@ -98,7 +124,8 @@ vips_dE76_init( VipsdE76 *dE76 ) /** * vips_dE76: - * @in: input image + * @left: first input image + * @right: second input image * @out: output image * * Calculate dE 76. diff --git a/libvips/colour/dECMC.c b/libvips/colour/dECMC.c index 04e00d5b..8966f943 100644 --- a/libvips/colour/dECMC.c +++ b/libvips/colour/dECMC.c @@ -72,7 +72,8 @@ vips_dECMC_init( VipsdECMC *dECMC ) /** * vips_dECMC: - * @in: input image + * @left: first input image + * @right: second input image * @out: output image * * Calculate dE CMC. The input images are transformed to UCS colour space and diff --git a/libvips/colour/im_dE00_fromLab.c b/libvips/colour/im_dE00_fromLab.c deleted file mode 100644 index c3f4ad79..00000000 --- a/libvips/colour/im_dE00_fromLab.c +++ /dev/null @@ -1,115 +0,0 @@ -/* im_dE00_fromLab.c - * - * 10/10/02 JC - * - from dECMC - * 30/10/09 - * - add im__colour_binary() and use it - * - 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 - -/* A colour difference operation. - */ -int -im__colour_difference( const char *domain, - IMAGE *in1, IMAGE *in2, IMAGE *out, - im_wrapmany_fn buffer_fn, void *a, void *b ) -{ - IMAGE *t[3]; - - if( im_check_uncoded( domain, in1 ) || - im_check_uncoded( domain, in2 ) || - im_check_bands( domain, in1, 3 ) || - im_check_bands( domain, in2, 3 ) || - im_check_size_same( domain, in1, in2 ) || - im_open_local_array( out, t, 2, domain, "p" ) || - im_clip2fmt( in1, t[0], IM_BANDFMT_FLOAT ) || - im_clip2fmt( in2, t[1], IM_BANDFMT_FLOAT ) ) - return( -1 ); - - if( im_cp_descv( out, t[0], t[1], NULL ) ) - return( -1 ); - out->Bands = 1; - out->Type = IM_TYPE_B_W; - - t[2] = NULL; - if( im_wrapmany( t, out, buffer_fn, a, b ) ) - return( -1 ); - - return( 0 ); -} - -/* Process a buffer. - */ -void -imb_dE00_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_dE00( L1, a1, b1, L2, a2, b2 ); - } -} - -/** - * im_dE00_fromLab: - * @in1: first input image - * @in2: second input image - * @out: output image - * - * Calculate CIE dE00 from two Lab images. - * - * Returns: 0 on success, -1 on error. - */ -int -im_dE00_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) -{ - return( im__colour_difference( "im_dE00_fromLab", - in1, in2, out, - (im_wrapmany_fn) imb_dE00_fromLab, NULL, NULL ) ); -} diff --git a/libvips/deprecated/Makefile.am b/libvips/deprecated/Makefile.am index ef636021..be37ac80 100644 --- a/libvips/deprecated/Makefile.am +++ b/libvips/deprecated/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libdeprecated.la libdeprecated_la_SOURCES = \ im_openslide2vips.c \ + im_lab_morph.c \ deprecated_dispatch.c \ wrapvips7.c \ lazy.c \ diff --git a/libvips/colour/im_lab_morph.c b/libvips/deprecated/im_lab_morph.c similarity index 100% rename from libvips/colour/im_lab_morph.c rename to libvips/deprecated/im_lab_morph.c diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 967096d4..fa9feb08 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -2807,3 +2807,20 @@ im_dECMC_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) return( 0 ); } + +int +im_dE00_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ) +{ + VipsImage *x; + + if( vips_dE00( 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 df0074ae..668bfcd7 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_dE00( VipsImage *left, VipsImage *right, VipsImage **out, ... ) + __attribute__((sentinel)); int vips_dECMC( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); @@ -195,21 +197,11 @@ int vips_col_XYZ2sRGB( float X, float Y, float Z, int *or_ret ); int vips_col_sRGB2XYZ( int r, int g, int b, float *X, float *Y, float *Z ); - -/* Colour loading and conversion functions. - */ float vips_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ); -float im_col_dE00( +float vips_col_dE00( float L1, float a1, float b1, float L2, float a2, float b2 ); -int im_dE00_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); - -int im_lab_morph( VipsImage *in, VipsImage *out, - DOUBLEMASK *mask, - double L_offset, double L_scale, - double a_scale, double b_scale ); - #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index ba8abd25..f9dbbe2c 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -779,6 +779,14 @@ 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 ); +int im_dE00_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); + +int im_lab_morph( VipsImage *in, VipsImage *out, + DOUBLEMASK *mask, + double L_offset, double L_scale, + double a_scale, double b_scale ); + +#define im_col_dE00 vips_col_dE00 /* ruby-vips uses this */