/src/libvips/libvips/colour/LabS2Lab.c
Line | Count | Source |
1 | | /* LabS2Lab() |
2 | | * |
3 | | * 12/12/02 JC |
4 | | * - adapted from im_LabS2LabQ() |
5 | | * 2/11/09 |
6 | | * - gtkdoc, cleanup |
7 | | */ |
8 | | |
9 | | /* |
10 | | |
11 | | This file is part of VIPS. |
12 | | |
13 | | VIPS is free software; you can redistribute it and/or modify |
14 | | it under the terms of the GNU Lesser General Public License as published by |
15 | | the Free Software Foundation; either version 2 of the License, or |
16 | | (at your option) any later version. |
17 | | |
18 | | This program is distributed in the hope that it will be useful, |
19 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | | GNU Lesser General Public License for more details. |
22 | | |
23 | | You should have received a copy of the GNU Lesser General Public License |
24 | | along with this program; if not, write to the Free Software |
25 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
26 | | 02110-1301 USA |
27 | | |
28 | | */ |
29 | | |
30 | | /* |
31 | | |
32 | | These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk |
33 | | |
34 | | */ |
35 | | |
36 | | #ifdef HAVE_CONFIG_H |
37 | | #include <config.h> |
38 | | #endif /*HAVE_CONFIG_H*/ |
39 | | #include <glib/gi18n-lib.h> |
40 | | |
41 | | #include <stdio.h> |
42 | | |
43 | | #include <vips/vips.h> |
44 | | |
45 | | #include "pcolour.h" |
46 | | |
47 | | typedef VipsColourCode VipsLabS2Lab; |
48 | | typedef VipsColourCodeClass VipsLabS2LabClass; |
49 | | |
50 | 39 | G_DEFINE_TYPE(VipsLabS2Lab, vips_LabS2Lab, VIPS_TYPE_COLOUR_CODE); |
51 | 39 | |
52 | 39 | /* Convert n pels from signed short to Lab. |
53 | 39 | */ |
54 | 39 | static void |
55 | 39 | vips_LabS2Lab_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width) |
56 | 398k | { |
57 | 398k | signed short *p = (signed short *) in[0]; |
58 | 398k | float *q = (float *) out; |
59 | 398k | int i; |
60 | | |
61 | 24.8M | for (i = 0; i < width; i++) { |
62 | 24.4M | q[0] = p[0] / (32767.0 / 100.0); |
63 | 24.4M | q[1] = p[1] / (32768.0 / 128.0); |
64 | 24.4M | q[2] = p[2] / (32768.0 / 128.0); |
65 | | |
66 | 24.4M | p += 3; |
67 | 24.4M | q += 3; |
68 | 24.4M | } |
69 | 398k | } |
70 | | |
71 | | static void |
72 | | vips_LabS2Lab_class_init(VipsLabS2LabClass *class) |
73 | 19 | { |
74 | 19 | VipsObjectClass *object_class = (VipsObjectClass *) class; |
75 | 19 | VipsColourClass *colour_class = VIPS_COLOUR_CLASS(class); |
76 | | |
77 | 19 | object_class->nickname = "LabS2Lab"; |
78 | 19 | object_class->description = _("transform signed short Lab to float"); |
79 | | |
80 | 19 | colour_class->process_line = vips_LabS2Lab_line; |
81 | 19 | } |
82 | | |
83 | | static void |
84 | | vips_LabS2Lab_init(VipsLabS2Lab *LabS2Lab) |
85 | 25.1k | { |
86 | 25.1k | VipsColour *colour = VIPS_COLOUR(LabS2Lab); |
87 | 25.1k | VipsColourCode *code = VIPS_COLOUR_CODE(LabS2Lab); |
88 | | |
89 | 25.1k | colour->interpretation = VIPS_INTERPRETATION_LAB; |
90 | 25.1k | colour->format = VIPS_FORMAT_FLOAT; |
91 | 25.1k | colour->input_bands = 3; |
92 | 25.1k | colour->bands = 3; |
93 | | |
94 | 25.1k | code->input_coding = VIPS_CODING_NONE; |
95 | 25.1k | code->input_format = VIPS_FORMAT_SHORT; |
96 | 25.1k | } |
97 | | |
98 | | /** |
99 | | * vips_LabS2Lab: (method) |
100 | | * @in: input image |
101 | | * @out: (out): output image |
102 | | * @...: `NULL`-terminated list of optional named arguments |
103 | | * |
104 | | * Convert a LabS three-band signed short image to a three-band float image. |
105 | | * |
106 | | * ::: seealso |
107 | | * [method@Image.LabS2Lab]. |
108 | | * |
109 | | * Returns: 0 on success, -1 on error. |
110 | | */ |
111 | | int |
112 | | vips_LabS2Lab(VipsImage *in, VipsImage **out, ...) |
113 | 25.1k | { |
114 | 25.1k | va_list ap; |
115 | 25.1k | int result; |
116 | | |
117 | 25.1k | va_start(ap, out); |
118 | 25.1k | result = vips_call_split("LabS2Lab", ap, in, out); |
119 | 25.1k | va_end(ap); |
120 | | |
121 | 25.1k | return result; |
122 | 25.1k | } |