source: soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem2x.c @ 827

Last change on this file since 827 was 826, checked in by meunier, 7 years ago
  • Mise à jour NR2 et Rosenfeld
File size: 15.4 KB
Line 
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) \
41void 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
49reset_endline_type_matrix(int8_t);
50reset_endline_type_matrix(uint8_t);
51reset_endline_type_matrix(int16_t);
52reset_endline_type_matrix(uint16_t);
53reset_endline_type_matrix(int32_t);
54reset_endline_type_matrix(uint32_t);
55reset_endline_type_matrix(int64_t);
56reset_endline_type_matrix(uint64_t);
57
58
59#undef endline_type_matrix
60#define endline_type_matrix(t) \
61void short_name(t,endline_,matrix)(t ** m, int32_t i, int32_t l) \
62{                        \
63    m[i + 1] = m[i] + l; \
64}                        \
65void 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}                            \
70void 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
76endline_type_matrix(int8_t);
77endline_type_matrix(uint8_t);
78endline_type_matrix(int16_t);
79endline_type_matrix(uint16_t);
80endline_type_matrix(int32_t);
81endline_type_matrix(uint32_t);
82endline_type_matrix(int64_t);
83endline_type_matrix(uint64_t);
84
85
86#undef resize_type_matrix
87#define resize_type_matrix(t) \
88void 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
96resize_type_matrix(si16Point);
97resize_type_matrix(ui16Point);
98resize_type_matrix(si32Point);
99resize_type_matrix(ui32Point);
100resize_type_matrix(f32Point);
101resize_type_matrix(si16Triplet);
102resize_type_matrix(ui16Triplet);
103resize_type_matrix(si32Triplet);
104resize_type_matrix(ui32Triplet);
105resize_type_matrix(f32Triplet);
106
107
108/*
109 * --------------
110 * matrix_reverse
111 * --------------
112 */
113
114#undef type_matrix_reverse
115#define type_matrix_reverse(t) \
116void 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
127type_matrix_reverse(int8_t);
128type_matrix_reverse(uint8_t);
129type_matrix_reverse(int16_t);
130type_matrix_reverse(uint16_t);
131type_matrix_reverse(int32_t);
132type_matrix_reverse(uint32_t);
133type_matrix_reverse(int64_t);
134type_matrix_reverse(uint64_t);
135type_matrix_reverse(float);
136type_matrix_reverse(double);
137
138
139#undef desinterlace_type_matrix
140#define desinterlace_type_matrix(t) \
141void 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
187desinterlace_type_matrix(int8_t);
188desinterlace_type_matrix(uint8_t);
189desinterlace_type_matrix(int16_t);
190desinterlace_type_matrix(uint16_t);
191desinterlace_type_matrix(int32_t);
192desinterlace_type_matrix(uint32_t);
193desinterlace_type_matrix(int64_t);
194desinterlace_type_matrix(uint64_t);
195desinterlace_type_matrix(float);
196desinterlace_type_matrix(double);
197desinterlace_type_matrix(rgb8);
198desinterlace_type_matrix(rgbx8);
199
200
201
202#undef interlace_type_matrix
203#define interlace_type_matrix(t) \
204void 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
223interlace_type_matrix(int8_t);
224interlace_type_matrix(uint8_t);
225interlace_type_matrix(int16_t);
226interlace_type_matrix(uint16_t);
227interlace_type_matrix(int32_t);
228interlace_type_matrix(uint32_t);
229interlace_type_matrix(int64_t);
230interlace_type_matrix(uint64_t);
231interlace_type_matrix(float);
232interlace_type_matrix(double);
233interlace_type_matrix(rgb8);
234interlace_type_matrix(rgbx8);
235
236
237#undef copyc_type_matrix
238#define copyc_type_matrix(t) \
239void 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
259copyc_type_matrix(int8_t);
260copyc_type_matrix(uint8_t);
261copyc_type_matrix(int16_t);
262copyc_type_matrix(uint16_t);
263copyc_type_matrix(int32_t);
264copyc_type_matrix(uint32_t);
265copyc_type_matrix(int64_t);
266copyc_type_matrix(uint64_t);
267copyc_type_matrix(float);
268copyc_type_matrix(double);
269
270
271#undef complete_border_type_matrix
272#define complete_border_type_matrix(t) \
273void 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
291complete_border_type_matrix(int8_t);
292complete_border_type_matrix(uint8_t);
293complete_border_type_matrix(int16_t);
294complete_border_type_matrix(uint16_t);
295complete_border_type_matrix(int32_t);
296complete_border_type_matrix(uint32_t);
297complete_border_type_matrix(int64_t);
298complete_border_type_matrix(uint64_t);
299complete_border_type_matrix(float);
300complete_border_type_matrix(double);
301complete_border_type_matrix(rgb8);
302complete_border_type_matrix(rgbx8);
303
304
305#undef complete_border1_type_matrix
306#define complete_border1_type_matrix(t) \
307void 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
319complete_border1_type_matrix(int8_t);
320complete_border1_type_matrix(uint8_t);
321complete_border1_type_matrix(int16_t);
322complete_border1_type_matrix(uint16_t);
323complete_border1_type_matrix(int32_t);
324complete_border1_type_matrix(uint32_t);
325complete_border1_type_matrix(int64_t);
326complete_border1_type_matrix(uint64_t);
327complete_border1_type_matrix(float);
328complete_border1_type_matrix(double);
329complete_border1_type_matrix(rgb8);
330complete_border1_type_matrix(rgbx8);
331
332
333#undef complete_border2_type_matrix
334#define complete_border2_type_matrix(t) \
335void 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
349complete_border2_type_matrix(int8_t);
350complete_border2_type_matrix(uint8_t);
351complete_border2_type_matrix(int16_t);
352complete_border2_type_matrix(uint16_t);
353complete_border2_type_matrix(int32_t);
354complete_border2_type_matrix(uint32_t);
355complete_border2_type_matrix(int64_t);
356complete_border2_type_matrix(uint64_t);
357complete_border2_type_matrix(float);
358complete_border2_type_matrix(double);
359complete_border2_type_matrix(rgb8);
360complete_border2_type_matrix(rgbx8);
361
362
363#undef copy1c_type_matrix
364#define copy1c_type_matrix(t) \
365void 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
372copy1c_type_matrix(int8_t);
373copy1c_type_matrix(uint8_t);
374copy1c_type_matrix(int16_t);
375copy1c_type_matrix(uint16_t);
376copy1c_type_matrix(int32_t);
377copy1c_type_matrix(uint32_t);
378copy1c_type_matrix(int64_t);
379copy1c_type_matrix(uint64_t);
380copy1c_type_matrix(float);
381copy1c_type_matrix(double);
382copy1c_type_matrix(rgb8);
383copy1c_type_matrix(rgbx8);
384
385
386#undef copy1r_type_matrix
387#define copy1r_type_matrix(t) \
388void 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
395copy1r_type_matrix(int8_t);
396copy1r_type_matrix(uint8_t);
397copy1r_type_matrix(int16_t);
398copy1r_type_matrix(uint16_t);
399copy1r_type_matrix(int32_t);
400copy1r_type_matrix(uint32_t);
401copy1r_type_matrix(int64_t);
402copy1r_type_matrix(uint64_t);
403copy1r_type_matrix(float);
404copy1r_type_matrix(double);
405copy1r_type_matrix(rgb8);
406copy1r_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
Note: See TracBrowser for help on using the repository browser.