source: soft/giet_vm/applications/rosenfeld/nrc2/src/nrset1.c @ 826

Last change on this file since 826 was 826, checked in by meunier, 7 years ago
  • Mise à jour NR2 et Rosenfeld
File size: 5.7 KB
Line 
1/* ---------------- */
2/* --- nrset1.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
18#include <stdio.h>
19#include <stddef.h>
20#include <stdlib.h>
21
22#include "mypredef.h"
23#include "nrtype.h"
24#include "nrdef.h"
25#include "nrmacro.h"
26#include "nrkernel.h"
27
28#include "nrset1.h"
29
30#define isdigit(x) ((x) >= 0x30 && (x) <= 0x39)
31
32/*
33 * -------------------
34 * --- zero_vector ---
35 * -------------------
36 */
37
38
39#undef zero_type_vector
40#define zero_type_vector(t) \
41void short_name(t,zero_,vector)(t * v, int32_t nl, int32_t nh) \
42{                                        \
43    for (int32_t i = nl; i <= nh; i++) { \
44        v[i] = 0;                        \
45    }                                    \
46}
47
48zero_type_vector(int8_t);
49zero_type_vector(uint8_t);
50zero_type_vector(int16_t);
51zero_type_vector(uint16_t);
52zero_type_vector(int32_t);
53zero_type_vector(uint32_t);
54zero_type_vector(int64_t);
55zero_type_vector(uint64_t);
56zero_type_vector(float);
57zero_type_vector(double);
58
59
60void zero_rgb8vector(rgb8 * v, int32_t nl, int32_t nh)
61{
62    rgb8 z = {0, 0, 0};
63    for (int32_t i = nl; i <= nh; i++) {
64        v[i] = z;
65    }
66}
67
68void zero_rgbx8vector(rgbx8 * v, int32_t nl, int32_t nh)
69{
70    rgbx8 z;
71    z.r = 0;
72    z.g = 0;
73    z.b = 0;
74    z.x = 0;
75    for (int32_t i = nl; i <= nh; i++) {
76        v[i] = z;
77    }
78}
79
80
81/*
82 * ------------------
83 * --- set_vector ---
84 * ------------------
85 */
86
87
88#undef set_type_vector
89#define set_type_vector(t) \
90void short_name(t,set_,vector)(t * v, int32_t nl, int32_t nh, t x) \
91{                                        \
92    for (int32_t i = nl; i <= nh; i++) { \
93        v[i] = x;                        \
94    }                                    \
95}
96
97set_type_vector(int8_t);
98set_type_vector(uint8_t);
99set_type_vector(int16_t);
100set_type_vector(uint16_t);
101set_type_vector(int32_t);
102set_type_vector(uint32_t);
103set_type_vector(int64_t);
104set_type_vector(uint64_t);
105set_type_vector(float);
106set_type_vector(double);
107set_type_vector(rgb8);
108set_type_vector(rgbx8);
109
110
111
112/*
113 * ------------------------
114 * --- set_vector_param ---
115 * ------------------------
116 */
117
118
119#undef set_type_vector_param
120#define set_type_vector_param(t) \
121void short_name(t,set_,vector_param)(t * v, int32_t nl, int32_t nh, t x, t xstep) \
122{                                        \
123    for (int32_t i = nl; i <= nh; i++) { \
124        v[i] = x;                        \
125        x += xstep;                      \
126    }                                    \
127}
128
129set_type_vector_param(int8_t);
130set_type_vector_param(uint8_t);
131set_type_vector_param(int16_t);
132set_type_vector_param(uint16_t);
133set_type_vector_param(int32_t);
134set_type_vector_param(uint32_t);
135set_type_vector_param(int64_t);
136set_type_vector_param(uint64_t);
137set_type_vector_param(float);
138set_type_vector_param(double);
139
140
141
142void set_rgb8vector_param(rgb8 * v, int32_t nl, int32_t nh, rgb8 x, rgb8 xstep)
143{
144    for (int32_t i = nl; i <= nh; i++) {
145        v[i] = x;
146        RGB8_ADD(x, xstep, x);
147    }
148}
149
150void set_rgbx8vector_param(rgbx8 * v, int32_t nl, int32_t nh, rgbx8 x, rgbx8 xstep)
151{
152    for (int32_t i = nl; i <= nh; i++) {
153        v[i] = x;
154        RGBX8_ADD(x, xstep, x);
155    }
156}
157
158
159/*
160 * --------------------
161 * --- set_vector_j ---
162 * --------------------
163 */
164
165#undef set_type_vector_j
166#define set_type_vector_j(t) \
167void short_name(t,set_,vector_j)(t * v, int32_t nl, int32_t nh) \
168{                                                               \
169    for (int32_t i = nl; i <= nh; i++) {                        \
170        v[i] = (t) i;                                           \
171    }                                                           \
172}
173
174set_type_vector_j(int8_t);
175set_type_vector_j(uint8_t);
176set_type_vector_j(int16_t);
177set_type_vector_j(uint16_t);
178set_type_vector_j(int32_t);
179set_type_vector_j(uint32_t);
180set_type_vector_j(int64_t);
181set_type_vector_j(uint64_t);
182set_type_vector_j(float);
183set_type_vector_j(double);
184
185
186void set_rgb8vector_j(rgb8 * v, int32_t nl, int32_t nh)
187{
188    for (int32_t i = nl; i <= nh; i++) {
189        v[i].r = (uint8) i;
190        v[i].g = (uint8) i;
191        v[i].b = (uint8) i;
192    }
193}
194
195
196void set_rgbx8vector_j(rgbx8 * v, int32_t nl, int32_t nh)
197{
198    for (int32_t i = nl; i <= nh; i++) {
199        v[i].r = (uint8) i;
200        v[i].g = (uint8) i;
201        v[i].b = (uint8) i;
202        v[i].x = (uint8) 255;
203    }
204}
205
206
207/*
208 * ----------------------
209 * --- set_vector_str ---
210 * ----------------------
211 */
212
213
214#undef set_type_vector_str
215#define set_type_vector_str(t) \
216void short_name(t,set_,vector_str)(t * v, int32_t nl, int32_t nh, char * str) \
217{                                        \
218    char c[2];                           \
219    c[1] = '\0';                         \
220    for (int32_t i = nl; i <= nh; i++) { \
221        c[0] = *str++;                   \
222        if (isdigit(c[0])) {             \
223            v[i] = (t) atoi(c);          \
224        }                                \
225        else {                           \
226            v[i] = (t) 0;                \
227        }                                \
228    }                                    \
229}
230
231set_type_vector_str(int8_t);
232set_type_vector_str(uint8_t);
233set_type_vector_str(int16_t);
234set_type_vector_str(uint16_t);
235set_type_vector_str(int32_t);
236set_type_vector_str(uint32_t);
237set_type_vector_str(int64_t);
238set_type_vector_str(uint64_t);
239
240
241// Local Variables:
242// tab-width: 4
243// c-basic-offset: 4
244// c-file-offsets:((innamespace . 0)(inline-open . 0))
245// indent-tabs-mode: nil
246// End:
247
248// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
249
Note: See TracBrowser for help on using the repository browser.