| [772] | 1 | /* ---------------- */ |
|---|
| 2 | /* --- nrset1.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 | /* |
|---|
| [826] | 15 | * 2002/06/11 ajout des fonctions endline |
|---|
| 16 | */ |
|---|
| 17 | |
|---|
| [772] | 18 | #include <stdio.h> |
|---|
| 19 | #include <stddef.h> |
|---|
| 20 | #include <stdlib.h> |
|---|
| 21 | |
|---|
| 22 | #include "mypredef.h" |
|---|
| 23 | #include "nrtype.h" |
|---|
| 24 | #include "nrdef.h" |
|---|
| 25 | #include "nrmacro.h" |
|---|
| 26 | #include "nrkernel.h" |
|---|
| 27 | |
|---|
| 28 | #include "nrset1.h" |
|---|
| 29 | |
|---|
| 30 | #define isdigit(x) ((x) >= 0x30 && (x) <= 0x39) |
|---|
| 31 | |
|---|
| 32 | /* |
|---|
| 33 | * ------------------- |
|---|
| 34 | * --- zero_vector --- |
|---|
| 35 | * ------------------- |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| [826] | 38 | |
|---|
| 39 | #undef zero_type_vector |
|---|
| 40 | #define zero_type_vector(t) \ |
|---|
| 41 | void short_name(t,zero_,vector)(t * v, int32_t nl, int32_t nh) \ |
|---|
| 42 | { \ |
|---|
| 43 | for (int32_t i = nl; i <= nh; i++) { \ |
|---|
| 44 | v[i] = 0; \ |
|---|
| 45 | } \ |
|---|
| [772] | 46 | } |
|---|
| [826] | 47 | |
|---|
| 48 | zero_type_vector(int8_t); |
|---|
| 49 | zero_type_vector(uint8_t); |
|---|
| 50 | zero_type_vector(int16_t); |
|---|
| 51 | zero_type_vector(uint16_t); |
|---|
| 52 | zero_type_vector(int32_t); |
|---|
| 53 | zero_type_vector(uint32_t); |
|---|
| 54 | zero_type_vector(int64_t); |
|---|
| 55 | zero_type_vector(uint64_t); |
|---|
| 56 | zero_type_vector(float); |
|---|
| 57 | zero_type_vector(double); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | void zero_rgb8vector(rgb8 * v, int32_t nl, int32_t nh) |
|---|
| [772] | 61 | { |
|---|
| [826] | 62 | rgb8 z = {0, 0, 0}; |
|---|
| 63 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| 64 | v[i] = z; |
|---|
| 65 | } |
|---|
| [772] | 66 | } |
|---|
| [826] | 67 | |
|---|
| 68 | void zero_rgbx8vector(rgbx8 * v, int32_t nl, int32_t nh) |
|---|
| [772] | 69 | { |
|---|
| [826] | 70 | rgbx8 z; |
|---|
| 71 | z.r = 0; |
|---|
| 72 | z.g = 0; |
|---|
| 73 | z.b = 0; |
|---|
| 74 | z.x = 0; |
|---|
| 75 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| 76 | v[i] = z; |
|---|
| 77 | } |
|---|
| [772] | 78 | } |
|---|
| [826] | 79 | |
|---|
| 80 | |
|---|
| [772] | 81 | /* |
|---|
| 82 | * ------------------ |
|---|
| 83 | * --- set_vector --- |
|---|
| 84 | * ------------------ |
|---|
| 85 | */ |
|---|
| 86 | |
|---|
| [826] | 87 | |
|---|
| 88 | #undef set_type_vector |
|---|
| 89 | #define set_type_vector(t) \ |
|---|
| 90 | void short_name(t,set_,vector)(t * v, int32_t nl, int32_t nh, t x) \ |
|---|
| 91 | { \ |
|---|
| 92 | for (int32_t i = nl; i <= nh; i++) { \ |
|---|
| 93 | v[i] = x; \ |
|---|
| 94 | } \ |
|---|
| [772] | 95 | } |
|---|
| [826] | 96 | |
|---|
| 97 | set_type_vector(int8_t); |
|---|
| 98 | set_type_vector(uint8_t); |
|---|
| 99 | set_type_vector(int16_t); |
|---|
| 100 | set_type_vector(uint16_t); |
|---|
| 101 | set_type_vector(int32_t); |
|---|
| 102 | set_type_vector(uint32_t); |
|---|
| 103 | set_type_vector(int64_t); |
|---|
| 104 | set_type_vector(uint64_t); |
|---|
| 105 | set_type_vector(float); |
|---|
| 106 | set_type_vector(double); |
|---|
| 107 | set_type_vector(rgb8); |
|---|
| 108 | set_type_vector(rgbx8); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| [772] | 112 | /* |
|---|
| 113 | * ------------------------ |
|---|
| 114 | * --- set_vector_param --- |
|---|
| 115 | * ------------------------ |
|---|
| 116 | */ |
|---|
| [826] | 117 | |
|---|
| 118 | |
|---|
| 119 | #undef set_type_vector_param |
|---|
| 120 | #define set_type_vector_param(t) \ |
|---|
| 121 | void short_name(t,set_,vector_param)(t * v, int32_t nl, int32_t nh, t x, t xstep) \ |
|---|
| 122 | { \ |
|---|
| 123 | for (int32_t i = nl; i <= nh; i++) { \ |
|---|
| 124 | v[i] = x; \ |
|---|
| 125 | x += xstep; \ |
|---|
| 126 | } \ |
|---|
| [772] | 127 | } |
|---|
| [826] | 128 | |
|---|
| 129 | set_type_vector_param(int8_t); |
|---|
| 130 | set_type_vector_param(uint8_t); |
|---|
| 131 | set_type_vector_param(int16_t); |
|---|
| 132 | set_type_vector_param(uint16_t); |
|---|
| 133 | set_type_vector_param(int32_t); |
|---|
| 134 | set_type_vector_param(uint32_t); |
|---|
| 135 | set_type_vector_param(int64_t); |
|---|
| 136 | set_type_vector_param(uint64_t); |
|---|
| 137 | set_type_vector_param(float); |
|---|
| 138 | set_type_vector_param(double); |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | void set_rgb8vector_param(rgb8 * v, int32_t nl, int32_t nh, rgb8 x, rgb8 xstep) |
|---|
| [772] | 143 | { |
|---|
| [826] | 144 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| [772] | 145 | v[i] = x; |
|---|
| [826] | 146 | RGB8_ADD(x, xstep, x); |
|---|
| [772] | 147 | } |
|---|
| 148 | } |
|---|
| [826] | 149 | |
|---|
| 150 | void set_rgbx8vector_param(rgbx8 * v, int32_t nl, int32_t nh, rgbx8 x, rgbx8 xstep) |
|---|
| [772] | 151 | { |
|---|
| [826] | 152 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| [772] | 153 | v[i] = x; |
|---|
| [826] | 154 | RGBX8_ADD(x, xstep, x); |
|---|
| [772] | 155 | } |
|---|
| 156 | } |
|---|
| [826] | 157 | |
|---|
| 158 | |
|---|
| [772] | 159 | /* |
|---|
| 160 | * -------------------- |
|---|
| 161 | * --- set_vector_j --- |
|---|
| 162 | * -------------------- |
|---|
| 163 | */ |
|---|
| [826] | 164 | |
|---|
| 165 | #undef set_type_vector_j |
|---|
| 166 | #define set_type_vector_j(t) \ |
|---|
| 167 | void short_name(t,set_,vector_j)(t * v, int32_t nl, int32_t nh) \ |
|---|
| 168 | { \ |
|---|
| 169 | for (int32_t i = nl; i <= nh; i++) { \ |
|---|
| 170 | v[i] = (t) i; \ |
|---|
| 171 | } \ |
|---|
| [772] | 172 | } |
|---|
| [826] | 173 | |
|---|
| 174 | set_type_vector_j(int8_t); |
|---|
| 175 | set_type_vector_j(uint8_t); |
|---|
| 176 | set_type_vector_j(int16_t); |
|---|
| 177 | set_type_vector_j(uint16_t); |
|---|
| 178 | set_type_vector_j(int32_t); |
|---|
| 179 | set_type_vector_j(uint32_t); |
|---|
| 180 | set_type_vector_j(int64_t); |
|---|
| 181 | set_type_vector_j(uint64_t); |
|---|
| 182 | set_type_vector_j(float); |
|---|
| 183 | set_type_vector_j(double); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | void set_rgb8vector_j(rgb8 * v, int32_t nl, int32_t nh) |
|---|
| [772] | 187 | { |
|---|
| [826] | 188 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| 189 | v[i].r = (uint8) i; |
|---|
| [772] | 190 | v[i].g = (uint8) i; |
|---|
| 191 | v[i].b = (uint8) i; |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| [826] | 194 | |
|---|
| 195 | |
|---|
| 196 | void set_rgbx8vector_j(rgbx8 * v, int32_t nl, int32_t nh) |
|---|
| [772] | 197 | { |
|---|
| [826] | 198 | for (int32_t i = nl; i <= nh; i++) { |
|---|
| 199 | v[i].r = (uint8) i; |
|---|
| [772] | 200 | v[i].g = (uint8) i; |
|---|
| 201 | v[i].b = (uint8) i; |
|---|
| 202 | v[i].x = (uint8) 255; |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| [826] | 206 | |
|---|
| [772] | 207 | /* |
|---|
| 208 | * ---------------------- |
|---|
| 209 | * --- set_vector_str --- |
|---|
| 210 | * ---------------------- |
|---|
| 211 | */ |
|---|
| 212 | |
|---|
| 213 | |
|---|
| [826] | 214 | #undef set_type_vector_str |
|---|
| 215 | #define set_type_vector_str(t) \ |
|---|
| 216 | void short_name(t,set_,vector_str)(t * v, int32_t nl, int32_t nh, char * str) \ |
|---|
| 217 | { \ |
|---|
| 218 | char c[2]; \ |
|---|
| 219 | c[1] = '\0'; \ |
|---|
| 220 | for (int32_t i = nl; i <= nh; i++) { \ |
|---|
| 221 | c[0] = *str++; \ |
|---|
| 222 | if (isdigit(c[0])) { \ |
|---|
| 223 | v[i] = (t) atoi(c); \ |
|---|
| 224 | } \ |
|---|
| 225 | else { \ |
|---|
| 226 | v[i] = (t) 0; \ |
|---|
| 227 | } \ |
|---|
| 228 | } \ |
|---|
| [772] | 229 | } |
|---|
| [826] | 230 | |
|---|
| 231 | set_type_vector_str(int8_t); |
|---|
| 232 | set_type_vector_str(uint8_t); |
|---|
| 233 | set_type_vector_str(int16_t); |
|---|
| 234 | set_type_vector_str(uint16_t); |
|---|
| 235 | set_type_vector_str(int32_t); |
|---|
| 236 | set_type_vector_str(uint32_t); |
|---|
| 237 | set_type_vector_str(int64_t); |
|---|
| 238 | set_type_vector_str(uint64_t); |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | // Local Variables: |
|---|
| 242 | // tab-width: 4 |
|---|
| 243 | // c-basic-offset: 4 |
|---|
| 244 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 245 | // indent-tabs-mode: nil |
|---|
| 246 | // End: |
|---|
| 247 | |
|---|
| 248 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 249 | |
|---|