[772] | 1 | /* ----------------- */ |
---|
| 2 | /* --- nrmem1x.c --- */ |
---|
| 3 | /* ----------------- */ |
---|
| 4 | |
---|
| 5 | /* |
---|
[826] | 6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
| 7 | * Univ Paris Sud XI, CNRS |
---|
| 8 | */ |
---|
[772] | 9 | |
---|
| 10 | #include <stdlib.h> |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <stddef.h> |
---|
[821] | 13 | #include <string.h> |
---|
[772] | 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" |
---|
[826] | 22 | |
---|
| 23 | void roll_si16vector(int16_t * v, int32_t nl, int32_t nh) |
---|
[772] | 24 | /* |
---|
[826] | 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 | */ |
---|
[772] | 30 | { |
---|
[826] | 31 | sint16 tmp; |
---|
| 32 | tmp = v[nl]; |
---|
| 33 | for (int32_t i = nl; i < nh; i++) { |
---|
| 34 | v[i] = v[i + 1]; |
---|
| 35 | } |
---|
| 36 | v[nh] = tmp; |
---|
[772] | 37 | } |
---|
[826] | 38 | |
---|
| 39 | |
---|
| 40 | void roll_ui16vector(uint16_t * v, int32_t nl, int32_t nh) |
---|
[772] | 41 | /* |
---|
[826] | 42 | * left rotate a uint16 vector with subscript range v[nl..nh] |
---|
| 43 | * nl & nh can be, respectively bigger and smaller than the |
---|
| 44 | * values used to allocate the vector (svector) |
---|
| 45 | * no check on nl and nh is done |
---|
| 46 | */ |
---|
[772] | 47 | { |
---|
[826] | 48 | uint16 tmp; |
---|
| 49 | tmp = v[nl]; |
---|
| 50 | for (int32_t i = nl; i < nh; i++) { |
---|
| 51 | v[i] = v[i + 1]; |
---|
| 52 | } |
---|
| 53 | v[nh] = tmp; |
---|
[772] | 54 | } |
---|
[826] | 55 | |
---|
[772] | 56 | /* |
---|
| 57 | * ------------------- |
---|
| 58 | * --- copy_vector --- |
---|
| 59 | * ------------------- |
---|
| 60 | */ |
---|
| 61 | |
---|
[826] | 62 | #undef copy_type_vector |
---|
| 63 | #define copy_type_vector(t) \ |
---|
| 64 | void short_name(t,copy_,vector)(t * src, int32_t nl1, int32_t nh1, t * dst, int32_t nl2, int32_t nh2) \ |
---|
| 65 | { \ |
---|
| 66 | int32_t len = nh1 - nl1 + 1; \ |
---|
| 67 | memcpy(dst + nl2, src + nl1, len * sizeof(t)); \ |
---|
[772] | 68 | } |
---|
[826] | 69 | |
---|
| 70 | copy_type_vector(int8_t); |
---|
| 71 | copy_type_vector(uint8_t); |
---|
| 72 | copy_type_vector(int16_t); |
---|
| 73 | copy_type_vector(uint16_t); |
---|
| 74 | copy_type_vector(int32_t); |
---|
| 75 | copy_type_vector(uint32_t); |
---|
| 76 | copy_type_vector(float); |
---|
| 77 | copy_type_vector(double); |
---|
| 78 | copy_type_vector(rgb8); |
---|
| 79 | copy_type_vector(rgbx8); |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | #undef copy1c_type_vector |
---|
| 83 | #define copy1c_type_vector(t) \ |
---|
| 84 | void short_name(t,copy1c_,vector)(t * src, int32_t nc, t * dst, int32_t nl, int32_t nh) \ |
---|
| 85 | { \ |
---|
| 86 | t c = src[nc]; \ |
---|
| 87 | for (int32_t j = nl; j < nh; j++) { \ |
---|
| 88 | dst[j] = c; \ |
---|
| 89 | } \ |
---|
[772] | 90 | } |
---|
[826] | 91 | |
---|
| 92 | copy1c_type_vector(int8_t); |
---|
| 93 | copy1c_type_vector(uint8_t); |
---|
| 94 | copy1c_type_vector(int16_t); |
---|
| 95 | copy1c_type_vector(uint16_t); |
---|
| 96 | copy1c_type_vector(int32_t); |
---|
| 97 | copy1c_type_vector(uint32_t); |
---|
| 98 | copy1c_type_vector(float); |
---|
| 99 | copy1c_type_vector(double); |
---|
| 100 | copy1c_type_vector(rgb8); |
---|
| 101 | copy1c_type_vector(rgbx8); |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | #undef copy_type_vector_mod |
---|
| 106 | #define copy_type_vector_mod(t) \ |
---|
| 107 | void short_name(t,copy_,vector_mod)(t * src, int32_t nl, int32_t nh, int32_t m, t * dst) \ |
---|
| 108 | { \ |
---|
| 109 | if (nh > nl) { \ |
---|
| 110 | int32_t len = nh - nl + 1; \ |
---|
| 111 | memcpy(dst, src + nl, len * sizeof(t)); \ |
---|
| 112 | } \ |
---|
| 113 | else { \ |
---|
| 114 | int32_t len1 = m - nl; \ |
---|
| 115 | int32_t len2 = nh + 1; \ |
---|
| 116 | memcpy(dst, src + nl, len1 * sizeof(t)); \ |
---|
| 117 | memcpy(dst + len1, src + nh, len2 * sizeof(t)); \ |
---|
| 118 | } \ |
---|
[772] | 119 | } |
---|
| 120 | |
---|
[826] | 121 | |
---|
| 122 | copy_type_vector_mod(int8_t); |
---|
| 123 | copy_type_vector_mod(uint8_t); |
---|
| 124 | copy_type_vector_mod(int16_t); |
---|
| 125 | copy_type_vector_mod(uint16_t); |
---|
| 126 | copy_type_vector_mod(int32_t); |
---|
| 127 | copy_type_vector_mod(uint32_t); |
---|
| 128 | copy_type_vector_mod(float); |
---|
| 129 | copy_type_vector_mod(double); |
---|
| 130 | copy_type_vector_mod(rgb8); |
---|
| 131 | copy_type_vector_mod(rgbx8); |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | // Local Variables: |
---|
| 136 | // tab-width: 4 |
---|
| 137 | // c-basic-offset: 4 |
---|
| 138 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 139 | // indent-tabs-mode: nil |
---|
| 140 | // End: |
---|
| 141 | |
---|
| 142 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 143 | |
---|