1 | /* ---------------- */ |
---|
2 | /* --- nrio2f.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 | |
---|
18 | #include "mypredef.h" |
---|
19 | #include "nrtype.h" |
---|
20 | #include "nrdef.h" |
---|
21 | #include "nrmacro.h" |
---|
22 | #include "nrkernel.h" |
---|
23 | |
---|
24 | #include "nralloc1.h" |
---|
25 | #include "nralloc2.h" |
---|
26 | #include "nrio0.h" |
---|
27 | #include "nrio1.h" |
---|
28 | #include "nrio2.h" |
---|
29 | |
---|
30 | /* |
---|
31 | * -------------------- |
---|
32 | * --- write_matrix --- |
---|
33 | * -------------------- |
---|
34 | */ |
---|
35 | |
---|
36 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
37 | IMAGE_EXPORT(void) write_si8matrix(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
38 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
39 | { |
---|
40 | int i,j; |
---|
41 | |
---|
42 | FILE *f; |
---|
43 | |
---|
44 | f = fopen(filename, "wt"); |
---|
45 | if(f == NULL) { |
---|
46 | nrerror("Can't open file in write_si8matrix"); |
---|
47 | } |
---|
48 | |
---|
49 | for(i=nrl; i<=nrh; i++) { |
---|
50 | for(j=ncl; j<=nch; j++) { |
---|
51 | fprintf(f, format, m[i][j]); |
---|
52 | } |
---|
53 | fputc('\n', f); |
---|
54 | } |
---|
55 | fclose(f); |
---|
56 | } |
---|
57 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
58 | IMAGE_EXPORT(void) write_ui8matrix(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
59 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
60 | { |
---|
61 | int i,j; |
---|
62 | |
---|
63 | FILE *f; |
---|
64 | |
---|
65 | f = fopen(filename, "wt"); |
---|
66 | if(f == NULL) { |
---|
67 | nrerror("Can't open file in write_ui8matrix"); |
---|
68 | } |
---|
69 | |
---|
70 | for(i=nrl; i<=nrh; i++) { |
---|
71 | for(j=ncl; j<=nch; j++) { |
---|
72 | fprintf(f, format, m[i][j]); |
---|
73 | } |
---|
74 | fputc('\n', f); |
---|
75 | } |
---|
76 | fclose(f); |
---|
77 | } |
---|
78 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
79 | IMAGE_EXPORT(void) write_si16matrix(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
80 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
81 | { |
---|
82 | int i,j; |
---|
83 | |
---|
84 | FILE *f; |
---|
85 | |
---|
86 | f = fopen(filename, "wt"); |
---|
87 | if(f == NULL) { |
---|
88 | nrerror("Can't open file in write_si16matrix"); |
---|
89 | } |
---|
90 | |
---|
91 | for(i=nrl; i<=nrh; i++) { |
---|
92 | for(j=ncl; j<=nch; j++) { |
---|
93 | fprintf(f, format, m[i][j]); |
---|
94 | } |
---|
95 | fputc('\n', f); |
---|
96 | } |
---|
97 | fclose(f); |
---|
98 | } |
---|
99 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
100 | IMAGE_EXPORT(void) write_ui16matrix(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
101 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
102 | { |
---|
103 | int i,j; |
---|
104 | |
---|
105 | FILE *f; |
---|
106 | |
---|
107 | f = fopen(filename, "wt"); |
---|
108 | if(f == NULL) { |
---|
109 | nrerror("Can't open file in write_ui16matrix"); |
---|
110 | } |
---|
111 | |
---|
112 | for(i=nrl; i<=nrh; i++) { |
---|
113 | for(j=ncl; j<=nch; j++) { |
---|
114 | fprintf(f, format, m[i][j]); |
---|
115 | } |
---|
116 | fputc('\n', f); |
---|
117 | } |
---|
118 | fclose(f); |
---|
119 | } |
---|
120 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
121 | IMAGE_EXPORT(void) write_si32matrix(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
122 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
123 | { |
---|
124 | int i,j; |
---|
125 | |
---|
126 | FILE *f; |
---|
127 | |
---|
128 | f = fopen(filename, "wt"); |
---|
129 | if(f == NULL) { |
---|
130 | nrerror("Can't open file in write_si32matrix"); |
---|
131 | } |
---|
132 | |
---|
133 | for(i=nrl; i<=nrh; i++) { |
---|
134 | for(j=ncl; j<=nch; j++) { |
---|
135 | fprintf(f, format, m[i][j]); |
---|
136 | } |
---|
137 | fputc('\n', f); |
---|
138 | } |
---|
139 | fclose(f); |
---|
140 | } |
---|
141 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
142 | IMAGE_EXPORT(void) write_ui32matrix(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
143 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
144 | { |
---|
145 | int i,j; |
---|
146 | |
---|
147 | FILE *f; |
---|
148 | |
---|
149 | f = fopen(filename, "wt"); |
---|
150 | if(f == NULL) { |
---|
151 | nrerror("Can't open file in write_ui32matrix"); |
---|
152 | } |
---|
153 | |
---|
154 | for(i=nrl; i<=nrh; i++) { |
---|
155 | for(j=ncl; j<=nch; j++) { |
---|
156 | fprintf(f, format, m[i][j]); |
---|
157 | } |
---|
158 | fputc('\n', f); |
---|
159 | } |
---|
160 | fclose(f); |
---|
161 | } |
---|
162 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
163 | IMAGE_EXPORT(void) write_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
164 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
165 | { |
---|
166 | int i,j; |
---|
167 | |
---|
168 | FILE *f; |
---|
169 | |
---|
170 | f = fopen(filename, "wt"); |
---|
171 | if(f == NULL) { |
---|
172 | nrerror("Can't open file in write_si64matrix"); |
---|
173 | } |
---|
174 | |
---|
175 | for(i=nrl; i<=nrh; i++) { |
---|
176 | for(j=ncl; j<=nch; j++) { |
---|
177 | fprintf(f, format, m[i][j]); |
---|
178 | } |
---|
179 | fputc('\n', f); |
---|
180 | } |
---|
181 | fclose(f); |
---|
182 | } |
---|
183 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
184 | IMAGE_EXPORT(void) write_ui64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
185 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
186 | { |
---|
187 | int i,j; |
---|
188 | |
---|
189 | FILE *f; |
---|
190 | |
---|
191 | f = fopen(filename, "wt"); |
---|
192 | if(f == NULL) { |
---|
193 | nrerror("Can't open file in write_ui64matrix"); |
---|
194 | } |
---|
195 | |
---|
196 | for(i=nrl; i<=nrh; i++) { |
---|
197 | for(j=ncl; j<=nch; j++) { |
---|
198 | fprintf(f, format, m[i][j]); |
---|
199 | } |
---|
200 | fputc('\n', f); |
---|
201 | } |
---|
202 | fclose(f); |
---|
203 | } |
---|
204 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
205 | IMAGE_EXPORT(void) write_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
206 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
207 | { |
---|
208 | int i,j; |
---|
209 | |
---|
210 | FILE *f; |
---|
211 | |
---|
212 | f = fopen(filename, "wt"); |
---|
213 | if(f == NULL) { |
---|
214 | nrerror("Can't open file in write_f32matrix"); |
---|
215 | } |
---|
216 | |
---|
217 | for(i=nrl; i<=nrh; i++) { |
---|
218 | for(j=ncl; j<=nch; j++) { |
---|
219 | fprintf(f, format, m[i][j]); |
---|
220 | } |
---|
221 | fputc('\n', f); |
---|
222 | } |
---|
223 | fclose(f); |
---|
224 | } |
---|
225 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
226 | IMAGE_EXPORT(void) write_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
227 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
228 | { |
---|
229 | int i,j; |
---|
230 | |
---|
231 | FILE *f; |
---|
232 | |
---|
233 | f = fopen(filename, "wt"); |
---|
234 | if(f == NULL) { |
---|
235 | nrerror("Can't open file in write_f64matrix"); |
---|
236 | } |
---|
237 | |
---|
238 | for(i=nrl; i<=nrh; i++) { |
---|
239 | for(j=ncl; j<=nch; j++) { |
---|
240 | fprintf(f, format, m[i][j]); |
---|
241 | } |
---|
242 | fputc('\n', f); |
---|
243 | } |
---|
244 | fclose(f); |
---|
245 | } |
---|
246 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
247 | IMAGE_EXPORT(void) write_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
248 | /* ---------------------------------------------------------------------------------------------------------- */ |
---|
249 | { |
---|
250 | int i,j; |
---|
251 | |
---|
252 | FILE *f; |
---|
253 | |
---|
254 | f = fopen(filename, "wt"); |
---|
255 | if(f == NULL) { |
---|
256 | nrerror("Can't open file in write_rgb8matrix"); |
---|
257 | } |
---|
258 | |
---|
259 | for(i=nrl; i<=nrh; i++) { |
---|
260 | for(j=ncl; j<=nch; j++) { |
---|
261 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
262 | } |
---|
263 | fputc('\n', f); |
---|
264 | } |
---|
265 | fclose(f); |
---|
266 | } |
---|
267 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
268 | IMAGE_EXPORT(void) write_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
269 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
270 | { |
---|
271 | int i,j; |
---|
272 | |
---|
273 | FILE *f; |
---|
274 | |
---|
275 | f = fopen(filename, "wt"); |
---|
276 | if(f == NULL) { |
---|
277 | nrerror("Can't open file in write_rgbx8matrix"); |
---|
278 | } |
---|
279 | |
---|
280 | for(i=nrl; i<=nrh; i++) { |
---|
281 | for(j=ncl; j<=nch; j++) { |
---|
282 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
283 | } |
---|
284 | fputc('\n', f); |
---|
285 | } |
---|
286 | fclose(f); |
---|
287 | } |
---|
288 | |
---|
289 | /* |
---|
290 | * ---------------------- |
---|
291 | * --- write_matrix_T --- |
---|
292 | * ---------------------- |
---|
293 | */ |
---|
294 | |
---|
295 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
296 | IMAGE_EXPORT(void) write_si8matrix_T(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
297 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
298 | { |
---|
299 | long i,j; |
---|
300 | |
---|
301 | FILE *f; |
---|
302 | |
---|
303 | f = fopen(filename, "wt"); |
---|
304 | if(f == NULL) { |
---|
305 | nrerror("Can't open file in write_si8matrix_T"); |
---|
306 | } |
---|
307 | |
---|
308 | for(j=ncl; j<=nch; j++) { |
---|
309 | for(i=nrl; i<=nrh; i++) { |
---|
310 | fprintf(f, format, m[i][j]); |
---|
311 | } |
---|
312 | fputc('\n', f); |
---|
313 | } |
---|
314 | fclose(f); |
---|
315 | } |
---|
316 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
317 | IMAGE_EXPORT(void) write_ui8matrix_T(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
318 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
319 | { |
---|
320 | long i,j; |
---|
321 | |
---|
322 | FILE *f; |
---|
323 | |
---|
324 | f = fopen(filename, "wt"); |
---|
325 | if(f == NULL) { |
---|
326 | nrerror("Can't open file in write_ui8matrix_T"); |
---|
327 | } |
---|
328 | |
---|
329 | for(j=ncl; j<=nch; j++) { |
---|
330 | for(i=nrl; i<=nrh; i++) { |
---|
331 | fprintf(f, format, m[i][j]); |
---|
332 | } |
---|
333 | fputc('\n', f); |
---|
334 | } |
---|
335 | fclose(f); |
---|
336 | } |
---|
337 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
338 | IMAGE_EXPORT(void) write_si32matrix_T(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
339 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
340 | { |
---|
341 | long i,j; |
---|
342 | |
---|
343 | FILE *f; |
---|
344 | |
---|
345 | f = fopen(filename, "wt"); |
---|
346 | if(f == NULL) { |
---|
347 | nrerror("Can't open file in write_si32matrix_T"); |
---|
348 | } |
---|
349 | |
---|
350 | for(j=ncl; j<=nch; j++) { |
---|
351 | for(i=nrl; i<=nrh; i++) { |
---|
352 | fprintf(f, format, m[i][j]); |
---|
353 | } |
---|
354 | fputc('\n', f); |
---|
355 | } |
---|
356 | fclose(f); |
---|
357 | } |
---|
358 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
359 | IMAGE_EXPORT(void) write_ui32matrix_T(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
360 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
361 | { |
---|
362 | long i,j; |
---|
363 | |
---|
364 | FILE *f; |
---|
365 | |
---|
366 | f = fopen(filename, "wt"); |
---|
367 | if(f == NULL) { |
---|
368 | nrerror("Can't open file in write_ui32matrix_T"); |
---|
369 | } |
---|
370 | |
---|
371 | for(j=ncl; j<=nch; j++) { |
---|
372 | for(i=nrl; i<=nrh; i++) { |
---|
373 | fprintf(f, format, m[i][j]); |
---|
374 | } |
---|
375 | fputc('\n', f); |
---|
376 | } |
---|
377 | fclose(f); |
---|
378 | } |
---|
379 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
380 | IMAGE_EXPORT(void) write_si64matrix_T(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
381 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
382 | { |
---|
383 | long i,j; |
---|
384 | |
---|
385 | FILE *f; |
---|
386 | |
---|
387 | f = fopen(filename, "wt"); |
---|
388 | if(f == NULL) { |
---|
389 | nrerror("Can't open file in write_si64matrix_T"); |
---|
390 | } |
---|
391 | |
---|
392 | for(j=ncl; j<=nch; j++) { |
---|
393 | for(i=nrl; i<=nrh; i++) { |
---|
394 | fprintf(f, format, m[i][j]); |
---|
395 | } |
---|
396 | fputc('\n', f); |
---|
397 | } |
---|
398 | fclose(f); |
---|
399 | } |
---|
400 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
401 | IMAGE_EXPORT(void) write_ui64matrix_T(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
402 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
403 | { |
---|
404 | long i,j; |
---|
405 | |
---|
406 | FILE *f; |
---|
407 | |
---|
408 | f = fopen(filename, "wt"); |
---|
409 | if(f == NULL) { |
---|
410 | nrerror("Can't open file in write_ui64matrix_T"); |
---|
411 | } |
---|
412 | |
---|
413 | for(j=ncl; j<=nch; j++) { |
---|
414 | for(i=nrl; i<=nrh; i++) { |
---|
415 | fprintf(f, format, m[i][j]); |
---|
416 | } |
---|
417 | fputc('\n', f); |
---|
418 | } |
---|
419 | fclose(f); |
---|
420 | } |
---|
421 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
422 | IMAGE_EXPORT(void) write_f32matrix_T(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
423 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
424 | { |
---|
425 | long i,j; |
---|
426 | |
---|
427 | FILE *f; |
---|
428 | |
---|
429 | f = fopen(filename, "wt"); |
---|
430 | if(f == NULL) { |
---|
431 | nrerror("Can't open file in write_f32matrix"); |
---|
432 | } |
---|
433 | |
---|
434 | for(j=ncl; j<=nch; j++) { |
---|
435 | for(i=nrl; i<=nrh; i++) { |
---|
436 | fprintf(f, format, m[i][j]); |
---|
437 | } |
---|
438 | fputc('\n', f); |
---|
439 | } |
---|
440 | fclose(f); |
---|
441 | } |
---|
442 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
443 | IMAGE_EXPORT(void) write_f64matrix_T(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
444 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
445 | { |
---|
446 | long i,j; |
---|
447 | |
---|
448 | FILE *f; |
---|
449 | |
---|
450 | f = fopen(filename, "wt"); |
---|
451 | if(f == NULL) { |
---|
452 | nrerror("Can't open file in write_f64matrix"); |
---|
453 | } |
---|
454 | |
---|
455 | for(j=ncl; j<=nch; j++) { |
---|
456 | for(i=nrl; i<=nrh; i++) { |
---|
457 | fprintf(f, format, m[i][j]); |
---|
458 | } |
---|
459 | fputc('\n', f); |
---|
460 | } |
---|
461 | fclose(f); |
---|
462 | } |
---|
463 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
464 | IMAGE_EXPORT(void) write_rgb8matrix_T(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
465 | /* ------------------------------------------------------------------------------------------------------------ */ |
---|
466 | { |
---|
467 | long i,j; |
---|
468 | |
---|
469 | FILE *f; |
---|
470 | |
---|
471 | f = fopen(filename, "wt"); |
---|
472 | if(f == NULL) { |
---|
473 | nrerror("Can't open file in write_rgb8matrix"); |
---|
474 | } |
---|
475 | |
---|
476 | for(j=ncl; j<=nch; j++) { |
---|
477 | for(i=nrl; i<=nrh; i++) { |
---|
478 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
479 | } |
---|
480 | fputc('\n', f); |
---|
481 | } |
---|
482 | fclose(f); |
---|
483 | } |
---|
484 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
485 | IMAGE_EXPORT(void) write_rgbx8matrix_T(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
486 | /* -------------------------------------------------------------------------------------------------------------- */ |
---|
487 | { |
---|
488 | long i,j; |
---|
489 | |
---|
490 | FILE *f; |
---|
491 | |
---|
492 | f = fopen(filename, "wt"); |
---|
493 | if(f == NULL) { |
---|
494 | nrerror("Can't open file in write_rgb8matrix"); |
---|
495 | } |
---|
496 | |
---|
497 | for(j=ncl; j<=nch; j++) { |
---|
498 | for(i=nrl; i<=nrh; i++) { |
---|
499 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
500 | } |
---|
501 | fputc('\n', f); |
---|
502 | } |
---|
503 | fclose(f); |
---|
504 | } |
---|
505 | |
---|
506 | /* |
---|
507 | * --------------------------- |
---|
508 | * --- write_matrix_number --- |
---|
509 | * --------------------------- |
---|
510 | */ |
---|
511 | |
---|
512 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
513 | IMAGE_EXPORT(void) write_si8matrix_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
514 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
515 | { |
---|
516 | int i,j; |
---|
517 | |
---|
518 | FILE *f; |
---|
519 | |
---|
520 | f = fopen(filename, "wt"); |
---|
521 | if(f == NULL) { |
---|
522 | nrerror("Can't open file in write_si8matrix_number"); |
---|
523 | } |
---|
524 | |
---|
525 | // entete |
---|
526 | fprintf(f, "%5c", '#'); |
---|
527 | for(j=ncl; j<=nch; j++) { |
---|
528 | fprintf(f, format, j); |
---|
529 | } |
---|
530 | fputc('\n', f); |
---|
531 | |
---|
532 | for(i=nrl; i<=nrh; i++) { |
---|
533 | fprintf(f, "[%3d]", i); |
---|
534 | for(j=ncl; j<=nch; j++) { |
---|
535 | fprintf(f, format, m[i][j]); |
---|
536 | } |
---|
537 | fputc('\n', f); |
---|
538 | } |
---|
539 | fclose(f); |
---|
540 | } |
---|
541 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
542 | IMAGE_EXPORT(void) write_ui8matrix_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
543 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
544 | { |
---|
545 | int i,j; |
---|
546 | |
---|
547 | FILE *f; |
---|
548 | |
---|
549 | f = fopen(filename, "wt"); |
---|
550 | if(f == NULL) { |
---|
551 | nrerror("Can't open file in write_ui8matrix_number"); |
---|
552 | } |
---|
553 | |
---|
554 | // entete |
---|
555 | fprintf(f, "%5c", '#'); |
---|
556 | for(j=ncl; j<=nch; j++) { |
---|
557 | fprintf(f, format, j); |
---|
558 | } |
---|
559 | fputc('\n', f); |
---|
560 | |
---|
561 | for(i=nrl; i<=nrh; i++) { |
---|
562 | fprintf(f, "[%3d]", i); |
---|
563 | for(j=ncl; j<=nch; j++) { |
---|
564 | fprintf(f, format, m[i][j]); |
---|
565 | } |
---|
566 | fputc('\n', f); |
---|
567 | } |
---|
568 | fclose(f); |
---|
569 | } |
---|
570 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
571 | IMAGE_EXPORT(void) write_si16matrix_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
572 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
573 | { |
---|
574 | int i,j; |
---|
575 | |
---|
576 | FILE *f; |
---|
577 | |
---|
578 | f = fopen(filename, "wt"); |
---|
579 | if(f == NULL) { |
---|
580 | nrerror("Can't open file in write_si16matrix"); |
---|
581 | } |
---|
582 | |
---|
583 | // entete |
---|
584 | fprintf(f, "%5c", '#'); |
---|
585 | for(j=ncl; j<=nch; j++) { |
---|
586 | fprintf(f, format, j); |
---|
587 | } |
---|
588 | fputc('\n', f); |
---|
589 | |
---|
590 | for(i=nrl; i<=nrh; i++) { |
---|
591 | fprintf(f, "[%3d]", i); |
---|
592 | for(j=ncl; j<=nch; j++) { |
---|
593 | fprintf(f, format, m[i][j]); |
---|
594 | } |
---|
595 | fputc('\n', f); |
---|
596 | } |
---|
597 | fclose(f); |
---|
598 | } |
---|
599 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
600 | IMAGE_EXPORT(void) write_ui16matrix_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
601 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
602 | { |
---|
603 | int i,j; |
---|
604 | |
---|
605 | FILE *f; |
---|
606 | |
---|
607 | f = fopen(filename, "wt"); |
---|
608 | if(f == NULL) { |
---|
609 | nrerror("Can't open file in write_ui16matrix"); |
---|
610 | } |
---|
611 | |
---|
612 | // entete |
---|
613 | fprintf(f, "%5c", '#'); |
---|
614 | for(j=ncl; j<=nch; j++) { |
---|
615 | fprintf(f, format, j); |
---|
616 | } |
---|
617 | fputc('\n', f); |
---|
618 | |
---|
619 | for(i=nrl; i<=nrh; i++) { |
---|
620 | fprintf(f, "[%3d]", i); |
---|
621 | for(j=ncl; j<=nch; j++) { |
---|
622 | fprintf(f, format, m[i][j]); |
---|
623 | } |
---|
624 | fputc('\n', f); |
---|
625 | } |
---|
626 | fclose(f); |
---|
627 | } |
---|
628 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
629 | IMAGE_EXPORT(void) write_si32matrix_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
630 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
631 | { |
---|
632 | int i,j; |
---|
633 | |
---|
634 | FILE *f; |
---|
635 | |
---|
636 | f = fopen(filename, "wt"); |
---|
637 | if(f == NULL) { |
---|
638 | nrerror("Can't open file in write_si32matrix"); |
---|
639 | } |
---|
640 | |
---|
641 | // entete |
---|
642 | fprintf(f, "%5c", '#'); |
---|
643 | for(j=ncl; j<=nch; j++) { |
---|
644 | fprintf(f, format, j); |
---|
645 | } |
---|
646 | fputc('\n', f); |
---|
647 | |
---|
648 | for(i=nrl; i<=nrh; i++) { |
---|
649 | fprintf(f, "[%3d]", i); |
---|
650 | for(j=ncl; j<=nch; j++) { |
---|
651 | fprintf(f, format, m[i][j]); |
---|
652 | } |
---|
653 | fputc('\n', f); |
---|
654 | } |
---|
655 | fclose(f); |
---|
656 | } |
---|
657 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
658 | IMAGE_EXPORT(void) write_ui32matrix_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
659 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
660 | { |
---|
661 | int i,j; |
---|
662 | |
---|
663 | FILE *f; |
---|
664 | |
---|
665 | f = fopen(filename, "wt"); |
---|
666 | if(f == NULL) { |
---|
667 | nrerror("Can't open file in write_ui32matrix"); |
---|
668 | } |
---|
669 | |
---|
670 | // entete |
---|
671 | fprintf(f, "%5c", '#'); |
---|
672 | for(j=ncl; j<=nch; j++) { |
---|
673 | fprintf(f, format, j); |
---|
674 | } |
---|
675 | fputc('\n', f); |
---|
676 | |
---|
677 | for(i=nrl; i<=nrh; i++) { |
---|
678 | fprintf(f, "[%3d]", i); |
---|
679 | for(j=ncl; j<=nch; j++) { |
---|
680 | fprintf(f, format, m[i][j]); |
---|
681 | } |
---|
682 | fputc('\n', f); |
---|
683 | } |
---|
684 | fclose(f); |
---|
685 | } |
---|
686 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
687 | IMAGE_EXPORT(void) write_si64matrix_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
688 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
689 | { |
---|
690 | int i,j; |
---|
691 | |
---|
692 | FILE *f; |
---|
693 | |
---|
694 | f = fopen(filename, "wt"); |
---|
695 | if(f == NULL) { |
---|
696 | nrerror("Can't open file in write_si64matrix"); |
---|
697 | } |
---|
698 | |
---|
699 | // entete |
---|
700 | fprintf(f, "%5c", '#'); |
---|
701 | for(j=ncl; j<=nch; j++) { |
---|
702 | fprintf(f, format, j); |
---|
703 | } |
---|
704 | fputc('\n', f); |
---|
705 | |
---|
706 | for(i=nrl; i<=nrh; i++) { |
---|
707 | fprintf(f, "[%3d]", i); |
---|
708 | for(j=ncl; j<=nch; j++) { |
---|
709 | fprintf(f, format, m[i][j]); |
---|
710 | } |
---|
711 | fputc('\n', f); |
---|
712 | } |
---|
713 | fclose(f); |
---|
714 | } |
---|
715 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
716 | IMAGE_EXPORT(void) write_ui64matrix_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
717 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
718 | { |
---|
719 | int i,j; |
---|
720 | |
---|
721 | FILE *f; |
---|
722 | |
---|
723 | f = fopen(filename, "wt"); |
---|
724 | if(f == NULL) { |
---|
725 | nrerror("Can't open file in write_ui64matrix"); |
---|
726 | } |
---|
727 | |
---|
728 | // entete |
---|
729 | fprintf(f, "%5c", '#'); |
---|
730 | for(j=ncl; j<=nch; j++) { |
---|
731 | fprintf(f, format, j); |
---|
732 | } |
---|
733 | fputc('\n', f); |
---|
734 | |
---|
735 | for(i=nrl; i<=nrh; i++) { |
---|
736 | fprintf(f, "[%3d]", i); |
---|
737 | for(j=ncl; j<=nch; j++) { |
---|
738 | fprintf(f, format, m[i][j]); |
---|
739 | } |
---|
740 | fputc('\n', f); |
---|
741 | } |
---|
742 | fclose(f); |
---|
743 | } |
---|
744 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
745 | IMAGE_EXPORT(void) write_f32matrix_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
746 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
747 | { |
---|
748 | int i,j; |
---|
749 | |
---|
750 | FILE *f; |
---|
751 | |
---|
752 | f = fopen(filename, "wt"); |
---|
753 | if(f == NULL) { |
---|
754 | nrerror("Can't open file in write_f32matrix_number"); |
---|
755 | } |
---|
756 | |
---|
757 | // entete |
---|
758 | fprintf(f, "%4d", 0); |
---|
759 | for(j=ncl; j<=nch; j++) { |
---|
760 | fprintf(f, format, (float32)j); |
---|
761 | } |
---|
762 | fputc('\n', f); |
---|
763 | |
---|
764 | for(i=nrl; i<=nrh; i++) { |
---|
765 | fprintf(f, "%4d", i); |
---|
766 | for(j=ncl; j<=nch; j++) { |
---|
767 | fprintf(f, format, m[i][j]); |
---|
768 | } |
---|
769 | fputc('\n', f); |
---|
770 | } |
---|
771 | fclose(f); |
---|
772 | } |
---|
773 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
774 | IMAGE_EXPORT(void) write_f64matrix_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
775 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
776 | { |
---|
777 | int i,j; |
---|
778 | |
---|
779 | FILE *f; |
---|
780 | |
---|
781 | f = fopen(filename, "wt"); |
---|
782 | if(f == NULL) { |
---|
783 | nrerror("Can't open file in write_f64matrix_number"); |
---|
784 | } |
---|
785 | |
---|
786 | // entete |
---|
787 | fprintf(f, "%4d", 0); |
---|
788 | for(j=ncl; j<=nch; j++) { |
---|
789 | fprintf(f, format, (float32)j); |
---|
790 | } |
---|
791 | fputc('\n', f); |
---|
792 | |
---|
793 | for(i=nrl; i<=nrh; i++) { |
---|
794 | fprintf(f, "%4d", i); |
---|
795 | for(j=ncl; j<=nch; j++) { |
---|
796 | fprintf(f, format, m[i][j]); |
---|
797 | } |
---|
798 | fputc('\n', f); |
---|
799 | } |
---|
800 | fclose(f); |
---|
801 | } |
---|
802 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
803 | IMAGE_EXPORT(void) write_rgb8matrix_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
804 | /* ----------------------------------------------------------------------------------------------------------------- */ |
---|
805 | { |
---|
806 | int i,j; |
---|
807 | |
---|
808 | FILE *f; |
---|
809 | |
---|
810 | f = fopen(filename, "wt"); |
---|
811 | if(f == NULL) { |
---|
812 | nrerror("Can't open file in write_rgb8matrix_number"); |
---|
813 | } |
---|
814 | |
---|
815 | // entete |
---|
816 | fprintf(f, "%4d", 0); |
---|
817 | for(j=ncl; j<=nch; j++) { |
---|
818 | fprintf(f, format, (float32)j); |
---|
819 | } |
---|
820 | fputc('\n', f); |
---|
821 | |
---|
822 | for(i=nrl; i<=nrh; i++) { |
---|
823 | fprintf(f, "%4d", i); |
---|
824 | for(j=ncl; j<=nch; j++) { |
---|
825 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b); |
---|
826 | } |
---|
827 | fputc('\n', f); |
---|
828 | } |
---|
829 | fclose(f); |
---|
830 | } |
---|
831 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
832 | IMAGE_EXPORT(void) write_rgb8xmatrix_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
833 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
834 | { |
---|
835 | int i,j; |
---|
836 | |
---|
837 | FILE *f; |
---|
838 | |
---|
839 | f = fopen(filename, "wt"); |
---|
840 | if(f == NULL) { |
---|
841 | nrerror("Can't open file in write_rgbx8matrix_number"); |
---|
842 | } |
---|
843 | |
---|
844 | // entete |
---|
845 | fprintf(f, "%4d", 0); |
---|
846 | for(j=ncl; j<=nch; j++) { |
---|
847 | fprintf(f, format, (float32)j); |
---|
848 | } |
---|
849 | fputc('\n', f); |
---|
850 | |
---|
851 | for(i=nrl; i<=nrh; i++) { |
---|
852 | fprintf(f, "%4d", i); |
---|
853 | for(j=ncl; j<=nch; j++) { |
---|
854 | fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x); |
---|
855 | } |
---|
856 | fputc('\n', f); |
---|
857 | } |
---|
858 | fclose(f); |
---|
859 | } |
---|
860 | /* |
---|
861 | * ----------------------------- |
---|
862 | * --- write_matrix_T_number --- |
---|
863 | * ----------------------------- |
---|
864 | */ |
---|
865 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
866 | IMAGE_EXPORT(void) write_si8matrix_T_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
867 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
868 | { |
---|
869 | int i,j; |
---|
870 | |
---|
871 | FILE *f; |
---|
872 | |
---|
873 | f = fopen(filename, "wt"); |
---|
874 | if(f == NULL) { |
---|
875 | nrerror("Can't open file in write_si8matrix_T_number"); |
---|
876 | } |
---|
877 | |
---|
878 | fprintf(f, "%5c", '#'); |
---|
879 | for(i=nrl; i<=nrh; i++) { |
---|
880 | fprintf(f, format, i); |
---|
881 | } |
---|
882 | fputc('\n', f); |
---|
883 | |
---|
884 | for(j=ncl; j<=nch; j++) { |
---|
885 | fprintf(f, "[%3d]", j); |
---|
886 | for(i=nrl; i<=nrh; i++) { |
---|
887 | fprintf(f, format, m[i][j]); |
---|
888 | } |
---|
889 | fputc('\n', f); |
---|
890 | } |
---|
891 | fclose(f); |
---|
892 | } |
---|
893 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
894 | IMAGE_EXPORT(void) write_ui8matrix_T_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
895 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
896 | { |
---|
897 | int i,j; |
---|
898 | |
---|
899 | FILE *f; |
---|
900 | |
---|
901 | f = fopen(filename, "wt"); |
---|
902 | if(f == NULL) { |
---|
903 | nrerror("Can't open file in write_ui8matrix_T_number"); |
---|
904 | } |
---|
905 | |
---|
906 | fprintf(f, "%5c", '#'); |
---|
907 | for(i=nrl; i<=nrh; i++) { |
---|
908 | fprintf(f, format, i); |
---|
909 | } |
---|
910 | fputc('\n', f); |
---|
911 | |
---|
912 | |
---|
913 | for(j=ncl; j<=nch; j++) { |
---|
914 | fprintf(f, "[%3d]", j); |
---|
915 | for(i=nrl; i<=nrh; i++) { |
---|
916 | fprintf(f, format, m[i][j]); |
---|
917 | } |
---|
918 | fputc('\n', f); |
---|
919 | } |
---|
920 | fclose(f); |
---|
921 | } |
---|
922 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
923 | IMAGE_EXPORT(void) write_si16matrix_T_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
924 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
925 | { |
---|
926 | int i,j; |
---|
927 | |
---|
928 | FILE *f; |
---|
929 | |
---|
930 | f = fopen(filename, "wt"); |
---|
931 | if(f == NULL) { |
---|
932 | nrerror("Can't open file in write_si16matrix_T_number"); |
---|
933 | } |
---|
934 | |
---|
935 | fprintf(f, "%5c", '#'); |
---|
936 | for(i=nrl; i<=nrh; i++) { |
---|
937 | fprintf(f, format, (float)i); |
---|
938 | } |
---|
939 | fputc('\n', f); |
---|
940 | |
---|
941 | for(j=ncl; j<=nch; j++) { |
---|
942 | fprintf(f, "[%3d]", j); |
---|
943 | for(i=nrl; i<=nrh; i++) { |
---|
944 | fprintf(f, format, m[i][j]); |
---|
945 | } |
---|
946 | fputc('\n', f); |
---|
947 | } |
---|
948 | fclose(f); |
---|
949 | } |
---|
950 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
951 | IMAGE_EXPORT(void) write_ui16matrix_T_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
952 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
953 | { |
---|
954 | int i,j; |
---|
955 | |
---|
956 | FILE *f; |
---|
957 | |
---|
958 | f = fopen(filename, "wt"); |
---|
959 | if(f == NULL) { |
---|
960 | nrerror("Can't open file in write_ui16matrix_T_number"); |
---|
961 | } |
---|
962 | |
---|
963 | fprintf(f, "%5c", '#'); |
---|
964 | for(i=nrl; i<=nrh; i++) { |
---|
965 | fprintf(f, format, (float)i); |
---|
966 | } |
---|
967 | fputc('\n', f); |
---|
968 | |
---|
969 | for(j=ncl; j<=nch; j++) { |
---|
970 | fprintf(f, "[%3d]", j); |
---|
971 | for(i=nrl; i<=nrh; i++) { |
---|
972 | fprintf(f, format, m[i][j]); |
---|
973 | } |
---|
974 | fputc('\n', f); |
---|
975 | } |
---|
976 | fclose(f); |
---|
977 | } |
---|
978 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
979 | IMAGE_EXPORT(void) write_si32matrix_T_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
980 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
981 | { |
---|
982 | int i,j; |
---|
983 | |
---|
984 | FILE *f; |
---|
985 | |
---|
986 | f = fopen(filename, "wt"); |
---|
987 | if(f == NULL) { |
---|
988 | nrerror("Can't open file in write_si32matrix_T_number"); |
---|
989 | } |
---|
990 | |
---|
991 | fprintf(f, "%5c", '#'); |
---|
992 | for(i=nrl; i<=nrh; i++) { |
---|
993 | fprintf(f, format, (float)i); |
---|
994 | } |
---|
995 | fputc('\n', f); |
---|
996 | |
---|
997 | for(j=ncl; j<=nch; j++) { |
---|
998 | fprintf(f, "[%3d]", j); |
---|
999 | for(i=nrl; i<=nrh; i++) { |
---|
1000 | fprintf(f, format, m[i][j]); |
---|
1001 | } |
---|
1002 | fputc('\n', f); |
---|
1003 | } |
---|
1004 | fclose(f); |
---|
1005 | } |
---|
1006 | |
---|
1007 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1008 | IMAGE_EXPORT(void) write_ui32matrix_T_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1009 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1010 | { |
---|
1011 | int i,j; |
---|
1012 | |
---|
1013 | FILE *f; |
---|
1014 | |
---|
1015 | f = fopen(filename, "wt"); |
---|
1016 | if(f == NULL) { |
---|
1017 | nrerror("Can't open file in write_ui32matrix_T_number"); |
---|
1018 | } |
---|
1019 | |
---|
1020 | fprintf(f, "%5c", '#'); |
---|
1021 | for(i=nrl; i<=nrh; i++) { |
---|
1022 | fprintf(f, format, (float)i); |
---|
1023 | } |
---|
1024 | fputc('\n', f); |
---|
1025 | |
---|
1026 | |
---|
1027 | for(j=ncl; j<=nch; j++) { |
---|
1028 | fprintf(f, "[%3d]", j); |
---|
1029 | for(i=nrl; i<=nrh; i++) { |
---|
1030 | fprintf(f, format, m[i][j]); |
---|
1031 | } |
---|
1032 | fputc('\n', f); |
---|
1033 | } |
---|
1034 | fclose(f); |
---|
1035 | } |
---|
1036 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1037 | IMAGE_EXPORT(void) write_si64matrix_T_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1038 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1039 | { |
---|
1040 | int i,j; |
---|
1041 | |
---|
1042 | FILE *f; |
---|
1043 | |
---|
1044 | f = fopen(filename, "wt"); |
---|
1045 | if(f == NULL) { |
---|
1046 | nrerror("Can't open file in write_si64matrix_T_number"); |
---|
1047 | } |
---|
1048 | |
---|
1049 | fprintf(f, "%5c", '#'); |
---|
1050 | for(i=nrl; i<=nrh; i++) { |
---|
1051 | fprintf(f, format, (float)i); |
---|
1052 | } |
---|
1053 | fputc('\n', f); |
---|
1054 | |
---|
1055 | for(j=ncl; j<=nch; j++) { |
---|
1056 | fprintf(f, "[%3d]", j); |
---|
1057 | for(i=nrl; i<=nrh; i++) { |
---|
1058 | fprintf(f, format, m[i][j]); |
---|
1059 | } |
---|
1060 | fputc('\n', f); |
---|
1061 | } |
---|
1062 | fclose(f); |
---|
1063 | } |
---|
1064 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1065 | IMAGE_EXPORT(void) write_ui64matrix_T_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1066 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1067 | { |
---|
1068 | int i,j; |
---|
1069 | |
---|
1070 | FILE *f; |
---|
1071 | |
---|
1072 | f = fopen(filename, "wt"); |
---|
1073 | if(f == NULL) { |
---|
1074 | nrerror("Can't open file in write_ui64matrix_T_number"); |
---|
1075 | } |
---|
1076 | |
---|
1077 | fprintf(f, "%5c", '#'); |
---|
1078 | for(i=nrl; i<=nrh; i++) { |
---|
1079 | fprintf(f, format, (float)i); |
---|
1080 | } |
---|
1081 | fputc('\n', f); |
---|
1082 | |
---|
1083 | for(j=ncl; j<=nch; j++) { |
---|
1084 | fprintf(f, "[%3d]", j); |
---|
1085 | for(i=nrl; i<=nrh; i++) { |
---|
1086 | fprintf(f, format, m[i][j]); |
---|
1087 | } |
---|
1088 | fputc('\n', f); |
---|
1089 | } |
---|
1090 | fclose(f); |
---|
1091 | } |
---|
1092 | |
---|
1093 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1094 | IMAGE_EXPORT(void) write_f32matrix_T_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1095 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1096 | { |
---|
1097 | int i,j; |
---|
1098 | |
---|
1099 | FILE *f; |
---|
1100 | |
---|
1101 | f = fopen(filename, "wt"); |
---|
1102 | if(f == NULL) { |
---|
1103 | nrerror("Can't open file in write_f32matrix_T_number"); |
---|
1104 | } |
---|
1105 | |
---|
1106 | fprintf(f, "%5c", '#'); |
---|
1107 | for(i=nrl; i<=nrh; i++) { |
---|
1108 | fprintf(f, format, (float)i); |
---|
1109 | } |
---|
1110 | fputc('\n', f); |
---|
1111 | |
---|
1112 | for(j=ncl; j<=nch; j++) { |
---|
1113 | fprintf(f, "[%3d]", j); |
---|
1114 | for(i=nrl; i<=nrh; i++) { |
---|
1115 | fprintf(f, format, m[i][j]); |
---|
1116 | } |
---|
1117 | fputc('\n', f); |
---|
1118 | } |
---|
1119 | fclose(f); |
---|
1120 | } |
---|
1121 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1122 | IMAGE_EXPORT(void) write_f64matrix_T_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1123 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1124 | { |
---|
1125 | int i,j; |
---|
1126 | |
---|
1127 | FILE *f; |
---|
1128 | |
---|
1129 | f = fopen(filename, "wt"); |
---|
1130 | if(f == NULL) { |
---|
1131 | nrerror("Can't open file in write_f64matrix_T_number"); |
---|
1132 | } |
---|
1133 | |
---|
1134 | fprintf(f, "%5c", '#'); |
---|
1135 | for(i=nrl; i<=nrh; i++) { |
---|
1136 | fprintf(f, format, (float)i); |
---|
1137 | } |
---|
1138 | fputc('\n', f); |
---|
1139 | |
---|
1140 | for(j=ncl; j<=nch; j++) { |
---|
1141 | fprintf(f, "[%3d]", j); |
---|
1142 | for(i=nrl; i<=nrh; i++) { |
---|
1143 | fprintf(f, format, m[i][j]); |
---|
1144 | } |
---|
1145 | fputc('\n', f); |
---|
1146 | } |
---|
1147 | fclose(f); |
---|
1148 | } |
---|
1149 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
1150 | IMAGE_EXPORT(void) write_rgb8matrix_T_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1151 | /* ------------------------------------------------------------------------------------------------------------------- */ |
---|
1152 | { |
---|
1153 | int i,j; |
---|
1154 | |
---|
1155 | FILE *f; |
---|
1156 | |
---|
1157 | f = fopen(filename, "wt"); |
---|
1158 | if(f == NULL) { |
---|
1159 | nrerror("Can't open file in write_rgb8matrix_T_number"); |
---|
1160 | } |
---|
1161 | |
---|
1162 | fprintf(f, "%5c", '#'); |
---|
1163 | for(i=nrl; i<=nrh; i++) { |
---|
1164 | fprintf(f, format, (float)i); |
---|
1165 | } |
---|
1166 | fputc('\n', f); |
---|
1167 | |
---|
1168 | for(j=ncl; j<=nch; j++) { |
---|
1169 | fprintf(f, "[%3d]", j); |
---|
1170 | for(i=nrl; i<=nrh; i++) { |
---|
1171 | fprintf(f, format, m[i][j]); |
---|
1172 | } |
---|
1173 | fputc('\n', f); |
---|
1174 | } |
---|
1175 | fclose(f); |
---|
1176 | } |
---|
1177 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1178 | IMAGE_EXPORT(void) write_rgbx8matrix_T_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename) |
---|
1179 | /* --------------------------------------------------------------------------------------------------------------------- */ |
---|
1180 | { |
---|
1181 | int i,j; |
---|
1182 | |
---|
1183 | FILE *f; |
---|
1184 | |
---|
1185 | f = fopen(filename, "wt"); |
---|
1186 | if(f == NULL) { |
---|
1187 | nrerror("Can't open file in write_rgbx8matrix_T_number"); |
---|
1188 | } |
---|
1189 | |
---|
1190 | fprintf(f, "%5c", '#'); |
---|
1191 | for(i=nrl; i<=nrh; i++) { |
---|
1192 | fprintf(f, format, (float)i); |
---|
1193 | } |
---|
1194 | fputc('\n', f); |
---|
1195 | |
---|
1196 | for(j=ncl; j<=nch; j++) { |
---|
1197 | fprintf(f, "[%3d]", j); |
---|
1198 | for(i=nrl; i<=nrh; i++) { |
---|
1199 | fprintf(f, format, m[i][j]); |
---|
1200 | } |
---|
1201 | fputc('\n', f); |
---|
1202 | } |
---|
1203 | fclose(f); |
---|
1204 | } |
---|
1205 | /* |
---|
1206 | * --------------------- |
---|
1207 | * --- fwrite_matrix --- |
---|
1208 | * --------------------- |
---|
1209 | */ |
---|
1210 | |
---|
1211 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1212 | IMAGE_EXPORT(void) fwrite_si8matrix(sint8 **m,long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1213 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1214 | { |
---|
1215 | long i, ncol = nch-ncl+1; |
---|
1216 | FILE *f; |
---|
1217 | |
---|
1218 | f = fopen(filename, "wb"); |
---|
1219 | if(f == NULL) nrerror("Can't open file in fwrite_si8matrix"); |
---|
1220 | |
---|
1221 | for(i=nrl; i<=nrh; i++) { |
---|
1222 | fwrite(m[i]+nrl, sizeof(sint8), ncol, f); |
---|
1223 | } |
---|
1224 | fclose(f); |
---|
1225 | } |
---|
1226 | /* ------------------------------------------------------------------------------------------------ */ |
---|
1227 | IMAGE_EXPORT(void) fwrite_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1228 | /* ------------------------------------------------------------------------------------------------ */ |
---|
1229 | { |
---|
1230 | long i, ncol = nch-ncl+1; |
---|
1231 | FILE *f; |
---|
1232 | |
---|
1233 | f = fopen(filename, "wb"); |
---|
1234 | if(f == NULL) nrerror("Can't open file in fwrite_ui8matrix"); |
---|
1235 | |
---|
1236 | for(i=nrl; i<=nrh; i++) { |
---|
1237 | fwrite(m[i]+nrl, sizeof(int8), ncol, f); |
---|
1238 | } |
---|
1239 | fclose(f); |
---|
1240 | } |
---|
1241 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1242 | IMAGE_EXPORT(void) fwrite_si16matrix(sint16 **m,long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1243 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1244 | { |
---|
1245 | long i, ncol = nch-ncl+1; |
---|
1246 | FILE *f; |
---|
1247 | |
---|
1248 | f = fopen(filename, "wb"); |
---|
1249 | if(f == NULL) |
---|
1250 | nrerror("Can't open file in fwrite_i16matrix"); |
---|
1251 | |
---|
1252 | for(i=nrl; i<=nrh; i++) { |
---|
1253 | fwrite(m[i]+nrl, sizeof(sint16), ncol, f); |
---|
1254 | } |
---|
1255 | fclose(f); |
---|
1256 | } |
---|
1257 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1258 | IMAGE_EXPORT(void) fwrite_ui16matrix(uint16 **m,long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1259 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1260 | { |
---|
1261 | long i, ncol = nch-ncl+1; |
---|
1262 | FILE *f; |
---|
1263 | |
---|
1264 | f = fopen(filename, "wb"); |
---|
1265 | if(f == NULL) |
---|
1266 | nrerror("Can't open file in fwrite_ui16matrix"); |
---|
1267 | |
---|
1268 | for(i=nrl; i<=nrh; i++) { |
---|
1269 | fwrite(m[i]+nrl, sizeof(uint16), ncol, f); |
---|
1270 | } |
---|
1271 | fclose(f); |
---|
1272 | } |
---|
1273 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1274 | IMAGE_EXPORT(void) fwrite_si32matrix(sint32 **m,long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1275 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1276 | { |
---|
1277 | long i, ncol = nch-ncl+1; |
---|
1278 | FILE *f; |
---|
1279 | |
---|
1280 | f = fopen(filename, "wb"); |
---|
1281 | if(f == NULL) |
---|
1282 | nrerror("Can't open file in fwrite_si32matrix"); |
---|
1283 | |
---|
1284 | for(i=nrl; i<=nrh; i++) { |
---|
1285 | fwrite(m[i]+nrl, sizeof(sint32), ncol, f); |
---|
1286 | } |
---|
1287 | fclose(f); |
---|
1288 | } |
---|
1289 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1290 | IMAGE_EXPORT(void) fwrite_ui32matrix(uint32 **m,long nrl, long nrh, long ncl, long nch, char *filename) |
---|
1291 | /* ------------------------------------------------------------------------------------------------- */ |
---|
1292 | { |
---|
1293 | long i, ncol = nch-ncl+1; |
---|
1294 | FILE *f; |
---|
1295 | |
---|
1296 | f = fopen(filename, "wb"); |
---|
1297 | if(f == NULL) |
---|
1298 | nrerror("Can't open file in fwrite_ui32matrix"); |
---|
1299 | |
---|
1300 | for(i=nrl; i<=nrh; i++) { |
---|
1301 | fwrite(m[i]+nrl, sizeof(uint32), ncol, f); |
---|
1302 | } |
---|
1303 | fclose(f); |
---|
1304 | } |
---|
1305 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1306 | IMAGE_EXPORT(void) fwrite_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1307 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1308 | { |
---|
1309 | long i, ncol = nch-ncl+1; |
---|
1310 | FILE *f; |
---|
1311 | |
---|
1312 | f = fopen(filename, "wb"); |
---|
1313 | if(f == NULL) |
---|
1314 | nrerror("Can't open file in fwrite_si64matrix"); |
---|
1315 | |
---|
1316 | for(i=nrl; i<=nrh; i++) { |
---|
1317 | fwrite(m[i]+nrl, sizeof(sint64), ncol, f); |
---|
1318 | } |
---|
1319 | fclose(f); |
---|
1320 | } |
---|
1321 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1322 | IMAGE_EXPORT(void) fwrite_ui64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1323 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1324 | { |
---|
1325 | long i, ncol = nch-ncl+1; |
---|
1326 | FILE *f; |
---|
1327 | |
---|
1328 | f = fopen(filename, "wb"); |
---|
1329 | if(f == NULL) |
---|
1330 | nrerror("Can't open file in fwrite_ui64matrix"); |
---|
1331 | |
---|
1332 | for(i=nrl; i<=nrh; i++) { |
---|
1333 | fwrite(m[i]+nrl, sizeof(uint64), ncol, f); |
---|
1334 | } |
---|
1335 | fclose(f); |
---|
1336 | } |
---|
1337 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1338 | IMAGE_EXPORT(void) fwrite_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1339 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1340 | { |
---|
1341 | long i, ncol = nch-ncl+1; |
---|
1342 | FILE *f; |
---|
1343 | |
---|
1344 | f = fopen(filename, "wb"); |
---|
1345 | if(f == NULL) nrerror("Can't open file in fwrite_f32matrix"); |
---|
1346 | |
---|
1347 | for(i=nrl; i<=nrh; i++) { |
---|
1348 | fwrite(m[i]+nrl, sizeof(float32), ncol, f); |
---|
1349 | } |
---|
1350 | fclose(f); |
---|
1351 | } |
---|
1352 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1353 | IMAGE_EXPORT(void) fwrite_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1354 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1355 | { |
---|
1356 | long i, ncol = nch-ncl+1; |
---|
1357 | FILE *f; |
---|
1358 | |
---|
1359 | f = fopen(filename, "wb"); |
---|
1360 | if(f == NULL) nrerror("Can't open file in f64write_matrix"); |
---|
1361 | |
---|
1362 | for(i=nrl; i<=nrh; i++) { |
---|
1363 | fwrite(m[i]+nrl, sizeof(float64), ncol, f); |
---|
1364 | } |
---|
1365 | fclose(f); |
---|
1366 | } |
---|
1367 | /* --------------------------------------------------------------------------------------------- */ |
---|
1368 | IMAGE_EXPORT(void) fwrite_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1369 | /* --------------------------------------------------------------------------------------------- */ |
---|
1370 | { |
---|
1371 | long i, ncol = nch-ncl+1; |
---|
1372 | FILE *f; |
---|
1373 | |
---|
1374 | f = fopen(filename, "wb"); |
---|
1375 | if(f == NULL) nrerror("Can't open file in fwrite_rgb8matrix"); |
---|
1376 | |
---|
1377 | for(i=nrl; i<=nrh; i++) { |
---|
1378 | fwrite(m[i]+nrl, sizeof(rgb8), ncol, f); |
---|
1379 | } |
---|
1380 | fclose(f); |
---|
1381 | } |
---|
1382 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1383 | IMAGE_EXPORT(void) fwrite_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *filename) |
---|
1384 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1385 | { |
---|
1386 | long i, ncol = nch-ncl+1; |
---|
1387 | FILE *f; |
---|
1388 | |
---|
1389 | f = fopen(filename, "wb"); |
---|
1390 | if(f == NULL) nrerror("Can't open file in fwrite_rgbx8matrix"); |
---|
1391 | |
---|
1392 | for(i=nrl; i<=nrh; i++) { |
---|
1393 | fwrite(m[i]+nrl, sizeof(rgbx8), ncol, f); |
---|
1394 | } |
---|
1395 | fclose(f); |
---|
1396 | } |
---|
1397 | |
---|
1398 | /* |
---|
1399 | * -------------------- |
---|
1400 | * --- fread_matrix --- |
---|
1401 | * -------------------- |
---|
1402 | */ |
---|
1403 | |
---|
1404 | /* -------------------------------------------------------------------------------------------- */ |
---|
1405 | IMAGE_EXPORT(void) fread_si8matrix(char *filename, sint8 **m,long nrl,long nrh,long ncl, long nch) |
---|
1406 | /* -------------------------------------------------------------------------------------------- */ |
---|
1407 | { |
---|
1408 | long i, ncol = nch-ncl+1, nread; |
---|
1409 | FILE *f; |
---|
1410 | |
---|
1411 | f = fopen(filename, "rb"); |
---|
1412 | if(f == NULL) nrerror("Can't open file in fread_i8matrix"); |
---|
1413 | |
---|
1414 | for(i=nrl; i<=nrh; i++) { |
---|
1415 | nread = fread(m[i]+ncl, sizeof(sint8), ncol, f); |
---|
1416 | if(nread != ncol) nrerror("fread_si8matrix : can't read data"); |
---|
1417 | } |
---|
1418 | fclose(f); |
---|
1419 | } |
---|
1420 | /* -------------------------------------------------------------------------------------------- */ |
---|
1421 | IMAGE_EXPORT(void) fread_ui8matrix(char *filename, uint8 **m,long nrl,long nrh,long ncl, long nch) |
---|
1422 | /* -------------------------------------------------------------------------------------------- */ |
---|
1423 | { |
---|
1424 | long i, ncol = nch-ncl+1, nread; |
---|
1425 | FILE *f; |
---|
1426 | |
---|
1427 | f = fopen(filename, "rb"); |
---|
1428 | if(f == NULL) nrerror("Can't open file in fread_ui8matrix"); |
---|
1429 | |
---|
1430 | for(i=nrl; i<=nrh; i++) { |
---|
1431 | nread = fread(m[i]+ncl, sizeof(uint8), ncol, f); |
---|
1432 | if(nread != ncol) nrerror("fread_ui8matrix : can't read data"); |
---|
1433 | } |
---|
1434 | fclose(f); |
---|
1435 | } |
---|
1436 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1437 | IMAGE_EXPORT(void) fread_si32matrix(char *filename, sint32 **m,long nrl,long nrh,long ncl, long nch) |
---|
1438 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1439 | { |
---|
1440 | long i, ncol = nch-ncl+1, nread; |
---|
1441 | FILE *f; |
---|
1442 | |
---|
1443 | f = fopen(filename, "rb"); |
---|
1444 | if(f == NULL) |
---|
1445 | nrerror("Can't open file in fread_si32matrix"); |
---|
1446 | |
---|
1447 | for(i=nrl; i<=nrh; i++) { |
---|
1448 | nread = fread(m[i]+ncl, sizeof(sint32), ncol, f); |
---|
1449 | if(nread != ncol) nrerror("fread_si32matrix : can't read data"); |
---|
1450 | } |
---|
1451 | fclose(f); |
---|
1452 | } |
---|
1453 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1454 | IMAGE_EXPORT(void) fread_ui32matrix(char *filename, uint32 **m,long nrl,long nrh,long ncl, long nch) |
---|
1455 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1456 | { |
---|
1457 | long i, ncol = nch-ncl+1, nread; |
---|
1458 | FILE *f; |
---|
1459 | |
---|
1460 | f = fopen(filename, "rb"); |
---|
1461 | if(f == NULL) |
---|
1462 | nrerror("Can't open file in fread_ui32matrix"); |
---|
1463 | |
---|
1464 | for(i=nrl; i<=nrh; i++) { |
---|
1465 | nread = fread(m[i]+ncl, sizeof(uint32), ncol, f); |
---|
1466 | if(nread != ncol) nrerror("fread_ui32matrix : can't read data"); |
---|
1467 | } |
---|
1468 | fclose(f); |
---|
1469 | } |
---|
1470 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1471 | IMAGE_EXPORT(void) fread_si64matrix(char *filename, sint64 **m,long nrl,long nrh,long ncl, long nch) |
---|
1472 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1473 | { |
---|
1474 | long i, ncol = nch-ncl+1, nread; |
---|
1475 | FILE *f; |
---|
1476 | |
---|
1477 | f = fopen(filename, "rb"); |
---|
1478 | if(f == NULL) |
---|
1479 | nrerror("Can't open file in fread_si64matrix"); |
---|
1480 | |
---|
1481 | for(i=nrl; i<=nrh; i++) { |
---|
1482 | nread = fread(m[i]+ncl, sizeof(sint32), ncol, f); |
---|
1483 | if(nread != ncol) nrerror("fread_si64matrix : can't read data"); |
---|
1484 | } |
---|
1485 | fclose(f); |
---|
1486 | } |
---|
1487 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1488 | IMAGE_EXPORT(void) fread_ui64matrix(char *filename, uint64 **m,long nrl,long nrh,long ncl, long nch) |
---|
1489 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1490 | { |
---|
1491 | long i, ncol = nch-ncl+1, nread; |
---|
1492 | FILE *f; |
---|
1493 | |
---|
1494 | f = fopen(filename, "rb"); |
---|
1495 | if(f == NULL) |
---|
1496 | nrerror("Can't open file in fread_ui64matrix"); |
---|
1497 | |
---|
1498 | for(i=nrl; i<=nrh; i++) { |
---|
1499 | nread = fread(m[i]+ncl, sizeof(uint64), ncol, f); |
---|
1500 | if(nread != ncol) nrerror("fread_ui64matrix : can't read data"); |
---|
1501 | } |
---|
1502 | fclose(f); |
---|
1503 | } |
---|
1504 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1505 | IMAGE_EXPORT(void) fread_f32matrix(char *filename, float32 **m,long nrl,long nrh,long ncl, long nch) |
---|
1506 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1507 | { |
---|
1508 | long i, ncol = nch-ncl+1, nread; |
---|
1509 | FILE *f; |
---|
1510 | |
---|
1511 | f = fopen(filename, "rb"); |
---|
1512 | if(f == NULL) nrerror("Can't open file in fread_f32matrix"); |
---|
1513 | |
---|
1514 | for(i=nrl; i<=nrh; i++) { |
---|
1515 | nread = fread(m[i]+ncl, sizeof(float32), ncol, f); |
---|
1516 | if(nread != ncol) nrerror("fread_f32matrix : can't read data"); |
---|
1517 | } |
---|
1518 | fclose(f); |
---|
1519 | } |
---|
1520 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1521 | IMAGE_EXPORT(void) fread_f64matrix(char *filename, float64 **m,long nrl,long nrh,long ncl, long nch) |
---|
1522 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1523 | { |
---|
1524 | long i, ncol = nch-ncl+1, nread; |
---|
1525 | FILE *f; |
---|
1526 | |
---|
1527 | f = fopen(filename, "rb"); |
---|
1528 | if(f == NULL) nrerror("Can't open file in fread_f64matrix"); |
---|
1529 | |
---|
1530 | for(i=nrl; i<=nrh; i++) { |
---|
1531 | nread = fread(m[i]+ncl, sizeof(float64), ncol, f); |
---|
1532 | if(nread != ncol) nrerror("fread_f64matrix : can't read data"); |
---|
1533 | } |
---|
1534 | fclose(f); |
---|
1535 | } |
---|
1536 | /* -------------------------------------------------------------------------------------------- */ |
---|
1537 | IMAGE_EXPORT(void) fread_rgb8matrix(char *filename, rgb8 **m,long nrl,long nrh,long ncl, long nch) |
---|
1538 | /* -------------------------------------------------------------------------------------------- */ |
---|
1539 | { |
---|
1540 | long i, ncol = nch-ncl+1, nread; |
---|
1541 | FILE *f; |
---|
1542 | |
---|
1543 | f = fopen(filename, "rb"); |
---|
1544 | if(f == NULL) nrerror("Can't open file in fread_rgb8matrix"); |
---|
1545 | |
---|
1546 | for(i=nrl; i<=nrh; i++) { |
---|
1547 | nread = fread(m[i]+ncl, sizeof(rgb8), ncol, f); |
---|
1548 | if(nread != ncol) nrerror("fread_rgb8matrix : can't read data"); |
---|
1549 | } |
---|
1550 | fclose(f); |
---|
1551 | } |
---|
1552 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1553 | IMAGE_EXPORT(void) fread_rgbx8matrix(char *filename, rgbx8 **m,long nrl,long nrh,long ncl, long nch) |
---|
1554 | /* ---------------------------------------------------------------------------------------------- */ |
---|
1555 | { |
---|
1556 | long i, ncol = nch-ncl+1, nread; |
---|
1557 | FILE *f; |
---|
1558 | |
---|
1559 | f = fopen(filename, "rb"); |
---|
1560 | if(f == NULL) nrerror("Can't open file in fread_rgbx8matrix"); |
---|
1561 | |
---|
1562 | for(i=nrl; i<=nrh; i++) { |
---|
1563 | nread = fread(m[i]+ncl, sizeof(rgbx8), ncol, f); |
---|
1564 | if(nread != ncol) nrerror("fread_rgbx8matrix : can't read data"); |
---|
1565 | } |
---|
1566 | fclose(f); |
---|
1567 | } |
---|
1568 | // -------------------------------------------------------------------------------------------------- |
---|
1569 | void write_ui8matrix_positive(uint8 **m, int i0, int i1, int j0, int j1, int iformat, char *filename) |
---|
1570 | // -------------------------------------------------------------------------------------------------- |
---|
1571 | { |
---|
1572 | int i, j; |
---|
1573 | char *format, *str; |
---|
1574 | FILE *f; |
---|
1575 | |
---|
1576 | select_display_positive_parameters(iformat, &format, &str); |
---|
1577 | |
---|
1578 | f = fopen(filename, "wt"); |
---|
1579 | if(f == NULL) { |
---|
1580 | nrerror("Can't open file in write_ui8matrix_positive"); |
---|
1581 | } |
---|
1582 | |
---|
1583 | for(i=i0; i<=i1; i++) { |
---|
1584 | for(j=j0; j<=j1; j++) { |
---|
1585 | if(m[i][j]) { |
---|
1586 | fprintf(f, format, m[i][j]); |
---|
1587 | } else { |
---|
1588 | fprintf(f, "%s", str); |
---|
1589 | } |
---|
1590 | } |
---|
1591 | fputc('\n', f); |
---|
1592 | } |
---|
1593 | fclose(f); |
---|
1594 | } |
---|
1595 | |
---|
1596 | // ---------------------------------------------------------------------------------------------------- |
---|
1597 | void write_ui16matrix_positive(uint16 **m, int i0, int i1, int j0, int j1, int iformat, char *filename) |
---|
1598 | // ---------------------------------------------------------------------------------------------------- |
---|
1599 | { |
---|
1600 | int i, j; |
---|
1601 | char *format, *str; |
---|
1602 | FILE *f; |
---|
1603 | |
---|
1604 | select_display_positive_parameters(iformat, &format, &str); |
---|
1605 | |
---|
1606 | f = fopen(filename, "wt"); |
---|
1607 | if(f == NULL) { |
---|
1608 | nrerror("Can't open file in write_ui16matrix_positive"); |
---|
1609 | } |
---|
1610 | |
---|
1611 | for(i=i0; i<=i1; i++) { |
---|
1612 | for(j=j0; j<=j1; j++) { |
---|
1613 | if(m[i][j]) { |
---|
1614 | fprintf(f, format, m[i][j]); |
---|
1615 | } else { |
---|
1616 | fprintf(f, "%s", str); |
---|
1617 | } |
---|
1618 | } |
---|
1619 | fputc('\n', f); |
---|
1620 | } |
---|
1621 | fclose(f); |
---|
1622 | } |
---|
1623 | // --------------------------------------------------------------------------------------------------- |
---|
1624 | void write_ui32matrix_positive(uint32 **m,int i0, int i1, int j0, int j1, int iformat, char *filename) |
---|
1625 | // --------------------------------------------------------------------------------------------------- |
---|
1626 | { |
---|
1627 | int i, j; |
---|
1628 | char *format, *str; |
---|
1629 | FILE *f; |
---|
1630 | |
---|
1631 | select_display_positive_parameters(iformat, &format, &str); |
---|
1632 | |
---|
1633 | f = fopen(filename, "wt"); |
---|
1634 | if(f == NULL) { |
---|
1635 | nrerror("Can't open file in write_ui32matrix_positive"); |
---|
1636 | } |
---|
1637 | |
---|
1638 | for(i=i0; i<=i1; i++) { |
---|
1639 | for(j=j0; j<=j1; j++) { |
---|
1640 | if(m[i][j]) { |
---|
1641 | fprintf(f, format, m[i][j]); |
---|
1642 | } else { |
---|
1643 | fprintf(f, "%s", str); |
---|
1644 | } |
---|
1645 | } |
---|
1646 | fputc('\n', f); |
---|
1647 | } |
---|
1648 | fclose(f); |
---|
1649 | } |
---|
1650 | |
---|
1651 | /* ------------------------ */ |
---|
1652 | /* -- PGM IO for bmatrix -- */ |
---|
1653 | /* ------------------------ */ |
---|
1654 | |
---|
1655 | PRIVATE char *readitem (FILE *file, char *buffer); |
---|
1656 | PRIVATE void ReadPGMrow (FILE *file, int width, uint8 *line); |
---|
1657 | PRIVATE void WritePGMrow(uint8 *line, int width, FILE *file); |
---|
1658 | |
---|
1659 | /* ------------------------------------------ */ |
---|
1660 | PRIVATE char *readitem(FILE *file, char *buffer) |
---|
1661 | /* ------------------------------------------ */ |
---|
1662 | // read a word |
---|
1663 | // public domain function: author is unknown |
---|
1664 | { |
---|
1665 | char *aux; |
---|
1666 | int k; |
---|
1667 | |
---|
1668 | k=0; |
---|
1669 | aux=buffer; |
---|
1670 | while (!feof(file)) |
---|
1671 | { |
---|
1672 | *aux=fgetc(file); |
---|
1673 | switch(k) |
---|
1674 | { |
---|
1675 | case 0: |
---|
1676 | if (*aux=='#') k=1; |
---|
1677 | if (isalnum(*aux)) k=2, aux++; |
---|
1678 | break; |
---|
1679 | case 1: |
---|
1680 | if (*aux==0xA) k=0; |
---|
1681 | break; |
---|
1682 | case 2: |
---|
1683 | if (!isalnum(*aux)) |
---|
1684 | { |
---|
1685 | *aux=0; |
---|
1686 | return buffer; |
---|
1687 | } |
---|
1688 | aux++; |
---|
1689 | break; |
---|
1690 | } |
---|
1691 | } |
---|
1692 | *aux=0; |
---|
1693 | return buffer; |
---|
1694 | } |
---|
1695 | /* ----------------------------------------------------- */ |
---|
1696 | PRIVATE void ReadPGMrow(FILE *file, int width, uint8 *line) |
---|
1697 | /* ----------------------------------------------------- */ |
---|
1698 | { |
---|
1699 | // file is already open (in read) and will not be closed at the end |
---|
1700 | fread(&(line[0]), sizeof(uint8), width, file); |
---|
1701 | } |
---|
1702 | /* ------------------------------------------------------- */ |
---|
1703 | PRIVATE void WritePGMrow(uint8 *line, int width, FILE *file) |
---|
1704 | /* ------------------------------------------------------- */ |
---|
1705 | { |
---|
1706 | // file is already open (in read) and will not be closed at the end |
---|
1707 | fwrite(&(line[0]), sizeof(uint8), width, file); |
---|
1708 | } |
---|
1709 | /* --------------------------------------------------------------------------------------- */ |
---|
1710 | IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch) |
---|
1711 | /* --------------------------------------------------------------------------------------- */ |
---|
1712 | { |
---|
1713 | // only for P5 binary type, not for text type |
---|
1714 | |
---|
1715 | int height, width, gris; |
---|
1716 | uint8 **m; |
---|
1717 | FILE *file; |
---|
1718 | |
---|
1719 | char *buffer; |
---|
1720 | char msg[1024]; |
---|
1721 | //char c; |
---|
1722 | int i; |
---|
1723 | |
---|
1724 | buffer = (char*) calloc(80, sizeof(char)); |
---|
1725 | |
---|
1726 | // open file |
---|
1727 | file = fopen(filename,"rb"); |
---|
1728 | if (file==NULL) { |
---|
1729 | //nrerror("ouverture du fichier impossible\n"); |
---|
1730 | sprintf(msg, "ouverture du fichier %s impossible dans LoadPGM_ui8matrix\n", filename); |
---|
1731 | nrerror(msg); |
---|
1732 | } |
---|
1733 | |
---|
1734 | // read PGM header |
---|
1735 | readitem(file, buffer); |
---|
1736 | /*fscanf(fichier, "%s", buffer);*/ |
---|
1737 | if(strcmp(buffer, "P5") != 0) nrerror("entete du fichier %s invalide\n"); |
---|
1738 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
1739 | |
---|
1740 | width = atoi(readitem(file, buffer)); |
---|
1741 | height = atoi(readitem(file, buffer)); |
---|
1742 | gris = atoi(readitem(file, buffer)); |
---|
1743 | |
---|
1744 | *nrl = 0; |
---|
1745 | *nrh = height - 1; |
---|
1746 | *ncl = 0; |
---|
1747 | *nch = width - 1; |
---|
1748 | m = ui8matrix(*nrl, *nrh, *ncl, *nch); |
---|
1749 | |
---|
1750 | for(i=0; i<height; i++) { |
---|
1751 | ReadPGMrow(file, width, m[i]); |
---|
1752 | } |
---|
1753 | |
---|
1754 | fclose(file); |
---|
1755 | free(buffer); |
---|
1756 | |
---|
1757 | return m; |
---|
1758 | } |
---|
1759 | /* ---------------------------------------------------------------------------------------- */ |
---|
1760 | IMAGE_EXPORT(uint8 **) LoadPGM_bmatrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch) |
---|
1761 | /* ---------------------------------------------------------------------------------------- */ |
---|
1762 | { |
---|
1763 | // only for P5 binary type, not for text type |
---|
1764 | |
---|
1765 | int height, width, gris; |
---|
1766 | uint8 **m; |
---|
1767 | FILE *file; |
---|
1768 | |
---|
1769 | char *buffer; |
---|
1770 | char msg[1024]; |
---|
1771 | //char c; |
---|
1772 | int i; |
---|
1773 | |
---|
1774 | buffer = (char*) calloc(80, sizeof(char)); |
---|
1775 | |
---|
1776 | // open file |
---|
1777 | file = fopen(filename,"rb"); |
---|
1778 | if (file==NULL) { |
---|
1779 | //nrerror("ouverture du fichier impossible\n"); |
---|
1780 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1781 | nrerror(msg); |
---|
1782 | } |
---|
1783 | |
---|
1784 | // read PGM header |
---|
1785 | readitem(file, buffer); |
---|
1786 | /*fscanf(fichier, "%s", buffer);*/ |
---|
1787 | if(strcmp(buffer, "P5") != 0) |
---|
1788 | nrerror("entete du fichier %s invalide\n"); |
---|
1789 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
1790 | |
---|
1791 | width = atoi(readitem(file, buffer)); |
---|
1792 | height = atoi(readitem(file, buffer)); |
---|
1793 | gris = atoi(readitem(file, buffer)); |
---|
1794 | |
---|
1795 | *nrl = 0; |
---|
1796 | *nrh = height - 1; |
---|
1797 | *ncl = 0; |
---|
1798 | *nch = width - 1; |
---|
1799 | m = ui8matrix(*nrl, *nrh, *ncl, *nch); |
---|
1800 | |
---|
1801 | for(i=0; i<height; i++) { |
---|
1802 | ReadPGMrow(file, width, m[i]); |
---|
1803 | } |
---|
1804 | |
---|
1805 | fclose(file); |
---|
1806 | free(buffer); |
---|
1807 | |
---|
1808 | return m; |
---|
1809 | } |
---|
1810 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1811 | IMAGE_EXPORT(void) LoadPGM_bmatrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, uint8 **m) |
---|
1812 | /* ----------------------------------------------------------------------------------------------- */ |
---|
1813 | { |
---|
1814 | // only for P5 binary type, not for text type |
---|
1815 | |
---|
1816 | int height, width, gris; |
---|
1817 | FILE *file; |
---|
1818 | |
---|
1819 | char *buffer; |
---|
1820 | char msg[1024]; |
---|
1821 | int i; |
---|
1822 | |
---|
1823 | buffer = (char*) calloc(80, sizeof(char)); |
---|
1824 | /* ouverture du fichier */ |
---|
1825 | file = fopen(filename,"rb"); |
---|
1826 | if (file==NULL) { |
---|
1827 | //nrerror("ouverture du fichier impossible\n"); |
---|
1828 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1829 | nrerror(msg); |
---|
1830 | } |
---|
1831 | |
---|
1832 | /* lecture de l'entete du fichier pgm */ |
---|
1833 | readitem(file, buffer); |
---|
1834 | /*fscanf(fichier, "%s", buffer);*/ |
---|
1835 | if(strcmp(buffer, "P5") != 0) |
---|
1836 | nrerror("entete du fichier %s invalide\n"); |
---|
1837 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
1838 | |
---|
1839 | width = atoi(readitem(file, buffer)); |
---|
1840 | height = atoi(readitem(file, buffer)); |
---|
1841 | gris = atoi(readitem(file, buffer)); |
---|
1842 | |
---|
1843 | *nrl = 0; |
---|
1844 | *nrh = height - 1; |
---|
1845 | *ncl = 0; |
---|
1846 | *nch = width - 1; |
---|
1847 | |
---|
1848 | for(i=0; i<height; i++) { |
---|
1849 | ReadPGMrow(file, width, m[i]); |
---|
1850 | } |
---|
1851 | |
---|
1852 | fclose(file); |
---|
1853 | free(buffer); |
---|
1854 | } |
---|
1855 | /* -------------------------------------------------------------------------------------------- */ |
---|
1856 | IMAGE_EXPORT(void) MLoadPGM_bmatrix(char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m) |
---|
1857 | /* -------------------------------------------------------------------------------------------- */ |
---|
1858 | { |
---|
1859 | // only for P5 binary type, not for text type |
---|
1860 | |
---|
1861 | int height, width, gris; |
---|
1862 | FILE *file; |
---|
1863 | |
---|
1864 | char *buffer; |
---|
1865 | char msg[1024]; |
---|
1866 | |
---|
1867 | int i; |
---|
1868 | |
---|
1869 | buffer = (char*) calloc(80, sizeof(char)); |
---|
1870 | /* ouverture du fichier */ |
---|
1871 | file = fopen(filename,"rb"); |
---|
1872 | if (file==NULL) { |
---|
1873 | //nrerror("ouverture du fichier impossible\n"); |
---|
1874 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1875 | nrerror(msg); |
---|
1876 | } |
---|
1877 | |
---|
1878 | /* lecture de l'entete du fichier pgm */ |
---|
1879 | readitem(file, buffer); |
---|
1880 | /*fscanf(fichier, "%s", buffer);*/ |
---|
1881 | if(strcmp(buffer, "P5") != 0) |
---|
1882 | nrerror("entete du fichier %s invalide\n"); |
---|
1883 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
1884 | |
---|
1885 | width = atoi(readitem(file, buffer)); |
---|
1886 | height = atoi(readitem(file, buffer)); |
---|
1887 | gris = atoi(readitem(file, buffer)); |
---|
1888 | |
---|
1889 | for(i=0; i<height; i++) { |
---|
1890 | ReadPGMrow(file, width, m[i]); |
---|
1891 | } |
---|
1892 | |
---|
1893 | fclose(file); |
---|
1894 | free(buffer); |
---|
1895 | } |
---|
1896 | /* ------------------------------------------------------------------------------------------ */ |
---|
1897 | IMAGE_EXPORT(void) SavePGM_bmatrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename) |
---|
1898 | /* ------------------------------------------------------------------------------------------ */ |
---|
1899 | { |
---|
1900 | int nrow = nrh-nrl+1; |
---|
1901 | int ncol = nch-ncl+1; |
---|
1902 | |
---|
1903 | char buffer[80]; |
---|
1904 | char msg[1024]; |
---|
1905 | |
---|
1906 | FILE *file; |
---|
1907 | int i; |
---|
1908 | |
---|
1909 | file = fopen(filename, "wb"); |
---|
1910 | if (file == NULL) { |
---|
1911 | //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1912 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1913 | nrerror(msg); |
---|
1914 | } |
---|
1915 | |
---|
1916 | /* enregistrement de l'image au format rpgm */ |
---|
1917 | sprintf(buffer,"P5\n%d %d\n255\n",ncol, nrow); |
---|
1918 | fwrite(buffer,strlen(buffer),1,file); |
---|
1919 | for(i=nrl; i<=nrh; i++) |
---|
1920 | WritePGMrow(m[i], ncol, file); |
---|
1921 | |
---|
1922 | /* fermeture du fichier */ |
---|
1923 | fclose(file); |
---|
1924 | } |
---|
1925 | /* --------------------------------------------------------------------------------------------- */ |
---|
1926 | IMAGE_EXPORT(void) SavePGM_ui8matrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename) |
---|
1927 | /* --------------------------------------------------------------------------------------------- */ |
---|
1928 | { |
---|
1929 | int nrow = nrh-nrl+1; |
---|
1930 | int ncol = nch-ncl+1; |
---|
1931 | |
---|
1932 | char buffer[80]; |
---|
1933 | char msg[1024]; |
---|
1934 | |
---|
1935 | FILE *file; |
---|
1936 | int i; |
---|
1937 | |
---|
1938 | file = fopen(filename, "wb"); |
---|
1939 | if (file == NULL) { |
---|
1940 | //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1941 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1942 | nrerror(msg); |
---|
1943 | } |
---|
1944 | |
---|
1945 | /* enregistrement de l'image au format rpgm */ |
---|
1946 | sprintf(buffer,"P5\n%d %d\n255\n",ncol, nrow); |
---|
1947 | fwrite(buffer,strlen(buffer),1,file); |
---|
1948 | for(i=nrl; i<=nrh; i++) |
---|
1949 | WritePGMrow(m[i], ncol, file); |
---|
1950 | |
---|
1951 | /* fermeture du fichier */ |
---|
1952 | fclose(file); |
---|
1953 | } |
---|
1954 | /* --------------------------- */ |
---|
1955 | /* -- PNM IO for rgb8matrix -- */ |
---|
1956 | /* --------------------------- */ |
---|
1957 | |
---|
1958 | /* ------------------------------------------------------ */ |
---|
1959 | PRIVATE void ReadPNMrow(FILE *file, int width, byte *line) |
---|
1960 | /* ------------------------------------------------------ */ |
---|
1961 | { |
---|
1962 | /* Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin */ |
---|
1963 | fread(&(line[0]), sizeof(byte), 3*sizeof(byte)*width, file); |
---|
1964 | } |
---|
1965 | /* ------------------------------------------------------- */ |
---|
1966 | PRIVATE void WritePNMrow(byte *line, int width, FILE *file) |
---|
1967 | /* ------------------------------------------------------- */ |
---|
1968 | { |
---|
1969 | /* Le fichier est deja ouvert et ne sera pas ferme a la fin */ |
---|
1970 | |
---|
1971 | fwrite(&(line[0]), sizeof(byte), 3*sizeof(byte)*width, file); |
---|
1972 | } |
---|
1973 | /* ------------------------------------------------------------------------------------------ */ |
---|
1974 | IMAGE_EXPORT(rgb8 **) LoadPPM_rgb8matrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch) |
---|
1975 | /* ------------------------------------------------------------------------------------------ */ |
---|
1976 | { |
---|
1977 | /* cette version ne lit plus que le type P6 */ |
---|
1978 | |
---|
1979 | int height, width, gris; |
---|
1980 | rgb8 **m; |
---|
1981 | FILE *file; |
---|
1982 | //int format; |
---|
1983 | |
---|
1984 | char *buffer; |
---|
1985 | char msg[1024]; |
---|
1986 | //char c; |
---|
1987 | int i; |
---|
1988 | |
---|
1989 | buffer = (char*) calloc(80, sizeof(char)); |
---|
1990 | /* ouverture du fichier */ |
---|
1991 | file = fopen(filename,"rb"); |
---|
1992 | if (file==NULL) { |
---|
1993 | //nrerror("ouverture du fichier impossible\n"); |
---|
1994 | sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
1995 | nrerror(msg); |
---|
1996 | } |
---|
1997 | |
---|
1998 | /* lecture de l'entete du fichier pgm */ |
---|
1999 | readitem(file, buffer); |
---|
2000 | /*fscanf(fichier, "%s", buffer);*/ |
---|
2001 | if(strcmp(buffer, "P6") != 0) |
---|
2002 | nrerror("entete du fichier %s invalide\n"); |
---|
2003 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
2004 | |
---|
2005 | width = atoi(readitem(file, buffer)); |
---|
2006 | height = atoi(readitem(file, buffer)); |
---|
2007 | gris = atoi(readitem(file, buffer)); |
---|
2008 | |
---|
2009 | *nrl = 0; |
---|
2010 | *nrh = height - 1; |
---|
2011 | *ncl = 0; |
---|
2012 | *nch = width - 1; |
---|
2013 | m = rgb8matrix(*nrl, *nrh, *ncl, *nch); |
---|
2014 | |
---|
2015 | for(i=0; i<height; i++) { |
---|
2016 | ReadPNMrow(file, width, (byte*)m[i]); |
---|
2017 | } |
---|
2018 | |
---|
2019 | fclose(file); |
---|
2020 | free(buffer); |
---|
2021 | |
---|
2022 | return m; |
---|
2023 | } |
---|
2024 | /* -------------------------------------------------------------------------------------------------- */ |
---|
2025 | IMAGE_EXPORT(void) LoadPPM_rgb8matrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, rgb8 **m) |
---|
2026 | /* -------------------------------------------------------------------------------------------------- */ |
---|
2027 | { |
---|
2028 | /* cette version ne lit plus que le type P6 */ |
---|
2029 | |
---|
2030 | int height, width, gris; |
---|
2031 | FILE *file; |
---|
2032 | //int format; |
---|
2033 | |
---|
2034 | char *buffer; |
---|
2035 | char msg[1024]; |
---|
2036 | //char c; |
---|
2037 | int i; |
---|
2038 | |
---|
2039 | buffer = (char*) calloc(80, sizeof(char)); |
---|
2040 | /* ouverture du fichier */ |
---|
2041 | file = fopen(filename,"rb"); |
---|
2042 | if (file==NULL) { |
---|
2043 | //nrerror("ouverture du fichier impossible\n"); |
---|
2044 | sprintf(msg, "ouverture du fichier %s impossible dans LoadPPM_rgb8matrix2\n", filename); |
---|
2045 | nrerror(msg); |
---|
2046 | } |
---|
2047 | |
---|
2048 | /* lecture de l'entete du fichier pgm */ |
---|
2049 | readitem(file, buffer); |
---|
2050 | /*fscanf(fichier, "%s", buffer);*/ |
---|
2051 | if(strcmp(buffer, "P6") != 0) |
---|
2052 | nrerror("entete du fichier %s invalide\n"); |
---|
2053 | //nrerror("entete du fichier %s invalide\n", filename); |
---|
2054 | |
---|
2055 | width = atoi(readitem(file, buffer)); |
---|
2056 | height = atoi(readitem(file, buffer)); |
---|
2057 | gris = atoi(readitem(file, buffer)); |
---|
2058 | |
---|
2059 | *nrl = 0; |
---|
2060 | *nrh = height - 1; |
---|
2061 | *ncl = 0; |
---|
2062 | *nch = width - 1; |
---|
2063 | |
---|
2064 | for(i=0; i<height; i++) { |
---|
2065 | ReadPNMrow(file, width, (byte*)m[i]); |
---|
2066 | } |
---|
2067 | fclose(file); |
---|
2068 | free(buffer); |
---|
2069 | } |
---|
2070 | /* ------------------------------------------------------------------------------------------------- */ |
---|
2071 | IMAGE_EXPORT(void) SavePPM_rgb8matrix(rgb8 **m, int nrl, int nrh, int ncl, int nch, char *filename) |
---|
2072 | /* ------------------------------------------------------------------------------------------------- */ |
---|
2073 | { |
---|
2074 | int nrow = nrh-nrl+1; |
---|
2075 | int ncol = nch-ncl+1; |
---|
2076 | |
---|
2077 | char buffer[80]; |
---|
2078 | char msg[1024]; |
---|
2079 | |
---|
2080 | FILE *file; |
---|
2081 | int i; |
---|
2082 | |
---|
2083 | file = fopen(filename, "wb"); |
---|
2084 | if (file == NULL) { |
---|
2085 | //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename); |
---|
2086 | //nrerror("ouverture du fichier %s impossible dans SavePPM_bmatrix\n"); |
---|
2087 | sprintf(msg, "ouverture du fichier %s impossible dans SavePPM_rgb8matrix\n", filename); |
---|
2088 | |
---|
2089 | nrerror(msg); |
---|
2090 | } |
---|
2091 | |
---|
2092 | /* enregistrement de l'image au format rpgm */ |
---|
2093 | |
---|
2094 | sprintf(buffer,"P6\n%d %d\n255\n",ncol, nrow); |
---|
2095 | fwrite(buffer,strlen(buffer),1,file); |
---|
2096 | for(i=nrl; i<=nrh; i++) |
---|
2097 | WritePNMrow((byte*)m[i], ncol, file); |
---|
2098 | |
---|
2099 | /* fermeture du fichier */ |
---|
2100 | fclose(file); |
---|
2101 | } |
---|