1 | /* ------------------ */ |
---|
2 | /* --- nralloc1.c --- */ |
---|
3 | /* ------------------ */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * Distributed under the Boost Software License, Version 1.0 |
---|
9 | * see accompanying file LICENSE.txt or copy it at |
---|
10 | * http://www.boost.org/LICENSE_1_0.txt |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * History: |
---|
15 | *2002/06/11 ajout des fonctions endline |
---|
16 | */ |
---|
17 | #include <stdio.h> |
---|
18 | #include <stddef.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <malloc.h> |
---|
21 | #include <math.h> // fabs |
---|
22 | // #include <memory.h> // memcpy |
---|
23 | |
---|
24 | #include "mypredef.h" |
---|
25 | #include "nrtype.h" |
---|
26 | #include "nrdef.h" |
---|
27 | #include "nrmacro.h" |
---|
28 | #include "nrkernel.h" |
---|
29 | |
---|
30 | //#include "nralloc.h" |
---|
31 | #include "nrarith1.h" |
---|
32 | |
---|
33 | /* |
---|
34 | * ------------------ |
---|
35 | * --- sum_vector --- |
---|
36 | * ------------------ |
---|
37 | */ |
---|
38 | |
---|
39 | /* -------------------------------------------------------- */ |
---|
40 | IMAGE_EXPORT(sint32) sum_si8vector(sint8 *v, long nl, long nh) |
---|
41 | /* -------------------------------------------------------- */ |
---|
42 | { |
---|
43 | int i; |
---|
44 | sint32 s = 0; |
---|
45 | for(i=nl; i<=nh; i++) { |
---|
46 | s += v[i]; |
---|
47 | } |
---|
48 | return s; |
---|
49 | } |
---|
50 | /* -------------------------------------------------------- */ |
---|
51 | IMAGE_EXPORT(uint32) sum_u8ivector(uint8 *v, long nl, long nh) |
---|
52 | /* -------------------------------------------------------- */ |
---|
53 | { |
---|
54 | int i; |
---|
55 | uint32 s = 0; |
---|
56 | for(i=nl; i<=nh; i++) { |
---|
57 | s += v[i]; |
---|
58 | } |
---|
59 | return s; |
---|
60 | } |
---|
61 | /* ---------------------------------------------------------- */ |
---|
62 | IMAGE_EXPORT(sint32) sum_si16vector(sint16 *v, long nl, long nh) |
---|
63 | /* ---------------------------------------------------------- */ |
---|
64 | { |
---|
65 | int i; |
---|
66 | sint32 s = 0; |
---|
67 | for(i=nl; i<=nh; i++) { |
---|
68 | s += v[i]; |
---|
69 | } |
---|
70 | return s; |
---|
71 | } |
---|
72 | /* ---------------------------------------------------------- */ |
---|
73 | IMAGE_EXPORT(uint32) sum_u16ivector(uint16 *v, long nl, long nh) |
---|
74 | /* ---------------------------------------------------------- */ |
---|
75 | { |
---|
76 | int i; |
---|
77 | uint32 s = 0; |
---|
78 | for(i=nl; i<=nh; i++) { |
---|
79 | s += v[i]; |
---|
80 | } |
---|
81 | return s; |
---|
82 | } |
---|
83 | /* ---------------------------------------------------------- */ |
---|
84 | IMAGE_EXPORT(sint32) sum_si32vector(sint32 *v, long nl, long nh) |
---|
85 | /* ---------------------------------------------------------- */ |
---|
86 | { |
---|
87 | int i; |
---|
88 | sint32 s = 0; |
---|
89 | for(i=nl; i<=nh; i++) { |
---|
90 | s += v[i]; |
---|
91 | } |
---|
92 | return s; |
---|
93 | } |
---|
94 | /* ---------------------------------------------------------- */ |
---|
95 | IMAGE_EXPORT(uint32) sum_u32ivector(uint32 *v, long nl, long nh) |
---|
96 | /* ---------------------------------------------------------- */ |
---|
97 | { |
---|
98 | int i; |
---|
99 | uint32 s = 0; |
---|
100 | for(i=nl; i<=nh; i++) { |
---|
101 | s += v[i]; |
---|
102 | } |
---|
103 | return s; |
---|
104 | } |
---|
105 | /* ----------------------------------------------------------- */ |
---|
106 | IMAGE_EXPORT(float32) sum_f32vector(float32 *v, long nl, long nh) |
---|
107 | /* ----------------------------------------------------------- */ |
---|
108 | { |
---|
109 | int i; |
---|
110 | float32 s = 0.0f; |
---|
111 | for(i=nl; i<=nh; i++) { |
---|
112 | s += v[i]; |
---|
113 | } |
---|
114 | return s; |
---|
115 | } |
---|
116 | /* ----------------------------------------------------------- */ |
---|
117 | IMAGE_EXPORT(float64) sum_f64vector(float64 *v, long nl, long nh) |
---|
118 | /* ----------------------------------------------------------- */ |
---|
119 | { |
---|
120 | int i; |
---|
121 | float64 s = 0.0; |
---|
122 | for(i=nl; i<=nh; i++) { |
---|
123 | s += v[i]; |
---|
124 | } |
---|
125 | return s; |
---|
126 | } |
---|
127 | |
---|
128 | /* |
---|
129 | * ------------------ |
---|
130 | * --- min_vector --- |
---|
131 | * ------------------ |
---|
132 | */ |
---|
133 | |
---|
134 | /* ------------------------------------------------------- */ |
---|
135 | IMAGE_EXPORT(sint8) min_si8vector(sint8 *v, long nl, long nh) |
---|
136 | /* ------------------------------------------------------- */ |
---|
137 | { |
---|
138 | int i; |
---|
139 | uint8 m; |
---|
140 | |
---|
141 | m = v[nl]; |
---|
142 | for(i=nl+1; i<=nh; i++) { |
---|
143 | if(v[i]<m) m = v[i]; |
---|
144 | } |
---|
145 | return m; |
---|
146 | } |
---|
147 | /* ------------------------------------------------------- */ |
---|
148 | IMAGE_EXPORT(uint8) min_ui8vector(uint8 *v, long nl, long nh) |
---|
149 | /* ------------------------------------------------------- */ |
---|
150 | { |
---|
151 | int i; |
---|
152 | uint8 m; |
---|
153 | |
---|
154 | m = v[nl]; |
---|
155 | for(i=nl+1; i<=nh; i++) { |
---|
156 | if(v[i]<m) m = v[i]; |
---|
157 | } |
---|
158 | return m; |
---|
159 | } |
---|
160 | /* ---------------------------------------------------------- */ |
---|
161 | IMAGE_EXPORT(sint16) min_si16vector(sint16 *v, long nl, long nh) |
---|
162 | /* ---------------------------------------------------------- */ |
---|
163 | { |
---|
164 | int i; |
---|
165 | int16 m; |
---|
166 | |
---|
167 | m = v[nl]; |
---|
168 | for(i=nl+1; i<=nh; i++) { |
---|
169 | if(v[i]<m) m = v[i]; |
---|
170 | } |
---|
171 | return m; |
---|
172 | } |
---|
173 | /* ---------------------------------------------------------- */ |
---|
174 | IMAGE_EXPORT(uint16) min_ui16vector(uint16 *v, long nl, long nh) |
---|
175 | /* ---------------------------------------------------------- */ |
---|
176 | { |
---|
177 | int i; |
---|
178 | uint16 m; |
---|
179 | |
---|
180 | m = v[nl]; |
---|
181 | for(i=nl+1; i<=nh; i++) { |
---|
182 | if(v[i]<m) m = v[i]; |
---|
183 | } |
---|
184 | return m; |
---|
185 | } |
---|
186 | /* ---------------------------------------------------------- */ |
---|
187 | IMAGE_EXPORT(sint32) min_si32vector(sint32 *v, long nl, long nh) |
---|
188 | /* ---------------------------------------------------------- */ |
---|
189 | { |
---|
190 | int i; |
---|
191 | int16 m; |
---|
192 | |
---|
193 | m = v[nl]; |
---|
194 | for(i=nl+1; i<=nh; i++) { |
---|
195 | if(v[i]<m) m = v[i]; |
---|
196 | } |
---|
197 | return m; |
---|
198 | } |
---|
199 | /* ---------------------------------------------------------- */ |
---|
200 | IMAGE_EXPORT(uint32) min_ui32vector(uint32 *v, long nl, long nh) |
---|
201 | /* ---------------------------------------------------------- */ |
---|
202 | { |
---|
203 | int i; |
---|
204 | uint32 m; |
---|
205 | |
---|
206 | m = v[nl]; |
---|
207 | for(i=nl+1; i<=nh; i++) { |
---|
208 | if(v[i]<m) m = v[i]; |
---|
209 | } |
---|
210 | return m; |
---|
211 | } |
---|
212 | /* ----------------------------------------------------------- */ |
---|
213 | IMAGE_EXPORT(float32) min_f32vector(float32 *v, long nl, long nh) |
---|
214 | /* ----------------------------------------------------------- */ |
---|
215 | { |
---|
216 | int i; |
---|
217 | float32 m; |
---|
218 | |
---|
219 | m = v[nl]; |
---|
220 | for(i=nl+1; i<=nh; i++) { |
---|
221 | if(v[i]<m) m = v[i]; |
---|
222 | } |
---|
223 | return m; |
---|
224 | } |
---|
225 | /* ----------------------------------------------------------- */ |
---|
226 | IMAGE_EXPORT(float64) min_f64vector(float64 *v, long nl, long nh) |
---|
227 | /* ----------------------------------------------------------- */ |
---|
228 | { |
---|
229 | int i; |
---|
230 | float64 m; |
---|
231 | |
---|
232 | m = v[nl]; |
---|
233 | for(i=nl+1; i<=nh; i++) { |
---|
234 | if(v[i]<m) m = v[i]; |
---|
235 | } |
---|
236 | return m; |
---|
237 | } |
---|
238 | |
---|
239 | /* |
---|
240 | * ------------------ |
---|
241 | * --- max_vector --- |
---|
242 | * ------------------ |
---|
243 | */ |
---|
244 | |
---|
245 | /* ------------------------------------------------------- */ |
---|
246 | IMAGE_EXPORT(sint8) max_si8vector(sint8 *v, long nl, long nh) |
---|
247 | /* ------------------------------------------------------- */ |
---|
248 | { |
---|
249 | int i; |
---|
250 | sint8 m; |
---|
251 | |
---|
252 | m = v[nl]; |
---|
253 | for(i=nl+1; i<=nh; i++) { |
---|
254 | if(v[i]>m) m = v[i]; |
---|
255 | } |
---|
256 | return m; |
---|
257 | } |
---|
258 | /* ------------------------------------------------------- */ |
---|
259 | IMAGE_EXPORT(uint8) max_ui8vector(uint8 *v, long nl, long nh) |
---|
260 | /* ------------------------------------------------------- */ |
---|
261 | { |
---|
262 | int i; |
---|
263 | uint8 m; |
---|
264 | |
---|
265 | m = v[nl]; |
---|
266 | for(i=nl+1; i<=nh; i++) { |
---|
267 | if(v[i]>m) m = v[i]; |
---|
268 | } |
---|
269 | return m; |
---|
270 | } |
---|
271 | /* ---------------------------------------------------------- */ |
---|
272 | IMAGE_EXPORT(sint16) max_si16vector(sint16 *v, long nl, long nh) |
---|
273 | /* ---------------------------------------------------------- */ |
---|
274 | { |
---|
275 | int i; |
---|
276 | sint16 m; |
---|
277 | |
---|
278 | m = v[nl]; |
---|
279 | for(i=nl+1; i<=nh; i++) { |
---|
280 | if(v[i]>m) m = v[i]; |
---|
281 | } |
---|
282 | return m; |
---|
283 | } |
---|
284 | /* ---------------------------------------------------------- */ |
---|
285 | IMAGE_EXPORT(uint16) max_ui16vector(uint16 *v, long nl, long nh) |
---|
286 | /* ---------------------------------------------------------- */ |
---|
287 | { |
---|
288 | int i; |
---|
289 | uint16 m; |
---|
290 | |
---|
291 | m = v[nl]; |
---|
292 | for(i=nl+1; i<=nh; i++) { |
---|
293 | if(v[i]>m) m = v[i]; |
---|
294 | } |
---|
295 | return m; |
---|
296 | } |
---|
297 | /* ---------------------------------------------------------- */ |
---|
298 | IMAGE_EXPORT(sint32) max_si32vector(sint32 *v, long nl, long nh) |
---|
299 | /* ---------------------------------------------------------- */ |
---|
300 | { |
---|
301 | int i; |
---|
302 | sint32 m; |
---|
303 | |
---|
304 | m = v[nl]; |
---|
305 | for(i=nl+1; i<=nh; i++) { |
---|
306 | if(v[i]>m) m = v[i]; |
---|
307 | } |
---|
308 | return m; |
---|
309 | } |
---|
310 | /* ---------------------------------------------------------- */ |
---|
311 | IMAGE_EXPORT(uint32) max_ui32vector(uint32 *v, long nl, long nh) |
---|
312 | /* ---------------------------------------------------------- */ |
---|
313 | { |
---|
314 | int i; |
---|
315 | uint32 m; |
---|
316 | |
---|
317 | m = v[nl]; |
---|
318 | for(i=nl+1; i<=nh; i++) { |
---|
319 | if(v[i]>m) m = v[i]; |
---|
320 | } |
---|
321 | return m; |
---|
322 | } |
---|
323 | /* ----------------------------------------------------------- */ |
---|
324 | IMAGE_EXPORT(float32) max_f32vector(float32 *v, long nl, long nh) |
---|
325 | /* ----------------------------------------------------------- */ |
---|
326 | { |
---|
327 | int i; |
---|
328 | float32 m; |
---|
329 | |
---|
330 | m = v[nl]; |
---|
331 | for(i=nl+1; i<=nh; i++) { |
---|
332 | if(v[i]>m) m = v[i]; |
---|
333 | } |
---|
334 | return m; |
---|
335 | } |
---|
336 | /* ----------------------------------------------------------- */ |
---|
337 | IMAGE_EXPORT(float64) max_f64vector(float64 *v, long nl, long nh) |
---|
338 | /* ----------------------------------------------------------- */ |
---|
339 | { |
---|
340 | int i; |
---|
341 | float64 m; |
---|
342 | |
---|
343 | m = v[nl]; |
---|
344 | for(i=nl+1; i<=nh; i++) { |
---|
345 | if(v[i]>m) m = v[i]; |
---|
346 | } |
---|
347 | return m; |
---|
348 | } |
---|
349 | /* |
---|
350 | * ---------------------- |
---|
351 | * --- min_vector_pos --- |
---|
352 | * ---------------------- |
---|
353 | */ |
---|
354 | |
---|
355 | /* --------------------------------------------------------------------- */ |
---|
356 | IMAGE_EXPORT(sint8) min_si8vector_pos(sint8 *v, long nl, long nh, int *pos) |
---|
357 | /* --------------------------------------------------------------------- */ |
---|
358 | { |
---|
359 | int i; |
---|
360 | sint8 m = v[nl]; |
---|
361 | int p = nl; |
---|
362 | |
---|
363 | for(i=nl+1; i<=nh; i++) { |
---|
364 | if(v[i]>m) { m = v[i]; p = i;} |
---|
365 | } |
---|
366 | *pos = p; |
---|
367 | return m; |
---|
368 | } |
---|
369 | /* --------------------------------------------------------------------- */ |
---|
370 | IMAGE_EXPORT(uint8) min_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) |
---|
371 | /* --------------------------------------------------------------------- */ |
---|
372 | { |
---|
373 | int i; |
---|
374 | uint8 m = v[nl]; |
---|
375 | int p = nl; |
---|
376 | |
---|
377 | for(i=nl+1; i<=nh; i++) { |
---|
378 | if(v[i]>m) { m = v[i]; p = i;} |
---|
379 | } |
---|
380 | *pos = p; |
---|
381 | return m; |
---|
382 | } |
---|
383 | /* ------------------------------------------------------------------------ */ |
---|
384 | IMAGE_EXPORT(sint16) min_si16vector_pos(sint16 *v, long nl, long nh, int *pos) |
---|
385 | /* ------------------------------------------------------------------------ */ |
---|
386 | { |
---|
387 | int i; |
---|
388 | sint16 m = v[nl]; |
---|
389 | int p = nl; |
---|
390 | |
---|
391 | for(i=nl+1; i<=nh; i++) { |
---|
392 | if(v[i]>m) { m = v[i]; p = i;} |
---|
393 | } |
---|
394 | *pos = p; |
---|
395 | return m; |
---|
396 | } |
---|
397 | /* ------------------------------------------------------------------------ */ |
---|
398 | IMAGE_EXPORT(uint16) min_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) |
---|
399 | /* ------------------------------------------------------------------------ */ |
---|
400 | { |
---|
401 | int i; |
---|
402 | uint16 m = v[nl]; |
---|
403 | int p = nl; |
---|
404 | |
---|
405 | for(i=nl+1; i<=nh; i++) { |
---|
406 | if(v[i]>m) { m = v[i]; p = i;} |
---|
407 | } |
---|
408 | *pos = p; |
---|
409 | return m; |
---|
410 | } |
---|
411 | /* ------------------------------------------------------------------------ */ |
---|
412 | IMAGE_EXPORT(sint32) min_si32vector_pos(sint32 *v, long nl, long nh, int *pos) |
---|
413 | /* ------------------------------------------------------------------------ */ |
---|
414 | { |
---|
415 | int i; |
---|
416 | sint32 m = v[nl]; |
---|
417 | int p = nl; |
---|
418 | |
---|
419 | for(i=nl+1; i<=nh; i++) { |
---|
420 | if(v[i]>m) { m = v[i]; p = i;} |
---|
421 | } |
---|
422 | *pos = p; |
---|
423 | return m; |
---|
424 | } |
---|
425 | /* ------------------------------------------------------------------------ */ |
---|
426 | IMAGE_EXPORT(uint32) min_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) |
---|
427 | /* ------------------------------------------------------------------------ */ |
---|
428 | { |
---|
429 | int i; |
---|
430 | uint32 m = v[nl]; |
---|
431 | int p = nl; |
---|
432 | |
---|
433 | for(i=nl+1; i<=nh; i++) { |
---|
434 | if(v[i]>m) { m = v[i]; p = i;} |
---|
435 | } |
---|
436 | *pos = p; |
---|
437 | return m; |
---|
438 | } |
---|
439 | /* ------------------------------------------------------------------------- */ |
---|
440 | IMAGE_EXPORT(float32) min_f32vector_pos(float32 *v, long nl, long nh, int *pos) |
---|
441 | /* ------------------------------------------------------------------------- */ |
---|
442 | { |
---|
443 | int i; |
---|
444 | float32 m = v[nl]; |
---|
445 | int p = nl; |
---|
446 | |
---|
447 | for(i=nl+1; i<=nh; i++) { |
---|
448 | if(v[i]>m) { m = v[i]; p = i;} |
---|
449 | } |
---|
450 | *pos = p; |
---|
451 | return m; |
---|
452 | } |
---|
453 | /* ------------------------------------------------------------------------- */ |
---|
454 | IMAGE_EXPORT(float64) min_f64vector_pos(float64 *v, long nl, long nh, int *pos) |
---|
455 | /* ------------------------------------------------------------------------- */ |
---|
456 | { |
---|
457 | int i; |
---|
458 | float64 m = v[nl]; |
---|
459 | int p = nl; |
---|
460 | |
---|
461 | for(i=nl+1; i<=nh; i++) { |
---|
462 | if(v[i]>m) { m = v[i]; p = i;} |
---|
463 | } |
---|
464 | *pos = p; |
---|
465 | return m; |
---|
466 | } |
---|
467 | |
---|
468 | /* |
---|
469 | * ---------------------- |
---|
470 | * --- max_vector_pos --- |
---|
471 | * ---------------------- |
---|
472 | */ |
---|
473 | |
---|
474 | /* --------------------------------------------------------------------- */ |
---|
475 | IMAGE_EXPORT(sint8) max_si8vector_pos(sint8 *v, long nl, long nh, int *pos) |
---|
476 | /* --------------------------------------------------------------------- */ |
---|
477 | { |
---|
478 | int i; |
---|
479 | sint8 m = v[nl]; |
---|
480 | int p = nl; |
---|
481 | |
---|
482 | for(i=nl+1; i<=nh; i++) { |
---|
483 | if(v[i]>m) { m = v[i]; p = i;} |
---|
484 | } |
---|
485 | *pos = p; |
---|
486 | |
---|
487 | return m; |
---|
488 | } |
---|
489 | /* --------------------------------------------------------------------- */ |
---|
490 | IMAGE_EXPORT(uint8) max_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) |
---|
491 | /* --------------------------------------------------------------------- */ |
---|
492 | { |
---|
493 | int i; |
---|
494 | uint8 m = v[nl]; |
---|
495 | int p = nl; |
---|
496 | |
---|
497 | for(i=nl+1; i<=nh; i++) { |
---|
498 | if(v[i]>m) { m = v[i]; p = i;} |
---|
499 | } |
---|
500 | *pos = p; |
---|
501 | |
---|
502 | return m; |
---|
503 | } |
---|
504 | /* ------------------------------------------------------------------------ */ |
---|
505 | IMAGE_EXPORT(sint16) max_si16vector_pos(sint16 *v, long nl, long nh, int *pos) |
---|
506 | /* ------------------------------------------------------------------------ */ |
---|
507 | { |
---|
508 | int i; |
---|
509 | int16 m = v[nl]; |
---|
510 | int p = nl; |
---|
511 | |
---|
512 | for(i=nl+1; i<=nh; i++) { |
---|
513 | if(v[i]>m) { m = v[i]; p = i;} |
---|
514 | } |
---|
515 | *pos = p; |
---|
516 | return m; |
---|
517 | } |
---|
518 | /* ----------------------------------------------------------------------- */ |
---|
519 | IMAGE_EXPORT(uint16) max_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) |
---|
520 | /* ----------------------------------------------------------------------- */ |
---|
521 | { |
---|
522 | int i; |
---|
523 | uint16 m = v[nl]; |
---|
524 | int p = nl; |
---|
525 | |
---|
526 | for(i=nl+1; i<=nh; i++) { |
---|
527 | if(v[i]>m) { m = v[i]; p = i;} |
---|
528 | } |
---|
529 | *pos = p; |
---|
530 | |
---|
531 | return m; |
---|
532 | } |
---|
533 | /* --------------------------------------------------------------------- */ |
---|
534 | IMAGE_EXPORT(sint32) max_si32vector_pos(sint32 *v, long nl, long nh, int *pos) |
---|
535 | /* --------------------------------------------------------------------- */ |
---|
536 | { |
---|
537 | int i; |
---|
538 | sint32 m = v[nl]; |
---|
539 | int p = nl; |
---|
540 | |
---|
541 | for(i=nl+1; i<=nh; i++) { |
---|
542 | if(v[i]>m) { m = v[i]; p = i;} |
---|
543 | } |
---|
544 | *pos = p; |
---|
545 | |
---|
546 | return m; |
---|
547 | } |
---|
548 | /* ------------------------------------------------------------------------ */ |
---|
549 | IMAGE_EXPORT(uint32) max_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) |
---|
550 | /* ------------------------------------------------------------------------ */ |
---|
551 | { |
---|
552 | int i; |
---|
553 | uint32 m = v[nl]; |
---|
554 | int p = nl; |
---|
555 | |
---|
556 | for(i=nl+1; i<=nh; i++) { |
---|
557 | if(v[i]>m) { m = v[i]; p = i;} |
---|
558 | } |
---|
559 | *pos = p; |
---|
560 | |
---|
561 | return m; |
---|
562 | } |
---|
563 | /* ----------------------------------------------------------------------- */ |
---|
564 | IMAGE_EXPORT(float32) max_f32vector_pos(float32 *v, long nl, long nh, int *pos) |
---|
565 | /* ----------------------------------------------------------------------- */ |
---|
566 | { |
---|
567 | int i; |
---|
568 | float32 m = v[nl]; |
---|
569 | int p = nl; |
---|
570 | |
---|
571 | for(i=nl+1; i<=nh; i++) { |
---|
572 | if(v[i]>m) { m = v[i]; p = i;} |
---|
573 | } |
---|
574 | *pos = p; |
---|
575 | |
---|
576 | return m; |
---|
577 | } |
---|
578 | /* ------------------------------------------------------------------------- */ |
---|
579 | IMAGE_EXPORT(float64) max_f64vector_pos(float64 *v, long nl, long nh, int *pos) |
---|
580 | /* ------------------------------------------------------------------------- */ |
---|
581 | { |
---|
582 | int i; |
---|
583 | float64 m = v[nl]; |
---|
584 | int p = nl; |
---|
585 | |
---|
586 | for(i=nl+1; i<=nh; i++) { |
---|
587 | if(v[i]>m) { m = v[i]; p = i;} |
---|
588 | } |
---|
589 | *pos = p; |
---|
590 | |
---|
591 | return m; |
---|
592 | } |
---|
593 | /* --------------------------------------------------------------------- */ |
---|
594 | IMAGE_EXPORT(void) beta_sum_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) |
---|
595 | /* --------------------------------------------------------------------- */ |
---|
596 | { |
---|
597 | long i; |
---|
598 | int32 r, g, b, s; |
---|
599 | for(i=nl; i<=nh; i++){ |
---|
600 | r = S[i].r; |
---|
601 | g = S[i].g; |
---|
602 | b = S[i].b; |
---|
603 | s = r + g + b; |
---|
604 | D[i].r = s; |
---|
605 | D[i].g = s; |
---|
606 | D[i].b = s; |
---|
607 | } |
---|
608 | } |
---|
609 | /* ----------------------------------------------------------------------- */ |
---|
610 | IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) |
---|
611 | /* ----------------------------------------------------------------------- */ |
---|
612 | { |
---|
613 | long i; |
---|
614 | int32 r, g, b, s; |
---|
615 | for(i=nl; i<=nh; i++){ |
---|
616 | r = S[i].r; |
---|
617 | g = S[i].g; |
---|
618 | b = S[i].b; |
---|
619 | s = (r + g + b) / 3; |
---|
620 | D[i].r = s; |
---|
621 | D[i].g = s; |
---|
622 | D[i].b = s; |
---|
623 | } |
---|
624 | } |
---|
625 | /* ------------------------------------------------------------------------ */ |
---|
626 | IMAGE_EXPORT(void) add_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) |
---|
627 | /* ------------------------------------------------------------------------ */ |
---|
628 | { |
---|
629 | long i; |
---|
630 | for(i=nl; i<=nh; i++) D[i] = S1[i] + S2[i]; |
---|
631 | } |
---|
632 | /* ------------------------------------------------------------------------ */ |
---|
633 | IMAGE_EXPORT(void) sub_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) |
---|
634 | /* ------------------------------------------------------------------------ */ |
---|
635 | { |
---|
636 | long i; |
---|
637 | for(i=nl; i<=nh; i++) D[i] = S1[i] - S2[i]; |
---|
638 | } |
---|
639 | /* ---------------------------------------------------------------------- */ |
---|
640 | IMAGE_EXPORT(void) mulc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) |
---|
641 | /* ---------------------------------------------------------------------- */ |
---|
642 | { |
---|
643 | long i; |
---|
644 | for(i=nl; i<=nh; i++) D[i] = c * S[i]; |
---|
645 | } |
---|
646 | /* ------------------------------------------------------------------------ */ |
---|
647 | IMAGE_EXPORT(void) mulc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) |
---|
648 | /* ------------------------------------------------------------------------ */ |
---|
649 | { |
---|
650 | long i; |
---|
651 | |
---|
652 | for(i=nl; i<=nh; i++) { |
---|
653 | D[i].r = c * S[i].r; |
---|
654 | D[i].g = c * S[i].g; |
---|
655 | D[i].b = c * S[i].b; |
---|
656 | } |
---|
657 | } |
---|
658 | /* ------------------------------------------------------------------------ */ |
---|
659 | IMAGE_EXPORT(void) divc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) |
---|
660 | /* ------------------------------------------------------------------------ */ |
---|
661 | { |
---|
662 | long i; |
---|
663 | for(i=nl; i<=nh; i++) D[i] = S[i] / c; |
---|
664 | } |
---|
665 | /* -------------------------------------------------------------------------- */ |
---|
666 | IMAGE_EXPORT(void) divc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) |
---|
667 | /* -------------------------------------------------------------------------- */ |
---|
668 | { |
---|
669 | long i; |
---|
670 | |
---|
671 | for(i=nl; i<=nh; i++) { |
---|
672 | D[i].r = S[i].r / c; |
---|
673 | D[i].g = S[i].g / c; |
---|
674 | D[i].b = S[i].b / c; |
---|
675 | } |
---|
676 | } |
---|
677 | /* -------------------------------------------------------------------- */ |
---|
678 | IMAGE_EXPORT(void) cumulleft_i32vector(int32 *S, long nl,long nh, int32 *D) |
---|
679 | /* -------------------------------------------------------------------- */ |
---|
680 | { |
---|
681 | // for histogram |
---|
682 | long i; |
---|
683 | |
---|
684 | for(i=nh-1; i>=nl; i--) { |
---|
685 | D[i] += S[i+1]; |
---|
686 | } |
---|
687 | } |
---|
688 | /* --------------------------------------------------------------------- */ |
---|
689 | IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) |
---|
690 | /* --------------------------------------------------------------------- */ |
---|
691 | { |
---|
692 | // for histogram |
---|
693 | long i; |
---|
694 | |
---|
695 | for(i=nh-1; i>=nl; i--) { |
---|
696 | D[i].r += S[i+1].r; |
---|
697 | D[i].g += S[i+1].g; |
---|
698 | D[i].b += S[i+1].b; |
---|
699 | } |
---|
700 | } |
---|
701 | /* -------------------------------------------------------------------- */ |
---|
702 | IMAGE_EXPORT(void) cumulright_i32vector(int32 *S, long nl,long nh, int32 *D) |
---|
703 | /* -------------------------------------------------------------------- */ |
---|
704 | { |
---|
705 | // for histogram |
---|
706 | long i; |
---|
707 | |
---|
708 | for(i=nl+1; i<=nh; i++) { |
---|
709 | D[i] += S[i-1]; |
---|
710 | } |
---|
711 | } |
---|
712 | /* ---------------------------------------------------------------------- */ |
---|
713 | IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) |
---|
714 | /* ---------------------------------------------------------------------- */ |
---|
715 | { |
---|
716 | // for histogram |
---|
717 | long i; |
---|
718 | |
---|
719 | for(i=nl+1; i<=nh; i++) { |
---|
720 | D[i].r += S[i-1].r; |
---|
721 | D[i].g += S[i-1].g; |
---|
722 | D[i].b += S[i-1].b; |
---|
723 | } |
---|
724 | } |
---|
725 | /* ----------------------------------------------------------------------------------- */ |
---|
726 | IMAGE_EXPORT(void) mulfrac_i32vector(int32 *S, long nl,long nh, int32 a, int32 b, int32 *D) |
---|
727 | /* ----------------------------------------------------------------------------------- */ |
---|
728 | { |
---|
729 | long i; |
---|
730 | |
---|
731 | for(i=nl; i<=nh; i++) { |
---|
732 | //D[i] = (a * S[i] + b) / b; |
---|
733 | D[i] = (a * S[i]) / b; |
---|
734 | } |
---|
735 | } |
---|
736 | /* ------------------------------------------------------------------------------------- */ |
---|
737 | IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl,long nh, int32 a, int32 b, rgb32 *D) |
---|
738 | /* ------------------------------------------------------------------------------------- */ |
---|
739 | { |
---|
740 | long i; |
---|
741 | |
---|
742 | for(i=nl; i<=nh; i++) { |
---|
743 | //D[i].r = (a * S[i].r + b) / b; |
---|
744 | //D[i].g = (a * S[i].g + b) / b; |
---|
745 | //D[i].b = (a * S[i].b + b) / b; |
---|
746 | D[i].r = (a * S[i].r) / b; |
---|
747 | D[i].g = (a * S[i].g) / b; |
---|
748 | D[i].b = (a * S[i].b) / b; |
---|
749 | } |
---|
750 | } |
---|