1 | /* ----------------- */ |
---|
2 | /* --- nrmem2X.c --- */ |
---|
3 | /* ----------------- */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * 2002/06/11 ajout des fonctions endline |
---|
13 | */ |
---|
14 | #include <stdio.h> |
---|
15 | #include <stddef.h> |
---|
16 | #include <stdlib.h> |
---|
17 | |
---|
18 | #include "mypredef.h" |
---|
19 | #include "nrtype.h" |
---|
20 | #include "nrdef.h" |
---|
21 | #include "nrmacro.h" |
---|
22 | #include "nrkernel.h" |
---|
23 | |
---|
24 | #include "nrtypex.h" |
---|
25 | |
---|
26 | #include "nrmem1.h" |
---|
27 | #include "nrmem2.h" |
---|
28 | #include "nrmem2x.h" |
---|
29 | |
---|
30 | |
---|
31 | /* ------------------------------------------ */ |
---|
32 | /* --- ATTENTION ---------------------------- */ |
---|
33 | /* ------------------------------------------ */ |
---|
34 | /* l'utilisation des fonctions endline */ |
---|
35 | /* necessite l'allocation d'une ligne de plus */ |
---|
36 | /* (a cause du m[i + 1] */ |
---|
37 | /* ------------------------------------------ */ |
---|
38 | |
---|
39 | #undef reset_endline_type_matrix |
---|
40 | #define reset_endline_type_matrix(t) \ |
---|
41 | void short_name(t,reset_endline_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
42 | { \ |
---|
43 | int32_t ncol = nch - ncl + 1; \ |
---|
44 | for (int32_t i = nrl + 1; i <= nrh; i++) { \ |
---|
45 | m[i] = m[i - 1] + ncol; \ |
---|
46 | } \ |
---|
47 | } |
---|
48 | |
---|
49 | reset_endline_type_matrix(int8_t); |
---|
50 | reset_endline_type_matrix(uint8_t); |
---|
51 | reset_endline_type_matrix(int16_t); |
---|
52 | reset_endline_type_matrix(uint16_t); |
---|
53 | reset_endline_type_matrix(int32_t); |
---|
54 | reset_endline_type_matrix(uint32_t); |
---|
55 | reset_endline_type_matrix(int64_t); |
---|
56 | reset_endline_type_matrix(uint64_t); |
---|
57 | |
---|
58 | |
---|
59 | #undef endline_type_matrix |
---|
60 | #define endline_type_matrix(t) \ |
---|
61 | void short_name(t,endline_,matrix)(t ** m, int32_t i, int32_t l) \ |
---|
62 | { \ |
---|
63 | m[i + 1] = m[i] + l; \ |
---|
64 | } \ |
---|
65 | void short_name(t,endline0_,matrix)(t ** m, int32_t i, int32_t l, int32_t ncl) \ |
---|
66 | { \ |
---|
67 | m[i + 1] = m[i] + l + 1; \ |
---|
68 | m[i][ncl] = (t) l; \ |
---|
69 | } \ |
---|
70 | void short_name(t,endline1_,matrix)(t ** m, int32_t i, int32_t l, int32_t ncl) \ |
---|
71 | { \ |
---|
72 | m[i + 1] = m[i] + l + 1; \ |
---|
73 | m[i][ncl - 1] = (t) l; \ |
---|
74 | } |
---|
75 | |
---|
76 | endline_type_matrix(int8_t); |
---|
77 | endline_type_matrix(uint8_t); |
---|
78 | endline_type_matrix(int16_t); |
---|
79 | endline_type_matrix(uint16_t); |
---|
80 | endline_type_matrix(int32_t); |
---|
81 | endline_type_matrix(uint32_t); |
---|
82 | endline_type_matrix(int64_t); |
---|
83 | endline_type_matrix(uint64_t); |
---|
84 | |
---|
85 | |
---|
86 | #undef resize_type_matrix |
---|
87 | #define resize_type_matrix(t) \ |
---|
88 | void short_name(t,resize_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
89 | { \ |
---|
90 | int32_t ncol = nch - ncl + 1; \ |
---|
91 | for (int32_t i = nrl + 1; i <= nrh; i++) { \ |
---|
92 | m[i] = m[i - 1] + ncol; \ |
---|
93 | } \ |
---|
94 | } |
---|
95 | |
---|
96 | resize_type_matrix(si16Point); |
---|
97 | resize_type_matrix(ui16Point); |
---|
98 | resize_type_matrix(si32Point); |
---|
99 | resize_type_matrix(ui32Point); |
---|
100 | resize_type_matrix(f32Point); |
---|
101 | resize_type_matrix(si16Triplet); |
---|
102 | resize_type_matrix(ui16Triplet); |
---|
103 | resize_type_matrix(si32Triplet); |
---|
104 | resize_type_matrix(ui32Triplet); |
---|
105 | resize_type_matrix(f32Triplet); |
---|
106 | |
---|
107 | |
---|
108 | /* |
---|
109 | * -------------- |
---|
110 | * matrix_reverse |
---|
111 | * -------------- |
---|
112 | */ |
---|
113 | |
---|
114 | #undef type_matrix_reverse |
---|
115 | #define type_matrix_reverse(t) \ |
---|
116 | void short_name(t,,matrix_reverse)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
117 | { \ |
---|
118 | int32_t mrow = (nrl + nrh + 1) / 2; \ |
---|
119 | t * temp; \ |
---|
120 | for (int32_t i = nrl; i < mrow; i++) { \ |
---|
121 | temp = m[i]; \ |
---|
122 | m[i] = m[nrh - i]; \ |
---|
123 | m[nrh - i] = temp; \ |
---|
124 | } \ |
---|
125 | } |
---|
126 | |
---|
127 | type_matrix_reverse(int8_t); |
---|
128 | type_matrix_reverse(uint8_t); |
---|
129 | type_matrix_reverse(int16_t); |
---|
130 | type_matrix_reverse(uint16_t); |
---|
131 | type_matrix_reverse(int32_t); |
---|
132 | type_matrix_reverse(uint32_t); |
---|
133 | type_matrix_reverse(int64_t); |
---|
134 | type_matrix_reverse(uint64_t); |
---|
135 | type_matrix_reverse(float); |
---|
136 | type_matrix_reverse(double); |
---|
137 | |
---|
138 | |
---|
139 | #undef desinterlace_type_matrix |
---|
140 | #define desinterlace_type_matrix(t) \ |
---|
141 | void short_name(t,desinterlace_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** D0, t ** D1) \ |
---|
142 | { \ |
---|
143 | int32_t i0, i1; \ |
---|
144 | i0 = i1 = nrl; \ |
---|
145 | if ((nrl & 1) == 0) { \ |
---|
146 | /* nrl is even */ \ |
---|
147 | for (int32_t i = nrl; i <= nrh; i += 2) { \ |
---|
148 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
149 | D0[i0][j] = S[i][j]; \ |
---|
150 | } \ |
---|
151 | i0++; \ |
---|
152 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
153 | D1[i1][j] = S[i][j]; \ |
---|
154 | } \ |
---|
155 | i1++; \ |
---|
156 | } \ |
---|
157 | /* epilog */ \ |
---|
158 | if ((nrh & 1) == 0) { \ |
---|
159 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
160 | D0[i0][j] = S[nrh][j]; \ |
---|
161 | } \ |
---|
162 | i0++; \ |
---|
163 | } \ |
---|
164 | } \ |
---|
165 | else { \ |
---|
166 | /* nrl is odd */ \ |
---|
167 | for (int32_t i = nrl; i <= nrh; i += 2) { \ |
---|
168 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
169 | D1[i1][j] = S[i][j]; \ |
---|
170 | } \ |
---|
171 | i1++; \ |
---|
172 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
173 | D0[i0][j] = S[i][j]; \ |
---|
174 | } \ |
---|
175 | i0++; \ |
---|
176 | } \ |
---|
177 | /* epilog */ \ |
---|
178 | if ((nrh & 1) == 1) { \ |
---|
179 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
180 | D1[i1][j] = S[nrh][j]; \ |
---|
181 | } \ |
---|
182 | i1++; \ |
---|
183 | } \ |
---|
184 | } \ |
---|
185 | } |
---|
186 | |
---|
187 | desinterlace_type_matrix(int8_t); |
---|
188 | desinterlace_type_matrix(uint8_t); |
---|
189 | desinterlace_type_matrix(int16_t); |
---|
190 | desinterlace_type_matrix(uint16_t); |
---|
191 | desinterlace_type_matrix(int32_t); |
---|
192 | desinterlace_type_matrix(uint32_t); |
---|
193 | desinterlace_type_matrix(int64_t); |
---|
194 | desinterlace_type_matrix(uint64_t); |
---|
195 | desinterlace_type_matrix(float); |
---|
196 | desinterlace_type_matrix(double); |
---|
197 | desinterlace_type_matrix(rgb8); |
---|
198 | desinterlace_type_matrix(rgbx8); |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | #undef interlace_type_matrix |
---|
203 | #define interlace_type_matrix(t) \ |
---|
204 | void short_name(t,interlace_,matrix)(t ** S0, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** S1, t ** D) \ |
---|
205 | { \ |
---|
206 | /* S1 & S2 are supposed to have the same height */ \ |
---|
207 | int i0, i1; \ |
---|
208 | i0 = i1 = nrl; \ |
---|
209 | for (int32_t i = nrl; i <= nrh;) { \ |
---|
210 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
211 | D[i][j] = S0[i0][j]; \ |
---|
212 | } \ |
---|
213 | i++; \ |
---|
214 | i0++; \ |
---|
215 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
216 | D[i][j] = S0[i1][j]; \ |
---|
217 | } \ |
---|
218 | i++; \ |
---|
219 | i1++; \ |
---|
220 | } \ |
---|
221 | } |
---|
222 | |
---|
223 | interlace_type_matrix(int8_t); |
---|
224 | interlace_type_matrix(uint8_t); |
---|
225 | interlace_type_matrix(int16_t); |
---|
226 | interlace_type_matrix(uint16_t); |
---|
227 | interlace_type_matrix(int32_t); |
---|
228 | interlace_type_matrix(uint32_t); |
---|
229 | interlace_type_matrix(int64_t); |
---|
230 | interlace_type_matrix(uint64_t); |
---|
231 | interlace_type_matrix(float); |
---|
232 | interlace_type_matrix(double); |
---|
233 | interlace_type_matrix(rgb8); |
---|
234 | interlace_type_matrix(rgbx8); |
---|
235 | |
---|
236 | |
---|
237 | #undef copyc_type_matrix |
---|
238 | #define copyc_type_matrix(t) \ |
---|
239 | void short_name(t,copyc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** cond, t c, t ** dst) \ |
---|
240 | { \ |
---|
241 | t * Xi; \ |
---|
242 | t * Yi; \ |
---|
243 | t * Ci; \ |
---|
244 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
245 | Xi = src [i]; \ |
---|
246 | Yi = dst [i]; \ |
---|
247 | Ci = cond[i]; \ |
---|
248 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
249 | if (Ci[j] == c) { \ |
---|
250 | Yi[j] = Xi[j]; \ |
---|
251 | } \ |
---|
252 | else { \ |
---|
253 | Yi[j] = 0; \ |
---|
254 | } \ |
---|
255 | } \ |
---|
256 | } \ |
---|
257 | } |
---|
258 | |
---|
259 | copyc_type_matrix(int8_t); |
---|
260 | copyc_type_matrix(uint8_t); |
---|
261 | copyc_type_matrix(int16_t); |
---|
262 | copyc_type_matrix(uint16_t); |
---|
263 | copyc_type_matrix(int32_t); |
---|
264 | copyc_type_matrix(uint32_t); |
---|
265 | copyc_type_matrix(int64_t); |
---|
266 | copyc_type_matrix(uint64_t); |
---|
267 | copyc_type_matrix(float); |
---|
268 | copyc_type_matrix(double); |
---|
269 | |
---|
270 | |
---|
271 | #undef complete_border_type_matrix |
---|
272 | #define complete_border_type_matrix(t) \ |
---|
273 | void short_name(t,complete_border_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t n) \ |
---|
274 | { \ |
---|
275 | t * Xi; \ |
---|
276 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
277 | Xi = m[i]; \ |
---|
278 | for (int32_t j = 1; j <= n; j++) { \ |
---|
279 | Xi[ncl - j] = Xi[ncl]; \ |
---|
280 | Xi[nch + j] = Xi[nch]; \ |
---|
281 | } \ |
---|
282 | } \ |
---|
283 | for (int32_t i = 1; i <= n; i++) { \ |
---|
284 | short_name(t,dup_,vector)(m[nrl], ncl - n, nch + n, m[nrl - i]); \ |
---|
285 | } \ |
---|
286 | for (int32_t i = 1; i <= n; i++) { \ |
---|
287 | short_name(t,dup_,vector)(m[nrh], ncl - n, nch + n, m[nrh + i]); \ |
---|
288 | } \ |
---|
289 | } |
---|
290 | |
---|
291 | complete_border_type_matrix(int8_t); |
---|
292 | complete_border_type_matrix(uint8_t); |
---|
293 | complete_border_type_matrix(int16_t); |
---|
294 | complete_border_type_matrix(uint16_t); |
---|
295 | complete_border_type_matrix(int32_t); |
---|
296 | complete_border_type_matrix(uint32_t); |
---|
297 | complete_border_type_matrix(int64_t); |
---|
298 | complete_border_type_matrix(uint64_t); |
---|
299 | complete_border_type_matrix(float); |
---|
300 | complete_border_type_matrix(double); |
---|
301 | complete_border_type_matrix(rgb8); |
---|
302 | complete_border_type_matrix(rgbx8); |
---|
303 | |
---|
304 | |
---|
305 | #undef complete_border1_type_matrix |
---|
306 | #define complete_border1_type_matrix(t) \ |
---|
307 | void short_name(t,complete_border1_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
308 | { \ |
---|
309 | t * Xi; \ |
---|
310 | short_name(t,dup_,vector)(m[nrl + 1], ncl, nch, m[nrl]); \ |
---|
311 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
312 | Xi = m[i]; \ |
---|
313 | Xi[nrl] = Xi[nrl + 1]; \ |
---|
314 | Xi[nrh] = Xi[nrh - 1]; \ |
---|
315 | } \ |
---|
316 | short_name(t,dup_,vector)(m[nrh - 1], ncl, nch, m[nrh]); \ |
---|
317 | } |
---|
318 | |
---|
319 | complete_border1_type_matrix(int8_t); |
---|
320 | complete_border1_type_matrix(uint8_t); |
---|
321 | complete_border1_type_matrix(int16_t); |
---|
322 | complete_border1_type_matrix(uint16_t); |
---|
323 | complete_border1_type_matrix(int32_t); |
---|
324 | complete_border1_type_matrix(uint32_t); |
---|
325 | complete_border1_type_matrix(int64_t); |
---|
326 | complete_border1_type_matrix(uint64_t); |
---|
327 | complete_border1_type_matrix(float); |
---|
328 | complete_border1_type_matrix(double); |
---|
329 | complete_border1_type_matrix(rgb8); |
---|
330 | complete_border1_type_matrix(rgbx8); |
---|
331 | |
---|
332 | |
---|
333 | #undef complete_border2_type_matrix |
---|
334 | #define complete_border2_type_matrix(t) \ |
---|
335 | void short_name(t,complete_border2_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
336 | { \ |
---|
337 | t * Xi; \ |
---|
338 | short_name(t,dup_,vector)(m[nrl + 2], ncl, nch, m[nrl + 0]); \ |
---|
339 | short_name(t,dup_,vector)(m[nrl + 2], ncl, nch, m[nrl + 1]); \ |
---|
340 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
341 | Xi = m[i]; \ |
---|
342 | Xi[nrl] = Xi[nrl + 1] = Xi[nrl + 2]; \ |
---|
343 | Xi[nrh] = Xi[nrh - 1] = Xi[nrh - 2]; \ |
---|
344 | } \ |
---|
345 | short_name(t,dup_,vector)(m[nrh - 2], ncl, nch, m[nrh - 1]); \ |
---|
346 | short_name(t,dup_,vector)(m[nrh - 2], ncl, nch, m[nrh - 0]); \ |
---|
347 | } |
---|
348 | |
---|
349 | complete_border2_type_matrix(int8_t); |
---|
350 | complete_border2_type_matrix(uint8_t); |
---|
351 | complete_border2_type_matrix(int16_t); |
---|
352 | complete_border2_type_matrix(uint16_t); |
---|
353 | complete_border2_type_matrix(int32_t); |
---|
354 | complete_border2_type_matrix(uint32_t); |
---|
355 | complete_border2_type_matrix(int64_t); |
---|
356 | complete_border2_type_matrix(uint64_t); |
---|
357 | complete_border2_type_matrix(float); |
---|
358 | complete_border2_type_matrix(double); |
---|
359 | complete_border2_type_matrix(rgb8); |
---|
360 | complete_border2_type_matrix(rgbx8); |
---|
361 | |
---|
362 | |
---|
363 | #undef copy1c_type_matrix |
---|
364 | #define copy1c_type_matrix(t) \ |
---|
365 | void short_name(t,copy1c_,matrix)(t ** X, int32_t nc, t ** Y, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
366 | { \ |
---|
367 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
368 | /* copy1c_ui8vector(X[i], nc, Y[i], ncl, nch); */ \ |
---|
369 | } \ |
---|
370 | } |
---|
371 | |
---|
372 | copy1c_type_matrix(int8_t); |
---|
373 | copy1c_type_matrix(uint8_t); |
---|
374 | copy1c_type_matrix(int16_t); |
---|
375 | copy1c_type_matrix(uint16_t); |
---|
376 | copy1c_type_matrix(int32_t); |
---|
377 | copy1c_type_matrix(uint32_t); |
---|
378 | copy1c_type_matrix(int64_t); |
---|
379 | copy1c_type_matrix(uint64_t); |
---|
380 | copy1c_type_matrix(float); |
---|
381 | copy1c_type_matrix(double); |
---|
382 | copy1c_type_matrix(rgb8); |
---|
383 | copy1c_type_matrix(rgbx8); |
---|
384 | |
---|
385 | |
---|
386 | #undef copy1r_type_matrix |
---|
387 | #define copy1r_type_matrix(t) \ |
---|
388 | void short_name(t,copy1r_,matrix)(t ** X, int32_t nr, t ** Y, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
389 | { \ |
---|
390 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
391 | short_name(t,dup_,vector)(X[nr], ncl, nch, Y[i]); \ |
---|
392 | } \ |
---|
393 | } |
---|
394 | |
---|
395 | copy1r_type_matrix(int8_t); |
---|
396 | copy1r_type_matrix(uint8_t); |
---|
397 | copy1r_type_matrix(int16_t); |
---|
398 | copy1r_type_matrix(uint16_t); |
---|
399 | copy1r_type_matrix(int32_t); |
---|
400 | copy1r_type_matrix(uint32_t); |
---|
401 | copy1r_type_matrix(int64_t); |
---|
402 | copy1r_type_matrix(uint64_t); |
---|
403 | copy1r_type_matrix(float); |
---|
404 | copy1r_type_matrix(double); |
---|
405 | copy1r_type_matrix(rgb8); |
---|
406 | copy1r_type_matrix(rgbx8); |
---|
407 | |
---|
408 | |
---|
409 | // Local Variables: |
---|
410 | // tab-width: 4 |
---|
411 | // c-basic-offset: 4 |
---|
412 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
413 | // indent-tabs-mode: nil |
---|
414 | // End: |
---|
415 | |
---|
416 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
417 | |
---|