source: soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c @ 823

Last change on this file since 823 was 821, checked in by meunier, 9 years ago
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File size: 11.9 KB
Line 
1/* ----------------- */
2/* --- nrmem1x.c --- */
3/* ----------------- */
4
5/*
6* Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7* Univ Paris Sud XI, CNRS
8*/
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <stddef.h>
13#include <string.h>
14
15#include "mypredef.h"
16#include "nrtype.h"
17#include "nrdef.h"
18#include "nrmacro.h"
19#include "nrkernel.h"
20
21#include "nrmem1x.h"
22/* --------------------------------------- */
23IMAGE_EXPORT(void) roll_si16vector(sint16 *v, long nl, long nh)
24/* --------------------------------------- */
25/*
26* left rotate a uint16 vector with subscript range v[nl..nh]
27* nl & nh can be, respectively bigger and smaller than the
28* values used to allocate the vector (svector)
29* no check on nl and nh is done
30*/
31{
32        long i;
33        sint16 tmp;
34       
35        tmp = v[nl];
36        for(i=nl; i<nh; i++) {
37                v[i] = v[i+1];
38        }
39        v[nh] = tmp;
40}
41/* ----------------------------------------- */
42IMAGE_EXPORT(void) roll_ui16vector(uint16 *v, long nl, long nh)
43/* ----------------------------------------- */
44/*
45* left rotate a uint16 vector with subscript range v[nl..nh]
46* nl & nh can be, respectively bigger and smaller than the
47* values used to allocate the vector (svector)
48* no check on nl and nh is done
49*/
50{
51        long i;
52        uint16 tmp;
53       
54        tmp = v[nl];
55        for(i=nl; i<nh; i++) {
56                v[i] = v[i+1];
57        }
58        v[nh] = tmp;
59}
60/*
61 * -------------------
62 * --- copy_vector ---
63 * -------------------
64 */
65
66/* --------------------------------------------------------------------------------------- */
67IMAGE_EXPORT(void) copy_bvector(uint8 *src, long nl1, long nh1, uint8 *dst, long nl2, long nh2)
68/* --------------------------------------------------------------------------------------- */
69{
70    long len = nh1 - nl1 + 1;
71    memcpy(dst + nl2, src + nl1, len);
72}
73/* ----------------------------------------------------------------------------------------- */
74IMAGE_EXPORT(void) copy_svector(uint16 *src, long nl1, long nh1, uint16 *dst, long nl2, long nh2)
75/* ----------------------------------------------------------------------------------------- */
76{
77    long len = nh1 - nl1 + 1;
78    static long size = sizeof(uint16);
79    memcpy(dst + nl2, src + nl1, len*size);
80}
81// ------------------------------------------------------------------------------------------------
82IMAGE_EXPORT(void) copy_si16vector(sint16 *src, long nl1, long nh1, int16 *dst, long nl2, long nh2)
83// ------------------------------------------------------------------------------------------------
84{
85    long len = nh1 - nl1 + 1;
86    memcpy(dst + nl2, src + nl1, 2*len);
87}
88// ------------------------------------------------------------------------------------------------
89IMAGE_EXPORT(void) copy_ui16vector(uint16 *src, long nl1, long nh1, uint16 *dst, long nl2, long nh2)
90// ------------------------------------------------------------------------------------------------
91{
92    long len = nh1 - nl1 + 1;
93    memcpy(dst + nl2, src + nl1, 2*len);
94}
95/* ------------------------------------------------------------------------------------- */
96IMAGE_EXPORT(void) copy_si32vector(sint32 *src, long nl1, long nh1, sint32 *dst, long nl2, long nh2)
97/* ------------------------------------------------------------------------------------- */
98{
99    long len = nh1 - nl1 + 1;
100    static long size = sizeof(sint32);
101    memcpy(dst + nl2, src + nl1, len*size);
102}
103/* ---------------------------------------------------------------------------------------- */
104IMAGE_EXPORT(void) copy_ui32vector(uint32 *src, long nl1, long nh1, uint32 *dst, long nl2, long nh2)
105/* ---------------------------------------------------------------------------------------- */
106{
107    long len = nh1 - nl1 + 1;
108    static long size = sizeof(uint32);
109    memcpy(dst + nl2, src + nl1, len*size);
110}
111/* ---------------------------------------------------------------------------------------- */
112IMAGE_EXPORT(void) copy_f32vector(float32 *src, long nl1, long nh1, float32 *dst, long nl2, long nh2)
113/* ---------------------------------------------------------------------------------------- */
114{
115    long len = nh1 - nl1 + 1;
116    static long size = sizeof(float32);
117    memcpy(dst + nl2, src + nl1, len*size);
118}
119/* ------------------------------------------------------------------------------------------- */
120IMAGE_EXPORT(void) copy_f64vector(float64 *src, long nl1, long nh1, float64 *dst, long nl2, long nh2)
121/* ------------------------------------------------------------------------------------------- */
122{
123    long len = nh1 - nl1 + 1;
124    static long size = sizeof(float64);
125    memcpy(dst + nl2, src + nl1, len*size);
126}
127/* ------------------------------------------------------------------------------------------ */
128IMAGE_EXPORT(void) copy_rgb8vector(rgb8 *src, long nl1, long nh1, rgb8 *dst, long nl2, long nh2)
129/* ------------------------------------------------------------------------------------------ */
130{
131    long len = nh1 - nl1 + 1;
132    static long size = sizeof(rgb8);
133    memcpy(dst + nl2, src + nl1, len*size);
134}
135/* --------------------------------------------------------------------------------------------- */
136IMAGE_EXPORT(void) copy_rgbx8vector(rgbx8 *src, long nl1, long nh1, rgbx8 *dst, long nl2, long nh2)
137/* --------------------------------------------------------------------------------------------- */
138{
139    long len = nh1 - nl1 + 1;
140    static long size = sizeof(rgbx8);
141    memcpy(dst + nl2, src + nl1, len*size);
142}
143/* ---------------------------------------------------------------------------- */
144IMAGE_EXPORT(void) copy1c_bvector(uint8 *src, long nc, uint8 *dst, long nl, long nh)
145/* ---------------------------------------------------------------------------- */
146{
147    int j;
148    uint8 c = src[nc];
149    for(j=nl; j<=nh; j++) dst[j] = c;
150}
151/* ----------------------------------------------------------------------------------- */
152IMAGE_EXPORT(void) copy1c_ui16vector(uint16 *src, long nc, uint16 *dst, long nl, long nh)
153/* ----------------------------------------------------------------------------------- */
154{
155    int j;
156    uint16 c = src[nc];
157    for(j=nl; j<=nh; j++) dst[j] = c;
158}
159/* ---------------------------------------------------------------------------------- */
160IMAGE_EXPORT(void) copy1c_si16vector(sint16 *src, long nc, sint16 *dst, long nl, long nh)
161/* ---------------------------------------------------------------------------------- */
162{
163    int j;
164    sint16 c = src[nc];
165    for(j=nl; j<=nh; j++) dst[j] = c;
166}
167/* -------------------------------------------------------------------------- */
168IMAGE_EXPORT(void) copy1c_ui32vector(uint32 *src, long nc, uint32 *dst, long nl, long nh)
169/* -------------------------------------------------------------------------- */
170{
171    int j;
172    int c = src[nc];
173    for(j=nl; j<=nh; j++) dst[j] = c;
174}
175/* ----------------------------------------------------------------------------- */
176IMAGE_EXPORT(void) copy1c_si32vector(sint32 *src, long nc, sint32 *dst, long nl, long nh)
177/* ----------------------------------------------------------------------------- */
178{
179    int j;
180    int c = src[nc];
181    for(j=nl; j<=nh; j++) dst[j] = c;
182}
183/* ----------------------------------------------------------------------------- */
184IMAGE_EXPORT(void) copy1c_f32vector(float32 *src, long nc, float32 *dst, long nl, long nh)
185/* ----------------------------------------------------------------------------- */
186{
187    int j;
188    float c = src[nc];
189    for(j=nl; j<=nh; j++) dst[j] = c;
190}
191/* -------------------------------------------------------------------------------- */
192IMAGE_EXPORT(void) copy1c_f64vector(float64 *src, long nc, float64 *dst, long nl, long nh)
193/* -------------------------------------------------------------------------------- */
194{
195    int j;
196    float64 c = src[nc];
197    for(j=nl; j<=nh; j++) dst[j] = c;
198}
199/* ------------------------------------------------------------------------------- */
200IMAGE_EXPORT(void) copy1c_rgb8vector(rgb8 *src, long nc, rgb8 *dst, long nl, long nh)
201/* ------------------------------------------------------------------------------- */
202{
203    int j;
204    rgb8 c = src[nc];
205    for(j=nl; j<=nh; j++) dst[j] = c;
206}
207/* ---------------------------------------------------------------------------------- */
208IMAGE_EXPORT(void) copy1c_rgbx8vector(rgbx8 *src, long nc, rgbx8 *dst, long nl, long nh)
209/* ---------------------------------------------------------------------------------- */
210{
211    int j;
212    rgbx8 c = src[nc];
213    for(j=nl; j<=nh; j++) dst[j] = c;
214}
215/* ----------------------------------------------------------------------------- */
216IMAGE_EXPORT(void) copy_bvector_mod(uint8 *src, long nl, long nh, long m, uint8 *dst)
217/* ----------------------------------------------------------------------------- */
218{
219    long len;
220    long len1, len2;
221   
222    if(nh>nl) {
223        len = nh - nl + 1; memcpy(dst, src + nl, len);
224    } else {
225        len1 = m - nl; memcpy(dst,      src + nl, len1);
226        len2 = nh + 1; memcpy(dst+len1, src + nh, len2);
227    }
228}
229/* ------------------------------------------------------------------------------- */
230IMAGE_EXPORT(void) copy_si16vector_mod(sint16 *src, long nl, long nh, long m, sint16 *dst)
231/* ------------------------------------------------------------------------------- */
232{
233    long len;
234    long len1, len2;
235   
236    if(nh>nl) {
237        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(uint16));
238    } else {
239        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(uint16));
240        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(uint16));
241    }
242}
243/* --------------------------------------------------------------------------------- */
244IMAGE_EXPORT(void) copy_ui16vector_mod(uint16 *src, long nl, long nh, long m, uint16 *dst)
245/* --------------------------------------------------------------------------------- */
246{
247    long len;
248    long len1, len2;
249   
250    if(nh>nl) {
251        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(uint16));
252    } else {
253        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(uint16));
254        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(uint16));
255    }
256}
257/* --------------------------------------------------------------------------- */
258IMAGE_EXPORT(void) copy_ui32vector_mod(uint32 *src, long nl, long nh, long m, uint32 *dst)
259/* --------------------------------------------------------------------------- */
260{
261    long len;
262    long len1, len2;
263   
264    if(nh>nl) {
265        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(uint32));
266    } else {
267        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(uint32));
268        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(uint32));
269    }
270}
271/* --------------------------------------------------------------------------- */
272IMAGE_EXPORT(void) copy_si32vector_mod(sint32 *src, long nl, long nh, long m, sint32 *dst)
273/* --------------------------------------------------------------------------- */
274{
275    long len;
276    long len1, len2;
277   
278    if(nh>nl) {
279        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(sint32));
280    } else {
281        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(sint32));
282        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(sint32));
283    }
284}
285/* ------------------------------------------------------------------------------ */
286IMAGE_EXPORT(void) copy_f32vector_mod(float32 *src, long nl, long nh, long m, float32 *dst)
287/* ------------------------------------------------------------------------------ */
288{
289    long len;
290    long len1, len2;
291   
292    if(nh>nl) {
293        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(float32));
294    } else {
295        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(float32));
296        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(float32));
297    }
298}
299/* --------------------------------------------------------------------------------- */
300IMAGE_EXPORT(void) copy_f64vector_mod(float64 *src, long nl, long nh, long m, float64 *dst)
301/* --------------------------------------------------------------------------------- */
302{
303    long len;
304    long len1, len2;
305   
306    if(nh>nl) {
307        len = nh - nl + 1; memcpy(dst, src + nl, len*sizeof(float64));
308    } else {
309        len1 = m - nl; memcpy(dst,      src + nl, len1*sizeof(float64));
310        len2 = nh + 1; memcpy(dst+len1, src + nh, len2*sizeof(float64));
311    }
312}
313
Note: See TracBrowser for help on using the repository browser.