diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index a1b9eb21..ec90714c 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -65,6 +65,7 @@ #include #include +#include #ifdef WITH_DMALLOC #include diff --git a/libvips/colour/derived.c b/libvips/colour/derived.c index 92109672..e5c88814 100644 --- a/libvips/colour/derived.c +++ b/libvips/colour/derived.c @@ -6,6 +6,9 @@ * - sRGB added * 17/6/99 JC * - minor reformatting + * 30/10/09 + * - gtkdoc comments + * - minor cleanups */ /* @@ -48,88 +51,131 @@ #include #endif /*WITH_DMALLOC*/ -/* LabQ to XYZ. +/** + * im_LabQ2XYZ: + * @in: input image + * @out: output image + * + * Convert an image from LabQ (Coding == IM_CODING_LABQ) to XYZ. + * + * Returns: 0 on success, -1 on error. */ int im_LabQ2XYZ( IMAGE *in, IMAGE *out ) { - IMAGE *t1; + IMAGE *t[1]; - if( !(t1 = im_open_local( out, "im_LabQ2XYZ:1", "p" )) || - im_LabQ2Lab( in, t1 ) || - im_Lab2XYZ( t1, out ) ) + if( im_open_local_array( out, t, 1, "im_LabQ2XYZ:1", "p" ) || + im_LabQ2Lab( in, t[0] ) || + im_Lab2XYZ( t[0], out ) ) return( -1 ); return( 0 ); } -/* Lab to UCS. +/** + * im_Lab2UCS: + * @in: input image + * @out: output image + * + * Convert an image from Lab to UCS. + * + * Returns: 0 on success, -1 on error. */ int im_Lab2UCS( IMAGE *in, IMAGE *out ) { - IMAGE *t1; + IMAGE *t[1]; - if( !(t1 = im_open_local( out, "im_Lab2UCS:1", "p" )) || - im_Lab2LCh( in, t1 ) || - im_LCh2UCS( t1, out ) ) + if( im_open_local_array( out, t, 1, "im_Lab2UCS:1", "p" ) || + im_Lab2LCh( in, t[0] ) || + im_LCh2UCS( t[0], out ) ) return( -1 ); return( 0 ); } + +/** + * im_UCS2Lab: + * @in: input image + * @out: output image + * + * Convert an image from UCS to Lab. + * + * Returns: 0 on success, -1 on error. + */ int im_UCS2Lab( IMAGE *in, IMAGE *out ) { - IMAGE *t1; + IMAGE *t[1]; - if( !(t1 = im_open_local( out, "im_UCS2Lab intermediate", "p" )) || - im_UCS2LCh( in, t1 ) || - im_LCh2Lab( t1, out ) ) + if( im_open_local_array( out, t, 1, "im_UCS2Lab:1", "p" ) || + im_UCS2LCh( in, t[0] ) || + im_LCh2Lab( t[0], out ) ) return( -1 ); return( 0 ); } +/** + * im_UCS2XYZ: + * @in: input image + * @out: output image + * + * Convert an image from UCS to XYZ. + * + * Returns: 0 on success, -1 on error. + */ int im_UCS2XYZ( IMAGE *in, IMAGE *out ) { - IMAGE *t1; + IMAGE *t[1]; - if( !(t1 = im_open_local( out, "im_UCS2XYZ intermediate", "p" )) || - im_UCS2Lab( in, t1 ) || - im_Lab2XYZ( t1, out ) ) + if( im_open_local_array( out, t, 1, "im_UCS2XYZ:1", "p" ) || + im_UCS2Lab( in, t[0] ) || + im_Lab2XYZ( t[0], out ) ) return( -1 ); return( 0 ); } + +/** + * im_XY2UCS: + * @in: input image + * @out: output image + * + * Convert an image from XYZ to UCS. + * + * Returns: 0 on success, -1 on error. + */ int im_XYZ2UCS( IMAGE *in, IMAGE *out ) { - IMAGE *t1; + IMAGE *t[1]; - if( !(t1 = im_open_local( out, "im_XYZ2UCS intermediate", "p" )) || - im_XYZ2Lab( in, t1 ) || - im_Lab2UCS( t1, out ) ) - return( -1 ); - - return( 0 ); -} - -int -im_Lab2disp( IMAGE *in, IMAGE *out, struct im_col_display *disp ) -{ - IMAGE *t1; - - if( !(t1 = im_open_local( out, "im_Lab2disp:1", "p" )) || - im_Lab2XYZ( in, t1 ) || - im_XYZ2disp( t1, out, disp ) ) + if( im_open_local_array( out, t, 1, "im_XYZ2UCS:1", "p" ) || + im_XYZ2Lab( in, t[0] ) || + im_Lab2UCS( t[0], out ) ) return( -1 ); return( 0 ); } +/** + * im_XYZ2sRGB: + * @in: input image + * @out: output image + * + * Convert an image from XYZ to sRGB. The conversion is supposed to be quick + * rather than accurate. Use an ICC profile with im_icc_transform() for more + * precision. + * + * See also: im_icc_transform. + * + * Returns: 0 on success, -1 on error. + */ int im_XYZ2sRGB( IMAGE *in, IMAGE *out ) { @@ -141,6 +187,20 @@ im_XYZ2sRGB( IMAGE *in, IMAGE *out ) return( 0 ); } +/** + * im_sRGB2XYZ: + * @in: input image + * @out: output image + * + * Convert an image from sRGB to XYZ. + * The conversion is supposed to be quick + * rather than accurate. Use an ICC profile with im_icc_transform() for more + * precision. + * + * See also: im_icc_transform. + * + * Returns: 0 on success, -1 on error. + */ int im_sRGB2XYZ( IMAGE *in, IMAGE *out ) { @@ -150,65 +210,25 @@ im_sRGB2XYZ( IMAGE *in, IMAGE *out ) return( 0 ); } -int -im_dECMC_fromdisp( IMAGE *im1, IMAGE *im2, - IMAGE *out, struct im_col_display *d ) -{ - IMAGE *t1, *t2, *t3, *t4; - - if( !(t1 = im_open_local( out, "im_dECMC_fromdisp:1", "p" )) || - !(t2 = im_open_local( out, "im_dECMC_fromdisp:2", "p" )) || - !(t3 = im_open_local( out, "im_dECMC_fromdisp:3", "p" )) || - !(t4 = im_open_local( out, "im_dECMC_fromdisp:4", "p" )) || - im_disp2XYZ( im1, t1, d ) || - im_XYZ2Lab( t1, t2 ) || - im_disp2XYZ( im2, t3, d ) || - im_XYZ2Lab( t3, t4 ) || - im_dECMC_fromLab( t2, t4, out ) ) - return( -1 ); - - return( 0 ); -} - +/** + * im_dE_fromXYZ: + * @in: input image + * @out: output image + * + * Calculate CIELAB dE 1976 from a pair of XYZ images. + * + * Returns: 0 on success, -1 on error. + */ int im_dE_fromXYZ( IMAGE *im1, IMAGE *im2, IMAGE *out ) { - IMAGE *t1, *t2; + IMAGE *t[2]; - if( !(t1 = im_open_local( out, "im_dE_fromXYZ:1", "p" )) || - !(t2 = im_open_local( out, "im_dE_fromXYZ:2", "p" )) || - im_XYZ2Lab( im1, t1 ) || - im_XYZ2Lab( im2, t2 ) || - im_dE_fromLab( t1, t2, out ) ) + if( im_open_local_array( out, t, 2, "im_dE_fromXYZ:1", "p" ) || + im_XYZ2Lab( im1, t[0] ) || + im_XYZ2Lab( im2, t[1] ) || + im_dE_fromLab( t[0], t[1], out ) ) return( -1 ); return( 0 ); } - -int -im_dE_fromdisp( IMAGE *im1, IMAGE *im2, IMAGE *out, struct im_col_display *d ) -{ - IMAGE *t1, *t2; - - if( !(t1 = im_open_local( out, "im_dE_fromdisp:1", "p" )) || - !(t2 = im_open_local( out, "im_dE_fromdisp:2", "p" )) || - im_disp2XYZ( im1, t1, d ) || - im_disp2XYZ( im2, t2, d ) || - im_dE_fromXYZ( t1, t2, out ) ) - return( -1 ); - - return( 0 ); -} - -int -im_disp2Lab( IMAGE *in, IMAGE *out, struct im_col_display *d ) -{ - IMAGE *t1; - - if( !(t1 = im_open_local( out, "im_disp2Lab:1", "p" )) || - im_disp2XYZ( in, t1, d ) || - im_XYZ2Lab( t1, out ) ) - return( -1 ); - - return( 0 ); -} diff --git a/libvips/colour/disp.c b/libvips/colour/disp.c index 6811b439..6a1cf9ea 100644 --- a/libvips/colour/disp.c +++ b/libvips/colour/disp.c @@ -535,3 +535,68 @@ im_col_XYZ2rgb( struct im_col_display *d, struct im_col_tab_disp *table, return( 0 ); } +/** + * im_Lab2disp: + * @in: input image + * @out: output image + * + * Convert an image from LabQ (Coding == IM_CODING_LABQ) to XYZ. + * + * Returns: 0 on success, -1 on error. + */ +int +im_Lab2disp( IMAGE *in, IMAGE *out, struct im_col_display *disp ) +{ + IMAGE *t[1]; + + if( im_open_local_array( out, t, 1, "im_Lab2disp:1", "p" ) || + im_Lab2XYZ( in, t[0] ) || + im_XYZ2disp( t[0], out, disp ) ) + return( -1 ); + + return( 0 ); +} + +int +im_dECMC_fromdisp( IMAGE *im1, IMAGE *im2, + IMAGE *out, struct im_col_display *d ) +{ + IMAGE *t[4]; + + if( im_open_local_array( out, t, 4, "im_dECMC_fromdisp:1", "p" ) || + im_disp2XYZ( im1, t[0], d ) || + im_XYZ2Lab( t[0], t[1] ) || + im_disp2XYZ( im2, t[2], d ) || + im_XYZ2Lab( t[2], t[3] ) || + im_dECMC_fromLab( t[1], t[3], out ) ) + return( -1 ); + + return( 0 ); +} + +int +im_dE_fromdisp( IMAGE *im1, IMAGE *im2, IMAGE *out, struct im_col_display *d ) +{ + IMAGE *t[2]; + + if( im_open_local_array( out, t, 2, "im_dE_fromdisp:1", "p" ) || + im_disp2XYZ( im1, t[0], d ) || + im_disp2XYZ( im2, t[1], d ) || + im_dE_fromXYZ( t[0], t[1], out ) ) + return( -1 ); + + return( 0 ); +} + +int +im_disp2Lab( IMAGE *in, IMAGE *out, struct im_col_display *d ) +{ + IMAGE *t[1]; + + if( im_open_local_array( out, t, 1, "im_disp2Lab:1", "p" ) || + im_disp2XYZ( in, t[0], d ) || + im_XYZ2Lab( t[1], out ) ) + return( -1 ); + + return( 0 ); +} diff --git a/libvips/include/vips/colour.h b/libvips/include/vips/colour.h index 002d8a94..08bbeca3 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -109,6 +109,8 @@ void im_col_Lab2XYZ( float L, float a, float b, float *X, float *Y, float *Z ); float im_col_pythagoras( float L1, float a1, float b1, float L2, float a2, float b2 ); +void im_col_make_tables_UCS( void ); + float im_col_L2Lucs( float L ); float im_col_Lucs2L( float Lucs ); float im_col_C2Cucs( float C ); @@ -122,49 +124,37 @@ float im_col_dECMC( float im_col_dE00( float L1, float a1, float b1, float L2, float a2, float b2 ); -int im_Lab2LCh( IMAGE *, IMAGE * ); -int im_LCh2Lab( IMAGE *, IMAGE * ); -int im_LabQ2XYZ( IMAGE *, IMAGE * ); -int im_rad2float( IMAGE *, IMAGE * ); -int im_float2rad( IMAGE *, IMAGE * ); -int im_LCh2UCS( IMAGE *, IMAGE * ); -int im_Lab2LCh( IMAGE *, IMAGE * ); -int im_Lab2LabQ( IMAGE *, IMAGE * ); -int im_Lab2LabS( IMAGE *, IMAGE * ); -int im_Lab2XYZ( IMAGE *, IMAGE * ); -int im_Lab2XYZ_temp( IMAGE *, IMAGE *, double X0, double Y0, double Z0 ); -int im_Lab2UCS( IMAGE *, IMAGE * ); -int im_LabQ2Lab( IMAGE *, IMAGE * ); -int im_LabQ2LabS( IMAGE *, IMAGE * ); -int im_LabS2LabQ( IMAGE *, IMAGE * ); -int im_LabS2Lab( IMAGE *, IMAGE * ); -int im_UCS2XYZ( IMAGE *, IMAGE * ); -int im_UCS2LCh( IMAGE *, IMAGE * ); -int im_UCS2Lab( IMAGE *, IMAGE * ); -int im_XYZ2Lab( IMAGE *, IMAGE * ); -int im_XYZ2Lab_temp( IMAGE *, IMAGE *, double X0, double Y0, double Z0 ); -int im_XYZ2UCS( IMAGE *, IMAGE * ); -int im_sRGB2XYZ( IMAGE *, IMAGE * ); -int im_XYZ2sRGB( IMAGE *, IMAGE * ); -int im_Yxy2XYZ( IMAGE *, IMAGE * ); -int im_XYZ2Yxy( IMAGE *, IMAGE * ); +int im_Lab2LCh( IMAGE *in, IMAGE *out ); +int im_LCh2Lab( IMAGE *in, IMAGE *out ); +int im_LabQ2XYZ( IMAGE *in, IMAGE *out ); +int im_rad2float( IMAGE *in, IMAGE *out ); +int im_float2rad( IMAGE *, IMAGE *out ); +int im_LCh2UCS( IMAGE *in, IMAGE *out ); +int im_Lab2LCh( IMAGE *in, IMAGE *out ); +int im_Lab2LabQ( IMAGE *in, IMAGE *out ); +int im_Lab2LabS( IMAGE *in, IMAGE *out ); +int im_Lab2XYZ( IMAGE *in, IMAGE *out ); +int im_Lab2XYZ_temp( IMAGE *in, IMAGE *out, double X0, double Y0, double Z0 ); +int im_Lab2UCS( IMAGE *in, IMAGE *out ); +int im_LabQ2Lab( IMAGE *in, IMAGE *out ); +int im_LabQ2LabS( IMAGE *in, IMAGE *out ); +int im_LabS2LabQ( IMAGE *in, IMAGE *out ); +int im_LabS2Lab( IMAGE *in, IMAGE *out ); +int im_UCS2XYZ( IMAGE *in, IMAGE *out ); +int im_UCS2LCh( IMAGE *in, IMAGE *out ); +int im_UCS2Lab( IMAGE *in, IMAGE *out ); +int im_XYZ2Lab( IMAGE *in, IMAGE *out ); +int im_XYZ2Lab_temp( IMAGE *in, IMAGE *out, double X0, double Y0, double Z0 ); +int im_XYZ2UCS( IMAGE *in, IMAGE *out ); +int im_sRGB2XYZ( IMAGE *in, IMAGE *out ); +int im_XYZ2sRGB( IMAGE *in, IMAGE *out ); +int im_Yxy2XYZ( IMAGE *in, IMAGE *out ); +int im_XYZ2Yxy( IMAGE *in, IMAGE *out ); -int im_dECMC_fromLab( IMAGE *, IMAGE *, IMAGE * ); -int im_dE00_fromLab( IMAGE *, IMAGE *, IMAGE * ); -int im_dE_fromXYZ( IMAGE *, IMAGE *, IMAGE * ); -int im_dE_fromLab( IMAGE *, IMAGE *, IMAGE * ); - -void imb_Lab2LCh( float *, float *, int ); -void imb_LCh2Lab( float *, float *, int ); -void imb_XYZ2Lab_tables( void ); -void imb_XYZ2Lab( float *, float *, int, im_colour_temperature * ); -void imb_Lab2XYZ( float *, float *, int, im_colour_temperature * ); -void imb_LabQ2Lab( PEL *, float *, int ); -void imb_Lab2LabQ( float *, PEL *, int ); -void imb_LabS2Lab( signed short *, float *, int ); -void imb_Lab2LabS( float *, signed short *, int n ); - -void im_col_make_tables_UCS( void ); +int im_dECMC_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ); +int im_dE00_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ); +int im_dE_fromXYZ( IMAGE *in1, IMAGE *in2, IMAGE *out ); +int im_dE_fromLab( IMAGE *in1, IMAGE *in2, IMAGE *out ); int im_lab_morph( IMAGE *in, IMAGE *out, DOUBLEMASK *mask, diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index d82c9dfa..74446477 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -203,6 +203,15 @@ int im__balance( IMAGE *ref, IMAGE *sec, IMAGE *out, IMAGE **ref_out, IMAGE **sec_out, int dx, int dy, int balancetype ); void im__black_region( REGION *reg ); +void imb_Lab2LCh( float *, float *, int ); +void imb_LCh2Lab( float *, float *, int ); +void imb_XYZ2Lab_tables( void ); +void imb_XYZ2Lab( float *, float *, int, im_colour_temperature * ); +void imb_Lab2XYZ( float *, float *, int, im_colour_temperature * ); +void imb_LabQ2Lab( PEL *, float *, int ); +void imb_Lab2LabQ( float *, PEL *, int ); +void imb_LabS2Lab( signed short *, float *, int ); +void imb_Lab2LabS( float *, signed short *, int n ); #ifdef __cplusplus } diff --git a/libvips/inplace/im_plotmask.c b/libvips/inplace/im_plotmask.c index 33b3ab98..c4edc17a 100644 --- a/libvips/inplace/im_plotmask.c +++ b/libvips/inplace/im_plotmask.c @@ -55,6 +55,7 @@ #include #include +#include #ifdef WITH_DMALLOC #include diff --git a/libvips/mosaicing/im_lrmerge.c b/libvips/mosaicing/im_lrmerge.c index e3dcd4b9..07ea2960 100644 --- a/libvips/mosaicing/im_lrmerge.c +++ b/libvips/mosaicing/im_lrmerge.c @@ -134,6 +134,7 @@ #include #include #include +#include #include "merge.h" diff --git a/libvips/mosaicing/im_tbmerge.c b/libvips/mosaicing/im_tbmerge.c index 42cf85f7..cc7f7754 100644 --- a/libvips/mosaicing/im_tbmerge.c +++ b/libvips/mosaicing/im_tbmerge.c @@ -108,6 +108,7 @@ #include #include #include +#include #include "merge.h"