1 | /* --------------- */ |
---|
2 | /* --- nrlut.c --- */ |
---|
3 | /* --------------- */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * |
---|
9 | * Distributed under the Boost Software License, Version 1.0 |
---|
10 | * see accompanying file LICENSE.txt or copy it at |
---|
11 | * http://www.boost.org/LICENSE_1_0.txt |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * 2002/06/11 ajout des fonctions endline |
---|
16 | */ |
---|
17 | #include <stdio.h> |
---|
18 | #include <stddef.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <math.h> // fabs |
---|
21 | |
---|
22 | #include "mypredef.h" |
---|
23 | #include "nrtype.h" |
---|
24 | #include "nrdef.h" |
---|
25 | #include "nrmacro.h" |
---|
26 | #include "nrkernel.h" |
---|
27 | |
---|
28 | #include "nrlut.h" |
---|
29 | |
---|
30 | /* ----------------------------------------------------------------------- */ |
---|
31 | IMAGE_EXPORT(void) init_blut(byte *v, int nl, int nh, int n0, int n1, byte k) |
---|
32 | /* ----------------------------------------------------------------------- */ |
---|
33 | { |
---|
34 | int i; |
---|
35 | |
---|
36 | if(nl<=nh) { |
---|
37 | // normal case |
---|
38 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
39 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
40 | for(i=n1+1; i<nh; i++) v[i] = 0; |
---|
41 | } else { |
---|
42 | for(i=nl; i< n1; i++) v[i] = k; |
---|
43 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
44 | for(i=n1+1; i<nh; i++) v[i] = k; |
---|
45 | } |
---|
46 | } |
---|
47 | /* ------------------------------------------------------------------------ */ |
---|
48 | IMAGE_EXPORT(void) init_ui8lut(uint8 *v, int nl, int nh, int n0, int n1, uint8 k) |
---|
49 | /* ------------------------------------------------------------------------ */ |
---|
50 | { |
---|
51 | int i; |
---|
52 | |
---|
53 | if(nl<=nh) { |
---|
54 | // normal case |
---|
55 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
56 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
57 | for(i=n1+1; i<nh; i++) v[i] = 0; |
---|
58 | } else { |
---|
59 | for(i=nl; i< n1; i++) v[i] = k; |
---|
60 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
61 | for(i=n1+1; i<nh; i++) v[i] = k; |
---|
62 | } |
---|
63 | } |
---|
64 | /* --------------------------------------------------------------------------- */ |
---|
65 | IMAGE_EXPORT(void) init_ui16lut(uint16 *v, int nl, int nh, int n0, int n1, uint16 k) |
---|
66 | /* --------------------------------------------------------------------------- */ |
---|
67 | { |
---|
68 | int i; |
---|
69 | |
---|
70 | if(nl<=nh) { |
---|
71 | // normal case |
---|
72 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
73 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
74 | for(i=n1+1; i<=nh; i++) v[i] = 0; |
---|
75 | } else { |
---|
76 | for(i=nl; i< n1; i++) v[i] = k; |
---|
77 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
78 | for(i=n1+1; i<=nh; i++) v[i] = k; |
---|
79 | } |
---|
80 | } |
---|
81 | /* --------------------------------------------------------------------------- */ |
---|
82 | IMAGE_EXPORT(void) init_si16lut(sint16 *v, int nl, int nh, int n0, int n1, sint16 k) |
---|
83 | /* --------------------------------------------------------------------------- */ |
---|
84 | { |
---|
85 | int i; |
---|
86 | |
---|
87 | if(nl<=nh) { |
---|
88 | // normal case |
---|
89 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
90 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
91 | for(i=n1+1; i<=nh; i++) v[i] = 0; |
---|
92 | } else { |
---|
93 | for(i=nl; i< n1; i++) v[i] = k; |
---|
94 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
95 | for(i=n1+1; i<=nh; i++) v[i] = k; |
---|
96 | } |
---|
97 | } |
---|
98 | /* --------------------------------------------------------------------------- */ |
---|
99 | IMAGE_EXPORT(void) init_ui32lut(uint32 *v, int nl, int nh, int n0, int n1, uint32 k) |
---|
100 | /* --------------------------------------------------------------------------- */ |
---|
101 | { |
---|
102 | int i; |
---|
103 | |
---|
104 | if(nl<=nh) { |
---|
105 | // normal case |
---|
106 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
107 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
108 | for(i=n1+1; i<=nh; i++) v[i] = 0; |
---|
109 | } else { |
---|
110 | for(i=nl; i< n1; i++) v[i] = k; |
---|
111 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
112 | for(i=n1+1; i<=nh; i++) v[i] = k; |
---|
113 | } |
---|
114 | } |
---|
115 | /* --------------------------------------------------------------------------- */ |
---|
116 | IMAGE_EXPORT(void) init_i32lut(sint32 *v, int nl, int nh, int n0, int n1, sint32 k) |
---|
117 | /* --------------------------------------------------------------------------- */ |
---|
118 | { |
---|
119 | int i; |
---|
120 | |
---|
121 | if(nl<=nh) { |
---|
122 | // normal case |
---|
123 | for(i=nl; i< n0; i++) v[i] = 0; |
---|
124 | for(i=n0; i<=n1; i++) v[i] = k; |
---|
125 | for(i=n1+1; i<=nh; i++) v[i] = 0; |
---|
126 | } else { |
---|
127 | for(i=nl; i< n1; i++) v[i] = k; |
---|
128 | for(i=n1; i<=n0; i++) v[i] = 0; |
---|
129 | for(i=n1+1; i<=nh; i++) v[i] = k; |
---|
130 | } |
---|
131 | } |
---|
132 | /* -------------------------------------------------------------------------- */ |
---|
133 | IMAGE_EXPORT(void) init_rgb8lut(rgb8 *v, int nl, int nh, int n0, int n1, rgb8 k) |
---|
134 | /* -------------------------------------------------------------------------- */ |
---|
135 | { |
---|
136 | int i; |
---|
137 | |
---|
138 | if(nl<=nh) { |
---|
139 | // normal case |
---|
140 | for(i=nl; i< n0; i++) { v[i].r = 0; v[i].g = 0; v[i].b = 0;} |
---|
141 | for(i=n0; i<=n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;} |
---|
142 | for(i=n1+1; i<=nh; i++) { v[i].r = 0; v[i].g = 0; v[i].b = 0;} |
---|
143 | } else { |
---|
144 | for(i=nl; i< n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;} |
---|
145 | for(i=n1; i<=n0; i++) { v[i].r = 0; v[i].g = 0; v[i].b = 0;} |
---|
146 | for(i=n1+1; i<=nh; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;} |
---|
147 | } |
---|
148 | } |
---|
149 | /* ------------------------------------------------------------------------------------------- */ |
---|
150 | IMAGE_EXPORT(void) lut_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte *L, byte **D) |
---|
151 | /* ------------------------------------------------------------------------------------------- */ |
---|
152 | { |
---|
153 | int i, j; |
---|
154 | |
---|
155 | for(i=nrl; i<=nrh; i++) { |
---|
156 | for(j=ncl; j<=nch; j++) { |
---|
157 | D[i][j] = L[(int)S[i][j]]; |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | /* -------------------------------------------------------------------------------------------- */ |
---|
162 | IMAGE_EXPORT(void) lut_ui8matrix(uint8 **S, long nrl,long nrh,long ncl, long nch, uint8 *L, uint8 **D) |
---|
163 | /* -------------------------------------------------------------------------------------------- */ |
---|
164 | { |
---|
165 | int i, j; |
---|
166 | |
---|
167 | for(i=nrl; i<=nrh; i++) { |
---|
168 | for(j=ncl; j<=nch; j++) { |
---|
169 | D[i][j] = L[(int)S[i][j]]; |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | /* -------------------------------------------------------------------------------------------- */ |
---|
174 | IMAGE_EXPORT(void) lut_si8matrix(sint8 **S, long nrl,long nrh,long ncl, long nch, sint8 *L, sint8 **D) |
---|
175 | /* -------------------------------------------------------------------------------------------- */ |
---|
176 | { |
---|
177 | int i, j; |
---|
178 | |
---|
179 | for(i=nrl; i<=nrh; i++) { |
---|
180 | for(j=ncl; j<=nch; j++) { |
---|
181 | D[i][j] = L[(int)S[i][j]]; |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | /* -------------------------------------------------------------------------------------------------- */ |
---|
186 | IMAGE_EXPORT(void) lut_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D) |
---|
187 | /* -------------------------------------------------------------------------------------------------- */ |
---|
188 | { |
---|
189 | int i, j; |
---|
190 | |
---|
191 | for(i=nrl; i<=nrh; i++) { |
---|
192 | for(j=ncl; j<=nch; j++) { |
---|
193 | D[i][j] = L[(int)S[i][j]]; |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | /* -------------------------------------------------------------------------------------------------- */ |
---|
198 | IMAGE_EXPORT(void) lut_si16matrix(sint16 **S, long nrl, long nrh, long ncl, long nch, sint16 *L, sint16 **D) |
---|
199 | /* -------------------------------------------------------------------------------------------------- */ |
---|
200 | { |
---|
201 | int i, j; |
---|
202 | |
---|
203 | for(i=nrl; i<=nrh; i++) { |
---|
204 | for(j=ncl; j<=nch; j++) { |
---|
205 | D[i][j] = L[(int)S[i][j]]; |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | /* -------------------------------------------------------------------------------------------------- */ |
---|
210 | IMAGE_EXPORT(void) lut_ui32matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint32 *L, uint32 **D) |
---|
211 | /* -------------------------------------------------------------------------------------------------- */ |
---|
212 | { |
---|
213 | int i, j; |
---|
214 | |
---|
215 | for(i=nrl; i<=nrh; i++) { |
---|
216 | for(j=ncl; j<=nch; j++) { |
---|
217 | D[i][j] = L[(int)S[i][j]]; |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | /* -------------------------------------------------------------------------------------------------- */ |
---|
222 | IMAGE_EXPORT(void) lut_si32matrix(sint32 **S, long nrl, long nrh, long ncl, long nch, sint32 *L, sint32 **D) |
---|
223 | /* -------------------------------------------------------------------------------------------------- */ |
---|
224 | { |
---|
225 | int i, j; |
---|
226 | |
---|
227 | for(i=nrl; i<=nrh; i++) { |
---|
228 | for(j=ncl; j<=nch; j++) { |
---|
229 | D[i][j] = L[(int)S[i][j]]; |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | /* ------------------------------------------------------------------------------------------------ */ |
---|
234 | IMAGE_EXPORT(void) lut_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb8 *L, rgb8 **D) |
---|
235 | /* ------------------------------------------------------------------------------------------------ */ |
---|
236 | { |
---|
237 | int i, j; |
---|
238 | |
---|
239 | for(i=nrl; i<=nrh; i++) { |
---|
240 | for(j=ncl; j<=nch; j++) { |
---|
241 | D[i][j].r = L[S[i][j].r].r; |
---|
242 | D[i][j].g = L[S[i][j].g].g; |
---|
243 | D[i][j].b = L[S[i][j].b].b; |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
248 | IMAGE_EXPORT(void) lut_ui16matrix_ui8matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint8 *L, uint8 **D) |
---|
249 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
250 | { |
---|
251 | int i, j; |
---|
252 | |
---|
253 | for(i=nrl; i<=nrh; i++) { |
---|
254 | for(j=ncl; j<=nch; j++) { |
---|
255 | D[i][j] = L[(int)S[i][j]]; |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
260 | IMAGE_EXPORT(void) lut_ui32matrix_ui16matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D) |
---|
261 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
262 | { |
---|
263 | int i, j; |
---|
264 | |
---|
265 | for(i=nrl; i<=nrh; i++) { |
---|
266 | for(j=ncl; j<=nch; j++) { |
---|
267 | D[i][j] = L[(int)S[i][j]]; |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | /* ---------------------------------------------------------------------------- */ |
---|
272 | IMAGE_EXPORT(void) histogram_bmatrix(byte **S, long nrl, long nrh, long ncl, long nch, int32 *H) |
---|
273 | /* ---------------------------------------------------------------------------- */ |
---|
274 | { |
---|
275 | int i, j; |
---|
276 | byte *Si; |
---|
277 | |
---|
278 | for(i=nrl; i<=nrh; i++) { |
---|
279 | Si = S[i]; |
---|
280 | for(j=ncl; j<=nch; j++) { |
---|
281 | H[(int) Si[j]]++; |
---|
282 | } |
---|
283 | } |
---|
284 | } |
---|
285 | /* --------------------------------------------------------------------------------- */ |
---|
286 | IMAGE_EXPORT(void) histogram_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, int32 *H) |
---|
287 | /* --------------------------------------------------------------------------------- */ |
---|
288 | { |
---|
289 | int i, j; |
---|
290 | uint16 *Si; |
---|
291 | |
---|
292 | for(i=nrl; i<=nrh; i++) { |
---|
293 | Si = S[i]; |
---|
294 | for(j=ncl; j<=nch; j++) { |
---|
295 | H[Si[j]]++; |
---|
296 | } |
---|
297 | } |
---|
298 | } |
---|
299 | /* ------------------------------------------------------------------------------- */ |
---|
300 | IMAGE_EXPORT(void) histogram_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb32 *H) |
---|
301 | /* ------------------------------------------------------------------------------- */ |
---|
302 | { |
---|
303 | int i, j; |
---|
304 | rgb8 *Si; |
---|
305 | int r, b, g; |
---|
306 | |
---|
307 | //FUNCTION_NAME("Histogram_rgbmatrix"); |
---|
308 | |
---|
309 | for(i=nrl; i<=nrh; i++) { |
---|
310 | Si = S[i]; |
---|
311 | //PROGRESS_INFO(function_name, i, nrl, nrh); |
---|
312 | for(j=ncl; j<=nch; j++) { |
---|
313 | |
---|
314 | //H[Si[j].r].r++; |
---|
315 | //H[Si[j].g].g++; |
---|
316 | //H[Si[j].b].b++; |
---|
317 | |
---|
318 | r = S[i][j].r; |
---|
319 | g = S[i][j].g; |
---|
320 | b = S[i][j].b; |
---|
321 | |
---|
322 | H[r].r++; |
---|
323 | H[g].g++; |
---|
324 | H[b].b++; |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | //END; |
---|
329 | return; |
---|
330 | } |
---|