1 | /* ---------------- */ |
---|
2 | /* --- nrmem1.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 | #include <stdio.h> |
---|
15 | #include <stddef.h> |
---|
16 | #include <stdlib.h> |
---|
17 | #include <math.h> // fabs |
---|
18 | |
---|
19 | #include "mypredef.h" |
---|
20 | #include "nrtype.h" |
---|
21 | #include "nrdef.h" |
---|
22 | #include "nrmacro.h" |
---|
23 | #include "nrkernel.h" |
---|
24 | |
---|
25 | #include "nrmem1.h" |
---|
26 | |
---|
27 | /* |
---|
28 | * ----------- |
---|
29 | * --- dup --- |
---|
30 | * ----------- |
---|
31 | */ |
---|
32 | |
---|
33 | |
---|
34 | #undef dup_type_vector |
---|
35 | #define dup_type_vector(t) \ |
---|
36 | void short_name(t,dup_,vector)(t * X, int32_t nl, int32_t nh, t * Y) \ |
---|
37 | { \ |
---|
38 | for (int32_t i = nl; i <= nh; i++) { \ |
---|
39 | Y[i] = X[i]; \ |
---|
40 | } \ |
---|
41 | } |
---|
42 | |
---|
43 | dup_type_vector(int8_t); |
---|
44 | dup_type_vector(uint8_t); |
---|
45 | dup_type_vector(int16_t); |
---|
46 | dup_type_vector(uint16_t); |
---|
47 | dup_type_vector(int32_t); |
---|
48 | dup_type_vector(uint32_t); |
---|
49 | dup_type_vector(int64_t); |
---|
50 | dup_type_vector(uint64_t); |
---|
51 | dup_type_vector(float); |
---|
52 | dup_type_vector(double); |
---|
53 | dup_type_vector(rgb8); |
---|
54 | dup_type_vector(rgbx8); |
---|
55 | |
---|
56 | |
---|
57 | /* |
---|
58 | * -------------------- |
---|
59 | * --- split_vector --- |
---|
60 | * -------------------- |
---|
61 | */ |
---|
62 | |
---|
63 | |
---|
64 | void split_rgb8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * R, uint8_t * G, uint8_t * B) |
---|
65 | { |
---|
66 | for (int32_t i = nl; i <= nh; i++) { |
---|
67 | R[i] = X[i].r; |
---|
68 | G[i] = X[i].g; |
---|
69 | B[i] = X[i].b; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void split_rgb32vector(rgb32 * X, int32_t nl, int32_t nh, uint32_t * R, uint32_t * G, uint32_t * B) |
---|
74 | { |
---|
75 | for (int32_t i = nl; i <= nh; i++) { |
---|
76 | R[i] = X[i].r; |
---|
77 | G[i] = X[i].g; |
---|
78 | B[i] = X[i].b; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | void merge_rgb8vector(uint8_t * R, uint8_t * G, uint8_t * B, int32_t nl, int32_t nh, rgb8 * X) |
---|
83 | { |
---|
84 | for (int32_t i = nl; i <= nh; i++) { |
---|
85 | X[i].r = R[i]; |
---|
86 | X[i].g = G[i]; |
---|
87 | X[i].b = B[i]; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | void merge_rgb32vector(uint32_t * R, uint32_t * G, uint32_t * B, int32_t nl, int32_t nh, rgb32 * X) |
---|
93 | { |
---|
94 | for (int32_t i = nl; i <= nh; i++) { |
---|
95 | X[i].r = R[i]; |
---|
96 | X[i].g = G[i]; |
---|
97 | X[i].b = B[i]; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | /* ---------------- */ |
---|
102 | /* -- Conversion -- */ |
---|
103 | /* ---------------- */ |
---|
104 | |
---|
105 | #undef convert_type1_vector_type2_vector |
---|
106 | #define convert_type1_vector_type2_vector(t1, t2) \ |
---|
107 | void short_name(t1,convert_,short_name(t2,vector_,vector))(t1 * X, int32_t nl, int32_t nh, t2 * Y) \ |
---|
108 | { \ |
---|
109 | for (int32_t i = nl; i <= nh; i++) { \ |
---|
110 | Y[i] = (t2) X[i]; \ |
---|
111 | } \ |
---|
112 | } |
---|
113 | |
---|
114 | convert_type1_vector_type2_vector(int8_t,int16_t); |
---|
115 | convert_type1_vector_type2_vector(int8_t,int32_t); |
---|
116 | convert_type1_vector_type2_vector(int8_t,float); |
---|
117 | convert_type1_vector_type2_vector(int8_t,double); |
---|
118 | convert_type1_vector_type2_vector(uint8_t,uint16_t); |
---|
119 | convert_type1_vector_type2_vector(uint8_t,uint32_t); |
---|
120 | convert_type1_vector_type2_vector(uint8_t,float); |
---|
121 | convert_type1_vector_type2_vector(uint8_t,double); |
---|
122 | convert_type1_vector_type2_vector(int16_t,int32_t); |
---|
123 | convert_type1_vector_type2_vector(int16_t,float); |
---|
124 | convert_type1_vector_type2_vector(int16_t,double); |
---|
125 | convert_type1_vector_type2_vector(uint16_t,uint32_t); |
---|
126 | convert_type1_vector_type2_vector(uint16_t,float); |
---|
127 | convert_type1_vector_type2_vector(uint16_t,double); |
---|
128 | convert_type1_vector_type2_vector(int32_t,float); |
---|
129 | convert_type1_vector_type2_vector(int32_t,double); |
---|
130 | convert_type1_vector_type2_vector(uint32_t,float); |
---|
131 | convert_type1_vector_type2_vector(uint32_t,double); |
---|
132 | convert_type1_vector_type2_vector(int16_t,int8_t); |
---|
133 | convert_type1_vector_type2_vector(uint16_t,uint8_t); |
---|
134 | convert_type1_vector_type2_vector(int32_t,int8_t); |
---|
135 | convert_type1_vector_type2_vector(int32_t,int16_t); |
---|
136 | convert_type1_vector_type2_vector(uint32_t,uint8_t); |
---|
137 | convert_type1_vector_type2_vector(uint32_t,uint16_t); |
---|
138 | convert_type1_vector_type2_vector(float,int8_t); |
---|
139 | convert_type1_vector_type2_vector(float,uint8_t); |
---|
140 | convert_type1_vector_type2_vector(float,int16_t); |
---|
141 | convert_type1_vector_type2_vector(float,uint16_t); |
---|
142 | convert_type1_vector_type2_vector(float,int32_t); |
---|
143 | convert_type1_vector_type2_vector(float,uint32_t); |
---|
144 | convert_type1_vector_type2_vector(double,int8_t); |
---|
145 | convert_type1_vector_type2_vector(double,uint8_t); |
---|
146 | convert_type1_vector_type2_vector(double,int16_t); |
---|
147 | convert_type1_vector_type2_vector(double,uint16_t); |
---|
148 | convert_type1_vector_type2_vector(double,int32_t); |
---|
149 | convert_type1_vector_type2_vector(double,uint32_t); |
---|
150 | convert_type1_vector_type2_vector(double,float); |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | void convert_ui8vector_rgb8vector(uint8_t * X, int32_t nl, int32_t nh, rgb8 * Y) |
---|
159 | { |
---|
160 | for (int32_t i = nl; i <= nh; i++) { |
---|
161 | Y[i].r = X[i]; |
---|
162 | Y[i].g = X[i]; |
---|
163 | Y[i].b = X[i]; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | void convert_ui8vector_rgbx8vector(uint8_t * X, int32_t nl, int32_t nh, rgbx8 * Y) |
---|
168 | { |
---|
169 | for (int32_t i = nl; i <= nh; i++) { |
---|
170 | Y[i].r = X[i]; |
---|
171 | Y[i].g = X[i]; |
---|
172 | Y[i].b = X[i]; |
---|
173 | Y[i].x = 255; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | void convert_rgb8vector_ui8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * Y) |
---|
179 | { |
---|
180 | for (int32_t i = nl; i <= nh; i++) { |
---|
181 | Y[i] = (X[i].r + X[i].g + X[i].b) / 3; |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | void convert_rgbx8vector_ui8vector(rgbx8 * X, int32_t nl, int32_t nh, uint8_t * Y) |
---|
186 | { |
---|
187 | for (int32_t i = nl; i <= nh; i++) { |
---|
188 | Y[i] = (X[i].r + X[i].g + X[i].b) / 3; |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | /* |
---|
193 | * --------------- |
---|
194 | * --- LowPart --- |
---|
195 | * --------------- |
---|
196 | */ |
---|
197 | |
---|
198 | void lowpart_ui16vector_ui8vector(uint16_t * X, int32_t nl, int32_t nh, uint8_t * Y) |
---|
199 | { |
---|
200 | for(int32_t i = nl; i <= nh; i++) { |
---|
201 | Y[i] = X[i] & 0xff; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | void lowpart_ui32vector_ui8vector(uint32_t * X, int32_t nl, int32_t nh, uint8_t * Y) |
---|
206 | { |
---|
207 | for (int32_t i = nl; i <= nh; i++) { |
---|
208 | Y[i] = X[i] & 0xff; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | // Local Variables: |
---|
214 | // tab-width: 4 |
---|
215 | // c-basic-offset: 4 |
---|
216 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
217 | // indent-tabs-mode: nil |
---|
218 | // End: |
---|
219 | |
---|
220 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
221 | |
---|