1 /* im_LCh2Lab
2 *
3 * 15/11/94 JC
4 * - error messages added
5 * - memory leak fixed
6 * 16/11/94 JC
7 * - uses im_wrap_oneonebuf() now
8 * 8/2/95 JC
9 * - im_wrap v2
10 * 2/11/09
11 * - gtkdoc
12 * 19/9/12
13 * - redone as a class
14 */
15
16 /*
17
18 This file is part of VIPS.
19
20 VIPS is free software; you can redistribute it and/or modify
21 it under the terms of the GNU Lesser General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU Lesser General Public License for more details.
29
30 You should have received a copy of the GNU Lesser General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33 02110-1301 USA
34
35 */
36
37 /*
38
39 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
40
41 */
42
43 #ifdef HAVE_CONFIG_H
44 #include <config.h>
45 #endif /*HAVE_CONFIG_H*/
46 #include <vips/intl.h>
47
48 #include <stdio.h>
49 #include <math.h>
50
51 #include <vips/vips.h>
52
53 #include "pcolour.h"
54
55 typedef VipsColourTransform VipsLCh2Lab;
56 typedef VipsColourTransformClass VipsLCh2LabClass;
57
58 G_DEFINE_TYPE( VipsLCh2Lab, vips_LCh2Lab, VIPS_TYPE_COLOUR_TRANSFORM );
59
60 /**
61 * vips_col_Ch2ab:
62 * @C: Chroma
63 * @h: Hue angle (degrees)
64 * @a: return CIE a* value
65 * @b: return CIE b* value
66 *
67 * Calculate ab from Ch, h in degrees.
68 */
69 void
vips_col_Ch2ab(float C,float h,float * a,float * b)70 vips_col_Ch2ab( float C, float h, float *a, float *b )
71 {
72 *a = C * cos( VIPS_RAD( h ) );
73 *b = C * sin( VIPS_RAD( h ) );
74 }
75
76 /* Process a buffer of data.
77 */
78 static void
vips_LCh2Lab_line(VipsColour * colour,VipsPel * out,VipsPel ** in,int width)79 vips_LCh2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
80 {
81 float * restrict p = (float *) in[0];
82 float * restrict q = (float *) out;
83
84 int x;
85
86 for( x = 0; x < width; x++ ) {
87 float L = p[0];
88 float C = p[1];
89 float h = p[2];
90 float a, b;
91
92 p += 3;
93
94 vips_col_Ch2ab( C, h, &a, &b );
95
96 q[0] = L;
97 q[1] = a;
98 q[2] = b;
99
100 q += 3;
101 }
102 }
103
104 static void
vips_LCh2Lab_class_init(VipsLCh2LabClass * class)105 vips_LCh2Lab_class_init( VipsLCh2LabClass *class )
106 {
107 VipsObjectClass *object_class = (VipsObjectClass *) class;
108 VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
109
110 object_class->nickname = "LCh2Lab";
111 object_class->description = _( "transform LCh to Lab" );
112
113 colour_class->process_line = vips_LCh2Lab_line;
114 }
115
116 static void
vips_LCh2Lab_init(VipsLCh2Lab * LCh2Lab)117 vips_LCh2Lab_init( VipsLCh2Lab *LCh2Lab )
118 {
119 VipsColour *colour = VIPS_COLOUR( LCh2Lab );
120
121 colour->interpretation = VIPS_INTERPRETATION_LAB;
122 }
123
124 /**
125 * vips_LCh2Lab: (method)
126 * @in: input image
127 * @out: (out): output image
128 * @...: %NULL-terminated list of optional named arguments
129 *
130 * Turn LCh to Lab.
131 *
132 * Returns: 0 on success, -1 on error
133 */
134 int
vips_LCh2Lab(VipsImage * in,VipsImage ** out,...)135 vips_LCh2Lab( VipsImage *in, VipsImage **out, ... )
136 {
137 va_list ap;
138 int result;
139
140 va_start( ap, out );
141 result = vips_call_split( "LCh2Lab", ap, in, out );
142 va_end( ap );
143
144 return( result );
145 }
146