diff --git a/ChangeLog b/ChangeLog index b8bcec45..d48bf2f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 31/8/12 started 7.31.0 - redone im_Lab2XYZ(), im_XYZ2Lab(), im_Lab2LCh(), im_LCh2Lab(), im_UCS2LCh, - im_LCh2UCS() as classes + im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ() as classes 13/9/12 started 7.30.3 - linecache sized itself too large diff --git a/libvips/colour/Makefile.am b/libvips/colour/Makefile.am index e8e1be92..c4c498ca 100644 --- a/libvips/colour/Makefile.am +++ b/libvips/colour/Makefile.am @@ -12,6 +12,8 @@ libcolour_la_SOURCES = \ LCh2UCS.c \ UCS2LCh.c \ XYZ2Lab.c \ + XYZ2Yxy.c \ + Yxy2XYZ.c \ im_icc_transform.c \ im_Lab2LabQ.c \ im_Lab2LabS.c \ @@ -21,9 +23,7 @@ libcolour_la_SOURCES = \ im_LabS2LabQ.c \ im_LabS2Lab.c \ im_lab_morph.c \ - im_XYZ2Yxy.c \ im_float2rad.c \ - im_Yxy2XYZ.c \ im_XYZ2disp.c \ im_dE00_fromLab.c \ im_dECMC_fromLab.c \ diff --git a/libvips/colour/im_XYZ2Yxy.c b/libvips/colour/XYZ2Yxy.c similarity index 57% rename from libvips/colour/im_XYZ2Yxy.c rename to libvips/colour/XYZ2Yxy.c index 05a3c2be..dbc3a9e8 100644 --- a/libvips/colour/im_XYZ2Yxy.c +++ b/libvips/colour/XYZ2Yxy.c @@ -43,16 +43,23 @@ #include #include -#include -/* Process a buffer of data. - */ -void -imb_XYZ2Yxy( float *p, float *q, int n ) +#include "colour.h" + +typedef VipsColorimetric VipsXYZ2Yxy; +typedef VipsColorimetricClass VipsXYZ2YxyClass; + +G_DEFINE_TYPE( VipsXYZ2Yxy, vips_XYZ2Yxy, VIPS_TYPE_COLORIMETRIC ); + +static void +vips_XYZ2Yxy_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) { + float *p = (float *) in[0]; + float *q = (float *) out; + int i; - for( i = 0; i < n; i++ ) { + for( i = 0; i < width; i++ ) { float X = p[0]; float Y = p[1]; float Z = p[2]; @@ -72,19 +79,42 @@ imb_XYZ2Yxy( float *p, float *q, int n ) } } +static void +vips_XYZ2Yxy_class_init( VipsXYZ2YxyClass *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class ); + + object_class->nickname = "XYZ2Yxy"; + object_class->description = _( "transform XYZ to Yxy" ); + + colour_class->process_line = vips_XYZ2Yxy_line; + colour_class->interpretation = VIPS_INTERPRETATION_YXY; +} + +static void +vips_XYZ2Yxy_init( VipsXYZ2Yxy *XYZ2Yxy ) +{ +} + /** - * im_XYZ2Yxy: + * vips_XYZ2Yxy: * @in: input image * @out: output image * * Turn XYZ to Yxy. * - * Returns: 0 on success, -1 on error. + * Returns: 0 on success, -1 on error */ -int -im_XYZ2Yxy( IMAGE *in, IMAGE *out ) -{ - return( im__colour_unary( "im_XYZ2Yxy", in, out, IM_TYPE_YXY, - (im_wrapone_fn) imb_XYZ2Yxy, NULL, NULL ) ); -} +int +vips_XYZ2Yxy( VipsImage *in, VipsImage **out, ... ) +{ + va_list ap; + int result; + va_start( ap, out ); + result = vips_call_split( "XYZ2Yxy", ap, in, out ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/colour/im_Yxy2XYZ.c b/libvips/colour/Yxy2XYZ.c similarity index 57% rename from libvips/colour/im_Yxy2XYZ.c rename to libvips/colour/Yxy2XYZ.c index 7a55deb1..9e7b2c5e 100644 --- a/libvips/colour/im_Yxy2XYZ.c +++ b/libvips/colour/Yxy2XYZ.c @@ -43,16 +43,23 @@ #include #include -#include -/* Process a buffer of data. - */ +#include "colour.h" + +typedef VipsColorimetric VipsYxy2XYZ; +typedef VipsColorimetricClass VipsYxy2XYZClass; + +G_DEFINE_TYPE( VipsYxy2XYZ, vips_Yxy2XYZ, VIPS_TYPE_COLORIMETRIC ); + void -imb_Yxy2XYZ( float *p, float *q, int n ) +vips_Yxy2XYZ_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) { + float *p = (float *) in[0]; + float *q = (float *) out; + int i; - for( i = 0; i < n; i++ ) { + for( i = 0; i < width; i++ ) { float Y = p[0]; float x = p[1]; float y = p[2]; @@ -73,19 +80,43 @@ imb_Yxy2XYZ( float *p, float *q, int n ) } } +static void +vips_Yxy2XYZ_class_init( VipsYxy2XYZClass *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class ); + + object_class->nickname = "Yxy2XYZ"; + object_class->description = _( "transform Yxy to XYZ" ); + + colour_class->process_line = vips_Yxy2XYZ_line; + colour_class->interpretation = VIPS_INTERPRETATION_XYZ; +} + +static void +vips_Yxy2XYZ_init( VipsYxy2XYZ *Yxy2XYZ ) +{ +} + /** - * im_Yxy2XYZ: + * vips_Yxy2XYZ: * @in: input image * @out: output image * - * Turn Yxy to XYZ. + * Turn XYZ to Yxy. * - * Returns: 0 on success, -1 on error. + * Returns: 0 on success, -1 on error */ -int -im_Yxy2XYZ( IMAGE *in, IMAGE *out ) +int +vips_Yxy2XYZ( VipsImage *in, VipsImage **out, ... ) { - return( im__colour_unary( "im_Yxy2XYZ", in, out, IM_TYPE_XYZ, - (im_wrapone_fn) imb_Yxy2XYZ, NULL, NULL ) ); + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "Yxy2XYZ", ap, in, out ); + va_end( ap ); + + return( result ); } diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index 4bc1f11d..98fdd563 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -244,14 +244,20 @@ void vips_colour_operation_init( void ) { extern GType vips_Lab2XYZ_get_type( void ); + extern GType vips_XYZ2Lab_get_type( void ); extern GType vips_Lab2LCh_get_type( void ); extern GType vips_LCh2Lab_get_type( void ); extern GType vips_LCh2UCS_get_type( void ); extern GType vips_UCS2LCh_get_type( void ); + extern GType vips_Yxy2XYZ_get_type( void ); + extern GType vips_XYZ2Yxy_get_type( void ); vips_Lab2XYZ_get_type(); + vips_XYZ2Lab_get_type(); vips_Lab2LCh_get_type(); vips_LCh2Lab_get_type(); vips_LCh2UCS_get_type(); vips_UCS2LCh_get_type(); + vips_XYZ2Yxy_get_type(); + vips_Yxy2XYZ_get_type(); } diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index ee285b15..f7a47725 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -2291,3 +2291,35 @@ im_UCS2LCh( IMAGE *in, IMAGE *out ) return( 0 ); } + +int +im_XYZ2Yxy( IMAGE *in, IMAGE *out ) +{ + VipsImage *x; + + if( vips_XYZ2Yxy( in, &x, NULL ) ) + return( -1 ); + if( im_copy( x, out ) ) { + g_object_unref( x ); + return( -1 ); + } + g_object_unref( x ); + + return( 0 ); +} + +int +im_Yxy2XYZ( IMAGE *in, IMAGE *out ) +{ + VipsImage *x; + + if( vips_Yxy2XYZ( 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 63276cb2..cdea862a 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -126,6 +126,10 @@ int vips_LCh2UCS( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); int vips_UCS2LCh( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); +int vips_XYZ2Yxy( VipsImage *in, VipsImage **out, ... ) + __attribute__((sentinel)); +int vips_Yxy2XYZ( VipsImage *in, VipsImage **out, ... ) + __attribute__((sentinel)); void vips_col_Lab2XYZ( float L, float a, float b, float *X, float *Y, float *Z ); @@ -174,8 +178,6 @@ int im_Lab2UCS( VipsImage *in, VipsImage *out ); int im_XYZ2UCS( VipsImage *in, VipsImage *out ); int im_sRGB2XYZ( VipsImage *in, VipsImage *out ); int im_XYZ2sRGB( VipsImage *in, VipsImage *out ); -int im_Yxy2XYZ( VipsImage *in, VipsImage *out ); -int im_XYZ2Yxy( VipsImage *in, VipsImage *out ); int im_dECMC_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_dE00_fromLab( VipsImage *in1, VipsImage *in2, VipsImage *out ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index d37f8860..75755439 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -716,6 +716,8 @@ int im_Lab2LCh( VipsImage *in, VipsImage *out ); int im_LCh2Lab( VipsImage *in, VipsImage *out ); int im_LCh2UCS( VipsImage *in, VipsImage *out ); int im_UCS2LCh( VipsImage *in, VipsImage *out ); +int im_XYZ2Yxy( VipsImage *in, VipsImage *out ); +int im_Yxy2XYZ( VipsImage *in, VipsImage *out ); /* ruby-vips uses this */