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

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