redo dEUCS as a class

This commit is contained in:
John Cupitt 2012-10-31 11:04:10 +00:00
parent 4901c9f6a5
commit de3298d69e
10 changed files with 132 additions and 144 deletions

View File

@ -3,7 +3,8 @@
im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ(), im_float2rad(), im_rad2float(), im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ(), im_float2rad(), im_rad2float(),
im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab(), im_LabQ2LabS(), im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab(), im_LabQ2LabS(),
im_LabS2LabQ(), im_LabQ2disp(), im_XYZ2disp(), im_disp2XYZ(), 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 as classes
- added vips_colour_convert(), replaces all derived conversions - added vips_colour_convert(), replaces all derived conversions
- dzsave can write zoomify and google maps layout as well - dzsave can write zoomify and google maps layout as well

View File

@ -5,6 +5,7 @@ libcolour_la_SOURCES = \
colour_funcs.c \ colour_funcs.c \
colour_dispatch.c \ colour_dispatch.c \
dE76.c \ dE76.c \
dECMC.c \
icc_transform.c \ icc_transform.c \
Lab2XYZ.c \ Lab2XYZ.c \
Lab2LCh.c \ Lab2LCh.c \
@ -26,7 +27,6 @@ libcolour_la_SOURCES = \
XYZ2sRGB.c \ XYZ2sRGB.c \
sRGB2XYZ.c \ sRGB2XYZ.c \
im_lab_morph.c \ im_lab_morph.c \
im_dE00_fromLab.c \ im_dE00_fromLab.c
im_dECMC_fromLab.c
INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@

View File

@ -200,6 +200,9 @@ typedef struct _VipsColourDifferenceClass {
GType vips_colour_difference_get_type( void ); GType vips_colour_difference_get_type( void );
void vips__pythagoras_line( VipsColour *colour,
VipsPel *out, VipsPel **in, int width );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -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. /* 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: * im_col_dE00:
* @L1: Input coordinate 1 * @L1: Input coordinate 1

View File

@ -57,8 +57,9 @@ G_DEFINE_TYPE( VipsdE76, vips_dE76, VIPS_TYPE_COLOUR_DIFFERENCE );
/* Find the difference between two buffers of LAB data. /* Find the difference between two buffers of LAB data.
*/ */
static void void
vips_dE76_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) vips__pythagoras_line( VipsColour *colour,
VipsPel *out, VipsPel **in, int width )
{ {
float *p1 = (float *) in[0]; float *p1 = (float *) in[0];
float *p2 = (float *) in[1]; float *p2 = (float *) in[1];
@ -84,7 +85,7 @@ vips_dE76_class_init( VipsdE76Class *class )
object_class->nickname = "dE76"; object_class->nickname = "dE76";
object_class->description = _( "calculate dE76" ); object_class->description = _( "calculate dE76" );
colour_class->process_line = vips_dE76_line; colour_class->process_line = vips__pythagoras_line;
} }
static void static void

100
libvips/colour/dECMC.c Normal file
View File

@ -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 <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips.h>
#include <vips/debug.h>
#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 );
}

View File

@ -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 <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips.h>
#include <vips/internal.h>
/* 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 ) );
}

View File

@ -2790,3 +2790,20 @@ im_dE_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out )
return( 0 ); 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 );
}

View File

@ -170,6 +170,8 @@ int vips_icc_ac2rc( VipsImage *in, VipsImage *out,
int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... ) int vips_dE76( VipsImage *left, VipsImage *right, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_dECMC( VipsImage *left, VipsImage *right, VipsImage **out, ... )
__attribute__((sentinel));
void vips_col_Lab2XYZ( float L, float a, float b, void vips_col_Lab2XYZ( float L, float a, float b,
float *X, float *Y, float *Z ); 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 vips_pythagoras( float L1, float a1, float b1,
float L2, float a2, float b2 ); 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 im_col_dE00(
float L1, float a1, float b1, float L2, float a2, float b2 ); 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_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, int im_lab_morph( VipsImage *in, VipsImage *out,
DOUBLEMASK *mask, DOUBLEMASK *mask,

View File

@ -777,6 +777,8 @@ int im_Lab2UCS( VipsImage *in, VipsImage *out );
int im_XYZ2UCS( VipsImage *in, VipsImage *out ); int im_XYZ2UCS( VipsImage *in, VipsImage *out );
int im_dE_fromLab( VipsImage *in1, VipsImage *in2, 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 /* ruby-vips uses this
*/ */