Changeset 821 for soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c
r772 r821 20 20 #include <malloc.h> 21 21 #include <math.h> // fabs 22 // #include <memory.h> // memcpy 23 22 23 #include "nrc_os_config.h" 24 24 #include "mypredef.h" 25 25 #include "nrtype.h" … … 28 28 #include "nrkernel.h" 29 29 30 //#include "nralloc.h"31 30 #include "nrarith1.h" 32 31 … … 37 36 */ 38 37 39 /* -------------------------------------------------------- */ 40 IMAGE_EXPORT(sint32) sum_si8vector(sint8 *v, long nl, long nh) 41 /* -------------------------------------------------------- */ 42 { 43 int i; 44 sint32 s = 0; 45 for(i=nl; i<=nh; i++) { 46 s += v[i]; 47 } 48 return s; 49 } 50 /* -------------------------------------------------------- */ 51 IMAGE_EXPORT(uint32) sum_u8ivector(uint8 *v, long nl, long nh) 52 /* -------------------------------------------------------- */ 53 { 54 int i; 55 uint32 s = 0; 56 for(i=nl; i<=nh; i++) { 57 s += v[i]; 58 } 59 return s; 60 } 61 /* ---------------------------------------------------------- */ 62 IMAGE_EXPORT(sint32) sum_si16vector(sint16 *v, long nl, long nh) 63 /* ---------------------------------------------------------- */ 64 { 65 int i; 66 sint32 s = 0; 67 for(i=nl; i<=nh; i++) { 68 s += v[i]; 69 } 70 return s; 71 } 72 /* ---------------------------------------------------------- */ 73 IMAGE_EXPORT(uint32) sum_u16ivector(uint16 *v, long nl, long nh) 74 /* ---------------------------------------------------------- */ 75 { 76 int i; 77 uint32 s = 0; 78 for(i=nl; i<=nh; i++) { 79 s += v[i]; 80 } 81 return s; 82 } 83 /* ---------------------------------------------------------- */ 84 IMAGE_EXPORT(sint32) sum_si32vector(sint32 *v, long nl, long nh) 85 /* ---------------------------------------------------------- */ 86 { 87 int i; 88 sint32 s = 0; 89 for(i=nl; i<=nh; i++) { 90 s += v[i]; 91 } 92 return s; 93 } 94 /* ---------------------------------------------------------- */ 95 IMAGE_EXPORT(uint32) sum_u32ivector(uint32 *v, long nl, long nh) 96 /* ---------------------------------------------------------- */ 97 { 98 int i; 99 uint32 s = 0; 100 for(i=nl; i<=nh; i++) { 101 s += v[i]; 102 } 103 return s; 104 } 105 /* ----------------------------------------------------------- */ 106 IMAGE_EXPORT(float32) sum_f32vector(float32 *v, long nl, long nh) 107 /* ----------------------------------------------------------- */ 108 { 109 int i; 110 float32 s = 0.0f; 111 for(i=nl; i<=nh; i++) { 112 s += v[i]; 113 } 114 return s; 115 } 116 /* ----------------------------------------------------------- */ 117 IMAGE_EXPORT(float64) sum_f64vector(float64 *v, long nl, long nh) 118 /* ----------------------------------------------------------- */ 119 { 120 int i; 121 float64 s = 0.0; 122 for(i=nl; i<=nh; i++) { 123 s += v[i]; 124 } 125 return s; 126 } 38 #undef sum_type_vector 39 #define sum_type_vector(t,r) \ 40 r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh) \ 41 { \ 42 r s = 0; \ 43 for (int32_t i = nl; i <= nh; i++) { \ 44 s += v[i]; \ 45 } \ 46 return s; \ 47 } 48 49 sum_type_vector(int8_t, int32_t); 50 sum_type_vector(uint8_t, uint32_t); 51 sum_type_vector(int16_t, int32_t); 52 sum_type_vector(uint16_t, uint32_t); 53 sum_type_vector(int32_t, int32_t); 54 sum_type_vector(uint32_t, uint32_t); 55 sum_type_vector(float, float); 56 sum_type_vector(double, double); 127 57 128 58 /* … … 132 62 */ 133 63 134 /* ------------------------------------------------------- */ 135 IMAGE_EXPORT(sint8) min_si8vector(sint8 *v, long nl, long nh) 136 /* ------------------------------------------------------- */ 137 { 138 int i; 139 uint8 m; 140 141 m = v[nl]; 142 for(i=nl+1; i<=nh; i++) { 143 if(v[i]<m) m = v[i]; 144 } 145 return m; 146 } 147 /* ------------------------------------------------------- */ 148 IMAGE_EXPORT(uint8) min_ui8vector(uint8 *v, long nl, long nh) 149 /* ------------------------------------------------------- */ 150 { 151 int i; 152 uint8 m; 153 154 m = v[nl]; 155 for(i=nl+1; i<=nh; i++) { 156 if(v[i]<m) m = v[i]; 157 } 158 return m; 159 } 160 /* ---------------------------------------------------------- */ 161 IMAGE_EXPORT(sint16) min_si16vector(sint16 *v, long nl, long nh) 162 /* ---------------------------------------------------------- */ 163 { 164 int i; 165 int16 m; 166 167 m = v[nl]; 168 for(i=nl+1; i<=nh; i++) { 169 if(v[i]<m) m = v[i]; 170 } 171 return m; 172 } 173 /* ---------------------------------------------------------- */ 174 IMAGE_EXPORT(uint16) min_ui16vector(uint16 *v, long nl, long nh) 175 /* ---------------------------------------------------------- */ 176 { 177 int i; 178 uint16 m; 179 180 m = v[nl]; 181 for(i=nl+1; i<=nh; i++) { 182 if(v[i]<m) m = v[i]; 183 } 184 return m; 185 } 186 /* ---------------------------------------------------------- */ 187 IMAGE_EXPORT(sint32) min_si32vector(sint32 *v, long nl, long nh) 188 /* ---------------------------------------------------------- */ 189 { 190 int i; 191 int16 m; 192 193 m = v[nl]; 194 for(i=nl+1; i<=nh; i++) { 195 if(v[i]<m) m = v[i]; 196 } 197 return m; 198 } 199 /* ---------------------------------------------------------- */ 200 IMAGE_EXPORT(uint32) min_ui32vector(uint32 *v, long nl, long nh) 201 /* ---------------------------------------------------------- */ 202 { 203 int i; 204 uint32 m; 205 206 m = v[nl]; 207 for(i=nl+1; i<=nh; i++) { 208 if(v[i]<m) m = v[i]; 209 } 210 return m; 211 } 212 /* ----------------------------------------------------------- */ 213 IMAGE_EXPORT(float32) min_f32vector(float32 *v, long nl, long nh) 214 /* ----------------------------------------------------------- */ 215 { 216 int i; 217 float32 m; 218 219 m = v[nl]; 220 for(i=nl+1; i<=nh; i++) { 221 if(v[i]<m) m = v[i]; 222 } 223 return m; 224 } 225 /* ----------------------------------------------------------- */ 226 IMAGE_EXPORT(float64) min_f64vector(float64 *v, long nl, long nh) 227 /* ----------------------------------------------------------- */ 228 { 229 int i; 230 float64 m; 231 232 m = v[nl]; 233 for(i=nl+1; i<=nh; i++) { 234 if(v[i]<m) m = v[i]; 235 } 236 return m; 237 } 64 #undef min_type_vector 65 #define min_type_vector(t) \ 66 t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh) \ 67 { \ 68 t m = v[nl]; \ 69 for (int32_t i = nl + 1; i <= nh; i++) { \ 70 if (v[i] < m) { \ 71 m = v[i]; \ 72 } \ 73 } \ 74 return m; \ 75 } 76 77 78 min_type_vector(int8_t); 79 min_type_vector(uint8_t); 80 min_type_vector(int16_t); 81 min_type_vector(uint16_t); 82 min_type_vector(int32_t); 83 min_type_vector(uint32_t); 84 min_type_vector(float); 85 min_type_vector(double); 86 238 87 239 88 /* … … 243 92 */ 244 93 245 /* ------------------------------------------------------- */ 246 IMAGE_EXPORT(sint8) max_si8vector(sint8 *v, long nl, long nh) 247 /* ------------------------------------------------------- */ 248 { 249 int i; 250 sint8 m; 251 252 m = v[nl]; 253 for(i=nl+1; i<=nh; i++) { 254 if(v[i]>m) m = v[i]; 255 } 256 return m; 257 } 258 /* ------------------------------------------------------- */ 259 IMAGE_EXPORT(uint8) max_ui8vector(uint8 *v, long nl, long nh) 260 /* ------------------------------------------------------- */ 261 { 262 int i; 263 uint8 m; 264 265 m = v[nl]; 266 for(i=nl+1; i<=nh; i++) { 267 if(v[i]>m) m = v[i]; 268 } 269 return m; 270 } 271 /* ---------------------------------------------------------- */ 272 IMAGE_EXPORT(sint16) max_si16vector(sint16 *v, long nl, long nh) 273 /* ---------------------------------------------------------- */ 274 { 275 int i; 276 sint16 m; 277 278 m = v[nl]; 279 for(i=nl+1; i<=nh; i++) { 280 if(v[i]>m) m = v[i]; 281 } 282 return m; 283 } 284 /* ---------------------------------------------------------- */ 285 IMAGE_EXPORT(uint16) max_ui16vector(uint16 *v, long nl, long nh) 286 /* ---------------------------------------------------------- */ 287 { 288 int i; 289 uint16 m; 290 291 m = v[nl]; 292 for(i=nl+1; i<=nh; i++) { 293 if(v[i]>m) m = v[i]; 294 } 295 return m; 296 } 297 /* ---------------------------------------------------------- */ 298 IMAGE_EXPORT(sint32) max_si32vector(sint32 *v, long nl, long nh) 299 /* ---------------------------------------------------------- */ 300 { 301 int i; 302 sint32 m; 303 304 m = v[nl]; 305 for(i=nl+1; i<=nh; i++) { 306 if(v[i]>m) m = v[i]; 307 } 308 return m; 309 } 310 /* ---------------------------------------------------------- */ 311 IMAGE_EXPORT(uint32) max_ui32vector(uint32 *v, long nl, long nh) 312 /* ---------------------------------------------------------- */ 313 { 314 int i; 315 uint32 m; 316 317 m = v[nl]; 318 for(i=nl+1; i<=nh; i++) { 319 if(v[i]>m) m = v[i]; 320 } 321 return m; 322 } 323 /* ----------------------------------------------------------- */ 324 IMAGE_EXPORT(float32) max_f32vector(float32 *v, long nl, long nh) 325 /* ----------------------------------------------------------- */ 326 { 327 int i; 328 float32 m; 329 330 m = v[nl]; 331 for(i=nl+1; i<=nh; i++) { 332 if(v[i]>m) m = v[i]; 333 } 334 return m; 335 } 336 /* ----------------------------------------------------------- */ 337 IMAGE_EXPORT(float64) max_f64vector(float64 *v, long nl, long nh) 338 /* ----------------------------------------------------------- */ 339 { 340 int i; 341 float64 m; 342 343 m = v[nl]; 344 for(i=nl+1; i<=nh; i++) { 345 if(v[i]>m) m = v[i]; 346 } 347 return m; 348 } 94 #undef max_type_vector 95 #define max_type_vector(t) \ 96 t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh) \ 97 { \ 98 t m = v[nl]; \ 99 for (int32_t i = nl + 1; i <= nh; i++) { \ 100 if (v[i] > m) { \ 101 m = v[i]; \ 102 } \ 103 } \ 104 return m; \ 105 } 106 107 108 max_type_vector(int8_t); 109 max_type_vector(uint8_t); 110 max_type_vector(int16_t); 111 max_type_vector(uint16_t); 112 max_type_vector(int32_t); 113 max_type_vector(uint32_t); 114 max_type_vector(float); 115 max_type_vector(double); 116 117 349 118 /* 350 119 * ---------------------- … … 353 122 */ 354 123 355 /* --------------------------------------------------------------------- */ 356 IMAGE_EXPORT(sint8) min_si8vector_pos(sint8 *v, long nl, long nh, int *pos) 357 /* --------------------------------------------------------------------- */ 358 { 359 int i; 360 sint8 m = v[nl]; 361 int p = nl; 362 363 for(i=nl+1; i<=nh; i++) { 364 if(v[i]>m) { m = v[i]; p = i;} 365 } 366 *pos = p; 367 return m; 368 } 369 /* --------------------------------------------------------------------- */ 370 IMAGE_EXPORT(uint8) min_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) 371 /* --------------------------------------------------------------------- */ 372 { 373 int i; 374 uint8 m = v[nl]; 375 int p = nl; 376 377 for(i=nl+1; i<=nh; i++) { 378 if(v[i]>m) { m = v[i]; p = i;} 379 } 380 *pos = p; 381 return m; 382 } 383 /* ------------------------------------------------------------------------ */ 384 IMAGE_EXPORT(sint16) min_si16vector_pos(sint16 *v, long nl, long nh, int *pos) 385 /* ------------------------------------------------------------------------ */ 386 { 387 int i; 388 sint16 m = v[nl]; 389 int p = nl; 390 391 for(i=nl+1; i<=nh; i++) { 392 if(v[i]>m) { m = v[i]; p = i;} 393 } 394 *pos = p; 395 return m; 396 } 397 /* ------------------------------------------------------------------------ */ 398 IMAGE_EXPORT(uint16) min_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) 399 /* ------------------------------------------------------------------------ */ 400 { 401 int i; 402 uint16 m = v[nl]; 403 int p = nl; 404 405 for(i=nl+1; i<=nh; i++) { 406 if(v[i]>m) { m = v[i]; p = i;} 407 } 408 *pos = p; 409 return m; 410 } 411 /* ------------------------------------------------------------------------ */ 412 IMAGE_EXPORT(sint32) min_si32vector_pos(sint32 *v, long nl, long nh, int *pos) 413 /* ------------------------------------------------------------------------ */ 414 { 415 int i; 416 sint32 m = v[nl]; 417 int p = nl; 418 419 for(i=nl+1; i<=nh; i++) { 420 if(v[i]>m) { m = v[i]; p = i;} 421 } 422 *pos = p; 423 return m; 424 } 425 /* ------------------------------------------------------------------------ */ 426 IMAGE_EXPORT(uint32) min_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) 427 /* ------------------------------------------------------------------------ */ 428 { 429 int i; 430 uint32 m = v[nl]; 431 int p = nl; 432 433 for(i=nl+1; i<=nh; i++) { 434 if(v[i]>m) { m = v[i]; p = i;} 435 } 436 *pos = p; 437 return m; 438 } 439 /* ------------------------------------------------------------------------- */ 440 IMAGE_EXPORT(float32) min_f32vector_pos(float32 *v, long nl, long nh, int *pos) 441 /* ------------------------------------------------------------------------- */ 442 { 443 int i; 444 float32 m = v[nl]; 445 int p = nl; 446 447 for(i=nl+1; i<=nh; i++) { 448 if(v[i]>m) { m = v[i]; p = i;} 449 } 450 *pos = p; 451 return m; 452 } 453 /* ------------------------------------------------------------------------- */ 454 IMAGE_EXPORT(float64) min_f64vector_pos(float64 *v, long nl, long nh, int *pos) 455 /* ------------------------------------------------------------------------- */ 456 { 457 int i; 458 float64 m = v[nl]; 459 int p = nl; 460 461 for(i=nl+1; i<=nh; i++) { 462 if(v[i]>m) { m = v[i]; p = i;} 463 } 464 *pos = p; 465 return m; 466 } 124 125 #undef min_type_vector_pos 126 #define min_type_vector_pos(t) \ 127 t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \ 128 { \ 129 t m = v[nl]; \ 130 int32_t p = nl; \ 131 for (int32_t i = nl + 1; i <= nh; i++) { \ 132 if (v[i] < m) { \ 133 m = v[i]; \ 134 p = i; \ 135 } \ 136 } \ 137 *pos = p; \ 138 return m; \ 139 } 140 141 142 min_type_vector_pos(int8_t); 143 min_type_vector_pos(uint8_t); 144 min_type_vector_pos(int16_t); 145 min_type_vector_pos(uint16_t); 146 min_type_vector_pos(int32_t); 147 min_type_vector_pos(uint32_t); 148 min_type_vector_pos(float); 149 min_type_vector_pos(double); 150 467 151 468 152 /* … … 472 156 */ 473 157 474 /* --------------------------------------------------------------------- */ 475 IMAGE_EXPORT(sint8) max_si8vector_pos(sint8 *v, long nl, long nh, int *pos) 476 /* --------------------------------------------------------------------- */ 477 { 478 int i; 479 sint8 m = v[nl]; 480 int p = nl; 481 482 for(i=nl+1; i<=nh; i++) { 483 if(v[i]>m) { m = v[i]; p = i;} 484 } 485 *pos = p; 486 487 return m; 488 } 489 /* --------------------------------------------------------------------- */ 490 IMAGE_EXPORT(uint8) max_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) 491 /* --------------------------------------------------------------------- */ 492 { 493 int i; 494 uint8 m = v[nl]; 495 int p = nl; 496 497 for(i=nl+1; i<=nh; i++) { 498 if(v[i]>m) { m = v[i]; p = i;} 499 } 500 *pos = p; 501 502 return m; 503 } 158 159 #undef max_type_vector_pos 160 #define max_type_vector_pos(t) \ 161 t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \ 162 { \ 163 t m = v[nl]; \ 164 int32_t p = nl; \ 165 for (int32_t i = nl + 1; i <= nh; i++) { \ 166 if (v[i] > m) { \ 167 m = v[i]; \ 168 p = i; \ 169 } \ 170 } \ 171 *pos = p; \ 172 return m; \ 173 } 174 175 176 max_type_vector_pos(int8_t); 177 max_type_vector_pos(uint8_t); 178 max_type_vector_pos(int16_t); 179 max_type_vector_pos(uint16_t); 180 max_type_vector_pos(int32_t); 181 max_type_vector_pos(uint32_t); 182 max_type_vector_pos(float); 183 max_type_vector_pos(double); 184 185 186 #undef add_type_vector 187 #define add_type_vector(t) \ 188 void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \ 189 { \ 190 for (int32_t i = nl; i <= nh; i++) { \ 191 D[i] = S1[i] + S2[i]; \ 192 } \ 193 } 194 195 add_type_vector(int8_t); 196 add_type_vector(uint8_t); 197 add_type_vector(int16_t); 198 add_type_vector(uint16_t); 199 add_type_vector(int32_t); 200 add_type_vector(uint32_t); 201 add_type_vector(float); 202 add_type_vector(double); 203 204 205 #undef sub_type_vector 206 #define sub_type_vector(t) \ 207 void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \ 208 { \ 209 for (int32_t i = nl; i <= nh; i++) { \ 210 D[i] = S1[i] - S2[i]; \ 211 } \ 212 } 213 214 sub_type_vector(int8_t); 215 sub_type_vector(uint8_t); 216 sub_type_vector(int16_t); 217 sub_type_vector(uint16_t); 218 sub_type_vector(int32_t); 219 sub_type_vector(uint32_t); 220 sub_type_vector(float); 221 sub_type_vector(double); 222 223 224 #undef mulc_type_vector 225 #define mulc_type_vector(t) \ 226 void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) \ 227 { \ 228 for (int32_t i = nl; i <= nh; i++) { \ 229 D[i] = S[i] * c; \ 230 } \ 231 } 232 233 mulc_type_vector(int8_t); 234 mulc_type_vector(uint8_t); 235 mulc_type_vector(int16_t); 236 mulc_type_vector(uint16_t); 237 mulc_type_vector(int32_t); 238 mulc_type_vector(uint32_t); 239 mulc_type_vector(float); 240 mulc_type_vector(double); 241 242 243 #undef divc_type_vector 244 #define divc_type_vector(t) \ 245 void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) \ 246 { \ 247 for (int32_t i = nl; i <= nh; i++) { \ 248 D[i] = S[i] / c; \ 249 } \ 250 } 251 252 divc_type_vector(int8_t); 253 divc_type_vector(uint8_t); 254 divc_type_vector(int16_t); 255 divc_type_vector(uint16_t); 256 divc_type_vector(int32_t); 257 divc_type_vector(uint32_t); 258 divc_type_vector(float); 259 divc_type_vector(double); 260 261 262 #undef cumulleft_type_vector 263 #define cumulleft_type_vector(t) \ 264 void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \ 265 { \ 266 for (int32_t i = nh - 1; i >= nl; i--) { \ 267 D[i] += S[i + 1]; \ 268 } \ 269 } 270 271 cumulleft_type_vector(int8_t); 272 cumulleft_type_vector(uint8_t); 273 cumulleft_type_vector(int16_t); 274 cumulleft_type_vector(uint16_t); 275 cumulleft_type_vector(int32_t); 276 cumulleft_type_vector(uint32_t); 277 cumulleft_type_vector(float); 278 cumulleft_type_vector(double); 279 280 281 #undef cumulright_type_vector 282 #define cumulright_type_vector(t) \ 283 void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \ 284 { \ 285 for (int32_t i = nl + 1; i <= nh; i++) { \ 286 D[i] += S[i - 1]; \ 287 } \ 288 } 289 290 cumulright_type_vector(int8_t); 291 cumulright_type_vector(uint8_t); 292 cumulright_type_vector(int16_t); 293 cumulright_type_vector(uint16_t); 294 cumulright_type_vector(int32_t); 295 cumulright_type_vector(uint32_t); 296 cumulright_type_vector(float); 297 cumulright_type_vector(double); 298 299 300 #undef mulfrac_type_vector 301 #define mulfrac_type_vector(t) \ 302 void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D) \ 303 { \ 304 for (int32_t i = nl; i <= nh; i++) { \ 305 D[i] = (a * S[i]) / b; \ 306 } \ 307 } 308 309 310 mulfrac_type_vector(int8_t); 311 mulfrac_type_vector(uint8_t); 312 mulfrac_type_vector(int16_t); 313 mulfrac_type_vector(uint16_t); 314 mulfrac_type_vector(int32_t); 315 mulfrac_type_vector(uint32_t); 316 mulfrac_type_vector(float); 317 mulfrac_type_vector(double); 318 319 320 /* --------------------------------------------------------------------- */ 321 void beta_sum_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 322 /* --------------------------------------------------------------------- */ 323 { 324 int32_t r, g, b; 325 int32_t s; 326 for (int32_t i = nl; i <= nh; i++) { 327 r = S[i].r; 328 g = S[i].g; 329 b = S[i].b; 330 s = r + g + b; 331 D[i].r = s; 332 D[i].g = s; 333 D[i].b = s; 334 } 335 } 336 337 /* ----------------------------------------------------------------------- */ 338 void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 339 /* ----------------------------------------------------------------------- */ 340 { 341 int32_t r, g, b; 342 int32_t s; 343 for (int32_t i = nl; i <= nh; i++) { 344 r = S[i].r; 345 g = S[i].g; 346 b = S[i].b; 347 s = (r + g + b) / 3; 348 D[i].r = s; 349 D[i].g = s; 350 D[i].b = s; 351 } 352 } 353 504 354 /* ------------------------------------------------------------------------ */ 505 IMAGE_EXPORT(sint16) max_si16vector_pos(sint16 *v, long nl, long nh, int *pos)355 void mulc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D) 506 356 /* ------------------------------------------------------------------------ */ 507 357 { 508 int i; 509 int16 m = v[nl]; 510 int p = nl; 511 512 for(i=nl+1; i<=nh; i++) { 513 if(v[i]>m) { m = v[i]; p = i;} 514 } 515 *pos = p; 516 return m; 517 } 518 /* ----------------------------------------------------------------------- */ 519 IMAGE_EXPORT(uint16) max_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) 520 /* ----------------------------------------------------------------------- */ 521 { 522 int i; 523 uint16 m = v[nl]; 524 int p = nl; 525 526 for(i=nl+1; i<=nh; i++) { 527 if(v[i]>m) { m = v[i]; p = i;} 528 } 529 *pos = p; 530 531 return m; 532 } 533 /* --------------------------------------------------------------------- */ 534 IMAGE_EXPORT(sint32) max_si32vector_pos(sint32 *v, long nl, long nh, int *pos) 535 /* --------------------------------------------------------------------- */ 536 { 537 int i; 538 sint32 m = v[nl]; 539 int p = nl; 540 541 for(i=nl+1; i<=nh; i++) { 542 if(v[i]>m) { m = v[i]; p = i;} 543 } 544 *pos = p; 545 546 return m; 547 } 548 /* ------------------------------------------------------------------------ */ 549 IMAGE_EXPORT(uint32) max_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) 550 /* ------------------------------------------------------------------------ */ 551 { 552 int i; 553 uint32 m = v[nl]; 554 int p = nl; 555 556 for(i=nl+1; i<=nh; i++) { 557 if(v[i]>m) { m = v[i]; p = i;} 558 } 559 *pos = p; 560 561 return m; 562 } 563 /* ----------------------------------------------------------------------- */ 564 IMAGE_EXPORT(float32) max_f32vector_pos(float32 *v, long nl, long nh, int *pos) 565 /* ----------------------------------------------------------------------- */ 566 { 567 int i; 568 float32 m = v[nl]; 569 int p = nl; 570 571 for(i=nl+1; i<=nh; i++) { 572 if(v[i]>m) { m = v[i]; p = i;} 573 } 574 *pos = p; 575 576 return m; 577 } 578 /* ------------------------------------------------------------------------- */ 579 IMAGE_EXPORT(float64) max_f64vector_pos(float64 *v, long nl, long nh, int *pos) 580 /* ------------------------------------------------------------------------- */ 581 { 582 int i; 583 float64 m = v[nl]; 584 int p = nl; 585 586 for(i=nl+1; i<=nh; i++) { 587 if(v[i]>m) { m = v[i]; p = i;} 588 } 589 *pos = p; 590 591 return m; 592 } 593 /* --------------------------------------------------------------------- */ 594 IMAGE_EXPORT(void) beta_sum_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) 595 /* --------------------------------------------------------------------- */ 596 { 597 long i; 598 int32 r, g, b, s; 599 for(i=nl; i<=nh; i++){ 600 r = S[i].r; 601 g = S[i].g; 602 b = S[i].b; 603 s = r + g + b; 604 D[i].r = s; 605 D[i].g = s; 606 D[i].b = s; 607 } 608 } 609 /* ----------------------------------------------------------------------- */ 610 IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) 611 /* ----------------------------------------------------------------------- */ 612 { 613 long i; 614 int32 r, g, b, s; 615 for(i=nl; i<=nh; i++){ 616 r = S[i].r; 617 g = S[i].g; 618 b = S[i].b; 619 s = (r + g + b) / 3; 620 D[i].r = s; 621 D[i].g = s; 622 D[i].b = s; 623 } 624 } 625 /* ------------------------------------------------------------------------ */ 626 IMAGE_EXPORT(void) add_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) 627 /* ------------------------------------------------------------------------ */ 628 { 629 long i; 630 for(i=nl; i<=nh; i++) D[i] = S1[i] + S2[i]; 631 } 632 /* ------------------------------------------------------------------------ */ 633 IMAGE_EXPORT(void) sub_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) 634 /* ------------------------------------------------------------------------ */ 635 { 636 long i; 637 for(i=nl; i<=nh; i++) D[i] = S1[i] - S2[i]; 638 } 639 /* ---------------------------------------------------------------------- */ 640 IMAGE_EXPORT(void) mulc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) 641 /* ---------------------------------------------------------------------- */ 642 { 643 long i; 644 for(i=nl; i<=nh; i++) D[i] = c * S[i]; 645 } 646 /* ------------------------------------------------------------------------ */ 647 IMAGE_EXPORT(void) mulc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) 648 /* ------------------------------------------------------------------------ */ 649 { 650 long i; 651 652 for(i=nl; i<=nh; i++) { 653 D[i].r = c * S[i].r; 654 D[i].g = c * S[i].g; 655 D[i].b = c * S[i].b; 656 } 657 } 658 /* ------------------------------------------------------------------------ */ 659 IMAGE_EXPORT(void) divc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) 660 /* ------------------------------------------------------------------------ */ 661 { 662 long i; 663 for(i=nl; i<=nh; i++) D[i] = S[i] / c; 664 } 665 /* -------------------------------------------------------------------------- */ 666 IMAGE_EXPORT(void) divc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) 667 /* -------------------------------------------------------------------------- */ 668 { 669 long i; 670 671 for(i=nl; i<=nh; i++) { 672 D[i].r = S[i].r / c; 673 D[i].g = S[i].g / c; 674 D[i].b = S[i].b / c; 675 } 676 } 677 /* -------------------------------------------------------------------- */ 678 IMAGE_EXPORT(void) cumulleft_i32vector(int32 *S, long nl,long nh, int32 *D) 679 /* -------------------------------------------------------------------- */ 680 { 681 // for histogram 682 long i; 683 684 for(i=nh-1; i>=nl; i--) { 685 D[i] += S[i+1]; 686 } 687 } 688 /* --------------------------------------------------------------------- */ 689 IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) 690 /* --------------------------------------------------------------------- */ 691 { 692 // for histogram 693 long i; 694 695 for(i=nh-1; i>=nl; i--) { 696 D[i].r += S[i+1].r; 697 D[i].g += S[i+1].g; 698 D[i].b += S[i+1].b; 699 } 700 } 701 /* -------------------------------------------------------------------- */ 702 IMAGE_EXPORT(void) cumulright_i32vector(int32 *S, long nl,long nh, int32 *D) 703 /* -------------------------------------------------------------------- */ 704 { 705 // for histogram 706 long i; 707 708 for(i=nl+1; i<=nh; i++) { 709 D[i] += S[i-1]; 710 } 711 } 712 /* ---------------------------------------------------------------------- */ 713 IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) 714 /* ---------------------------------------------------------------------- */ 715 { 716 // for histogram 717 long i; 718 719 for(i=nl+1; i<=nh; i++) { 720 D[i].r += S[i-1].r; 721 D[i].g += S[i-1].g; 722 D[i].b += S[i-1].b; 723 } 724 } 725 /* ----------------------------------------------------------------------------------- */ 726 IMAGE_EXPORT(void) mulfrac_i32vector(int32 *S, long nl,long nh, int32 a, int32 b, int32 *D) 727 /* ----------------------------------------------------------------------------------- */ 728 { 729 long i; 730 731 for(i=nl; i<=nh; i++) { 732 //D[i] = (a * S[i] + b) / b; 733 D[i] = (a * S[i]) / b; 734 } 735 } 358 for (int32_t i = nl; i <= nh; i++) { 359 D[i].r = c * S[i].r; 360 D[i].g = c * S[i].g; 361 D[i].b = c * S[i].b; 362 } 363 } 364 365 /* --------------------------------------------------------------------- */ 366 void divc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D) 367 /* --------------------------------------------------------------------- */ 368 { 369 for (int32_t i = nl; i <= nh; i++) { 370 D[i].r = S[i].r / c; 371 D[i].g = S[i].g / c; 372 D[i].b = S[i].b / c; 373 } 374 } 375 376 /* --------------------------------------------------------------------- */ 377 void cumulleft_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 378 /* --------------------------------------------------------------------- */ 379 { 380 // for histogram 381 for (int32_t i = nh - 1; i >= nl; i--) { 382 D[i].r += S[i + 1].r; 383 D[i].g += S[i + 1].g; 384 D[i].b += S[i + 1].b; 385 } 386 } 387 388 389 /* --------------------------------------------------------------------- */ 390 void cumulright_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 391 /* --------------------------------------------------------------------- */ 392 { 393 // for histogram 394 for (int32_t i = nl + 1; i <= nh; i++) { 395 D[i].r += S[i - 1].r; 396 D[i].g += S[i - 1].g; 397 D[i].b += S[i - 1].b; 398 } 399 } 400 401 736 402 /* ------------------------------------------------------------------------------------- */ 737 IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl,long nh, int32 a, int32 b, rgb32 *D)403 void mulfrac_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t a, int32_t b, rgb32 * D) 738 404 /* ------------------------------------------------------------------------------------- */ 739 405 { 740 long i; 741 742 for(i=nl; i<=nh; i++) { 743 //D[i].r = (a * S[i].r + b) / b; 744 //D[i].g = (a * S[i].g + b) / b; 745 //D[i].b = (a * S[i].b + b) / b; 746 D[i].r = (a * S[i].r) / b; 747 D[i].g = (a * S[i].g) / b; 748 D[i].b = (a * S[i].b) / b; 749 } 750 } 406 for (int32_t i = nl; i <= nh; i++) { 407 D[i].r = (a * S[i].r) / b; 408 D[i].g = (a * S[i].g) / b; 409 D[i].b = (a * S[i].b) / b; 410 } 411 } 412 413 // Local Variables: 414 // tab-width: 4 415 // c-basic-offset: 4 416 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 417 // indent-tabs-mode: nil 418 // End: 419 420 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 421
Note: See TracChangeset
for help on using the changeset viewer.