diff --git a/ChangeLog b/ChangeLog index f824639b..784aa331 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ 31/8/12 started 7.31.0 -- redone im_Lab2XYZ(), im_Lab2LCh() as classes +- redone im_Lab2XYZ(), im_Lab2LCh(), im_LCh2Lab() as classes 13/9/12 started 7.30.3 - linecache sized itself too large diff --git a/libvips/colour/LCh2Lab.c b/libvips/colour/LCh2Lab.c new file mode 100644 index 00000000..76095d4c --- /dev/null +++ b/libvips/colour/LCh2Lab.c @@ -0,0 +1,146 @@ +/* im_LCh2Lab + * + * 15/11/94 JC + * - error messages added + * - memory leak fixed + * 16/11/94 JC + * - uses im_wrap_oneonebuf() now + * 8/2/95 JC + * - im_wrap v2 + * 2/11/09 + * - gtkdoc + * 19/9/12 + * - redone as a class + */ + +/* + + 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 + +#include "colour.h" + +typedef VipsColorimetric VipsLCh2Lab; +typedef VipsColorimetricClass VipsLCh2LabClass; + +G_DEFINE_TYPE( VipsLCh2Lab, vips_LCh2Lab, VIPS_TYPE_COLORIMETRIC ); + +/* Process a buffer of data. + */ +static void +vips_LCh2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) +{ + float *p = (float *) in[0]; + float *q = (float *) out; + + int x; + + for( x = 0; x < width; x++ ) { + float L = p[0]; + float C = p[1]; + float h = p[2]; + float a, b; + + p += 3; + + a = C * cos( VIPS_RAD( h ) ); + b = C * sin( VIPS_RAD( h ) ); + + q[0] = L; + q[1] = a; + q[2] = b; + q += 3; + } +} + +/** + * vips_col_Ch2ab: + * @C: Chroma + * @h: Hue angle (degrees) + * @a: return CIE a* value + * @b: return CIE b* value + * + * Calculate ab from Ch, h in degrees. + */ +void +vips_col_Ch2ab( float C, float h, float *a, float *b ) +{ + float in[3], out[3]; + + in[1] = C; + in[2] = h; + vips_LCh2Lab_line( NULL, (VipsPel *) out, (VipsPel **) &in, 1 ); + *a = out[1]; + *b = out[2]; +} + +static void +vips_LCh2Lab_class_init( VipsLCh2LabClass *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class ); + + object_class->nickname = "LCh2Lab"; + object_class->description = _( "transform LCh to Lab" ); + + colour_class->process_line = vips_LCh2Lab_line; + colour_class->interpretation = VIPS_INTERPRETATION_LAB; +} + +static void +vips_LCh2Lab_init( VipsLCh2Lab *LCh2Lab ) +{ +} + +/** + * vips_LCh2Lab: + * @in: input image + * @out: output image + * + * Turn LCh to Lab. + * + * Returns: 0 on success, -1 on error + */ +int +vips_LCh2Lab( VipsImage *in, VipsImage **out, ... ) +{ + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "LCh2Lab", ap, in, out ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/colour/Makefile.am b/libvips/colour/Makefile.am index 73236bb9..f218ec1e 100644 --- a/libvips/colour/Makefile.am +++ b/libvips/colour/Makefile.am @@ -9,7 +9,7 @@ libcolour_la_SOURCES = \ Lab2XYZ.c \ Lab2LCh.c \ im_icc_transform.c \ - im_LCh2Lab.c \ + LCh2Lab.c \ im_LCh2UCS.c \ im_Lab2LabQ.c \ im_Lab2LabS.c \ diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index 1b56ab85..a22068f3 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -116,7 +116,7 @@ vips_colour_build( VipsObject *object ) return( -1 ); vips_demand_hint_array( colour->out, VIPS_DEMAND_STYLE_THINSTRIP, colour->in ); - out->Type = class->interpretation; + colour->out->Type = class->interpretation; if( vips_image_generate( colour->out, vips_start_many, vips_colour_gen, vips_stop_many, @@ -221,7 +221,7 @@ vips_colorimetric_class_init( VipsColorimetricClass *class ) gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - vobject_class->nickname = "colour"; + vobject_class->nickname = "colorimetric"; vobject_class->description = _( "colorimetric operations" ); vobject_class->build = vips_colorimetric_build; @@ -245,7 +245,9 @@ vips_colour_operation_init( void ) { extern GType vips_Lab2XYZ_get_type( void ); extern GType vips_Lab2LCh_get_type( void ); + extern GType vips_LCh2Lab_get_type( void ); vips_Lab2XYZ_get_type(); vips_Lab2LCh_get_type(); + vips_LCh2Lab_get_type(); } diff --git a/libvips/colour/colour_funcs.c b/libvips/colour/colour_funcs.c index 43ed12ac..71d1d521 100644 --- a/libvips/colour/colour_funcs.c +++ b/libvips/colour/colour_funcs.c @@ -77,27 +77,6 @@ static float LI[ 1001 ]; static float CI[ 3001 ]; static float hI[ 101 ][ 361 ]; -/** - * im_col_Ch2ab: - * @C: Chroma - * @h: Hue angle (degrees) - * @a: return CIE a* value - * @b: return CIE b* value - * - * Calculate ab from Ch, h in degrees. - */ -void -im_col_Ch2ab( float C, float h, float *a, float *b ) -{ - float in[3], out[3]; - - in[1] = C; - in[2] = h; - imb_LCh2Lab( in, out, 1 ); - *a = out[1]; - *b = out[2]; -} - /** * im_col_XYZ2Lab: * @X: Input CIE XYZ colour @@ -767,19 +746,6 @@ vips_Lab2LabQ( VipsImage *in, VipsImage **out, ... ) return( result ); } -int -vips_LCh2Lab( VipsImage *in, VipsImage **out, ... ) -{ - va_list ap; - int result; - - va_start( ap, out ); - result = vips_call_split( "im_LCh2Lab", ap, in, out ); - va_end( ap ); - - return( result ); -} - int vips_Yxy2Lab( VipsImage *in, VipsImage **out, ... ) { diff --git a/libvips/colour/im_LCh2Lab.c b/libvips/colour/im_LCh2Lab.c deleted file mode 100644 index 3ac7c3d9..00000000 --- a/libvips/colour/im_LCh2Lab.c +++ /dev/null @@ -1,90 +0,0 @@ -/* im_LCh2Lab - * - * 15/11/94 JC - * - error messages added - * - memory leak fixed - * 16/11/94 JC - * - uses im_wrap_oneonebuf() now - * 8/2/95 JC - * - im_wrap v2 - * 2/11/09 - * - gtkdoc - */ - -/* - - 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 -#include - -/* Process a buffer of data. - */ -void -imb_LCh2Lab( float *p, float *q, int n ) -{ - int x; - - for( x = 0; x < n; x++ ) { - float L = p[0]; - float C = p[1]; - float h = p[2]; - float a, b; - - p += 3; - - a = C * cos( IM_RAD( h ) ); - b = C * sin( IM_RAD( h ) ); - - q[0] = L; - q[1] = a; - q[2] = b; - q += 3; - } -} - -/** - * im_LCh2Lab: - * @in: input image - * @out: output image - * - * Turn LCh to Lab. - * - * Returns: 0 on success, -1 on error. - */ -int -im_LCh2Lab( IMAGE *in, IMAGE *out ) -{ - return( im__colour_unary( "im_LCh2Lab", in, out, IM_TYPE_LAB, - (im_wrapone_fn) imb_LCh2Lab, NULL, NULL ) ); -} diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index ac9cfa97..51a26932 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -2201,3 +2201,19 @@ im_Lab2LCh( IMAGE *in, IMAGE *out ) return( 0 ); } + +int +im_LCh2Lab( IMAGE *in, IMAGE *out ) +{ + VipsImage *x; + + if( vips_LCh2Lab( in, &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 2b6223db..d29a1bf7 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -125,6 +125,7 @@ void vips_col_Lab2XYZ( float L, float a, float b, float *X, float *Y, float *Z ); double vips_col_ab2h( double a, double b ); void vips_col_ab2Ch( float a, float b, float *C, float *h ); +void vips_col_Ch2ab( float C, float h, float *a, float *b ); @@ -133,7 +134,6 @@ void vips_col_ab2Ch( float a, float b, float *C, float *h ); /* Colour loading and conversion functions. */ void im_col_ab2Ch( float a, float b, float *C, float *h ); -void im_col_Ch2ab( float C, float h, float *a, float *b ); void im_col_XYZ2Lab( float X, float Y, float Z, float *L, float *a, float *b ); float im_col_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ); @@ -152,7 +152,6 @@ float im_col_dECMC( float im_col_dE00( float L1, float a1, float b1, float L2, float a2, float b2 ); -int im_LCh2Lab( VipsImage *in, VipsImage *out ); int im_LabQ2XYZ( VipsImage *in, VipsImage *out ); int im_rad2float( VipsImage *in, VipsImage *out ); int im_float2rad( VipsImage *in, VipsImage *out ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index e3a9e25f..6b4958e2 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -83,6 +83,7 @@ extern "C" { #define im_col_Lab2XYZ vips_col_Lab2XYZ #define im_col_ab2h vips_col_ab2h #define im_col_ab2Ch vips_col_ab2Ch +#define im_col_Ch2ab vips_col_Ch2ab #define PEL VipsPel @@ -699,6 +700,7 @@ int im_shrink( VipsImage *in, VipsImage *out, double xshrink, double yshrink ); int im_Lab2XYZ_temp( IMAGE *in, IMAGE *out, double X0, double Y0, double Z0 ); int im_Lab2XYZ( IMAGE *in, IMAGE *out ); int im_Lab2LCh( VipsImage *in, VipsImage *out ); +int im_LCh2Lab( VipsImage *in, VipsImage *out ); /* ruby-vips uses this */