[772] | 1 | /* --------------- */ |
---|
| 2 | /* --- nrio2.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 <stdlib.h> |
---|
[798] | 16 | #include <string.h> |
---|
[772] | 17 | |
---|
| 18 | #include "nrc_os_config.h" |
---|
[798] | 19 | |
---|
| 20 | #if TARGET_OS == LINUX |
---|
| 21 | #include <sys/types.h> |
---|
| 22 | #include <sys/stat.h> |
---|
| 23 | #include <fcntl.h> |
---|
| 24 | #include <unistd.h> |
---|
| 25 | #endif |
---|
| 26 | |
---|
| 27 | |
---|
[772] | 28 | #include "mypredef.h" |
---|
| 29 | #include "nrtype.h" |
---|
| 30 | #include "nrdef.h" |
---|
| 31 | #include "nrmacro.h" |
---|
| 32 | #include "nrkernel.h" |
---|
| 33 | |
---|
| 34 | #include "nralloc1.h" |
---|
| 35 | #include "nralloc2.h" |
---|
| 36 | #include "nrio0.h" |
---|
| 37 | #include "nrio1.h" |
---|
| 38 | #include "nrio2.h" |
---|
| 39 | |
---|
[798] | 40 | #define isalnum(x) (((x) >= 0x30 && (x) <= 0x39) \ |
---|
| 41 | || ((x) >= 0x41 && (x) <= 0x5A) \ |
---|
| 42 | || ((x) >= 0x61 && (x) <= 0x7A)) |
---|
| 43 | |
---|
| 44 | |
---|
[772] | 45 | /* |
---|
| 46 | * ---------------------- |
---|
| 47 | * --- display_matrix --- |
---|
| 48 | * ---------------------- |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 52 | IMAGE_EXPORT(void) display_ui8matrix(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 53 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 54 | { |
---|
| 55 | long i,j; |
---|
| 56 | |
---|
| 57 | if(name != NULL) printf(name); |
---|
| 58 | |
---|
| 59 | for(i=nrl; i<=nrh; i++) { |
---|
| 60 | for(j=ncl; j<=nch; j++) { |
---|
| 61 | printf(format, m[i][j]); |
---|
| 62 | } |
---|
| 63 | printf("\n"); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 67 | IMAGE_EXPORT(void) display_si8matrix(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 68 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 69 | { |
---|
| 70 | long i,j; |
---|
| 71 | |
---|
| 72 | if(name != NULL) printf(name); |
---|
| 73 | |
---|
| 74 | for(i=nrl; i<=nrh; i++) { |
---|
| 75 | for(j=ncl; j<=nch; j++) { |
---|
| 76 | printf(format, m[i][j]); |
---|
| 77 | } |
---|
| 78 | printf("\n"); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 82 | IMAGE_EXPORT(void) display_si16matrix(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 83 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 84 | { |
---|
| 85 | long i,j; |
---|
| 86 | |
---|
| 87 | if(name != NULL) printf(name); |
---|
| 88 | |
---|
| 89 | for(i=nrl; i<=nrh; i++) { |
---|
| 90 | for(j=ncl; j<=nch; j++) { |
---|
| 91 | printf(format, m[i][j]); |
---|
| 92 | } |
---|
| 93 | printf("\n"); |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 97 | IMAGE_EXPORT(void) display_ui16matrix(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 98 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 99 | { |
---|
| 100 | long i,j; |
---|
| 101 | |
---|
| 102 | if(name != NULL) printf(name); |
---|
| 103 | |
---|
| 104 | for(i=nrl; i<=nrh; i++) { |
---|
| 105 | for(j=ncl; j<=nch; j++) { |
---|
| 106 | printf(format, m[i][j]); |
---|
| 107 | } |
---|
| 108 | printf("\n"); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 112 | IMAGE_EXPORT(void) display_si32matrix(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 113 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 114 | { |
---|
| 115 | long i,j; |
---|
| 116 | |
---|
| 117 | if(name != NULL) printf(name); |
---|
| 118 | |
---|
| 119 | for(i=nrl; i<=nrh; i++) { |
---|
| 120 | for(j=ncl; j<=nch; j++) { |
---|
| 121 | printf(format, m[i][j]); |
---|
| 122 | } |
---|
| 123 | printf("\n"); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 127 | IMAGE_EXPORT(void) display_ui32matrix(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 128 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 129 | { |
---|
| 130 | long i,j; |
---|
| 131 | |
---|
| 132 | if(name != NULL) printf(name); |
---|
| 133 | |
---|
| 134 | for(i=nrl; i<=nrh; i++) { |
---|
| 135 | for(j=ncl; j<=nch; j++) { |
---|
| 136 | printf(format, m[i][j]); |
---|
| 137 | } |
---|
| 138 | printf("\n"); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 142 | IMAGE_EXPORT(void) display_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 143 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 144 | { |
---|
| 145 | long i,j; |
---|
| 146 | |
---|
| 147 | if(name != NULL) printf(name); |
---|
| 148 | |
---|
| 149 | for(i=nrl; i<=nrh; i++) { |
---|
| 150 | for(j=ncl; j<=nch; j++) { |
---|
| 151 | printf(format, m[i][j]); |
---|
| 152 | } |
---|
| 153 | printf("\n"); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
| 157 | IMAGE_EXPORT(void) display_i64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 158 | /* --------------------------------------------------------------------------------------------------------- */ |
---|
| 159 | { |
---|
| 160 | long i,j; |
---|
| 161 | |
---|
| 162 | if(name != NULL) printf(name); |
---|
| 163 | |
---|
| 164 | for(i=nrl; i<=nrh; i++) { |
---|
| 165 | for(j=ncl; j<=nch; j++) { |
---|
| 166 | printf(format, m[i][j]); |
---|
| 167 | } |
---|
| 168 | printf("\n"); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 172 | IMAGE_EXPORT(void) display_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 173 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 174 | { |
---|
| 175 | long i,j; |
---|
| 176 | |
---|
| 177 | if(name != NULL) printf(name); |
---|
| 178 | |
---|
| 179 | for(i=nrl; i<=nrh; i++) { |
---|
| 180 | for(j=ncl; j<=nch; j++) { |
---|
| 181 | printf(format, m[i][j]); |
---|
| 182 | } |
---|
| 183 | printf("\n"); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 187 | IMAGE_EXPORT(void) display_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 188 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 189 | { |
---|
| 190 | long i,j; |
---|
| 191 | |
---|
| 192 | if(name != NULL) printf(name); |
---|
| 193 | |
---|
| 194 | for(i=nrl; i<=nrh; i++) { |
---|
| 195 | for(j=ncl; j<=nch; j++) { |
---|
| 196 | printf(format, m[i][j]); |
---|
| 197 | } |
---|
| 198 | printf("\n"); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 202 | IMAGE_EXPORT(void) display_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 203 | /* -------------------------------------------------------------------------------------------------------- */ |
---|
| 204 | { |
---|
| 205 | long i,j; |
---|
| 206 | |
---|
| 207 | if(name != NULL) printf(name); |
---|
| 208 | |
---|
| 209 | for(i=nrl; i<=nrh; i++) { |
---|
| 210 | for(j=ncl; j<=nch; j++) { |
---|
| 211 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
| 212 | } |
---|
| 213 | printf("\n"); |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 217 | IMAGE_EXPORT(void) display_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 218 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 219 | { |
---|
| 220 | long i,j; |
---|
| 221 | |
---|
| 222 | if(name != NULL) printf(name); |
---|
| 223 | |
---|
| 224 | for(i=nrl; i<=nrh; i++) { |
---|
| 225 | for(j=ncl; j<=nch; j++) { |
---|
| 226 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
| 227 | } |
---|
| 228 | printf("\n"); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | /* |
---|
| 232 | * ---------------------- |
---|
| 233 | * --- display_matrix --- |
---|
| 234 | * ---------------------- |
---|
| 235 | */ |
---|
| 236 | |
---|
| 237 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 238 | IMAGE_EXPORT(void) display_si8matrix_T(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 239 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 240 | { |
---|
| 241 | long i,j; |
---|
| 242 | |
---|
| 243 | if(name != NULL) printf(name); |
---|
| 244 | |
---|
| 245 | for(j=ncl; j<=nch; j++) { |
---|
| 246 | for(i=nrl; i<=nrh; i++) { |
---|
| 247 | printf(format, m[i][j]); |
---|
| 248 | } |
---|
| 249 | printf("\n"); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 253 | IMAGE_EXPORT(void) display_ui8matrix_T(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 254 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 255 | { |
---|
| 256 | long i,j; |
---|
| 257 | |
---|
| 258 | if(name != NULL) printf(name); |
---|
| 259 | |
---|
| 260 | for(j=ncl; j<=nch; j++) { |
---|
| 261 | for(i=nrl; i<=nrh; i++) { |
---|
| 262 | printf(format, m[i][j]); |
---|
| 263 | } |
---|
| 264 | printf("\n"); |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 268 | IMAGE_EXPORT(void) display_si16matrix_T(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 269 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 270 | { |
---|
| 271 | long i,j; |
---|
| 272 | |
---|
| 273 | if(name != NULL) printf(name); |
---|
| 274 | |
---|
| 275 | for(j=ncl; j<=nch; j++) { |
---|
| 276 | for(i=nrl; i<=nrh; i++) { |
---|
| 277 | printf(format, m[i][j]); |
---|
| 278 | } |
---|
| 279 | printf("\n"); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 283 | IMAGE_EXPORT(void) display_ui16matrix_T(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 284 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 285 | { |
---|
| 286 | long i,j; |
---|
| 287 | |
---|
| 288 | if(name != NULL) printf(name); |
---|
| 289 | |
---|
| 290 | for(j=ncl; j<=nch; j++) { |
---|
| 291 | for(i=nrl; i<=nrh; i++) { |
---|
| 292 | printf(format, m[i][j]); |
---|
| 293 | } |
---|
| 294 | printf("\n"); |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 298 | IMAGE_EXPORT(void) display_si32matrix_T(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 299 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 300 | { |
---|
| 301 | long i,j; |
---|
| 302 | |
---|
| 303 | if(name != NULL) printf(name); |
---|
| 304 | |
---|
| 305 | for(j=ncl; j<=nch; j++) { |
---|
| 306 | for(i=nrl; i<=nrh; i++) { |
---|
| 307 | printf(format, m[i][j]); |
---|
| 308 | } |
---|
| 309 | printf("\n"); |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 313 | IMAGE_EXPORT(void) display_ui32matrix_T(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 314 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 315 | { |
---|
| 316 | long i,j; |
---|
| 317 | |
---|
| 318 | if(name != NULL) printf(name); |
---|
| 319 | |
---|
| 320 | for(j=ncl; j<=nch; j++) { |
---|
| 321 | for(i=nrl; i<=nrh; i++) { |
---|
| 322 | printf(format, m[i][j]); |
---|
| 323 | } |
---|
| 324 | printf("\n"); |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 328 | IMAGE_EXPORT(void) display_si64matrix_T(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 329 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 330 | { |
---|
| 331 | long i,j; |
---|
| 332 | |
---|
| 333 | if(name != NULL) printf(name); |
---|
| 334 | |
---|
| 335 | for(j=ncl; j<=nch; j++) { |
---|
| 336 | for(i=nrl; i<=nrh; i++) { |
---|
| 337 | printf(format, m[i][j]); |
---|
| 338 | } |
---|
| 339 | printf("\n"); |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 343 | IMAGE_EXPORT(void) display_ui64matrix_T(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 344 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 345 | { |
---|
| 346 | long i,j; |
---|
| 347 | |
---|
| 348 | if(name != NULL) printf(name); |
---|
| 349 | |
---|
| 350 | for(j=ncl; j<=nch; j++) { |
---|
| 351 | for(i=nrl; i<=nrh; i++) { |
---|
| 352 | printf(format, m[i][j]); |
---|
| 353 | } |
---|
| 354 | printf("\n"); |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 358 | IMAGE_EXPORT(void) display_f32matrix_T(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 359 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 360 | { |
---|
| 361 | long i,j; |
---|
| 362 | |
---|
| 363 | if(name != NULL) printf(name); |
---|
| 364 | |
---|
| 365 | for(j=ncl; j<=nch; j++) { |
---|
| 366 | for(i=nrl; i<=nrh; i++) { |
---|
| 367 | printf(format, m[i][j]); |
---|
| 368 | } |
---|
| 369 | printf("\n"); |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 373 | IMAGE_EXPORT(void) display_f64matrix_T(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 374 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 375 | { |
---|
| 376 | long i,j; |
---|
| 377 | |
---|
| 378 | if(name != NULL) printf(name); |
---|
| 379 | |
---|
| 380 | for(j=ncl; j<=nch; j++) { |
---|
| 381 | for(i=nrl; i<=nrh; i++) { |
---|
| 382 | printf(format, m[i][j]); |
---|
| 383 | } |
---|
| 384 | printf("\n"); |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 388 | IMAGE_EXPORT(void) display_rgb8matrix_T(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 389 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
| 390 | { |
---|
| 391 | long i,j; |
---|
| 392 | |
---|
| 393 | if(name != NULL) printf(name); |
---|
| 394 | |
---|
| 395 | for(j=ncl; j<=nch; j++) { |
---|
| 396 | for(i=nrl; i<=nrh; i++) { |
---|
| 397 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
| 398 | } |
---|
| 399 | printf("\n"); |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 403 | IMAGE_EXPORT(void) display_rgbx8matrix_T(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 404 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
| 405 | { |
---|
| 406 | long i,j; |
---|
| 407 | |
---|
| 408 | if(name != NULL) printf(name); |
---|
| 409 | |
---|
| 410 | for(j=ncl; j<=nch; j++) { |
---|
| 411 | for(i=nrl; i<=nrh; i++) { |
---|
| 412 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
| 413 | } |
---|
| 414 | printf("\n"); |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | /* |
---|
| 419 | * ------------------------ |
---|
| 420 | * --- display_matrix_T --- |
---|
| 421 | * ------------------------ |
---|
| 422 | */ |
---|
| 423 | |
---|
| 424 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 425 | IMAGE_EXPORT(void) display_si8matrix_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 426 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 427 | { |
---|
| 428 | int i,j; |
---|
| 429 | |
---|
| 430 | if(name != NULL) printf(name); |
---|
| 431 | |
---|
| 432 | // 1ere ligne |
---|
| 433 | printf("%5c", '#'); |
---|
| 434 | for(j=ncl; j<=nch; j++) { |
---|
| 435 | printf(format, j); |
---|
| 436 | } |
---|
| 437 | printf("\n"); |
---|
| 438 | for(i=nrl; i<=nrh; i++) { |
---|
| 439 | printf("[%3d]", i); |
---|
| 440 | for(j=ncl; j<=nch; j++) { |
---|
| 441 | printf(format, m[i][j]); |
---|
| 442 | } |
---|
| 443 | printf("\n"); |
---|
| 444 | } |
---|
| 445 | printf("\n"); |
---|
| 446 | } |
---|
| 447 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 448 | IMAGE_EXPORT(void) display_ui8matrix_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 449 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 450 | { |
---|
| 451 | int i,j; |
---|
| 452 | |
---|
| 453 | if(name != NULL) printf(name); |
---|
| 454 | |
---|
| 455 | // 1ere ligne |
---|
| 456 | printf("%5c", '#'); |
---|
| 457 | for(j=ncl; j<=nch; j++) { |
---|
| 458 | printf(format, j); |
---|
| 459 | } |
---|
| 460 | printf("\n"); |
---|
| 461 | for(i=nrl; i<=nrh; i++) { |
---|
| 462 | printf("[%3d]", i); |
---|
| 463 | for(j=ncl; j<=nch; j++) { |
---|
| 464 | printf(format, m[i][j]); |
---|
| 465 | } |
---|
| 466 | printf("\n"); |
---|
| 467 | } |
---|
| 468 | printf("\n"); |
---|
| 469 | } |
---|
| 470 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 471 | IMAGE_EXPORT(void) display_si16matrix_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 472 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 473 | { |
---|
| 474 | int i,j; |
---|
| 475 | |
---|
| 476 | if(name != NULL) printf(name); |
---|
| 477 | |
---|
| 478 | // 1ere ligne |
---|
| 479 | printf("%5c", '#'); |
---|
| 480 | for(j=ncl; j<=nch; j++) { |
---|
| 481 | printf(format, j); |
---|
| 482 | } |
---|
| 483 | printf("\n"); |
---|
| 484 | for(i=nrl; i<=nrh; i++) { |
---|
| 485 | printf("[%3d]", i); |
---|
| 486 | for(j=ncl; j<=nch; j++) { |
---|
| 487 | printf(format, m[i][j]); |
---|
| 488 | } |
---|
| 489 | printf("\n"); |
---|
| 490 | } |
---|
| 491 | printf("\n"); |
---|
| 492 | } |
---|
| 493 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 494 | IMAGE_EXPORT(void) display_ui16matrix_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 495 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 496 | { |
---|
| 497 | int i,j; |
---|
| 498 | |
---|
| 499 | if(name != NULL) printf(name); |
---|
| 500 | |
---|
| 501 | // 1ere ligne |
---|
| 502 | printf("%5c", '#'); |
---|
| 503 | for(j=ncl; j<=nch; j++) { |
---|
| 504 | printf(format, j); |
---|
| 505 | } |
---|
| 506 | printf("\n"); |
---|
| 507 | for(i=nrl; i<=nrh; i++) { |
---|
| 508 | printf("[%3d]", i); |
---|
| 509 | for(j=ncl; j<=nch; j++) { |
---|
| 510 | printf(format, m[i][j]); |
---|
| 511 | } |
---|
| 512 | printf("\n"); |
---|
| 513 | } |
---|
| 514 | printf("\n"); |
---|
| 515 | } |
---|
| 516 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 517 | IMAGE_EXPORT(void) display_si32matrix_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 518 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 519 | { |
---|
| 520 | int i,j; |
---|
| 521 | |
---|
| 522 | if(name != NULL) printf(name); |
---|
| 523 | |
---|
| 524 | // 1ere ligne |
---|
| 525 | printf("%5c", '#'); |
---|
| 526 | for(j=ncl; j<=nch; j++) { |
---|
| 527 | printf(format, j); |
---|
| 528 | } |
---|
| 529 | printf("\n"); |
---|
| 530 | for(i=nrl; i<=nrh; i++) { |
---|
| 531 | printf("[%3d]", i); |
---|
| 532 | for(j=ncl; j<=nch; j++) { |
---|
| 533 | printf(format, m[i][j]); |
---|
| 534 | } |
---|
| 535 | printf("\n"); |
---|
| 536 | } |
---|
| 537 | printf("\n"); |
---|
| 538 | } |
---|
| 539 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 540 | IMAGE_EXPORT(void) display_ui32matrix_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 541 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 542 | { |
---|
| 543 | int i,j; |
---|
| 544 | |
---|
| 545 | if(name != NULL) printf(name); |
---|
| 546 | |
---|
| 547 | // 1ere ligne |
---|
| 548 | printf("%5c", '#'); |
---|
| 549 | for(j=ncl; j<=nch; j++) { |
---|
| 550 | printf(format, j); |
---|
| 551 | } |
---|
| 552 | printf("\n"); |
---|
| 553 | for(i=nrl; i<=nrh; i++) { |
---|
| 554 | printf("[%3d]", i); |
---|
| 555 | for(j=ncl; j<=nch; j++) { |
---|
| 556 | printf(format, m[i][j]); |
---|
| 557 | } |
---|
| 558 | printf("\n"); |
---|
| 559 | } |
---|
| 560 | printf("\n"); |
---|
| 561 | } |
---|
| 562 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 563 | IMAGE_EXPORT(void) display_si64matrix_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 564 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 565 | { |
---|
| 566 | int i,j; |
---|
| 567 | |
---|
| 568 | if(name != NULL) printf(name); |
---|
| 569 | |
---|
| 570 | // 1ere ligne |
---|
| 571 | printf("%5c", '#'); |
---|
| 572 | for(j=ncl; j<=nch; j++) { |
---|
| 573 | printf(format, j); |
---|
| 574 | } |
---|
| 575 | printf("\n"); |
---|
| 576 | for(i=nrl; i<=nrh; i++) { |
---|
| 577 | printf("[%3d]", i); |
---|
| 578 | for(j=ncl; j<=nch; j++) { |
---|
| 579 | printf(format, m[i][j]); |
---|
| 580 | } |
---|
| 581 | printf("\n"); |
---|
| 582 | } |
---|
| 583 | printf("\n"); |
---|
| 584 | } |
---|
| 585 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 586 | IMAGE_EXPORT(void) display_ui64matrix_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 587 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 588 | { |
---|
| 589 | int i,j; |
---|
| 590 | |
---|
| 591 | if(name != NULL) printf(name); |
---|
| 592 | |
---|
| 593 | // 1ere ligne |
---|
| 594 | printf("%5c", '#'); |
---|
| 595 | for(j=ncl; j<=nch; j++) { |
---|
| 596 | printf(format, j); |
---|
| 597 | } |
---|
| 598 | printf("\n"); |
---|
| 599 | for(i=nrl; i<=nrh; i++) { |
---|
| 600 | printf("[%3d]", i); |
---|
| 601 | for(j=ncl; j<=nch; j++) { |
---|
| 602 | printf(format, m[i][j]); |
---|
| 603 | } |
---|
| 604 | printf("\n"); |
---|
| 605 | } |
---|
| 606 | printf("\n"); |
---|
| 607 | } |
---|
| 608 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 609 | IMAGE_EXPORT(void) display_f32matrix_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 610 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 611 | { |
---|
| 612 | int i,j; |
---|
| 613 | |
---|
| 614 | if(name != NULL) printf(name); |
---|
| 615 | |
---|
| 616 | // 1ere ligne |
---|
| 617 | printf("%5c", '#'); |
---|
| 618 | for(j=ncl; j<=nch; j++) { |
---|
| 619 | printf(format, j); |
---|
| 620 | } |
---|
| 621 | printf("\n"); |
---|
| 622 | for(i=nrl; i<=nrh; i++) { |
---|
| 623 | printf("[%3d]", i); |
---|
| 624 | for(j=ncl; j<=nch; j++) { |
---|
| 625 | printf(format, m[i][j]); |
---|
| 626 | } |
---|
| 627 | printf("\n"); |
---|
| 628 | } |
---|
| 629 | printf("\n"); |
---|
| 630 | } |
---|
| 631 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 632 | IMAGE_EXPORT(void) display_f64matrix_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 633 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 634 | { |
---|
| 635 | int i,j; |
---|
| 636 | |
---|
| 637 | if(name != NULL) printf(name); |
---|
| 638 | |
---|
| 639 | // 1ere ligne |
---|
| 640 | printf("%5c", '#'); |
---|
| 641 | for(j=ncl; j<=nch; j++) { |
---|
| 642 | printf(format, j); |
---|
| 643 | } |
---|
| 644 | printf("\n"); |
---|
| 645 | for(i=nrl; i<=nrh; i++) { |
---|
| 646 | printf("[%3d]", i); |
---|
| 647 | for(j=ncl; j<=nch; j++) { |
---|
| 648 | printf(format, m[i][j]); |
---|
| 649 | } |
---|
| 650 | printf("\n"); |
---|
| 651 | } |
---|
| 652 | printf("\n"); |
---|
| 653 | } |
---|
| 654 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 655 | IMAGE_EXPORT(void) display_rgb8matrix_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 656 | /* --------------------------------------------------------------------------------------------------------------- */ |
---|
| 657 | { |
---|
| 658 | int i,j; |
---|
| 659 | |
---|
| 660 | if(name != NULL) printf(name); |
---|
| 661 | |
---|
| 662 | // 1ere ligne |
---|
| 663 | printf("%5c", '#'); |
---|
| 664 | for(j=ncl; j<=nch; j++) { |
---|
| 665 | printf(format, j); |
---|
| 666 | } |
---|
| 667 | printf("\n"); |
---|
| 668 | for(i=nrl; i<=nrh; i++) { |
---|
| 669 | printf("[%3d]", i); |
---|
| 670 | for(j=ncl; j<=nch; j++) { |
---|
| 671 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
| 672 | } |
---|
| 673 | printf("\n"); |
---|
| 674 | } |
---|
| 675 | printf("\n"); |
---|
| 676 | } |
---|
| 677 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 678 | IMAGE_EXPORT(void) display_rgbx8matrix_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
| 679 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
| 680 | { |
---|
| 681 | int i,j; |
---|
| 682 | |
---|
| 683 | if(name != NULL) printf(name); |
---|
| 684 | |
---|
| 685 | // 1ere ligne |
---|
| 686 | printf("%5c", '#'); |
---|
| 687 | for(j=ncl; j<=nch; j++) { |
---|
| 688 | printf(format, j); |
---|
| 689 | } |
---|
| 690 | printf("\n"); |
---|
| 691 | for(i=nrl; i<=nrh; i++) { |
---|
| 692 | printf("[%3d]", i); |
---|
| 693 | for(j=ncl; j<=nch; j++) { |
---|
| 694 | printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
| 695 | } |
---|
| 696 | printf("\n"); |
---|
| 697 | } |
---|
| 698 | printf("\n"); |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | /* |
---|
| 702 | * ------------------------------- |
---|
| 703 | * --- display_matrix_positive --- |
---|
| 704 | * ------------------------------- |
---|
| 705 | */ |
---|
| 706 | |
---|
| 707 | // ------------------------------------------------------------------------------------------------ |
---|
| 708 | void display_si8matrix_positive(sint8 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 709 | // ------------------------------------------------------------------------------------------------ |
---|
| 710 | { |
---|
| 711 | int i, j; |
---|
| 712 | |
---|
| 713 | char *format, *str; |
---|
| 714 | |
---|
| 715 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 716 | |
---|
| 717 | if(name != NULL) printf(name); |
---|
| 718 | |
---|
| 719 | for(i=i0; i<=i1; i++) { |
---|
| 720 | for(j=j0; j<=j1; j++) { |
---|
| 721 | if(m[i][j]) { |
---|
| 722 | printf(format, m[i][j]); |
---|
| 723 | } else { |
---|
| 724 | printf("%s", str); |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | printf("\n"); |
---|
| 728 | } |
---|
| 729 | } |
---|
| 730 | // ------------------------------------------------------------------------------------------------ |
---|
| 731 | void display_ui8matrix_positive(uint8 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 732 | // ------------------------------------------------------------------------------------------------ |
---|
| 733 | { |
---|
| 734 | int i, j; |
---|
| 735 | |
---|
[805] | 736 | char * format; |
---|
| 737 | char * str; |
---|
[772] | 738 | |
---|
| 739 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 740 | |
---|
[805] | 741 | if (name != NULL) { |
---|
| 742 | printf("%s\n", name); |
---|
| 743 | } |
---|
[772] | 744 | |
---|
[805] | 745 | // @QM have to hack this function for the giet |
---|
| 746 | for (i = i0; i <= i1; i++) { |
---|
| 747 | for (j = j0; j <= j1; j++) { |
---|
| 748 | if (m[i][j]) { |
---|
| 749 | // For the giet |
---|
| 750 | int a = m[i][j]; |
---|
| 751 | int len = 0; |
---|
| 752 | if (a == 0) { |
---|
| 753 | len = 1; |
---|
| 754 | } |
---|
| 755 | else { |
---|
| 756 | while (a != 0) { |
---|
| 757 | a = a / 10; |
---|
| 758 | len++; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | for (int k = len; k < iformat; k++) { |
---|
| 762 | printf(" "); |
---|
| 763 | } |
---|
| 764 | printf("%d", m[i][j]); |
---|
| 765 | } |
---|
| 766 | else { |
---|
[772] | 767 | printf("%s", str); |
---|
| 768 | } |
---|
| 769 | } |
---|
| 770 | printf("\n"); |
---|
| 771 | } |
---|
| 772 | } |
---|
[805] | 773 | |
---|
| 774 | |
---|
[772] | 775 | // -------------------------------------------------------------------------------------------------- |
---|
| 776 | void display_si16matrix_positive(sint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 777 | // -------------------------------------------------------------------------------------------------- |
---|
| 778 | { |
---|
| 779 | int i, j; |
---|
| 780 | |
---|
| 781 | char *format, *str; |
---|
| 782 | |
---|
| 783 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 784 | |
---|
| 785 | if(name != NULL) printf(name); |
---|
| 786 | |
---|
| 787 | for(i=i0; i<=i1; i++) { |
---|
| 788 | for(j=j0; j<=j1; j++) { |
---|
| 789 | if(m[i][j]) { |
---|
| 790 | printf(format, m[i][j]); |
---|
| 791 | } else { |
---|
| 792 | printf("%s", str); |
---|
| 793 | } |
---|
| 794 | } |
---|
| 795 | printf("\n"); |
---|
| 796 | } |
---|
| 797 | } |
---|
| 798 | // -------------------------------------------------------------------------------------------------- |
---|
| 799 | void display_ui16matrix_positive(uint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 800 | // -------------------------------------------------------------------------------------------------- |
---|
| 801 | { |
---|
| 802 | int i, j; |
---|
| 803 | char *format, *str; |
---|
| 804 | |
---|
| 805 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 806 | |
---|
| 807 | if(name != NULL) printf(name); |
---|
| 808 | |
---|
| 809 | for(i=i0; i<=i1; i++) { |
---|
| 810 | for(j=j0; j<=j1; j++) { |
---|
| 811 | if(m[i][j]) { |
---|
| 812 | printf(format, m[i][j]); |
---|
| 813 | } else { |
---|
| 814 | printf("%s", str); |
---|
| 815 | } |
---|
| 816 | } |
---|
| 817 | printf("\n"); |
---|
| 818 | } |
---|
| 819 | } |
---|
| 820 | // -------------------------------------------------------------------------------------------------- |
---|
| 821 | void display_si32matrix_positive(sint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 822 | // -------------------------------------------------------------------------------------------------- |
---|
| 823 | { |
---|
| 824 | int i, j; |
---|
| 825 | char *format, *str; |
---|
| 826 | |
---|
| 827 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 828 | |
---|
| 829 | if(name != NULL) printf(name); |
---|
| 830 | |
---|
| 831 | for(i=i0; i<=i1; i++) { |
---|
| 832 | for(j=j0; j<=j1; j++) { |
---|
| 833 | if(m[i][j]) { |
---|
| 834 | printf(format, m[i][j]); |
---|
| 835 | } else { |
---|
| 836 | printf("%s", str); |
---|
| 837 | } |
---|
| 838 | } |
---|
| 839 | printf("\n"); |
---|
| 840 | } |
---|
| 841 | } |
---|
| 842 | // -------------------------------------------------------------------------------------------------- |
---|
| 843 | void display_ui32matrix_positive(uint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 844 | // -------------------------------------------------------------------------------------------------- |
---|
| 845 | { |
---|
| 846 | int i, j; |
---|
[805] | 847 | char * format; |
---|
| 848 | char * str; |
---|
[772] | 849 | |
---|
| 850 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 851 | |
---|
[805] | 852 | if (name != NULL) { |
---|
| 853 | printf("%s\n", name); |
---|
| 854 | } |
---|
[772] | 855 | |
---|
[805] | 856 | // @QM have to hack this function for the giet |
---|
| 857 | for (i = i0; i <= i1; i++) { |
---|
| 858 | for (j = j0; j <= j1; j++) { |
---|
| 859 | if (m[i][j] != 0) { |
---|
| 860 | int a = m[i][j]; |
---|
| 861 | int len = 0; |
---|
| 862 | if (a == 0) { |
---|
| 863 | len = 1; |
---|
| 864 | } |
---|
| 865 | else { |
---|
| 866 | while (a != 0) { |
---|
| 867 | a = a / 10; |
---|
| 868 | len++; |
---|
| 869 | } |
---|
| 870 | } |
---|
| 871 | for (int k = len; k < iformat; k++) { |
---|
| 872 | printf(" "); |
---|
| 873 | } |
---|
| 874 | printf("%d", m[i][j]); |
---|
| 875 | } |
---|
| 876 | else { |
---|
[772] | 877 | printf("%s", str); |
---|
| 878 | } |
---|
| 879 | } |
---|
| 880 | printf("\n"); |
---|
| 881 | } |
---|
[805] | 882 | |
---|
[772] | 883 | } |
---|
| 884 | // -------------------------------------------------------------------------------------------------- |
---|
| 885 | void display_si64matrix_positive(sint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 886 | // -------------------------------------------------------------------------------------------------- |
---|
| 887 | { |
---|
| 888 | int i, j; |
---|
| 889 | char *format, *str; |
---|
| 890 | |
---|
| 891 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 892 | |
---|
| 893 | if(name != NULL) printf(name); |
---|
| 894 | |
---|
| 895 | for(i=i0; i<=i1; i++) { |
---|
| 896 | for(j=j0; j<=j1; j++) { |
---|
| 897 | if(m[i][j]) { |
---|
| 898 | printf(format, m[i][j]); |
---|
| 899 | } else { |
---|
| 900 | printf("%s", str); |
---|
| 901 | } |
---|
| 902 | } |
---|
| 903 | printf("\n"); |
---|
| 904 | } |
---|
| 905 | } |
---|
| 906 | // -------------------------------------------------------------------------------------------------- |
---|
| 907 | void display_ui64matrix_positive(uint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name) |
---|
| 908 | // -------------------------------------------------------------------------------------------------- |
---|
| 909 | { |
---|
| 910 | int i, j; |
---|
| 911 | char *format, *str; |
---|
| 912 | |
---|
| 913 | select_display_positive_parameters(iformat, &format, &str); |
---|
| 914 | |
---|
| 915 | if(name != NULL) printf(name); |
---|
| 916 | |
---|
| 917 | for(i=i0; i<=i1; i++) { |
---|
| 918 | for(j=j0; j<=j1; j++) { |
---|
| 919 | if(m[i][j]) { |
---|
| 920 | printf(format, m[i][j]); |
---|
| 921 | } else { |
---|
| 922 | printf("%s", str); |
---|
| 923 | } |
---|
| 924 | } |
---|
| 925 | printf("\n"); |
---|
| 926 | } |
---|
| 927 | } |
---|
[798] | 928 | |
---|
| 929 | |
---|
| 930 | |
---|
| 931 | /* --------------------------------------- */ |
---|
| 932 | static char * readitem(int fd, char * buffer) |
---|
| 933 | /* --------------------------------------- */ |
---|
| 934 | { |
---|
| 935 | char * aux; |
---|
| 936 | int k; |
---|
| 937 | int n; |
---|
| 938 | |
---|
| 939 | k = 0; |
---|
| 940 | aux = buffer; |
---|
| 941 | while (1) { |
---|
| 942 | n = read(fd, aux, 1); |
---|
| 943 | if (n == 0) { |
---|
| 944 | break; |
---|
| 945 | } |
---|
| 946 | switch (k) { |
---|
| 947 | case 0: |
---|
| 948 | if (*aux == '#') { |
---|
| 949 | k = 1; |
---|
| 950 | } |
---|
| 951 | if (isalnum(*aux)) { |
---|
| 952 | k = 2; |
---|
| 953 | aux++; |
---|
| 954 | } |
---|
| 955 | break; |
---|
| 956 | case 1: |
---|
| 957 | if (*aux == 0xA) { |
---|
| 958 | k = 0; |
---|
| 959 | } |
---|
| 960 | break; |
---|
| 961 | case 2: |
---|
| 962 | if (!isalnum(*aux)) { |
---|
| 963 | *aux = 0; |
---|
| 964 | return buffer; |
---|
| 965 | } |
---|
| 966 | aux++; |
---|
| 967 | break; |
---|
| 968 | } |
---|
| 969 | } |
---|
| 970 | *aux = 0; |
---|
| 971 | return buffer; |
---|
| 972 | } |
---|
| 973 | |
---|
| 974 | |
---|
| 975 | /* ------------------------------------------------- */ |
---|
| 976 | static void ReadPGMrow(int fd, int width, uint8 * line) |
---|
| 977 | /* ------------------------------------------------- */ |
---|
| 978 | { |
---|
| 979 | read(fd, &line[0], sizeof(uint8) * width); |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | |
---|
| 983 | /* -------------------------------------------------- */ |
---|
| 984 | static void WritePGMrow(uint8 * line, int width, int fd) |
---|
| 985 | /* -------------------------------------------------- */ |
---|
| 986 | { |
---|
| 987 | write(fd, &line[0], sizeof(uint8) * width); |
---|
| 988 | } |
---|
| 989 | |
---|
| 990 | |
---|
| 991 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 992 | IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char * filename, int * nrl, int * nrh, int * ncl, int * nch) |
---|
| 993 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 994 | { |
---|
| 995 | // only for P5 binary type, not for text type |
---|
| 996 | |
---|
| 997 | int height, width, gris; |
---|
| 998 | uint8 ** m; |
---|
| 999 | int fd; |
---|
| 1000 | |
---|
| 1001 | char buffer[80]; |
---|
| 1002 | int i; |
---|
| 1003 | |
---|
| 1004 | // open file |
---|
| 1005 | fd = open(filename, O_RDONLY); |
---|
| 1006 | if (fd < 0) { |
---|
| 1007 | printf("*** Error: Can't open file %s in %s.\n", filename, __func__); |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | // read PGM header |
---|
| 1011 | readitem(fd, &buffer[0]); |
---|
| 1012 | if (strcmp(&buffer[0], "P5") != 0) { |
---|
| 1013 | printf("*** Error: Invalid file header in file %s\n", filename); |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | width = atoi(readitem(fd, &buffer[0])); |
---|
| 1017 | height = atoi(readitem(fd, &buffer[0])); |
---|
| 1018 | gris = atoi(readitem(fd, &buffer[0])); |
---|
| 1019 | |
---|
| 1020 | *nrl = 0; |
---|
| 1021 | *nrh = height - 1; |
---|
| 1022 | *ncl = 0; |
---|
| 1023 | *nch = width - 1; |
---|
| 1024 | m = ui8matrix(*nrl, *nrh, *ncl, *nch); |
---|
| 1025 | |
---|
| 1026 | for (i = 0; i < height; i++) { |
---|
| 1027 | ReadPGMrow(fd, width, m[i]); |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | close(fd); |
---|
| 1031 | |
---|
| 1032 | return m; |
---|
| 1033 | } |
---|
| 1034 | |
---|
| 1035 | |
---|
| 1036 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 1037 | IMAGE_EXPORT(void) SavePGM_ui8matrix(uint8 ** m, int nrl, int nrh, int ncl, int nch, char * filename) |
---|
| 1038 | /* ----------------------------------------------------------------------------------------------- */ |
---|
| 1039 | { |
---|
| 1040 | int nrow = nrh - nrl + 1; |
---|
| 1041 | int ncol = nch - ncl + 1; |
---|
| 1042 | |
---|
| 1043 | char buffer[80]; |
---|
| 1044 | |
---|
| 1045 | int fd; |
---|
| 1046 | int i; |
---|
| 1047 | |
---|
| 1048 | fd = open(filename, O_TRUNC | O_CREAT); |
---|
| 1049 | if (fd < 0) { |
---|
| 1050 | printf("*** Error: Impossible to open file %s in %s\n", filename, __func__); |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | /* enregistrement de l'image au format rpgm */ |
---|
| 1054 | snprintf(buffer, 80, "P5\n%d %d\n255\n", ncol, nrow); |
---|
| 1055 | write(fd, buffer, strlen(buffer)); |
---|
| 1056 | for (i = nrl; i <= nrh; i++) { |
---|
| 1057 | WritePGMrow(m[i], ncol, fd); |
---|
| 1058 | } |
---|
| 1059 | |
---|
| 1060 | /* fermeture du fichier */ |
---|
| 1061 | close(fd); |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | |
---|
| 1065 | |
---|