| 1 | /* --------------- */ |
|---|
| 2 | /* --- nrlut.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 | * 2002/06/11 ajout des fonctions endline |
|---|
| 16 | */ |
|---|
| 17 | #include <stdio.h> |
|---|
| 18 | #include <stddef.h> |
|---|
| 19 | #include <stdlib.h> |
|---|
| 20 | #include <math.h> // fabs |
|---|
| 21 | |
|---|
| 22 | #include "mypredef.h" |
|---|
| 23 | #include "nrtype.h" |
|---|
| 24 | #include "nrdef.h" |
|---|
| 25 | #include "nrmacro.h" |
|---|
| 26 | #include "nrkernel.h" |
|---|
| 27 | |
|---|
| 28 | #include "nrlut.h" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | #undef init_type_lut |
|---|
| 32 | #define init_type_lut(t) \ |
|---|
| 33 | void short_name(t,init_,lut)(t * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, t k) \ |
|---|
| 34 | { \ |
|---|
| 35 | if (nl <= nh) { \ |
|---|
| 36 | for (int32_t i = nl; i < n0; i++) { \ |
|---|
| 37 | v[i] = 0; \ |
|---|
| 38 | } \ |
|---|
| 39 | for (int32_t i = n0; i <= n1; i++) { \ |
|---|
| 40 | v[i] = k; \ |
|---|
| 41 | } \ |
|---|
| 42 | for (int32_t i = n1 + 1; i <= nh; i++) { \ |
|---|
| 43 | v[i] = 0; \ |
|---|
| 44 | } \ |
|---|
| 45 | } \ |
|---|
| 46 | else { \ |
|---|
| 47 | for (int32_t i = nl; i < n1; i++) { \ |
|---|
| 48 | v[i] = k; \ |
|---|
| 49 | } \ |
|---|
| 50 | for (int32_t i = n1; i <= n0; i++) { \ |
|---|
| 51 | v[i] = 0; \ |
|---|
| 52 | } \ |
|---|
| 53 | for (int32_t i = n1 + 1; i <= nh; i++) { \ |
|---|
| 54 | v[i] = k; \ |
|---|
| 55 | } \ |
|---|
| 56 | } \ |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | init_type_lut(int8_t); |
|---|
| 61 | init_type_lut(uint8_t); |
|---|
| 62 | init_type_lut(int16_t); |
|---|
| 63 | init_type_lut(uint16_t); |
|---|
| 64 | init_type_lut(int32_t); |
|---|
| 65 | init_type_lut(uint32_t); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | void init_rgb8lut(rgb8 * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, rgb8 k) |
|---|
| 70 | { |
|---|
| 71 | if (nl <= nh) { |
|---|
| 72 | // normal case |
|---|
| 73 | for (int32_t i = nl; i < n0; i++) { |
|---|
| 74 | v[i].r = 0; |
|---|
| 75 | v[i].g = 0; |
|---|
| 76 | v[i].b = 0; |
|---|
| 77 | } |
|---|
| 78 | for (int32_t i = n0; i <= n1; i++) { |
|---|
| 79 | v[i].r = k.r; |
|---|
| 80 | v[i].g = k.g; |
|---|
| 81 | v[i].b = k.b; |
|---|
| 82 | } |
|---|
| 83 | for (int32_t i = n1 + 1; i <= nh; i++) { |
|---|
| 84 | v[i].r = 0; |
|---|
| 85 | v[i].g = 0; |
|---|
| 86 | v[i].b = 0; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | else { |
|---|
| 90 | for (int32_t i = nl; i < n1; i++) { |
|---|
| 91 | v[i].r = k.r; |
|---|
| 92 | v[i].g = k.g; |
|---|
| 93 | v[i].b = k.b; |
|---|
| 94 | } |
|---|
| 95 | for (int32_t i = n1; i <= n0; i++) { |
|---|
| 96 | v[i].r = 0; |
|---|
| 97 | v[i].g = 0; |
|---|
| 98 | v[i].b = 0; |
|---|
| 99 | } |
|---|
| 100 | for (int32_t i = n1 + 1; i <= nh; i++) { |
|---|
| 101 | v[i].r = k.r; |
|---|
| 102 | v[i].g = k.g; |
|---|
| 103 | v[i].b = k.b; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | #undef lut_type_matrix |
|---|
| 110 | #define lut_type_matrix(t) \ |
|---|
| 111 | void short_name(t,lut_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * L, t ** D) \ |
|---|
| 112 | { \ |
|---|
| 113 | for (int32_t i = nrl; i <= nrh; i++) { \ |
|---|
| 114 | for (int32_t j = ncl; j <= nch; j++) { \ |
|---|
| 115 | D[i][j] = L[(int32_t) S[i][j]]; \ |
|---|
| 116 | } \ |
|---|
| 117 | } \ |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | lut_type_matrix(int8_t); |
|---|
| 121 | lut_type_matrix(uint8_t); |
|---|
| 122 | lut_type_matrix(int16_t); |
|---|
| 123 | lut_type_matrix(uint16_t); |
|---|
| 124 | lut_type_matrix(int32_t); |
|---|
| 125 | lut_type_matrix(uint32_t); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | void lut_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 * L, rgb8 ** D) |
|---|
| 130 | { |
|---|
| 131 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 132 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 133 | D[i][j].r = L[S[i][j].r].r; |
|---|
| 134 | D[i][j].g = L[S[i][j].g].g; |
|---|
| 135 | D[i][j].b = L[S[i][j].b].b; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | void lut_ui16matrix_ui8matrix(uint16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, uint8_t ** D) |
|---|
| 142 | { |
|---|
| 143 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 144 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 145 | D[i][j] = L[(int32_t) S[i][j]]; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | void lut_i16matrix_i8matrix(int16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, int8_t ** D) |
|---|
| 151 | { |
|---|
| 152 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 153 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 154 | D[i][j] = L[(int32_t) S[i][j]]; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | void lut_ui32matrix_ui16matrix(uint32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, uint16_t ** D) |
|---|
| 160 | { |
|---|
| 161 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 162 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 163 | D[i][j] = L[(int32_t) S[i][j]]; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | void lut_i32matrix_i16matrix(int32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, int16_t ** D) |
|---|
| 169 | { |
|---|
| 170 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 171 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 172 | D[i][j] = L[(int32_t) S[i][j]]; |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | #undef histogram_type_matrix |
|---|
| 179 | #define histogram_type_matrix(t) \ |
|---|
| 180 | void short_name(t,histogram_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * H) \ |
|---|
| 181 | { \ |
|---|
| 182 | t * Si; \ |
|---|
| 183 | for (int32_t i = nrl; i <= nrh; i++) { \ |
|---|
| 184 | Si = S[i]; \ |
|---|
| 185 | for (int32_t j = ncl; j <= nch; j++) { \ |
|---|
| 186 | H[(int32_t) Si[j]]++; \ |
|---|
| 187 | } \ |
|---|
| 188 | } \ |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | histogram_type_matrix(int8_t); |
|---|
| 192 | histogram_type_matrix(uint8_t); |
|---|
| 193 | histogram_type_matrix(int16_t); |
|---|
| 194 | histogram_type_matrix(uint16_t); |
|---|
| 195 | histogram_type_matrix(int32_t); |
|---|
| 196 | histogram_type_matrix(uint32_t); |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | void histogram_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 * H) |
|---|
| 201 | { |
|---|
| 202 | rgb8 * Si; |
|---|
| 203 | int r, b, g; |
|---|
| 204 | (void) Si; |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | for (int32_t i = nrl; i <= nrh; i++) { |
|---|
| 208 | Si = S[i]; |
|---|
| 209 | for (int32_t j = ncl; j <= nch; j++) { |
|---|
| 210 | r = S[i][j].r; |
|---|
| 211 | g = S[i][j].g; |
|---|
| 212 | b = S[i][j].b; |
|---|
| 213 | |
|---|
| 214 | H[r].r++; |
|---|
| 215 | H[g].g++; |
|---|
| 216 | H[b].b++; |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | return; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | // Local Variables: |
|---|
| 223 | // tab-width: 4 |
|---|
| 224 | // c-basic-offset: 4 |
|---|
| 225 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 226 | // indent-tabs-mode: nil |
|---|
| 227 | // End: |
|---|
| 228 | |
|---|
| 229 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 230 | |
|---|