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

Last change on this file since 805 was 805, checked in by meunier, 8 years ago
  • Adding the parallel version of rosenfeld
File size: 16.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#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 "nrset1.h"
29
30#define isdigit(x) ((x) >= 0x30 && (x) <= 0x39)
31
32/*
33 * -------------------
34 * --- zero_vector ---
35 * -------------------
36 */
37
38/* ------------------------------------------------------- */
39IMAGE_EXPORT(void) zero_si8vector(sint8 *v, long nl, long nh)
40/* ------------------------------------------------------- */
41{
42        int i;
43        for(i=nl; i<=nh; i++) v[i] = 0;
44}
45/* ------------------------------------------------------- */
46IMAGE_EXPORT(void) zero_ui8vector(uint8 *v, long nl, long nh)
47/* ------------------------------------------------------- */
48{
49        int i;
50        for(i=nl; i<=nh; i++) v[i] = 0;
51}
52/* --------------------------------------------------------- */
53IMAGE_EXPORT(void) zero_si16vector(sint16 *v, long nl, long nh)
54/* --------------------------------------------------------- */
55{
56    int i;
57    for(i=nl; i<=nh; i++) v[i] = 0;
58}
59/* --------------------------------------------------------- */
60IMAGE_EXPORT(void) zero_ui16vector(uint16 *v, long nl, long nh)
61/* --------------------------------------------------------- */
62{
63        int i;
64        for(i=nl; i<=nh; i++) v[i] = 0;
65}
66/* --------------------------------------------------------- */
67IMAGE_EXPORT(void) zero_si32vector(sint32 *v, long nl, long nh)
68/* --------------------------------------------------------- */
69{
70    int i;
71    for(i=nl; i<=nh; i++) v[i] = 0;
72}
73/* --------------------------------------------------------- */
74IMAGE_EXPORT(void) zero_ui32vector(uint32 *v, long nl, long nh)
75/* --------------------------------------------------------- */
76{
77    int i;
78    for(i=nl; i<=nh; i++) v[i] = 0;
79}
80/* --------------------------------------------------------- */
81IMAGE_EXPORT(void) zero_si64vector(sint64 *v, long nl, long nh)
82/* --------------------------------------------------------- */
83{
84    int i;
85    for(i=nl; i<=nh; i++) v[i] = 0;
86}
87/* --------------------------------------------------------- */
88IMAGE_EXPORT(void) zero_ui64vector(uint64 *v, long nl, long nh)
89/* --------------------------------------------------------- */
90{
91    int i;
92    for(i=nl; i<=nh; i++) v[i] = 0;
93}
94/* --------------------------------------------------------- */
95IMAGE_EXPORT(void) zero_f32vector(float32 *v, long nl, long nh)
96/* --------------------------------------------------------- */
97{
98        int i;
99        for(i=nl; i<=nh; i++) v[i] = 0;
100}
101/* --------------------------------------------------------- */
102IMAGE_EXPORT(void) zero_f64vector(float64 *v, long nl, long nh)
103/* --------------------------------------------------------- */
104{
105        int i;
106        for(i=nl; i<=nh; i++) v[i] = 0;
107}
108/* ------------------------------------------------------- */
109IMAGE_EXPORT(void) zero_rgb8vector(rgb8 *v, long nl, long nh)
110/* ------------------------------------------------------- */
111{
112        int i;
113        rgb8 z;
114        z.r = 0; z.g = 0; z.b = 0;
115        for(i=nl; i<=nh; i++) v[i] = z;
116}
117/* --------------------------------------------------------- */
118IMAGE_EXPORT(void) zero_rgbx8vector(rgbx8 *v, long nl, long nh)
119/* --------------------------------------------------------- */
120{
121        int i;
122        rgbx8 z;
123        z.r = 0; z.g = 0; z.b = 0; z.x = 0;
124    for(i=nl; i<=nh; i++) v[i] = z;
125}
126/*
127 * ------------------
128 * --- set_vector ---
129 * ------------------
130 */
131
132/* -------------------------------------------------------------- */
133IMAGE_EXPORT(void) set_si8vector(sint8 *v, long nl, long nh, sint8 x)
134/* -------------------------------------------------------------- */
135{
136    int i;   
137    for(i=nl; i<=nh; i++)
138        v[i] = x;
139}
140/* --------------------------------------------------------------- */
141IMAGE_EXPORT(void) set_ui8vector(uint8 *v, long nl, long nh, uint8 x)
142/* --------------------------------------------------------------- */
143{
144    int i;
145    for(i=nl; i<=nh; i++)
146        v[i] = x;
147}
148/* ------------------------------------------------------------------ */
149IMAGE_EXPORT(void) set_si16vector(sint16 *v, long nl, long nh, sint16 x)
150/* ------------------------------------------------------------------ */
151{
152        int i; 
153        for(i=nl; i<=nh; i++)
154                v[i] = x;
155}
156/* ------------------------------------------------------------------ */
157IMAGE_EXPORT(void) set_ui16vector(uint16 *v, long nl, long nh, uint16 x)
158/* ------------------------------------------------------------------ */
159{
160        int i; 
161        for(i=nl; i<=nh; i++)
162                v[i] = x;
163}
164/* ------------------------------------------------------------------ */
165IMAGE_EXPORT(void) set_si32vector(sint32 *v, long nl, long nh, sint32 x)
166/* ------------------------------------------------------------------ */
167{
168        int i; 
169        for(i=nl; i<=nh; i++)
170                v[i] = x;
171}
172/* ------------------------------------------------------------------ */
173IMAGE_EXPORT(void) set_ui32vector(uint32 *v, long nl, long nh, uint32 x)
174/* ------------------------------------------------------------------ */
175{
176        int i;
177        for(i=nl; i<=nh; i++)
178                v[i] = x;
179}
180/* ----------------------------------------------------------------- */
181IMAGE_EXPORT(void) set_si64vector(sint64 *v, long nl, long nh, sint64 x)
182/* ----------------------------------------------------------------- */
183{
184        int i; 
185        for(i=nl; i<=nh; i++)
186                v[i] = x;
187}
188/* ------------------------------------------------------------------ */
189IMAGE_EXPORT(void) set_ui64vector(uint64 *v, long nl, long nh, uint64 x)
190/* ------------------------------------------------------------------ */
191{
192        int i;
193        for(i=nl; i<=nh; i++)
194                v[i] = x;
195}
196/* ------------------------------------------------------------------- */
197IMAGE_EXPORT(void) set_f32vector(float32 *v, long nl, long nh, float32 x)
198/* ------------------------------------------------------------------- */
199{
200        int i; 
201        for(i=nl; i<=nh; i++)
202                v[i] = x;
203}
204/* ------------------------------------------------------------------- */
205IMAGE_EXPORT(void) set_f64vector(float64 *v, long nl, long nh, float64 x)
206/* ------------------------------------------------------------------- */
207{
208        int i; 
209        for(i=nl; i<=nh; i++)
210                v[i] = x;
211}
212/* -------------------------------------------------------------- */
213IMAGE_EXPORT(void) set_rgb8vector(rgb8 *v, long nl, long nh, rgb8 x)
214/* -------------------------------------------------------------- */
215{
216        int i;
217       
218        for(i=nl; i<=nh; i++)
219                v[i] = x;
220}
221/* ----------------------------------------------------------------- */
222IMAGE_EXPORT(void) set_rgbx8vector(rgbx8 *v, long nl, long nh, rgbx8 x)
223/* ----------------------------------------------------------------- */
224{
225        int i;
226       
227        for(i=nl; i<=nh; i++)
228                v[i] = x;
229}
230/*
231 * ------------------------
232 * --- set_vector_param ---
233 * ------------------------
234 */
235/* ---------------------------------------------------------------------------- */
236IMAGE_EXPORT(void) set_si8vector_param(sint8 *v, long nl, long nh, sint8 x, sint8 xstep)
237/* ---------------------------------------------------------------------------- */
238{
239    int i;   
240    for(i=nl; i<=nh; i++) {
241        v[i] = x;
242        x += xstep;
243    }
244}
245/* ---------------------------------------------------------------------------- */
246IMAGE_EXPORT(void) set_ui8vector_param(uint8 *v, long nl, long nh, uint8 x, uint8 xstep)
247/* ---------------------------------------------------------------------------- */
248{
249    int i;   
250    for(i=nl; i<=nh; i++) {
251        v[i] = x;
252        x += xstep;
253    }
254}
255/* -------------------------------------------------------------------------------- */
256IMAGE_EXPORT(void) set_si16vector_param(sint16 *v, long nl, long nh, sint16 x, sint16 xstep)
257/* -------------------------------------------------------------------------------- */
258{
259    int i;   
260    for(i=nl; i<=nh; i++) {
261        v[i] = x;
262        x += xstep;
263    }
264}
265/* -------------------------------------------------------------------------------- */
266IMAGE_EXPORT(void) set_ui16vector_param(uint16 *v, long nl, long nh, uint16 x, uint16 xstep)
267/* -------------------------------------------------------------------------------- */
268{
269    int i;   
270    for(i=nl; i<=nh; i++) {
271        v[i] = x;
272        x += xstep;
273    }
274}
275/* -------------------------------------------------------------------------------- */
276IMAGE_EXPORT(void) set_si32vector_param(sint32 *v, long nl, long nh, sint32 x, sint32 xstep)
277/* -------------------------------------------------------------------------------- */
278{
279    int i;   
280    for(i=nl; i<=nh; i++) {
281        v[i] = x;
282        x += xstep;
283    }
284}
285/* -------------------------------------------------------------------------------- */
286IMAGE_EXPORT(void) set_ui32vector_param(uint32 *v, long nl, long nh, uint32 x, uint32 xstep)
287/* -------------------------------------------------------------------------------- */
288{
289    int i;   
290    for(i=nl; i<=nh; i++) {
291        v[i] = x;
292        x += xstep;
293    }
294}
295/* -------------------------------------------------------------------------------- */
296IMAGE_EXPORT(void) set_si64vector_param(sint64 *v, long nl, long nh, sint64 x, sint64 xstep)
297/* -------------------------------------------------------------------------------- */
298{
299    int i;   
300    for(i=nl; i<=nh; i++) {
301        v[i] = x;
302        x += xstep;
303    }
304}
305/* -------------------------------------------------------------------------------- */
306IMAGE_EXPORT(void) set_ui64vector_param(uint64 *v, long nl, long nh, uint64 x, uint64 xstep)
307/* -------------------------------------------------------------------------------- */
308{
309    int i;   
310    for(i=nl; i<=nh; i++) {
311        v[i] = x;
312        x += xstep;
313    }
314}
315/* --------------------------------------------------------------------------------- */
316IMAGE_EXPORT(void) set_f32vector_param(float32 *v, long nl, long nh, float32 x, float32 xstep)
317/* ---------------------------------------------------------------------------------- */
318{
319    int i;   
320    for(i=nl; i<=nh; i++) {
321        v[i] = x;
322        x += xstep;
323    }
324}/* --------------------------------------------------------------------------------- */
325IMAGE_EXPORT(void) set_f64vector_param(float64 *v, long nl, long nh, float64 x, float64 xstep)
326/* --------------------------------------------------------------------------------- */
327{
328    int i;   
329    for(i=nl; i<=nh; i++) {
330        v[i] = x;
331        x += xstep;
332    }
333}/* ------------------------------------------------------------------------- */
334IMAGE_EXPORT(void) set_rgb8vector_param(rgb8 *v, long nl, long nh, rgb8 x, rgb8 xstep)
335/* ------------------------------------------------------------------------- */
336{
337    int i;   
338    for(i=nl; i<=nh; i++) {
339        v[i] = x;
340        RGB8_ADD(x, xstep, x);
341    }
342}/* ----------------------------------------------------------------------------- */
343IMAGE_EXPORT(void) set_rgbx8vector_param(rgbx8 *v, long nl, long nh, rgbx8 x, rgbx8 xstep)
344/* ------------------------------------------------------------------------------ */
345{
346        int i;
347       
348    for(i=nl; i<=nh; i++) {
349                v[i] = x;
350        RGB8_ADD(x, xstep, x);
351    }
352}
353/*
354 * --------------------
355 * --- set_vector_j ---
356 * --------------------
357 */
358/* -------------------------------------------------------- */
359IMAGE_EXPORT(void) set_si8vector_j(sint8 *v, long nl, long nh)
360/* -------------------------------------------------------- */
361{
362        int i;
363       
364        for(i=nl; i<=nh; i++)
365                v[i] = (sint8) i;
366}
367/* -------------------------------------------------------- */
368IMAGE_EXPORT(void) set_ui8vector_j(uint8 *v, long nl, long nh)
369/* -------------------------------------------------------- */
370{
371        int i;
372       
373        for(i=nl; i<=nh; i++)
374                v[i] = (uint8) i;
375}
376/* ---------------------------------------------------------- */
377IMAGE_EXPORT(void) set_si16vector_j(sint16 *v, long nl, long nh)
378/* ---------------------------------------------------------- */
379{
380        int i;
381       
382        for(i=nl; i<=nh; i++)
383                v[i] = (sint16) i;
384}
385/* ---------------------------------------------------------- */
386IMAGE_EXPORT(void) set_ui16vector_j(uint16 *v, long nl, long nh)
387/* ---------------------------------------------------------- */
388{
389        int i;
390       
391        for(i=nl; i<=nh; i++)
392                v[i] = (uint16) i;
393}
394/* ---------------------------------------------------------- */
395IMAGE_EXPORT(void) set_si32vector_j(sint32 *v, long nl, long nh)
396/* ---------------------------------------------------------- */
397{
398        int i;
399       
400        for(i=nl; i<=nh; i++)
401                v[i] = (sint32) i;
402}
403/* ---------------------------------------------------------- */
404IMAGE_EXPORT(void) set_ui32vector_j(uint32 *v, long nl, long nh)
405/* ---------------------------------------------------------- */
406{
407        int i;
408       
409        for(i=nl; i<=nh; i++)
410                v[i] = (uint32) i;
411}
412/* ---------------------------------------------------------- */
413IMAGE_EXPORT(void) set_si64vector_j(sint64 *v, long nl, long nh)
414/* ---------------------------------------------------------- */
415{
416        int i;
417       
418        for(i=nl; i<=nh; i++)
419                v[i] = (sint64) i;
420}
421/* ---------------------------------------------------------- */
422IMAGE_EXPORT(void) set_ui64vector_j(uint64 *v, long nl, long nh)
423/* ---------------------------------------------------------- */
424{
425        int i;
426       
427        for(i=nl; i<=nh; i++)
428                v[i] = (uint64) i;
429}
430/* ---------------------------------------------------------- */
431IMAGE_EXPORT(void) set_f32vector_j(float32 *v, long nl, long nh)
432/* ---------------------------------------------------------- */
433{
434        int i;
435       
436        for(i=nl; i<=nh; i++)
437                v[i] = (float32) i;
438}
439/* ---------------------------------------------------------- */
440IMAGE_EXPORT(void) set_f64vector_j(float64 *v, long nl, long nh)
441/* ---------------------------------------------------------- */
442{
443        int i;
444       
445        for(i=nl; i<=nh; i++)
446                v[i] = (float64) i;
447}
448/* -------------------------------------------------------- */
449IMAGE_EXPORT(void) set_rgb8vector_j(rgb8 *v, long nl, long nh)
450/* -------------------------------------------------------- */
451{
452        int i;
453       
454    for(i=nl; i<=nh; i++) {
455                v[i].r = (uint8) i;
456        v[i].g = (uint8) i;
457        v[i].b = (uint8) i;
458    }
459}
460/* ---------------------------------------------------------- */
461IMAGE_EXPORT(void) set_rgbx8vector_j(rgbx8 *v, long nl, long nh)
462/* ---------------------------------------------------------- */
463{
464        int i;
465       
466    for(i=nl; i<=nh; i++) {
467                v[i].r = (uint8) i;
468        v[i].g = (uint8) i;
469        v[i].b = (uint8) i;
470        v[i].x = (uint8) 255;
471    }
472}
473
474/*
475 * ----------------------
476 * --- set_vector_str ---
477 * ----------------------
478 */
479
480/* --------------------------------------------------------------------- */
481IMAGE_EXPORT(void) set_si8vector_str(sint8 *v, long nl, long nh, char *str)
482/* --------------------------------------------------------------------- */
483{
484        int i;
485        char c[1];
486        for(i=nl; i<=nh; i++) {
487
488                *c = *str++;
489                if(isdigit(*c))
490                        v[i] = (sint8) atoi(c);
491                else
492                        v[i] = (sint8) 0;
493        }
494}
495/* --------------------------------------------------------------------- */
496IMAGE_EXPORT(void) set_ui8vector_str(uint8 *v, long nl, long nh, char *str)
497/* --------------------------------------------------------------------- */
498{
499    // @QM
500        int i;
501        char c[2];
502    c[1] = '\0';
503        for (i = nl; i <= nh; i++) {
504                c[0] = *str++;
505                if (isdigit(c[0])) {
506                        v[i] = (uint8) atoi(c);
507        }
508                else {
509                        v[i] = (uint8) 0;
510        }
511        }
512}
513/* ----------------------------------------------------------------------- */
514IMAGE_EXPORT(void) set_si16vector_str(sint16 *v, long nl, long nh, char *str)
515/* ----------------------------------------------------------------------- */
516{
517    int i;
518    char c[1];
519    for(i=nl; i<=nh; i++) {
520       
521        *c = *str++;
522        if(isdigit(*c))
523            v[i] = (sint16) atoi(c);
524        else
525            v[i] = (sint16) 0;
526    }
527}
528/* ----------------------------------------------------------------------- */
529IMAGE_EXPORT(void) set_ui16vector_str(uint16 *v, long nl, long nh, char *str)
530/* ----------------------------------------------------------------------- */
531{
532    int i;
533    char c[1];
534    for(i=nl; i<=nh; i++) {
535       
536        *c = *str++;
537        if(isdigit(*c))
538            v[i] = (uint16) atoi(c);
539        else
540            v[i] = (uint16) 0;
541    }
542}
543/* ----------------------------------------------------------------------- */
544IMAGE_EXPORT(void) set_si32vector_str(sint32 *v, long nl, long nh, char *str)
545/* ----------------------------------------------------------------------- */
546{
547    int i;
548    char c[1];
549    for(i=nl; i<=nh; i++) {
550       
551        *c = *str++;
552        if(isdigit(*c))
553            v[i] = (sint32) atoi(c);
554        else
555            v[i] = (sint32) 0;
556    }
557}
558/* ----------------------------------------------------------------------- */
559IMAGE_EXPORT(void) set_ui32vector_str(uint32 *v, long nl, long nh, char *str)
560/* ----------------------------------------------------------------------- */
561{
562    int i;
563    char c[1];
564    for(i=nl; i<=nh; i++) {
565       
566        *c = *str++;
567        if(isdigit(*c))
568            v[i] = (uint32) atoi(c);
569        else
570            v[i] = (uint32) 0;
571    }
572}
Note: See TracBrowser for help on using the repository browser.