[772] | 1 | /* ---------------- */ |
---|
| 2 | /* --- nrset2.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 | |
---|
| 15 | #include <stdio.h> |
---|
| 16 | #include <stddef.h> |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | |
---|
| 19 | #include "mypredef.h" |
---|
| 20 | #include "nrtype.h" |
---|
| 21 | #include "nrdef.h" |
---|
| 22 | #include "nrmacro.h" |
---|
| 23 | #include "nrkernel.h" |
---|
| 24 | |
---|
| 25 | #include "nrset1.h" |
---|
| 26 | #include "nrset2.h" |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * ------------ |
---|
| 30 | * --- Zero --- |
---|
| 31 | * ------------ |
---|
| 32 | */ |
---|
| 33 | |
---|
[826] | 34 | |
---|
| 35 | #undef zero_type_matrix |
---|
| 36 | #define zero_type_matrix(t) \ |
---|
| 37 | void short_name(t,zero_,matrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) \ |
---|
| 38 | { \ |
---|
| 39 | for (int32_t i = i0; i <= i1; i++) { \ |
---|
| 40 | short_name(t,zero_,vector)(m[i], j0, j1); \ |
---|
| 41 | } \ |
---|
[772] | 42 | } |
---|
[826] | 43 | |
---|
| 44 | zero_type_matrix(int8_t); |
---|
| 45 | zero_type_matrix(uint8_t); |
---|
| 46 | zero_type_matrix(int16_t); |
---|
| 47 | zero_type_matrix(uint16_t); |
---|
| 48 | zero_type_matrix(int32_t); |
---|
| 49 | zero_type_matrix(uint32_t); |
---|
| 50 | zero_type_matrix(int64_t); |
---|
| 51 | zero_type_matrix(uint64_t); |
---|
| 52 | zero_type_matrix(float); |
---|
| 53 | zero_type_matrix(double); |
---|
| 54 | zero_type_matrix(rgb8); |
---|
| 55 | zero_type_matrix(rgbx8); |
---|
| 56 | |
---|
[772] | 57 | /* |
---|
| 58 | * ------------------ |
---|
| 59 | * --- set_matrix --- |
---|
| 60 | * ------------------ |
---|
| 61 | */ |
---|
| 62 | |
---|
[826] | 63 | #undef set_type_matrix |
---|
| 64 | #define set_type_matrix(t) \ |
---|
| 65 | void short_name(t,set_,matrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, t x) \ |
---|
| 66 | { \ |
---|
| 67 | for (int32_t i = i0; i <= i1; i++) { \ |
---|
| 68 | short_name(t,set_,vector)(m[i], j0, j1, x); \ |
---|
| 69 | } \ |
---|
[772] | 70 | } |
---|
[826] | 71 | |
---|
| 72 | set_type_matrix(int8_t); |
---|
| 73 | set_type_matrix(uint8_t); |
---|
| 74 | set_type_matrix(int16_t); |
---|
| 75 | set_type_matrix(uint16_t); |
---|
| 76 | set_type_matrix(int32_t); |
---|
| 77 | set_type_matrix(uint32_t); |
---|
| 78 | set_type_matrix(int64_t); |
---|
| 79 | set_type_matrix(uint64_t); |
---|
| 80 | set_type_matrix(float); |
---|
| 81 | set_type_matrix(double); |
---|
| 82 | set_type_matrix(rgb8); |
---|
| 83 | set_type_matrix(rgbx8); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
[772] | 87 | /* |
---|
| 88 | * ---------------- |
---|
| 89 | * set_matrix_param |
---|
| 90 | * ---------------- |
---|
| 91 | */ |
---|
[826] | 92 | |
---|
| 93 | #undef set_type_matrix_param |
---|
| 94 | #define set_type_matrix_param(t) \ |
---|
| 95 | void short_name(t,set_,matrix_param)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, t x, t xstep, t ystep) \ |
---|
| 96 | { \ |
---|
| 97 | for (int32_t i = i0; i <= i1; i++) { \ |
---|
| 98 | short_name(t,set_,vector_param)(m[i], j0, j1, x, xstep); \ |
---|
| 99 | x += ystep; \ |
---|
| 100 | } \ |
---|
[772] | 101 | } |
---|
[826] | 102 | |
---|
| 103 | set_type_matrix_param(int8_t); |
---|
| 104 | set_type_matrix_param(uint8_t); |
---|
| 105 | set_type_matrix_param(int16_t); |
---|
| 106 | set_type_matrix_param(uint16_t); |
---|
| 107 | set_type_matrix_param(int32_t); |
---|
| 108 | set_type_matrix_param(uint32_t); |
---|
| 109 | set_type_matrix_param(int64_t); |
---|
| 110 | set_type_matrix_param(uint64_t); |
---|
| 111 | set_type_matrix_param(float); |
---|
| 112 | set_type_matrix_param(double); |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | void set_rgb8matrix_param(rgb8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, rgb8 x, rgb8 xstep, rgb8 ystep) |
---|
[772] | 116 | { |
---|
[826] | 117 | for (int32_t i = i0; i <= i1; i++) { |
---|
[772] | 118 | set_rgb8vector_param(m[i], j0, j1, x, xstep); |
---|
| 119 | x.r += ystep.r; |
---|
| 120 | x.g += ystep.g; |
---|
| 121 | x.b += ystep.b; |
---|
| 122 | } |
---|
| 123 | } |
---|
[826] | 124 | |
---|
| 125 | void set_rgbx8matrix_param(rgbx8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, rgbx8 x, rgbx8 xstep, rgbx8 ystep) |
---|
[772] | 126 | { |
---|
| 127 | x.x = 0; |
---|
[826] | 128 | for (int32_t i = i0; i <= i1; i++) { |
---|
[772] | 129 | set_rgbx8vector_param(m[i], j0, j1, x, xstep); |
---|
| 130 | x.r += ystep.r; |
---|
| 131 | x.g += ystep.g; |
---|
| 132 | x.b += ystep.b; |
---|
[826] | 133 | x.x += ystep.x; |
---|
[772] | 134 | } |
---|
| 135 | } |
---|
[826] | 136 | |
---|
| 137 | |
---|
[772] | 138 | /* |
---|
| 139 | * -------------------- |
---|
| 140 | * --- set_matrix_i --- |
---|
| 141 | * -------------------- |
---|
| 142 | */ |
---|
[826] | 143 | |
---|
| 144 | #undef set_type_matrix_i |
---|
| 145 | #define set_type_matrix_i(t) \ |
---|
| 146 | void short_name(t,set_,matrix_i)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) \ |
---|
| 147 | { \ |
---|
| 148 | short_name(t,set_,matrix_param)(m, i0, i1, j0, j1, i0, 0, 1); \ |
---|
[772] | 149 | } |
---|
[826] | 150 | |
---|
| 151 | set_type_matrix_i(int8_t); |
---|
| 152 | set_type_matrix_i(uint8_t); |
---|
| 153 | set_type_matrix_i(int16_t); |
---|
| 154 | set_type_matrix_i(uint16_t); |
---|
| 155 | set_type_matrix_i(int32_t); |
---|
| 156 | set_type_matrix_i(uint32_t); |
---|
| 157 | set_type_matrix_i(int64_t); |
---|
| 158 | set_type_matrix_i(uint64_t); |
---|
| 159 | set_type_matrix_i(float); |
---|
| 160 | set_type_matrix_i(double); |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | void set_rgb8matrix_i(rgb8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) |
---|
[772] | 164 | { |
---|
[826] | 165 | rgb8 x0; |
---|
| 166 | rgb8 xstep; |
---|
| 167 | rgb8 ystep; |
---|
[772] | 168 | |
---|
| 169 | x0.r = x0.g = x0.b = i0; |
---|
| 170 | xstep.r = xstep.g = xstep.b = 0; |
---|
| 171 | ystep.r = ystep.g = ystep.b = 1; |
---|
| 172 | |
---|
| 173 | set_rgb8matrix_param(m, i0, i1, j0, j1, x0, xstep, ystep); |
---|
| 174 | } |
---|
[826] | 175 | |
---|
| 176 | |
---|
| 177 | void set_rgbx8matrix_i(rgbx8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) |
---|
[772] | 178 | { |
---|
[826] | 179 | rgbx8 x; |
---|
| 180 | rgbx8 xstep; |
---|
| 181 | rgbx8 ystep; |
---|
[772] | 182 | |
---|
[826] | 183 | x.r = x.g = x.b = i0; |
---|
| 184 | x.x = 255; |
---|
| 185 | xstep.r = xstep.g = xstep.b = 0; |
---|
| 186 | xstep.x = 255; |
---|
| 187 | ystep.r = ystep.g = ystep.b = 1; |
---|
| 188 | ystep.x = 255; |
---|
[772] | 189 | |
---|
| 190 | set_rgbx8matrix_param(m, i0, i1, j0, j1, x, xstep, ystep); |
---|
| 191 | } |
---|
[826] | 192 | |
---|
| 193 | |
---|
[772] | 194 | /* |
---|
| 195 | * -------------------- |
---|
| 196 | * --- set_matrix_j --- |
---|
| 197 | * -------------------- |
---|
| 198 | */ |
---|
[826] | 199 | |
---|
| 200 | #undef set_type_matrix_j |
---|
| 201 | #define set_type_matrix_j(t) \ |
---|
| 202 | void short_name(t,set_,matrix_j)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) \ |
---|
| 203 | { \ |
---|
| 204 | short_name(t,set_,matrix_param)(m, i0, i1, j0, j1, j0, 1, 0); \ |
---|
[772] | 205 | } |
---|
[826] | 206 | |
---|
| 207 | set_type_matrix_j(int8_t); |
---|
| 208 | set_type_matrix_j(uint8_t); |
---|
| 209 | set_type_matrix_j(int16_t); |
---|
| 210 | set_type_matrix_j(uint16_t); |
---|
| 211 | set_type_matrix_j(int32_t); |
---|
| 212 | set_type_matrix_j(uint32_t); |
---|
| 213 | set_type_matrix_j(int64_t); |
---|
| 214 | set_type_matrix_j(uint64_t); |
---|
| 215 | set_type_matrix_j(float); |
---|
| 216 | set_type_matrix_j(double); |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | void set_rgb8matrix_j(rgb8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) |
---|
[772] | 221 | { |
---|
[826] | 222 | rgb8 x; |
---|
| 223 | rgb8 xstep; |
---|
| 224 | rgb8 ystep; |
---|
[772] | 225 | |
---|
[826] | 226 | x.r = x.g = x.b = j0; |
---|
[772] | 227 | xstep.r = xstep.g = xstep.b = 1; |
---|
| 228 | ystep.r = ystep.g = ystep.b = 0; |
---|
| 229 | |
---|
| 230 | set_rgb8matrix_param(m, i0, i1, j0, j1, x, xstep, ystep); |
---|
| 231 | } |
---|
[826] | 232 | |
---|
| 233 | void set_rgbx8matrix_j(rgbx8 ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1) |
---|
[772] | 234 | { |
---|
| 235 | rgbx8 x, xstep, ystep; |
---|
| 236 | |
---|
[826] | 237 | x.r = x.g = x.b = j0; |
---|
| 238 | x.x = 255; |
---|
| 239 | xstep.r = xstep.g = xstep.b = 1; |
---|
| 240 | xstep.x = 255; |
---|
| 241 | ystep.r = ystep.g = ystep.b = 0; |
---|
| 242 | ystep.x = 255; |
---|
[772] | 243 | |
---|
| 244 | set_rgbx8matrix_param(m, i0, i1, j0, j1, x, xstep, ystep); |
---|
[826] | 245 | } |
---|
| 246 | |
---|
| 247 | /* |
---|
[772] | 248 | * -------------- |
---|
| 249 | * --- autres --- |
---|
| 250 | * -------------- |
---|
| 251 | */ |
---|
[826] | 252 | |
---|
| 253 | #undef set_type_matrix_border1 |
---|
| 254 | #define set_type_matrix_border1(t) \ |
---|
| 255 | void short_name(t,set_,matrix_border1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, t x) \ |
---|
| 256 | { \ |
---|
| 257 | short_name(t,set_,vector)(m[i0], j0, j1, x); \ |
---|
| 258 | for (int32_t i = i0 + 1; i <= i1 - 1; i++) { \ |
---|
| 259 | m[i][j0] = x; \ |
---|
| 260 | m[i][j1] = x; \ |
---|
| 261 | } \ |
---|
| 262 | short_name(t,set_,vector)(m[i0], j0, j1, x); \ |
---|
[772] | 263 | } |
---|
[826] | 264 | |
---|
| 265 | |
---|
| 266 | set_type_matrix_border1(int8_t); |
---|
| 267 | set_type_matrix_border1(uint8_t); |
---|
| 268 | set_type_matrix_border1(int16_t); |
---|
| 269 | set_type_matrix_border1(uint16_t); |
---|
| 270 | set_type_matrix_border1(int32_t); |
---|
| 271 | set_type_matrix_border1(uint32_t); |
---|
| 272 | set_type_matrix_border1(int64_t); |
---|
| 273 | set_type_matrix_border1(uint64_t); |
---|
| 274 | set_type_matrix_border1(float); |
---|
| 275 | set_type_matrix_border1(double); |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | #undef set_type_matrix_border |
---|
| 279 | #define set_type_matrix_border(t) \ |
---|
| 280 | void short_name(t,set_,matrix_border)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t n, t x) \ |
---|
| 281 | { \ |
---|
| 282 | t * Xi = NULL; \ |
---|
| 283 | for (int32_t i = i0; i < i0 + n; i++) { \ |
---|
| 284 | Xi = m[i]; \ |
---|
| 285 | for (int32_t j = j0; j <= j1; j++) { \ |
---|
| 286 | Xi[j] = x; \ |
---|
| 287 | } \ |
---|
| 288 | } \ |
---|
| 289 | for (int32_t i = i0 + n; i < i1; i++) { \ |
---|
| 290 | Xi = m[i]; \ |
---|
| 291 | for (int32_t j = 0; j < n; j++) { \ |
---|
| 292 | Xi[j0 + j] = x; \ |
---|
| 293 | Xi[j1 - j] = x; \ |
---|
| 294 | } \ |
---|
| 295 | } \ |
---|
| 296 | for (int32_t i = i1 - n + 1; i <= i1; i++) { \ |
---|
| 297 | Xi = m[i]; \ |
---|
| 298 | for (int32_t j = j0; j <= j1; j++) { \ |
---|
| 299 | Xi[j] = x; \ |
---|
| 300 | } \ |
---|
| 301 | } \ |
---|
[772] | 302 | } |
---|
[826] | 303 | |
---|
| 304 | |
---|
| 305 | set_type_matrix_border(int8_t); |
---|
| 306 | set_type_matrix_border(uint8_t); |
---|
| 307 | set_type_matrix_border(int16_t); |
---|
| 308 | set_type_matrix_border(uint16_t); |
---|
| 309 | set_type_matrix_border(int32_t); |
---|
| 310 | set_type_matrix_border(uint32_t); |
---|
| 311 | set_type_matrix_border(int64_t); |
---|
| 312 | set_type_matrix_border(uint64_t); |
---|
| 313 | set_type_matrix_border(float); |
---|
| 314 | set_type_matrix_border(double); |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | // Local Variables: |
---|
| 318 | // tab-width: 4 |
---|
| 319 | // c-basic-offset: 4 |
---|
| 320 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 321 | // indent-tabs-mode: nil |
---|
| 322 | // End: |
---|
| 323 | |
---|
| 324 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 325 | |
---|