[772] | 1 | /* ------------------ */ |
---|
| 2 | /* --- nrarith2.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 <malloc.h> |
---|
| 18 | #include <math.h> // fabs |
---|
| 19 | |
---|
[821] | 20 | #include "nrc_os_config.h" |
---|
[772] | 21 | #include "mypredef.h" |
---|
| 22 | #include "nrtype.h" |
---|
| 23 | #include "nrdef.h" |
---|
| 24 | #include "nrmacro.h" |
---|
| 25 | #include "nrkernel.h" |
---|
| 26 | |
---|
| 27 | #include "nrarith2.h" |
---|
| 28 | |
---|
| 29 | /* ------------------ */ |
---|
| 30 | /* --- min_matrix --- */ |
---|
| 31 | /* ------------------ */ |
---|
| 32 | |
---|
[821] | 33 | #undef min_type_matrix |
---|
| 34 | #define min_type_matrix(t) \ |
---|
| 35 | t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
| 36 | { \ |
---|
| 37 | t minimum = m[nrl][nrh]; \ |
---|
| 38 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 39 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 40 | if (m[i][j] < minimum) { \ |
---|
| 41 | minimum = m[i][j]; \ |
---|
| 42 | } \ |
---|
| 43 | } \ |
---|
| 44 | } \ |
---|
| 45 | return minimum; \ |
---|
[772] | 46 | } |
---|
| 47 | |
---|
[821] | 48 | min_type_matrix(int8_t); |
---|
| 49 | min_type_matrix(uint8_t); |
---|
| 50 | min_type_matrix(int16_t); |
---|
| 51 | min_type_matrix(uint16_t); |
---|
| 52 | min_type_matrix(int32_t); |
---|
| 53 | min_type_matrix(uint32_t); |
---|
| 54 | min_type_matrix(int64_t); |
---|
| 55 | min_type_matrix(uint64_t); |
---|
| 56 | min_type_matrix(float); |
---|
| 57 | min_type_matrix(double); |
---|
| 58 | |
---|
| 59 | |
---|
[772] | 60 | /* ------------------ */ |
---|
| 61 | /* --- max_matrix --- */ |
---|
| 62 | /* ------------------ */ |
---|
| 63 | |
---|
[821] | 64 | #undef max_type_matrix |
---|
| 65 | #define max_type_matrix(t) \ |
---|
| 66 | t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ |
---|
| 67 | { \ |
---|
| 68 | t maximum = m[nrl][nrh]; \ |
---|
| 69 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 70 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 71 | if (m[i][j] > maximum) { \ |
---|
| 72 | maximum = m[i][j]; \ |
---|
| 73 | } \ |
---|
| 74 | } \ |
---|
| 75 | } \ |
---|
| 76 | return maximum; \ |
---|
[772] | 77 | } |
---|
| 78 | |
---|
[821] | 79 | max_type_matrix(int8_t); |
---|
| 80 | max_type_matrix(uint8_t); |
---|
| 81 | max_type_matrix(int16_t); |
---|
| 82 | max_type_matrix(uint16_t); |
---|
| 83 | max_type_matrix(int32_t); |
---|
| 84 | max_type_matrix(uint32_t); |
---|
| 85 | max_type_matrix(int64_t); |
---|
| 86 | max_type_matrix(uint64_t); |
---|
| 87 | max_type_matrix(float); |
---|
| 88 | max_type_matrix(double); |
---|
[772] | 89 | |
---|
[821] | 90 | |
---|
| 91 | |
---|
[772] | 92 | /* ------------------ */ |
---|
| 93 | /* --- Add Matrix --- */ |
---|
| 94 | /* ------------------ */ |
---|
| 95 | |
---|
[821] | 96 | |
---|
| 97 | #undef add_type_matrix |
---|
| 98 | #define add_type_matrix(t) \ |
---|
| 99 | void short_name(t,add_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \ |
---|
| 100 | { \ |
---|
| 101 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 102 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 103 | Z[i][j] = X[i][j] + Y[i][j]; \ |
---|
| 104 | } \ |
---|
| 105 | } \ |
---|
[772] | 106 | } |
---|
[821] | 107 | |
---|
| 108 | add_type_matrix(int8_t); |
---|
| 109 | add_type_matrix(uint8_t); |
---|
| 110 | add_type_matrix(int16_t); |
---|
| 111 | add_type_matrix(uint16_t); |
---|
| 112 | add_type_matrix(int32_t); |
---|
| 113 | add_type_matrix(uint32_t); |
---|
| 114 | add_type_matrix(int64_t); |
---|
| 115 | add_type_matrix(uint64_t); |
---|
| 116 | add_type_matrix(float); |
---|
| 117 | add_type_matrix(double); |
---|
| 118 | |
---|
| 119 | |
---|
[772] | 120 | /* ----------------------------------------------------------------------------------------------- */ |
---|
[821] | 121 | void add_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z) |
---|
[772] | 122 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 123 | { |
---|
[821] | 124 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 125 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 126 | //z = x + y; |
---|
| 127 | RGB8_ADD(X[i][j], Y[i][j], Z[i][j]); |
---|
| 128 | } |
---|
| 129 | } |
---|
[772] | 130 | } |
---|
[821] | 131 | |
---|
[772] | 132 | /* --------------------------------------------------------------------------------------------------- */ |
---|
[821] | 133 | void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z) |
---|
[772] | 134 | /* --------------------------------------------------------------------------------------------------- */ |
---|
| 135 | { |
---|
[821] | 136 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 137 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 138 | //z = x + y; |
---|
| 139 | RGBX8_ADD(X[i][j], Y[i][j], Z[i][j]); |
---|
| 140 | } |
---|
| 141 | } |
---|
[772] | 142 | } |
---|
| 143 | |
---|
| 144 | /* -------------------- */ |
---|
| 145 | /* --- Add constant --- */ |
---|
| 146 | /* -------------------- */ |
---|
| 147 | |
---|
[821] | 148 | #undef addc_type_matrix |
---|
| 149 | #define addc_type_matrix(t) \ |
---|
| 150 | void short_name(t,addc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ |
---|
| 151 | { \ |
---|
| 152 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 153 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 154 | Z[i][j] = X[i][j] + y; \ |
---|
| 155 | } \ |
---|
| 156 | } \ |
---|
[772] | 157 | } |
---|
[821] | 158 | |
---|
| 159 | addc_type_matrix(int8_t); |
---|
| 160 | addc_type_matrix(uint8_t); |
---|
| 161 | addc_type_matrix(int16_t); |
---|
| 162 | addc_type_matrix(uint16_t); |
---|
| 163 | addc_type_matrix(int32_t); |
---|
| 164 | addc_type_matrix(uint32_t); |
---|
| 165 | addc_type_matrix(int64_t); |
---|
| 166 | addc_type_matrix(uint64_t); |
---|
| 167 | addc_type_matrix(float); |
---|
| 168 | addc_type_matrix(double); |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | |
---|
[772] | 172 | /* ---------------------------------------------------------------------------------------------- */ |
---|
[821] | 173 | void addc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) |
---|
[772] | 174 | /* ---------------------------------------------------------------------------------------------- */ |
---|
| 175 | { |
---|
[821] | 176 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 177 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 178 | RGB8_ADD(X[i][j], y, Z[i][j]); |
---|
| 179 | } |
---|
| 180 | } |
---|
[772] | 181 | } |
---|
[821] | 182 | |
---|
[772] | 183 | /* -------------------------------------------------------------------------------------------------- */ |
---|
[821] | 184 | void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) |
---|
[772] | 185 | /* -------------------------------------------------------------------------------------------------- */ |
---|
| 186 | { |
---|
[821] | 187 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 188 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 189 | RGBX8_ADD(X[i][j], y, Z[i][j]); |
---|
| 190 | } |
---|
| 191 | } |
---|
[772] | 192 | } |
---|
[821] | 193 | |
---|
| 194 | |
---|
[772] | 195 | /* ------------------ */ |
---|
[821] | 196 | /* --- Sub Matrix --- */ |
---|
[772] | 197 | /* ------------------ */ |
---|
| 198 | |
---|
[821] | 199 | #undef sub_type_matrix |
---|
| 200 | #define sub_type_matrix(t) \ |
---|
| 201 | void short_name(t,sub_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \ |
---|
| 202 | { \ |
---|
| 203 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 204 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 205 | Z[i][j] = X[i][j] - Y[i][j]; \ |
---|
| 206 | } \ |
---|
| 207 | } \ |
---|
[772] | 208 | } |
---|
[821] | 209 | |
---|
| 210 | sub_type_matrix(int8_t); |
---|
| 211 | sub_type_matrix(uint8_t); |
---|
| 212 | sub_type_matrix(int16_t); |
---|
| 213 | sub_type_matrix(uint16_t); |
---|
| 214 | sub_type_matrix(int32_t); |
---|
| 215 | sub_type_matrix(uint32_t); |
---|
| 216 | sub_type_matrix(int64_t); |
---|
| 217 | sub_type_matrix(uint64_t); |
---|
| 218 | sub_type_matrix(float); |
---|
| 219 | sub_type_matrix(double); |
---|
| 220 | |
---|
| 221 | |
---|
[772] | 222 | /* ----------------------------------------------------------------------------------------------- */ |
---|
[821] | 223 | void sub_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z) |
---|
[772] | 224 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 225 | { |
---|
[821] | 226 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 227 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 228 | //z = x + y; |
---|
| 229 | RGB8_SUB(X[i][j], Y[i][j], Z[i][j]); |
---|
| 230 | } |
---|
| 231 | } |
---|
[772] | 232 | } |
---|
[821] | 233 | |
---|
[772] | 234 | /* --------------------------------------------------------------------------------------------------- */ |
---|
[821] | 235 | void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z) |
---|
[772] | 236 | /* --------------------------------------------------------------------------------------------------- */ |
---|
| 237 | { |
---|
[821] | 238 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 239 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 240 | //z = x + y; |
---|
| 241 | RGBX8_SUB(X[i][j], Y[i][j], Z[i][j]); |
---|
| 242 | } |
---|
| 243 | } |
---|
[772] | 244 | } |
---|
| 245 | |
---|
[821] | 246 | |
---|
[772] | 247 | /* -------------------- */ |
---|
| 248 | /* --- Sub constant --- */ |
---|
| 249 | /* -------------------- */ |
---|
| 250 | |
---|
[821] | 251 | #undef subc_type_matrix |
---|
| 252 | #define subc_type_matrix(t) \ |
---|
| 253 | void short_name(t,subc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ |
---|
| 254 | { \ |
---|
| 255 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 256 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 257 | Z[i][j] = X[i][j] - y; \ |
---|
| 258 | } \ |
---|
| 259 | } \ |
---|
[772] | 260 | } |
---|
[821] | 261 | |
---|
| 262 | subc_type_matrix(int8_t); |
---|
| 263 | subc_type_matrix(uint8_t); |
---|
| 264 | subc_type_matrix(int16_t); |
---|
| 265 | subc_type_matrix(uint16_t); |
---|
| 266 | subc_type_matrix(int32_t); |
---|
| 267 | subc_type_matrix(uint32_t); |
---|
| 268 | subc_type_matrix(int64_t); |
---|
| 269 | subc_type_matrix(uint64_t); |
---|
| 270 | subc_type_matrix(float); |
---|
| 271 | subc_type_matrix(double); |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | |
---|
[772] | 275 | /* ---------------------------------------------------------------------------------------------- */ |
---|
[821] | 276 | void subc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) |
---|
[772] | 277 | /* ---------------------------------------------------------------------------------------------- */ |
---|
| 278 | { |
---|
[821] | 279 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 280 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 281 | RGB8_SUB(X[i][j], y, Z[i][j]); |
---|
| 282 | } |
---|
| 283 | } |
---|
[772] | 284 | } |
---|
[821] | 285 | |
---|
[772] | 286 | /* -------------------------------------------------------------------------------------------------- */ |
---|
[821] | 287 | void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) |
---|
[772] | 288 | /* -------------------------------------------------------------------------------------------------- */ |
---|
| 289 | { |
---|
[821] | 290 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 291 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 292 | RGBX8_SUB(X[i][j], y, Z[i][j]); |
---|
| 293 | } |
---|
| 294 | } |
---|
[772] | 295 | } |
---|
[821] | 296 | |
---|
| 297 | |
---|
[772] | 298 | /* -------------------- */ |
---|
| 299 | /* --- Mul constant --- */ |
---|
| 300 | /* -------------------- */ |
---|
| 301 | |
---|
[821] | 302 | #undef mulc_type_matrix |
---|
| 303 | #define mulc_type_matrix(t) \ |
---|
| 304 | void short_name(t,mulc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ |
---|
| 305 | { \ |
---|
| 306 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 307 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 308 | Z[i][j] = X[i][j] * y; \ |
---|
| 309 | } \ |
---|
| 310 | } \ |
---|
[772] | 311 | } |
---|
[821] | 312 | |
---|
| 313 | mulc_type_matrix(int8_t); |
---|
| 314 | mulc_type_matrix(uint8_t); |
---|
| 315 | mulc_type_matrix(int16_t); |
---|
| 316 | mulc_type_matrix(uint16_t); |
---|
| 317 | mulc_type_matrix(int32_t); |
---|
| 318 | mulc_type_matrix(uint32_t); |
---|
| 319 | mulc_type_matrix(int64_t); |
---|
| 320 | mulc_type_matrix(uint64_t); |
---|
| 321 | mulc_type_matrix(float); |
---|
| 322 | mulc_type_matrix(double); |
---|
| 323 | |
---|
| 324 | |
---|
| 325 | |
---|
[772] | 326 | /* ---------------------------------------------------------------------------------------------- */ |
---|
[821] | 327 | void mulc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) |
---|
[772] | 328 | /* ---------------------------------------------------------------------------------------------- */ |
---|
| 329 | { |
---|
[821] | 330 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 331 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 332 | RGB8_MUL(X[i][j], y, Z[i][j]); |
---|
| 333 | } |
---|
| 334 | } |
---|
[772] | 335 | } |
---|
[821] | 336 | |
---|
[772] | 337 | /* -------------------------------------------------------------------------------------------------- */ |
---|
[821] | 338 | void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) |
---|
[772] | 339 | /* -------------------------------------------------------------------------------------------------- */ |
---|
| 340 | { |
---|
[821] | 341 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 342 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 343 | RGBX8_MUL(X[i][j], y, Z[i][j]); |
---|
| 344 | } |
---|
| 345 | } |
---|
[772] | 346 | } |
---|
[821] | 347 | |
---|
| 348 | |
---|
[772] | 349 | /* --------------- */ |
---|
| 350 | /* --- MulFrac --- */ |
---|
| 351 | /* --------------- */ |
---|
| 352 | |
---|
[821] | 353 | // Y = (a * X) / b |
---|
[772] | 354 | |
---|
[821] | 355 | #undef mulfrac_type_matrix |
---|
| 356 | #define mulfrac_type_matrix(t) \ |
---|
| 357 | void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ |
---|
| 358 | int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y) \ |
---|
| 359 | { \ |
---|
| 360 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 361 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 362 | Y[i][j] = (t) ((a * X[i][j]) / b); \ |
---|
| 363 | } \ |
---|
| 364 | } \ |
---|
[772] | 365 | } |
---|
[821] | 366 | |
---|
| 367 | mulfrac_type_matrix(int8_t); |
---|
| 368 | mulfrac_type_matrix(uint8_t); |
---|
| 369 | mulfrac_type_matrix(int16_t); |
---|
| 370 | mulfrac_type_matrix(uint16_t); |
---|
| 371 | mulfrac_type_matrix(int32_t); |
---|
| 372 | mulfrac_type_matrix(uint32_t); |
---|
| 373 | mulfrac_type_matrix(int64_t); |
---|
| 374 | mulfrac_type_matrix(uint64_t); |
---|
| 375 | mulfrac_type_matrix(float); |
---|
| 376 | mulfrac_type_matrix(double); |
---|
| 377 | |
---|
| 378 | |
---|
[772] | 379 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
[821] | 380 | void mulfrac_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 b, rgb8 ** Y) |
---|
[772] | 381 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 382 | { |
---|
[821] | 383 | rgb32 y32; |
---|
| 384 | rgb8 x8, y8; |
---|
| 385 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 386 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 387 | x8 = X[i][j]; |
---|
| 388 | RGB8_MULFRAC(x8, a, b, y32); |
---|
| 389 | RGB32CAST8(y32, y8); |
---|
| 390 | Y[i][j] = y8; |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | } |
---|
[772] | 394 | |
---|
| 395 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
[821] | 396 | void mulfrac_rgb8xmatrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 b, rgbx8 ** Y) |
---|
[772] | 397 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 398 | { |
---|
[821] | 399 | rgbx32 y32; |
---|
| 400 | rgbx8 x8, y8; |
---|
| 401 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 402 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 403 | x8 = X[i][j]; |
---|
| 404 | RGBX8_MULFRAC(x8, a, b, y32); |
---|
| 405 | RGBX32CAST8(y32, y8); |
---|
| 406 | Y[i][j] = y8; |
---|
| 407 | } |
---|
| 408 | } |
---|
[772] | 409 | } |
---|
| 410 | |
---|
[821] | 411 | |
---|
[772] | 412 | /* ---------------- */ |
---|
| 413 | /* --- MulShift --- */ |
---|
| 414 | /* ---------------- */ |
---|
| 415 | |
---|
[821] | 416 | // m3 = (a * m1) >> s |
---|
[772] | 417 | |
---|
[821] | 418 | #undef mulshift_type_matrix |
---|
| 419 | #define mulshift_type_matrix(t) \ |
---|
| 420 | void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ |
---|
| 421 | int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y) \ |
---|
| 422 | { \ |
---|
| 423 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
| 424 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
| 425 | Y[i][j] = (t) ((a * X[i][j]) >> s); \ |
---|
| 426 | } \ |
---|
| 427 | } \ |
---|
[772] | 428 | } |
---|
[821] | 429 | |
---|
| 430 | mulshift_type_matrix(int8_t); |
---|
| 431 | mulshift_type_matrix(uint8_t); |
---|
| 432 | mulshift_type_matrix(int16_t); |
---|
| 433 | mulshift_type_matrix(uint16_t); |
---|
| 434 | mulshift_type_matrix(int32_t); |
---|
| 435 | mulshift_type_matrix(uint32_t); |
---|
| 436 | mulshift_type_matrix(int64_t); |
---|
| 437 | mulshift_type_matrix(uint64_t); |
---|
| 438 | |
---|
| 439 | |
---|
[772] | 440 | /* ---------------------------------------------------------------------------------------------------------------- */ |
---|
[821] | 441 | void mulshift_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 s, rgb8 ** Y) |
---|
[772] | 442 | /* ---------------------------------------------------------------------------------------------------------------- */ |
---|
| 443 | { |
---|
[821] | 444 | rgb32 y32; |
---|
| 445 | rgb8 x8, y8; |
---|
| 446 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 447 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 448 | x8 = X[i][j]; |
---|
| 449 | RGB8_MULSHIFT(x8, a, s, y32); |
---|
| 450 | RGB32CAST8(y32, y8); |
---|
| 451 | Y[i][j] = y8; |
---|
| 452 | } |
---|
| 453 | } |
---|
[772] | 454 | } |
---|
[821] | 455 | |
---|
[772] | 456 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
[821] | 457 | void mulshift_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** Y) |
---|
[772] | 458 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 459 | { |
---|
[821] | 460 | rgbx32 y32; |
---|
| 461 | rgbx8 x8, y8; |
---|
| 462 | for (int32_t i = nrl; i <= nrh; i++) { |
---|
| 463 | for (int32_t j = ncl; j <= nch; j++) { |
---|
| 464 | x8 = X[i][j]; |
---|
| 465 | RGBX8_MULSHIFT(x8, a, s, y32); |
---|
| 466 | RGBX32CAST8(y32, y8); |
---|
| 467 | Y[i][j] = y8; |
---|
| 468 | } |
---|
| 469 | } |
---|
[772] | 470 | } |
---|
[821] | 471 | |
---|
| 472 | // Local Variables: |
---|
| 473 | // tab-width: 4 |
---|
| 474 | // c-basic-offset: 4 |
---|
| 475 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 476 | // indent-tabs-mode: nil |
---|
| 477 | // End: |
---|
| 478 | |
---|
| 479 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 480 | |
---|