1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
4 libgpiv - library for Particle Image Velocimetry
6 Copyright (C) 2011 Gerber van der Graaf
8 This file is part of libgpiv.
9 Libgpiv is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ------------------------------------------------------------------------------*/
31 #define PNM_GET1(x) PPM_GETB(x)
32 #define PPM_GETB(x) ((x) & 0x3ff)
33 #define PNG_BYTES_TO_CHECK 4
34 #define PNG_KEY__PIV_XCORR "Piv: Xcorr (TRUE/FALSE)"
35 #define PNG_KEY__PIV_DT "Piv: Delta_t (milliseconds)"
39 get_png_val (png_byte
**pp
,
44 matrix_png_byte (long nr
,
49 free_matrix_png_byte (png_byte
**m
53 get_imgpar_from_textchunks (GpivImagePar
*image_par
,
58 set_textchunks_from_imgpar (GpivImagePar
*image_par
,
65 print_img_parameters_set (GpivImagePar
*gpiv_image_par
);
68 read_raw_image_frames (FILE *fp
,
73 write_raw_image_frames (FILE *fp
,
82 gpiv_read_image (FILE *fp
84 /*---------------------------------------------------------------------------*/
86 * Reads image from fp, png formatted.
89 GpivImage
*image
= NULL
;
92 if (fp
== NULL
) fp
= stdin
;
94 if ((image
= gpiv_read_png_image (fp
)) == NULL
) {
95 g_message ("gpiv_read_image: gpiv_read_png_image failed");
105 gpiv_fread_image (const gchar
*fname
107 /* ----------------------------------------------------------------------------
108 * checks filename extension on valid image / data name,
109 * loads image header and data
112 GpivImage
*image
= NULL
;
114 char *err_msg
= NULL
;
115 gchar
*ext
, *ext_ORG
= NULL
,
119 *fname_org
= g_strdup(fname
);
120 gchar command
[2 * GPIV_MAX_CHARS
];
123 gchar tmp_textfile
[GPIV_MAX_CHARS
];
124 /* BUGFIX: for the moment use the variable: cleanup_tmp_image */
125 gboolean cleanup_tmp_image
= TRUE
;
129 gpiv_warning ("gpiv_fread_image: failing \"fname == NULL\"");
133 if (g_file_test (fname
, G_FILE_TEST_EXISTS
) == FALSE
) {
134 gpiv_warning ("gpiv_fread_image: file does not exist");
139 * Stripping file name to examine suffix
142 ext
= g_strdup(strrchr(fname
, '.'));
143 dirname
= g_strdup(g_path_get_dirname(fname
));
144 fname_base
= g_strdup(g_path_get_basename(fname
));
145 strtok(fname_base
, ".");
146 fname_ext
= g_strdup (g_strconcat (dirname
, G_DIR_SEPARATOR_S
,
149 g_message("gpiv_fread_image:: dirname = %s\n fname_base = %s\n fname_ext = %s",
150 dirname
, fname_base
, fname_ext
);
154 * Converting image from pgm, gif, tif, bmp, ppm format to png
155 * Creating tempory text file to include as required comment in PNG image
156 * for use in gpiv software
158 if (g_str_has_suffix (fname
, GPIV_EXT_PGM_IMAGE
)
159 || g_str_has_suffix (fname
, GPIV_EXT_PGM_IMAGE_UPCASE
)) {
160 /* if (strcmp(ext, GPIV_EXT_PGM_IMAGE) == 0) { */
161 g_snprintf (command
, 2 * GPIV_MAX_CHARS
,
162 "pnmtopng < %s > %s%s",
163 fname
, fname_ext
, GPIV_EXT_PNG_IMAGE
);
165 if (system (command
) != 0) {
166 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
170 ext_ORG
= g_strdup(ext
);
172 ext
= g_strdup(GPIV_EXT_PNG_IMAGE
);
173 fname
= g_strdup_printf("%s%s", fname_ext
, ext
);
176 } else if (g_str_has_suffix (fname
, ".gif")
177 || g_str_has_suffix (fname
, ".GIF")) {
178 g_snprintf (command
, 2 * GPIV_MAX_CHARS
,
179 "giftopnm < %s | pnmtopng > %s%s",
180 fname
, fname_ext
, GPIV_EXT_PNG_IMAGE
);
181 if (system (command
) != 0) {
182 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
185 ext_ORG
= g_strdup(ext
);
187 ext
= g_strdup(GPIV_EXT_PNG_IMAGE
);
188 fname
= g_strdup_printf("%s%s", fname_ext
, ext
);
191 } else if (g_str_has_suffix (fname
, ".tif")
192 || g_str_has_suffix (fname
, ".TIF")) {
193 g_snprintf (command
, 2 * GPIV_MAX_CHARS
,
194 "tifftopnm < %s | pnmtopng > %s%s",
195 fname
, fname_ext
, GPIV_EXT_PNG_IMAGE
);
197 if (system (command
) != 0) {
198 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
202 ext_ORG
= g_strdup(ext
);
204 ext
= g_strdup(GPIV_EXT_PNG_IMAGE
);
205 fname
= g_strdup_printf("%s%s", fname_ext
, ext
);
208 } else if (g_str_has_suffix (fname
, ".bmp")
209 || g_str_has_suffix (fname
, ".BMP")) {
210 g_snprintf (command
, 2 * GPIV_MAX_CHARS
,
211 "bmptoppm < %s | pnmtopng > %s%s",
212 fname
, fname_ext
, GPIV_EXT_PNG_IMAGE
);
214 if (system (command
) != 0) {
215 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
219 ext_ORG
= g_strdup(ext
);
221 ext
= g_strdup(GPIV_EXT_PNG_IMAGE
);
222 fname
= g_strdup_printf("%s%s", fname_ext
, ext
);
224 } else if (g_str_has_suffix (fname
, ".ppm")
225 || g_str_has_suffix (fname
, ".PPM")) {
226 g_snprintf (command
, 2 * GPIV_MAX_CHARS
,
227 "pnmtopng < %s > %s%s",
228 fname
, fname_ext
, GPIV_EXT_PNG_IMAGE
);
230 if (system (command
) != 0) {
231 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
235 ext_ORG
= g_strdup(ext
);
237 ext
= g_strdup(GPIV_EXT_PNG_IMAGE
);
238 fname
= g_strdup_printf("%s%s", fname_ext
, ext
);
242 * reading image data from raw, PNG, hdf or Davis(tm) format
244 if (strcmp (ext
, GPIV_EXT_RAW_IMAGE
) == 0
245 || strcmp (ext
, GPIV_EXT_PNG_IMAGE
) == 0
246 || strcmp (ext
, GPIV_EXT_PNG_IMAGE_UPCASE
) == 0
247 || strcmp (ext
, GPIV_EXT_GPIV
) == 0
248 || strcmp (ext
, GPIV_EXT_GPIV_UPCASE
) == 0
249 || strcmp (ext
, GPIV_EXT_DAVIS
) == 0
250 || strcmp (ext
, GPIV_EXT_DAVIS_UPCASE
) == 0) {
253 g_message ("gpiv_fread_image:: my_utils_open_img");
255 if ((image
= my_utils_open_img (fname
)) == NULL
) {
256 gpiv_warning ("gpiv_fread_image: failure open_img");
261 gpiv_warning ("gpiv_fread_image: image format not recognised");
266 * Remove original image if it has temporarly been converted to png
269 && (strcmp(ext_ORG
, GPIV_EXT_PGM_IMAGE
) == 0
270 || strcmp(ext_ORG
, ".pgm") == 0
271 || strcmp(ext_ORG
, ".PGM") == 0
272 || strcmp(ext_ORG
, ".gif") == 0
273 || strcmp(ext_ORG
, ".GIF") == 0
274 || strcmp(ext_ORG
, ".tif") == 0
275 || strcmp(ext_ORG
, ".TIF") == 0
276 || strcmp(ext_ORG
, ".bmp") == 0
277 || strcmp(ext_ORG
, ".BMP") == 0
278 || strcmp(ext_ORG
, ".ppm") == 0
279 || strcmp(ext_ORG
, ".PPM") == 0
282 if (cleanup_tmp_image
) {
283 g_snprintf (command
, 2 * GPIV_MAX_CHARS
, "rm %s%s",
284 fname_ext
, GPIV_EXT_PNG_IMAGE
);
286 g_snprintf (command
, 2 * GPIV_MAX_CHARS
, "rm %s ", fname_org
);
288 if (system (command
) != 0) {
289 gpiv_warning ("gpiv_fread_image: could not exec shell command \"%s\"",
308 gpiv_read_png_image (FILE *fp
310 /*---------------------------------------------------------------------------*/
312 * Reads png formatted image.
314 * @param[in] fp input file
317 /*---------------------------------------------------------------------------*/
319 GpivImage
*gpiv_image
= NULL
;
320 GpivImagePar
*gpiv_image_par
= g_new0 (GpivImagePar
, 1);
322 char buf
[PNG_BYTES_TO_CHECK
];
325 png_infop info_ptr
, end_info_ptr
;
326 unsigned int sig_read
= 0;
327 png_uint_32 width
, height
;
328 gint bit_depth
, color_type
, interlace_type
, compression_type
,
329 unit_type_offs
, filter_method
;
332 png_int_32 x_offset
= 0, y_offset
= 0;
335 png_byte
**png_image
= NULL
;
336 png_byte
*png_rowpointer
;
339 /* @param[in] allocate boolean whether to allocate memory for image arrays
340 * @param[in] x_corr__set boolean if x_corr has been defined
341 * @param[in] x_corr boolean whether image contains two frames for cross-correlation.
342 * Will only be used if absent in header of input image and if
346 #ifdef PNG_tIME_SUPPORTED
348 #endif /* PNG_tIME_SUPPORTED */
350 gpiv_img_parameters_set (gpiv_image_par
, FALSE
);
352 g_message ("gpiv_read_png_image:: 00");
355 /* Read in some of the signature bytes */
356 if (fread (buf
, 1, PNG_BYTES_TO_CHECK
, fp
) != PNG_BYTES_TO_CHECK
) {
357 g_warning ("gpiv_read_png_image: failing fread (buf, 1, PNG_BYTES_TO_CHECK, fp)");
361 /* Testing the signature bytes */
362 if (png_sig_cmp ((png_bytep
)buf
, (png_size_t
)0, PNG_BYTES_TO_CHECK
) != 0) {
363 g_warning ("gpiv_read_png_image: failing signature bytes test");
369 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
,
370 png_voidp_NULL
, png_error_ptr_NULL
,
372 if (png_ptr
== NULL
) {
373 g_warning ("gpiv_read_png_image: failing png_create_read_struct()");
377 info_ptr
= png_create_info_struct (png_ptr
);
378 if (info_ptr
== NULL
) {
380 png_destroy_read_struct (&png_ptr
, png_infopp_NULL
, png_infopp_NULL
);
381 g_warning ("gpiv_read_png_image: failing png_create_info_struct (png_ptr)");
385 end_info_ptr
= png_create_info_struct (png_ptr
);
387 if (setjmp (png_jmpbuf (png_ptr
))) {
388 /* Free all of the memory associated with the png_ptr and info_ptr */
389 /* If we get here, we had a problem reading the file */
390 png_destroy_read_struct (&png_ptr
, &info_ptr
,
391 /* NULL */ &end_info_ptr
);
392 g_warning ("gpiv_read_png_image: failing setjmp (png_jmpbuf (png_ptr)");
396 png_init_io (png_ptr
, fp
);
398 /* If we have already read some of the signature */
400 png_set_sig_bytes (png_ptr
, PNG_BYTES_TO_CHECK
);
404 png_read_png (png_ptr
, info_ptr
, PNG_TRANSFORM_IDENTITY
, png_voidp_NULL
);
406 png_read_info (png_ptr
, info_ptr
);
410 /* Quering image info: */
411 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
412 &interlace_type
, &compression_type
, &filter_method
);
414 /* Other metadata chunks: */
415 #ifdef PNG_oFFs_SUPPORTED
416 png_get_oFFs (png_ptr
, info_ptr
, &x_offset
, &y_offset
, &unit_type_offs
);
417 #endif /* PNG_oFFs_SUPPORTED */
419 #ifdef PNG_pCAL_SUPPORTED
420 res_x
= png_get_x_pixels_per_meter (png_ptr
, info_ptr
);
421 #endif /* PNG_pCAL_SUPPORTED */
423 #ifdef PNG_tIME_SUPPORTED
424 png_get_tIME (png_ptr
, info_ptr
, &mod_time
);
425 #endif /* PNG_tIME_SUPPORTED */
428 #ifdef PNG_TEXT_SUPPORTED
429 get_imgpar_from_textchunks (gpiv_image_par
, png_ptr
, info_ptr
);
430 #endif /* PNG_TEXT_SUPPORTED */
432 /* if (gpiv_image_par.x_corr__set == FALSE) { */
433 /* g_warning ("GPIV_READ_PNG_IMAGE: couldn't read or x_corr"); */
439 printf ("Image info:\nwidth = %d height = %d depth = %d \n",
445 if (color_type
== PNG_COLOR_TYPE_GRAY
) {
446 printf ("color_type = PNG_COLOR_TYPE_GRAY\n");
447 } else if (color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
) {
448 printf ("color_type = PNG_COLOR_TYPE_GRAY_ALPHA\n");
449 } else if (color_type
== PNG_COLOR_TYPE_PALETTE
) {
450 printf ("color_type = PNG_COLOR_TYPE_PALETTE\n");
451 } else if (color_type
== PNG_COLOR_TYPE_RGB
) {
452 printf ("color_type = PNG_COLOR_TYPE_RGB\n");
453 } else if (color_type
== PNG_COLOR_TYPE_RGB_ALPHA
) {
454 printf ("color_type = PNG_COLOR_TYPE_RGB_ALPHA\n");
455 } else if (color_type
== PNG_COLOR_MASK_PALETTE
) {
456 printf ("color_type = PNG_COLOR_MASK_PALETTE\n");
457 } else if (color_type
== PNG_COLOR_MASK_COLOR
) {
458 printf ("color_type = PNG_COLOR_MASK_COLOR\n");
459 } else if (color_type
== PNG_COLOR_MASK_ALPHA
) {
460 printf ("color_type = PNG_COLOR_MASK_ALPHA\n");
462 g_warning ("gpiv_read_png_image: no existing color type");
466 if (compression_type
== PNG_COMPRESSION_TYPE_DEFAULT
) {
467 printf ("compression_type = PNG_COMPRESSION_TYPE_DEFAULT\n");
469 g_warning ("gpiv_read_png_image: no existing compression type");
473 if (interlace_type
== PNG_INTERLACE_NONE
) {
474 printf ("interlace_type = PNG_INTERLACE_NONE\n");
475 } else if (interlace_type
== PNG_INTERLACE_ADAM7
) {
476 printf ("interlace_type = PNG_INTERLACE_ADAM7\n");
478 g_warning ("gpiv_read_png_image: no existing interlace type");
483 #ifdef PNG_oFFs_SUPPORTED
484 printf ("x_offset = %d y_offset = %d\n",
485 (int)x_offset
, (int)y_offset
);
486 #endif /* PNG_oFFs_SUPPORTED */
488 #ifdef PNG_pCAL_SUPPORTED
489 printf ("resolution (pixels/meter) res_x = %d \n",
493 #ifdef PNG_tIME_SUPPORTED
494 printf ("Modification GMT time: (Y/M/D: h/m/s) %d/%d/%d: %d/%d/%d \n",
495 mod_time
->year
, mod_time
->month
, mod_time
->day
,
496 mod_time
->hour
, mod_time
->minute
, mod_time
->second
498 #endif /* PNG_tIME_SUPPORTED */
505 * If the image is of correct format GRAY and has no INTERLACE, apply header
506 * info to gpiv_image structure
508 gpiv_image_par
->depth
= bit_depth
;
509 gpiv_image_par
->depth__set
= TRUE
;
511 if (color_type
!= PNG_COLOR_TYPE_GRAY
) {
512 g_warning ("gpiv_read_png_image: image is not PNG_COLOR_TYPE_GRAY");
516 if (interlace_type
!= PNG_INTERLACE_NONE
) {
517 g_warning ("gpiv_read_png_image: image is not PNG_INTERLACE_NONE");
521 if (info_ptr
->bit_depth
== 16) {
522 linesize
= 2 * width
;
526 gpiv_image_par
->ncolumns
= width
;
527 gpiv_image_par
->ncolumns__set
= TRUE
;
530 #ifdef GPIV_IMG_PARAM_RESOURCES
532 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, gpiv_image_par
, TRUE
);
534 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, gpiv_image_par
, FALSE
);
536 #endif /* GPIV_IMG_PARAM_RESOURCES */
538 if (gpiv_image_par
->x_corr__set
== FALSE
) {
539 g_warning ("gpiv_read_png_image: couldn't read or x_corr");
543 if (gpiv_image_par
->x_corr
) {
544 gpiv_image_par
->nrows
= height
/ 2;
546 gpiv_image_par
->nrows
= height
;
548 gpiv_image_par
->nrows__set
= TRUE
;
552 gpiv_image_par
->s_scale
= res_x
;
553 gpiv_image_par
->s_scale__set
= TRUE
;
555 gpiv_image_par
->s_scale__set
= FALSE
;
560 * Allocating (png) image
562 gpiv_image
= gpiv_alloc_img (gpiv_image_par
);
564 if ((png_image
= matrix_png_byte (height
, linesize
)) == NULL
) {
565 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info_ptr
);
566 g_warning ("gpiv_read_png_image: couldn't allocate space for image");
572 * Obtaining image frame data
575 png_image
= png_get_rows (png_ptr
, info_ptr
);
577 png_read_image (png_ptr
, png_image
);
578 png_read_end (png_ptr
, info_ptr
);
583 * Copy png image data to img1, img2
585 for (row
= 0; row
< gpiv_image
->header
->nrows
; row
++) {
587 printf ("\ngpiv_read_png_image: IMG1 row = %d img_png: \n", row
);
589 png_rowpointer
= png_image
[row
];
590 for (column
= 0; column
< gpiv_image
->header
->ncolumns
; column
++) {
591 gpiv_image
->frame1
[row
][column
] =
592 get_png_val (&png_rowpointer
, bit_depth
);
594 printf ("%d ", (int) gpiv_image
->frame1
[row
][column
]);
599 if (gpiv_image
->header
->x_corr
) {
600 for (row
= 0; row
< gpiv_image
->header
->nrows
; row
++) {
602 printf ("\ngpiv_read_png_image: IMG2 row = %d img_png: \n",
605 png_rowpointer
= png_image
[row
+ gpiv_image
->header
->nrows
];
606 for (column
= 0; column
< gpiv_image
->header
->ncolumns
;
608 gpiv_image
->frame2
[row
][column
] =
609 get_png_val (&png_rowpointer
, bit_depth
);
611 printf ("%d ", (int) gpiv_image
->frame2
[row
][column
]);
618 * clean up after the read, and free any memory allocated
620 free_matrix_png_byte (png_image
);
623 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info_ptr
);
630 gpiv_fwrite_png_image (const gchar
*fname
,
631 GpivImage
*gpiv_image
,
634 /*------------------------------------------------------------------------------
636 * Writes image data and header to png formatted image.
637 * Frees allocated image data.
639 *--------------------------------------------------------------------------- */
642 gchar
*err_msg
= NULL
;
646 gpiv_warning ("gpiv_fwrite_png_image: failing \"fname == NULL\"");
647 return "gpiv_fwrite_png_image: failing \"fname == NULL\"";
650 if ((fp
= fopen (fname
, "wb")) == NULL
) {
651 gpiv_warning ("LIBGPIV internal error: gpiv_fwrite_png_image: failure \
653 return "gpiv_fwrite_png_image: failing fopen";
656 if ((err_msg
= gpiv_write_png_image (fp
, gpiv_image
, free
)) != NULL
) {
669 gpiv_write_png_image (FILE *fp
,
670 GpivImage
*gpiv_image
,
673 /*------------------------------------------------------------------------------
675 * Writes image data and header to png formatted image.
676 * Frees allocated image data.
678 *--------------------------------------------------------------------------- */
680 gchar
*err_msg
= NULL
;
681 /* guint16 **img1, **img2; */
685 png_uint_32 width
= gpiv_image
->header
->ncolumns
, height
;
686 gint bit_depth
= gpiv_image
->header
->depth
;
687 gint color_type
= PNG_COLOR_TYPE_GRAY
;
688 gint interlace_type
= PNG_INTERLACE_NONE
;
689 gint compression_type
= PNG_COMPRESSION_TYPE_BASE
;
690 gint filter_method
= PNG_FILTER_TYPE_BASE
;
691 gint linesize
= 2 * width
;
693 #ifdef PNG_tIME_SUPPORTED
696 #endif /* PNG_tIME_SUPPORTED */
700 if (gpiv_image
->frame1
== NULL
) {
701 err_msg
= "gpiv_write_png_image: gpiv_image->frame1 == NULL";
704 if (gpiv_image
->header
->x_corr
705 && gpiv_image
->frame2
== NULL
) {
706 err_msg
= "gpiv_write_png_image: gpiv_image->frame2 == NULL";
711 * Allocate png_ structures
713 png_ptr
= png_create_write_struct (PNG_LIBPNG_VER_STRING
,
714 png_voidp_NULL
, png_error_ptr_NULL
,
716 if (png_ptr
== NULL
) {
717 err_msg
= "gpiv_write_png_image: failing png_create_write_struct()";
721 info_ptr
= png_create_info_struct (png_ptr
);
722 if (info_ptr
== NULL
) {
723 png_destroy_write_struct (&png_ptr
, &info_ptr
);
724 err_msg
= "gpiv_write_png_image: failing png_create_info_struct (png_ptr)";
728 if (setjmp (png_jmpbuf (png_ptr
))) {
729 png_destroy_write_struct (&png_ptr
, &info_ptr
);
730 err_msg
= "gpiv_write_png_image: failing at setjmp(png_jmpbuf (png_ptr)";
735 png_init_io (png_ptr
, fp
);
738 * Apply gpiv_image->header to png header
740 if (gpiv_image
->header
->x_corr
) {
741 height
= 2 * gpiv_image
->header
->nrows
;
743 height
= gpiv_image
->header
->nrows
;
746 png_set_compression_level (png_ptr
, Z_BEST_COMPRESSION
);
747 png_set_IHDR (png_ptr
, info_ptr
, width
, height
, bit_depth
, color_type
,
748 interlace_type
, compression_type
, filter_method
);
751 #ifdef PNG_pCAL_SUPPORTED
752 if (gpiv_image
->header
->s_scale__set
) {
753 png_set_sCAL (png_ptr
, info_ptr
, PNG_SCALE_METER
,
754 (png_int_32
) gpiv_image
->header
->s_scale
* width
,
755 (png_int_32
) gpiv_image
->header
->s_scale
* height
);
757 #endif /* PNG_pCAL_SUPPORTED */
759 #ifdef PNG_oFFs_SUPPORTED
760 if (gpiv_image
->header
->z_off_x__set
761 && gpiv_image
->header
->z_off_y__set
) {
762 /* / gpiv_image->header.sscale * 1.0e3 */ /* x_offset*/
763 /* / gpiv_image->header.sscale * 1.0e3 */ /* y_offset*/
764 png_set_oFFs (png_ptr
, info_ptr
,
765 (png_uint_32
) gpiv_image
->header
->z_off_x
,
766 (png_uint_32
) gpiv_image
->header
->z_off_y
,
769 #endif /* PNG_oFFs_SUPPORTED */
772 #ifdef PNG_tIME_SUPPORTED
773 ltime_t
= time (<ime_t
);
774 png_convert_from_time_t (&mod_time
, ltime_t
);
775 png_set_tIME (png_ptr
, info_ptr
, &mod_time
);
776 #endif /* PNG_tIME_SUPPORTED */
779 #ifdef PNG_TEXT_SUPPORTED
780 set_textchunks_from_imgpar (gpiv_image
->header
, png_ptr
, info_ptr
);
781 #endif /* PNG_TEXT_SUPPORTED */
783 png_write_info (png_ptr
, info_ptr
);
786 * Write image to png struct
788 if (info_ptr
->color_type
== PNG_COLOR_TYPE_GRAY
) {
789 #ifdef WRITE_IMAGEDATA_LINE
792 png_byte
**png_image
;
793 #endif /* WRITE_IMAGEDATA_LINE */
794 unsigned long p_png
; /* (pi)xel */
797 #ifdef WRITE_IMAGEDATA_LINE
798 if ((line
= (png_byte
*) g_malloc (linesize
)) == NULL
) {
799 png_destroy_write_struct (&png_ptr
, &info_ptr
);
800 err_msg
= "gpiv_write_png_image: out of memory allocating PNG row buffer";
804 if ((png_image
= matrix_png_byte (gpiv_image
->header
->nrows
, linesize
))
806 png_destroy_write_struct (&png_ptr
, &info_ptr
);
807 err_msg
= "gpiv_write_png_image: out of memory allocating PNG row buffer";
810 #endif /* WRITE_IMAGEDATA_LINE */
813 for (i
= 0; i
< gpiv_image
->header
->nrows
; i
++) {
814 #ifdef WRITE_IMAGEDATA_LINE
818 #endif /* WRITE_IMAGEDATA_LINE */
819 for (j
= 0; j
< width
; j
++) {
820 p_png
= gpiv_image
->frame1
[i
][j
];
821 if (bit_depth
== 16) *pp
++ = PNM_GET1 (p_png
) >> 8;
822 *pp
++ = PNM_GET1 (p_png
) & 0xff;
824 #ifdef WRITE_IMAGEDATA_LINE
825 png_write_row (png_ptr
, line
);
826 #endif /* WRITE_IMAGEDATA_LINE */
828 #ifndef WRITE_IMAGEDATA_LINE
829 png_write_rows (png_ptr
, png_image
, gpiv_image
->header
->nrows
);
830 #endif /* WRITE_IMAGEDATA_LINE */
833 if (gpiv_image
->header
->x_corr
) {
834 for (i
= 0; i
< gpiv_image
->header
->nrows
; i
++) {
835 #ifdef WRITE_IMAGEDATA_LINE
839 #endif /* WRITE_IMAGEDATA_LINE */
840 for (j
= 0; j
< width
; j
++) {
841 p_png
= gpiv_image
->frame2
[i
][j
];
842 if (bit_depth
== 16) *pp
++ = PNM_GET1 (p_png
) >> 8;
843 *pp
++ = PNM_GET1 (p_png
) & 0xff;
845 #ifdef WRITE_IMAGEDATA_LINE
846 png_write_row (png_ptr
, line
);
847 #endif /* WRITE_IMAGEDATA_LINE */
849 #ifndef WRITE_IMAGEDATA_LINE
850 png_write_rows (png_ptr
, png_image
, gpiv_image
->header
->nrows
);
851 #endif /* WRITE_IMAGEDATA_LINE */
855 #ifdef WRITE_IMAGEDATA_LINE
858 free_matrix_png_byte (png_image
);
859 #endif /* WRITE_IMAGEDATA_LINE */
862 png_destroy_write_struct (&png_ptr
, &info_ptr
);
863 err_msg
= "gpiv_write_png_image: color_type is not PNG_COLOR_TYPE_GRAY";
867 png_write_end (png_ptr
, info_ptr
);
871 * Freeing image memory
874 gpiv_free_img (gpiv_image
);
878 png_destroy_write_struct (&png_ptr
, &info_ptr
);
886 get_png_val (png_byte
**pp
,
889 /*-----------------------------------------------------------------------------
895 if (bit_depth
== 16) {
896 c
= (*((*pp
)++)) << 8;
900 /* if (maxval > maxmaxval) */
901 /* c /= ((maxval + 1) / (maxmaxval + 1)); */
910 matrix_png_byte (long nr
,
913 /*-----------------------------------------------------------------------------
915 * allocate a png_byte matrix with subscript range m[0..nr][0..nc]
919 * nc: number of columns
925 *---------------------------------------------------------------------------*/
931 m
= (png_byte
**) g_malloc0 (nr
* sizeof (png_byte
*));
932 m
[0] = (png_byte
*) g_malloc0 (nr
* nc
* sizeof (png_byte
));
933 for (i
= 1; i
< nr
; i
++) {
934 m
[i
] = m
[0] + i
* nc
;
944 free_matrix_png_byte (png_byte
**m
946 /*-----------------------------------------------------------------------------
948 * free a png_byte matrix allocated by matrix_png_byte
957 *---------------------------------------------------------------------------*/
959 g_return_if_fail (m
[0] != NULL
);
968 get_imgpar_from_textchunks (GpivImagePar
*image_par
,
972 /*------------------------------------------------------------------------------
974 * Obtains image paramameters from text chunks in png image
977 * png_ptr: png structure
978 * info_ptr: png info structure
981 * image_par: image parameter structure
984 *--------------------------------------------------------------------------- */
987 gint num_text
= 0, i
= 0;
988 png_uint_32 num_comments
= 0;
991 num_comments
= png_get_text (png_ptr
, info_ptr
, &text
, &num_text
);
993 for (i
= 0; i
< num_comments
; i
++) {
994 if (strcmp (text
[i
].key
, PNG_KEY__PIV_XCORR
) == 0) {
995 sscanf (text
[i
].text
, "%d", &image_par
->x_corr
);
996 image_par
->x_corr__set
= TRUE
;
999 if (strcmp (text
[i
].key
, PNG_KEY__PIV_DT
) == 0) {
1000 sscanf (text
[i
].text
, "%f", &image_par
->t_scale
);
1001 image_par
->t_scale__set
= TRUE
;
1005 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__TITLE
) == 0) {
1006 g_snprintf (image_par
->title
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1007 image_par
->title__set
= TRUE
;
1010 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__AUTHOR
) == 0) {
1011 g_snprintf (image_par
->author
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1012 image_par
->author__set
= TRUE
;
1015 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__USERTEXT
) == 0) {
1016 g_snprintf (image_par
->usertext
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1017 image_par
->usertext__set
= TRUE
;
1020 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__SOFTWARE
) == 0) {
1021 g_snprintf (image_par
->software
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1022 image_par
->software__set
= TRUE
;
1025 if (strcmp (text
[i
].key
,GPIV_IMGPAR_KEY__DISCLAIMER
) == 0) {
1026 g_snprintf (image_par
->disclaimer
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1027 image_par
->disclaimer__set
= TRUE
;
1030 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__WARNING
) == 0) {
1031 g_snprintf (image_par
->warning
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1032 image_par
->warning__set
= TRUE
;
1035 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__SOURCE
) == 0) {
1036 g_snprintf (image_par
->source
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1037 image_par
->source__set
= TRUE
;
1040 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__COMMENT
) == 0) {
1041 g_snprintf (image_par
->comment
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1042 image_par
->comment__set
= TRUE
;
1045 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__CREATION_DATE
) == 0) {
1046 g_snprintf (image_par
->creation_date
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1047 image_par
->creation_date__set
= TRUE
;
1050 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__COPYRIGHT
) == 0) {
1051 g_snprintf (image_par
->copyright
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1052 image_par
->copyright__set
= TRUE
;
1055 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__EMAIL
) == 0) {
1056 g_snprintf (image_par
->email
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1057 image_par
->email__set
= TRUE
;
1060 if (strcmp (text
[i
].key
, GPIV_IMGPAR_KEY__URL
) == 0) {
1061 g_snprintf (image_par
->url
, GPIV_MAX_CHARS
, "%s", text
[i
].text
);
1062 image_par
->url__set
= TRUE
;
1068 printf ("num_comments = %d\n", (int) num_comments
);
1069 for (i
= 0; i
< num_comments
; i
++) {
1070 printf ("key[%d] = %s: text[%d] = %s\n",
1071 i
, text
[i
].key
, i
, text
[i
].text
);
1081 set_textchunks_from_imgpar (GpivImagePar
*image_par
,
1082 png_structp png_ptr
,
1085 /*------------------------------------------------------------------------------
1087 * Set text chunks for png image from image paramameters
1090 * image_par: image parameter structure
1093 * png_ptr: png structure
1094 * info_ptr: png info structure
1097 *--------------------------------------------------------------------------- */
1104 * Additional header text, needed for (G)PIV
1106 if (image_par
->x_corr__set
== TRUE
) {
1107 text
[num_text
].key
= PNG_KEY__PIV_XCORR
;
1108 text
[num_text
].text
= g_strdup_printf ("%d", image_par
->x_corr
);
1109 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1112 #ifdef PNG_iTXt_SUPPORTED
1113 text
[0].lang
= NULL
;
1116 if (image_par
->t_scale__set
== TRUE
) {
1117 text
[num_text
].key
= PNG_KEY__PIV_DT
;
1118 text
[num_text
].text
= g_strdup_printf ("%f", image_par
->t_scale
);
1119 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1122 #ifdef PNG_iTXt_SUPPORTED
1123 text
[1].lang
= NULL
;
1127 * non required header info
1128 * PNG recognized header text
1130 if (image_par
->title__set
== TRUE
) {
1131 text
[num_text
].key
= GPIV_IMGPAR_KEY__TITLE
;
1132 text
[num_text
].text
= image_par
->title
;
1133 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1136 #ifdef PNG_iTXt_SUPPORTED
1137 text
[2].lang
= NULL
;
1140 if (image_par
->author__set
== TRUE
) {
1141 text
[num_text
].key
= GPIV_IMGPAR_KEY__AUTHOR
;
1142 text
[num_text
].text
= image_par
->author
;
1143 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1146 #ifdef PNG_iTXt_SUPPORTED
1147 text
[3].lang
= NULL
;
1150 if (image_par
->usertext__set
== TRUE
) {
1151 text
[num_text
].key
= GPIV_IMGPAR_KEY__USERTEXT
;
1152 text
[num_text
].text
= image_par
->usertext
;
1153 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1156 #ifdef PNG_iTXt_SUPPORTED
1157 text
[4].lang
= NULL
;
1160 if (image_par
->software__set
== TRUE
) {
1161 text
[num_text
].key
= GPIV_IMGPAR_KEY__SOFTWARE
;
1162 text
[num_text
].text
= image_par
->software
;
1163 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1166 #ifdef PNG_iTXt_SUPPORTED
1167 text
[5].lang
= NULL
;
1170 if (image_par
->disclaimer__set
== TRUE
) {
1171 text
[num_text
].key
= GPIV_IMGPAR_KEY__DISCLAIMER
;
1172 text
[num_text
].text
= image_par
->disclaimer
;
1173 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1176 #ifdef PNG_iTXt_SUPPORTED
1177 text
[6].lang
= NULL
;
1180 if (image_par
->warning__set
== TRUE
) {
1181 text
[num_text
].key
= GPIV_IMGPAR_KEY__WARNING
;
1182 text
[num_text
].text
= image_par
->warning
;
1183 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1185 #ifdef PNG_iTXt_SUPPORTED
1186 text
[7].lang
= NULL
;
1190 if (image_par
->source__set
== TRUE
) {
1191 text
[num_text
].key
= GPIV_IMGPAR_KEY__SOURCE
;
1192 text
[num_text
].text
= image_par
->source
;
1193 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1196 #ifdef PNG_iTXt_SUPPORTED
1197 text
[8].lang
= NULL
;
1200 if (image_par
->comment__set
== TRUE
) {
1201 text
[num_text
].key
= GPIV_IMGPAR_KEY__COMMENT
;
1202 text
[num_text
].text
= image_par
->comment
;
1203 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1206 #ifdef PNG_iTXt_SUPPORTED
1207 text
[9].lang
= NULL
;
1210 if (image_par
->creation_date__set
== TRUE
) {
1211 text
[num_text
].key
= GPIV_IMGPAR_KEY__CREATION_DATE
;
1212 text
[num_text
].text
= image_par
->creation_date
;
1213 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1216 #ifdef PNG_iTXt_SUPPORTED
1217 text
[10].lang
= NULL
;
1221 if (image_par
->copyright__set
== TRUE
) {
1222 text
[num_text
].key
= GPIV_IMGPAR_KEY__COPYRIGHT
;
1223 text
[num_text
].text
= image_par
->copyright
;
1224 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1227 #ifdef PNG_iTXt_SUPPORTED
1228 text
[11].lang
= NULL
;
1231 if (image_par
->email__set
== TRUE
) {
1232 text
[num_text
].key
= GPIV_IMGPAR_KEY__EMAIL
;
1233 text
[num_text
].text
= image_par
->email
;
1234 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1237 #ifdef PNG_iTXt_SUPPORTED
1238 text
[12].lang
= NULL
;
1241 if (image_par
->url__set
== TRUE
) {
1242 text
[num_text
].key
= GPIV_IMGPAR_KEY__URL
;
1243 text
[num_text
].text
= image_par
->url
;
1244 text
[num_text
].compression
= PNG_TEXT_COMPRESSION_NONE
;
1247 #ifdef PNG_iTXt_SUPPORTED
1248 text
[13].lang
= NULL
;
1252 png_set_text (png_ptr
, info_ptr
, text
, num_text
);
1264 gpiv_fread_hdf5_image (const gchar
*fname
1266 /*-----------------------------------------------------------------------------
1268 * Opens an image from hdf file
1269 * Expects the arrray(s) have not been allocated yet
1271 *--------------------------------------------------------------------------- */
1273 GpivImage
*gpiv_image
= NULL
;
1274 GpivImagePar
*gpiv_image_par
= g_new0 (GpivImagePar
, 1);
1275 gchar
*err_msg
= NULL
;
1276 int i
, j
, rank_x
, rank_y
, rank_vx
, rank_vy
;
1277 float *point_x_hdf
= NULL
, *point_y_hdf
= NULL
;
1282 hid_t file_id
, group_id
, attribute_id
, dataset_id
,
1289 if (fname
== NULL
) {
1290 gpiv_warning ("gpiv_fread_hdf5_image: failing \"fname == NULL\"");
1294 if ((i
= H5Fis_hdf5 (fname
)) == 0) {
1295 gpiv_warning ("gpiv_fread_hdf5_image: not an hdf5 file");
1300 gpiv_img_parameters_set (gpiv_image_par
, FALSE
);
1301 if ((gpiv_image_par
= gpiv_img_fread_hdf5_parameters (fname
))
1303 gpiv_warning ("gpiv_fread_hdf5_image: failing gpiv_img_fread_hdf5_parameters");
1307 #ifdef GPIV_IMG_PARAM_RESOURCES
1308 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, &gpiv_image_par
, TRUE
);
1311 gpiv_img_check_header_required_read (gpiv_image_par
))
1313 gpiv_warning (err_msg
);
1317 gpiv_image
= gpiv_alloc_img (gpiv_image_par
);
1320 file_id
= H5Fopen(fname
, H5F_ACC_RDONLY
, H5P_DEFAULT
);
1321 group_id
= H5Gopen (file_id
, "IMAGE", H5P_DEFAULT
);
1327 dataset_id
= H5Dopen (group_id
, "#1", H5P_DEFAULT
);
1328 dataspace_id
= H5Dget_space (dataset_id
);
1329 #ifdef HD5_IMAGE_INT
1330 if ((status
= H5Dread (dataset_id
, H5T_NATIVE_INT
, H5S_ALL
, H5S_ALL
,
1331 H5P_DEFAULT
, gpiv_image
->frame1
[0])) < 0) {
1332 gpiv_warning ("gpiv_fread_hdf5_image: failing H5Dread");
1336 if ((status
= H5Dread(dataset_id
, H5T_NATIVE_USHORT
, H5S_ALL
, H5S_ALL
,
1337 H5P_DEFAULT
, gpiv_image
->frame1
[0])) < 0) {
1338 gpiv_warning ("gpiv_fread_hdf5_image: failing H5Dread");
1342 /* msg_error = "H5Dread: no image data";
1346 status
= H5Sclose(dataspace_id
);
1347 status
= H5Dclose(dataset_id
);
1352 if (gpiv_image
->header
->x_corr
) {
1353 dataset_id
= H5Dopen(group_id
, "#2", H5P_DEFAULT
);
1354 dataspace_id
= H5Dget_space(dataset_id
);
1355 #ifdef HD5_IMAGE_INT
1356 status
= H5Dread(dataset_id
, H5T_NATIVE_INT
, H5S_ALL
, H5S_ALL
,
1357 H5P_DEFAULT
, gpiv_image
->frame2
[0]);
1359 status
= H5Dread(dataset_id
, H5T_NATIVE_USHORT
, H5S_ALL
, H5S_ALL
,
1360 H5P_DEFAULT
, gpiv_image
->frame2
[0]);
1362 status
= H5Sclose(dataspace_id
);
1363 status
= H5Dclose(dataset_id
);
1365 gpiv_image
->frame2
= gpiv_image
->frame1
;
1370 H5Gclose (group_id
);
1371 status
= H5Fclose(file_id
);
1378 gpiv_fwrite_hdf5_image (const gchar
*fname
,
1382 /*-----------------------------------------------------------------------------
1384 * Writes IMAGE data to file in hdf version 5 format
1386 *---------------------------------------------------------------------------*/
1388 gchar
*err_msg
= NULL
;
1389 gint i
, j
, k
, line_nr
=0, image_white_is_zero
= 0;
1390 gfloat
*point_x_hdf
= NULL
;
1392 * HDF file, dataset,-space identifier
1394 hid_t file_id
, group_id
, dataset_id
, dataspace_id
,
1395 attribute_id
, atype
;
1400 g_return_val_if_fail (image
->frame1
[0] != NULL
, "frame1[0] != NULL");
1401 if (image
->header
->x_corr
) g_return_val_if_fail (image
->frame2
[0] != NULL
, "frame2[0] != NULL");
1405 if ((err_msg
= gpiv_img_fwrite_hdf5_parameters (fname
, image
->header
))
1411 if ((i
= H5Fis_hdf5(fname
)) == 0) {
1412 err_msg
= "gpiv_fwrite_hdf5_image: not an hdf5 file";
1413 gpiv_warning("%s", err_msg
);
1416 file_id
= H5Fopen(fname
, H5F_ACC_RDWR
, H5P_DEFAULT
);
1417 group_id
= H5Gopen (file_id
, "IMAGE", H5P_DEFAULT
);
1418 /* H5Gset_comment (group_id, ".", RCSID); */
1421 * Hdf required image specifications
1425 dataspace_id
= H5Screate(H5S_SCALAR
);
1426 atype
= H5Tcopy(H5T_C_S1
);
1427 H5Tset_size(atype
, 5);
1428 attribute_id
= H5Acreate(group_id
, "CLASS", atype
,
1429 dataspace_id
, H5P_DEFAULT
, H5P_DEFAULT
);
1430 status
= H5Awrite(attribute_id
, atype
,
1432 status
= H5Aclose(attribute_id
);
1433 status
= H5Sclose(dataspace_id
);
1436 dataspace_id
= H5Screate(H5S_SCALAR
);
1437 atype
= H5Tcopy(H5T_C_S1
);
1438 H5Tset_size(atype
, 15);
1439 attribute_id
= H5Acreate(group_id
, "SUBCLASS", atype
,
1440 dataspace_id
, H5P_DEFAULT
, H5P_DEFAULT
);
1441 status
= H5Awrite(attribute_id
, atype
,
1443 status
= H5Aclose(attribute_id
);
1444 status
= H5Sclose(dataspace_id
);
1447 dataspace_id
= H5Screate_simple(1, dims
, NULL
);
1448 attribute_id
= H5Acreate(group_id
, "IMAGE_WHITE_IS_ZERO",
1449 H5T_NATIVE_USHORT
, dataspace_id
,
1450 H5P_DEFAULT
, H5P_DEFAULT
);
1451 status
= H5Awrite(attribute_id
, H5T_NATIVE_USHORT
, &image_white_is_zero
);
1452 status
= H5Aclose(attribute_id
);
1453 status
= H5Sclose(dataspace_id
);
1456 dataspace_id
= H5Screate(H5S_SCALAR
);
1457 atype
= H5Tcopy(H5T_C_S1
);
1458 H5Tset_size(atype
, 3);
1459 attribute_id
= H5Acreate(group_id
, "IMAGE_VERSION", atype
,
1460 dataspace_id
, H5P_DEFAULT
, H5P_DEFAULT
);
1461 status
= H5Awrite(attribute_id
, atype
,
1463 status
= H5Aclose(attribute_id
);
1464 status
= H5Sclose(dataspace_id
);
1468 * Create the data space.
1470 dims
[0] = image
->header
->ncolumns
;
1471 dims
[1] = image
->header
->nrows
;
1472 dataspace_id
= H5Screate_simple(2, dims
, NULL
);
1478 #ifdef HD5_IMAGE_INT
1479 dataset_id
= H5Dcreate (group_id
, "#1", H5T_NATIVE_INT
,
1480 dataspace_id
, H5P_DEFAULT
);
1481 status
= H5Dwrite (dataset_id
, H5T_NATIVE_INT
, H5S_ALL
, H5S_ALL
,
1482 H5P_DEFAULT
, image
->frame1
[0][0]);
1484 /* dataset_id = H5Dcreate (group_id, "#1", H5T_NATIVE_USHORT, */
1485 /* dataspace_id, H5P_DEFAULT); */
1486 /* status = H5Dwrite (dataset_id, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL, */
1487 /* H5P_DEFAULT, image->frame1[0][0]); */
1489 status
= H5Dclose (dataset_id
);
1495 if (image
->header
->x_corr
) {
1496 #ifdef HD5_IMAGE_INT
1497 dataset_id
= H5Dcreate(group_id
, "#2", H5T_NATIVE_INT
,
1498 dataspace_id
, H5P_DEFAULT
);
1499 status
= H5Dwrite(dataset_id
, H5T_NATIVE_INT
, H5S_ALL
, H5S_ALL
,
1500 H5P_DEFAULT
, &image
->frame2
[0][0]);
1502 /* dataset_id = H5Dcreate(group_id, "#2", H5T_NATIVE_USHORT, */
1503 /* dataspace_id, H5P_DEFAULT); */
1504 /* status = H5Dwrite(dataset_id, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL, */
1505 /* H5P_DEFAULT, &image->frame2[0][0]); */
1507 status
= H5Dclose(dataset_id
);
1511 status
= H5Sclose(dataspace_id
);
1512 status
= H5Gclose (group_id
);
1513 status
= H5Fclose(file_id
);
1514 if (free
== TRUE
) gpiv_free_img (image
);
1521 gpiv_read_davis_image (FILE *fp
1523 /*-----------------------------------------------------------------------------
1525 * Reads Davis formatted image, with ext .IMG from file
1527 * PROTOTYPE LOCATATION:
1531 * fp: pointer to input file
1533 * NULL on success or *err_msg on failure
1534 *---------------------------------------------------------------------------*/
1536 GpivImage
*gpiv_image
= NULL
;
1537 GpivImagePar
*gpiv_image_par
= g_new0 (GpivImagePar
, 1);
1538 gchar
*err_msg
= NULL
;
1542 * Obtaining image dimensions
1544 fseek (fp
, 10, SEEK_SET
);
1545 fread (&gpiv_image_par
->nrows
, sizeof (guint16
), 1, fp
);
1546 fread (&gpiv_image_par
->ncolumns
, sizeof (guint16
), 1, fp
);
1549 * Obtaining other requitered parameters, like depth and x_corr.
1550 * These will definitely no be present in the image header.
1551 * So searching unconditionally.
1554 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, &gpiv_image_par
, TRUE
);
1556 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, &gpiv_image_par
, FALSE
);
1559 if ((err_msg
= gpiv_img_check_header_required_read (gpiv_image_par
))
1561 gpiv_warning ("gpiv_read_davis_image: %s", err_msg
);
1566 * Reading image data
1568 gpiv_image
= gpiv_alloc_img (gpiv_image_par
);
1569 fseek (fp
, 256, SEEK_SET
);
1570 fread (gpiv_image
->frame1
[0], sizeof (guint16
)
1571 * gpiv_image
->header
->ncolumns
1572 * gpiv_image
->header
->nrows
, 1, fp
);
1573 fread (gpiv_image
->frame2
[0], sizeof (guint16
)
1574 * gpiv_image
->header
->ncolumns
1575 * gpiv_image
->header
->nrows
, 1, fp
);
1583 gpiv_read_raw_image (FILE *fp
1585 /*-----------------------------------------------------------------------------
1587 * Read raw image data from fp.
1588 * Frames memory will be allocated here.
1591 * fname: pointer to complete filename to be written
1594 * GpivImage on success or NULL on failure
1595 *---------------------------------------------------------------------------*/
1597 GpivImage
*image
= NULL
;
1598 GpivImagePar
*image_par
= g_new0 (GpivImagePar
, 1);
1600 gchar
*err_msg
= NULL
;
1603 * Read header info. If required parameters are absent, scan from resource
1604 * files, check again if present, else bail out.
1606 gpiv_img_parameters_set (image_par
, FALSE
);
1607 gpiv_img_read_header (fp
, image_par
, FALSE
, FALSE
, NULL
);
1609 #ifdef GPIV_IMG_PARAM_RESOURCES
1610 if ((err_msg
= gpiv_img_check_header_required_read (image_par
))
1613 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, image_par
, TRUE
);
1615 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, image_par
, FALSE
);
1618 #endif /* GPIV_IMG_PARAM_RESOURCES */
1621 if ((err_msg
= gpiv_img_check_header_required_read (image_par
))
1623 gpiv_warning ("%s", err_msg
);
1628 * From header info memory allocation of image arrays can be done
1630 image
= gpiv_alloc_img (image_par
);
1631 read_raw_image_frames (fp
, image
);
1639 gpiv_fread_raw_image (const gchar
*fname
1641 /*-----------------------------------------------------------------------------
1643 * Reads an image from raw binary file.
1644 * Expects the arrray(s) have not been allocated yet
1645 * Reads image header data from file.h
1651 * image1_p: pointer to first 2-dimensional image array
1652 * image1_p: pointer to second 2-dimensional image array
1653 * image_par: pointer to image parameter structure
1656 * GpivImage on success or NULL on failure
1657 *--------------------------------------------------------------------------- */
1659 GpivImage
*image
= NULL
;
1660 GpivImagePar
*image_par
= g_new0 (GpivImagePar
, 1);
1661 gchar
*err_msg
= NULL
;
1662 gchar fname_header
[GPIV_MAX_CHARS
];
1663 gchar
*dirname
, *fname_base
, *fname_nosuffix
;
1667 if (fname
== NULL
) {
1668 gpiv_warning ("gpiv_fread_raw_image: failing \"fname == NULL\"");
1672 /* image->header = image_par; */
1673 gpiv_img_parameters_set (image_par
, FALSE
);
1676 * Stripping fname and create header filename
1678 dirname
= g_strdup (g_path_get_dirname (fname
));
1679 fname_base
= g_strdup (g_path_get_basename (fname
));
1680 strtok (fname_base
, ".");
1681 fname_nosuffix
= g_strdup (g_strconcat (dirname
, G_DIR_SEPARATOR_S
,
1684 g_message ("gpiv_fread_raw_image: dirname = %s\n fname_base = %s\n fname_nosuffix = %s",
1685 dirname
, fname_base
, fname_nosuffix
);
1688 g_snprintf(fname_header
, GPIV_MAX_CHARS
, "%s%s",
1689 fname_nosuffix
, GPIV_EXT_HEADER
);
1692 g_message ("gpiv_fread_raw_image: image header is: %s", fname_header
);
1696 * Read header info. If required parameters are absent, scan from resource files,
1697 * check again if present, else bail out.
1699 if ((fp
= fopen (fname_header
, "rb")) == NULL
) {
1700 gpiv_warning ("gpiv_fread_raw_image: failure opening %s for input", fname_header
);
1703 gpiv_img_read_header (fp
, image_par
, FALSE
, FALSE
, NULL
);
1707 #ifdef GPIV_IMG_PARAM_RESOURCES
1708 if ((err_msg
= gpiv_img_check_header_required_read (image_par
))
1711 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, image_par
, TRUE
);
1713 gpiv_scan_resourcefiles (GPIV_IMGPAR_KEY
, image_par
, FALSE
);
1716 #endif /* GPIV_IMG_PARAM_RESOURCES */
1719 if ((err_msg
= gpiv_img_check_header_required_read (image_par
))
1721 gpiv_warning ("%s", err_msg
);
1727 * reads image data from file in binary format
1729 if ((fp
= fopen (fname
, "rb")) == NULL
) {
1730 err_msg
= "gpiv_fread_raw_image: failure opening for input";
1731 gpiv_warning ("%s", err_msg
);
1735 image
= gpiv_alloc_img (image_par
);
1736 read_raw_image_frames (fp
, image
);
1742 g_free(fname_nosuffix
);
1748 gpiv_write_raw_image (FILE *fp
,
1751 /*---------------------------------------------------------------------------
1752 * Writes raw binary image to fp
1754 *---------------------------------------------------------------------------*/
1756 gchar
*err_msg
= NULL
;
1759 gpiv_img_print_header (fp
, image
->header
);
1760 write_raw_image_frames (fp
, image
);
1768 gpiv_fwrite_raw_image (const gchar
*fname
,
1771 /*-----------------------------------------------------------------------------
1773 * Writess binary image to file fname.r and header to fname.h
1775 *---------------------------------------------------------------------------*/
1777 gchar
*err_msg
= NULL
;
1778 gchar fname_header
[GPIV_MAX_CHARS
];
1779 gchar
*dirname
, *fname_base
, *fname_nosuffix
;
1783 if (fname
== NULL
) {
1784 gpiv_warning ("gpiv_fwrite_raw_image: failing \"fname == NULL\"");
1788 g_return_if_fail (image
->frame1
[0] != NULL
);
1789 g_return_if_fail (image
->frame2
[0] != NULL
);
1794 * Stripping file name, create header filename and print header info
1796 dirname
= g_strdup (g_path_get_dirname (fname
));
1797 fname_base
= g_strdup (g_path_get_basename (fname
));
1798 strtok (fname_base
, ".");
1799 fname_nosuffix
= g_strdup (g_strconcat (dirname
, G_DIR_SEPARATOR_S
,
1801 g_snprintf(fname_header
, GPIV_MAX_CHARS
, "%s%s",
1802 fname_nosuffix
, GPIV_EXT_HEADER
);
1804 if ((fp
= fopen (fname_header
, "wb")) == NULL
) {
1805 gpiv_warning ("gpiv_fwrite_raw_image: failure opening %s for output",
1807 return "PIV_FWRITE_RAW_IMAGE: failure opening header for output";
1810 gpiv_img_print_header (fp
, image
->header
);
1814 * Write image frames
1816 if ((fp
= fopen (fname
, "wb")) == NULL
) {
1817 gpiv_warning ("gpiv_fwrite_raw_image: failure opening %s for output",
1819 return "gpiv_fwrite_raw_image: failure opening image for output";
1822 write_raw_image_frames (fp
, image
);
1836 print_img_parameters_set (GpivImagePar
*gpiv_image_par
)
1838 printf ("ncolumns__set = %d \n", gpiv_image_par
->ncolumns__set
);
1839 printf ("nrows__set = %d \n", gpiv_image_par
->nrows__set
);
1840 printf ("x_corr__set = %d \n", gpiv_image_par
->x_corr__set
);
1841 printf ("depth__set = %d \n", gpiv_image_par
->depth__set
);
1842 printf ("s_scale__set = %d \n", gpiv_image_par
->s_scale__set
);
1843 printf ("t_scale__set = %d \n", gpiv_image_par
->t_scale__set
);
1844 printf ("z_off_x__set = %d \n", gpiv_image_par
->z_off_x__set
);
1845 printf ("z_off_y__set = %d \n", gpiv_image_par
->z_off_y__set
);
1846 printf ("title__set = %d \n", gpiv_image_par
->title__set
);
1847 printf ("creation_date__set = %d \n", gpiv_image_par
->creation_date__set
);
1848 printf ("location__set = %d \n", gpiv_image_par
->location__set
);
1849 printf ("author__set = %d \n", gpiv_image_par
->author__set
);
1850 printf ("software__set = %d \n", gpiv_image_par
->software__set
);
1851 printf ("source__set = %d \n", gpiv_image_par
->source__set
);
1852 printf ("usertext__set = %d \n", gpiv_image_par
->usertext__set
);
1853 printf ("warning__set = %d \n", gpiv_image_par
->warning__set
);
1854 printf ("disclaimer__set = %d \n", gpiv_image_par
->disclaimer__set
);
1855 printf ("comment__set = %d \n", gpiv_image_par
->comment__set
);
1856 printf ("copyright__set = %d \n", gpiv_image_par
->copyright__set
);
1857 printf ("email__set = %d \n", gpiv_image_par
->email__set
);
1858 printf ("url__set = %d \n", gpiv_image_par
->url__set
);
1863 read_raw_image_frames (FILE *fp
,
1866 /*-----------------------------------------------------------------------------
1867 * Read raw image data frames from fp.
1870 guint8
**lo_img1
, **lo_img2
;
1874 if (fp
== stdin
|| fp
== NULL
) {
1875 if (image
->header
->depth
<= 8) {
1876 lo_img1
= gpiv_matrix_guint8 (image
->header
->nrows
,
1877 image
->header
->ncolumns
);
1878 read (0, lo_img1
[0], image
->header
->ncolumns
1879 * image
->header
->nrows
* (sizeof(guint8
)));
1881 if (image
->header
->x_corr
) {
1882 lo_img2
= gpiv_matrix_guint8(image
->header
->nrows
,
1883 image
->header
->ncolumns
);
1884 read (0, lo_img2
[0], image
->header
->ncolumns
*
1885 image
->header
->nrows
* (sizeof(guint8
)));
1891 for (i
= 0; i
< image
->header
->nrows
; i
++) {
1892 for (j
= 0; j
< image
->header
->ncolumns
; j
++) {
1893 image
->frame1
[i
][j
] = lo_img1
[i
][j
];
1894 image
->frame2
[i
][j
] = lo_img2
[i
][j
];
1898 gpiv_free_matrix_guint8 (lo_img1
);
1899 if (image
->header
->x_corr
) {
1900 gpiv_free_matrix_guint8 (lo_img2
);
1904 read (0, image
->frame1
[0], image
->header
->ncolumns
1905 * image
->header
->nrows
1906 * (sizeof(guint16
)));
1908 if (image
->header
->x_corr
) {
1909 read (0, image
->frame2
[0], image
->header
->ncolumns
1910 * image
->header
->nrows
1911 * (sizeof(guint16
)));
1913 image
->frame2
= image
->frame1
;
1920 if (image
->header
->depth
<= 8) {
1921 lo_img1
= gpiv_matrix_guint8 (image
->header
->nrows
,
1922 image
->header
->ncolumns
);
1923 fread (lo_img1
[0], image
->header
->ncolumns
1924 * image
->header
->nrows
* (sizeof(guint8
)), 1, fp
);
1926 if (image
->header
->x_corr
) {
1927 lo_img2
= gpiv_matrix_guint8(image
->header
->nrows
,
1928 image
->header
->ncolumns
);
1929 fread (lo_img2
[0], image
->header
->ncolumns
*
1930 image
->header
->nrows
* (sizeof(guint8
)), 1, fp
);
1936 for (i
= 0; i
< image
->header
->nrows
; i
++) {
1937 for (j
= 0; j
< image
->header
->ncolumns
; j
++) {
1938 image
->frame1
[i
][j
] = lo_img1
[i
][j
];
1939 image
->frame2
[i
][j
] = lo_img2
[i
][j
];
1943 gpiv_free_matrix_guint8 (lo_img1
);
1944 if (image
->header
->x_corr
) {
1945 gpiv_free_matrix_guint8 (lo_img2
);
1950 fread (image
->frame1
[0], image
->header
->ncolumns
1951 * image
->header
->nrows
1952 * (sizeof(guint16
)), 1, fp
);
1954 if (image
->header
->x_corr
) {
1955 fread (image
->frame2
[0], image
->header
->ncolumns
1956 * image
->header
->nrows
1957 * (sizeof(guint16
)), 1, fp
);
1959 image
->frame2
= image
->frame1
;
1967 write_raw_image_frames (FILE *fp
,
1970 /*---------------------------------------------------------------------------
1971 * Writes raw binary image frames to fp
1974 guint ncolumns
= image
->header
->ncolumns
;
1975 guint nrows
= image
->header
->nrows
;
1978 if (fp
== stdout
|| fp
== NULL
) {
1979 if (image
->header
->depth
<= 8) {
1980 write (1, image
->frame1
[0], ncolumns
* nrows
* (sizeof (guint8
)));
1982 if (image
->header
->x_corr
) {
1983 write (1, image
->frame2
[0], ncolumns
* nrows
* (sizeof (guint8
)));
1988 write (1, image
->frame1
[0], ncolumns
* nrows
* (sizeof (guint16
)));
1990 if (image
->header
->x_corr
) {
1991 write (1, image
->frame2
[0], ncolumns
* nrows
* (sizeof (guint16
)));
1996 if (image
->header
->depth
<= 8) {
1997 fwrite (image
->frame1
[0], ncolumns
* nrows
* (sizeof (guint8
)), 1, fp
);
1999 if (image
->header
->x_corr
) {
2000 fwrite (image
->frame2
[0], ncolumns
* nrows
* (sizeof (guint8
)), 1, fp
);
2005 fwrite (image
->frame1
[0], ncolumns
* nrows
* (sizeof (guint16
)), 1,
2008 if (image
->header
->x_corr
) {
2009 fwrite (image
->frame2
[0], ncolumns
* nrows
* (sizeof (guint16
)), 1,
2017 * From gpiv_img_utils.h
2020 gpiv_alloc_imgframe(GpivImage
*image
)
2021 /*-----------------------------------------------------------------------------
2022 * Allocates GpivImage frame data
2024 { image
->frame1
= gpiv_matrix_guint16 (image
->header
->nrows
,
2025 image
->header
->ncolumns
);
2026 if (image
->header
->x_corr
) {
2027 image
->frame2
= gpiv_matrix_guint16 (image
->header
->nrows
,
2028 image
->header
->ncolumns
);
2030 image
->frame2
= image
->frame1
;
2036 gpiv_alloc_img (const GpivImagePar
*image_par
2038 /*-----------------------------------------------------------------------------
2040 * Allocates memory for GpivImage frames
2043 * image_par: image parameters
2048 * img: 2-dim image data arry
2049 *---------------------------------------------------------------------------*/
2051 GpivImage
*image
= g_new0 (GpivImage
, 1);;
2052 GpivImagePar
*image_par_dest
= NULL
;
2055 image_par_dest
= gpiv_img_cp_parameters (image_par
);
2056 image
->header
= image_par_dest
;
2058 gpiv_alloc_imgframe (image
);
2067 gpiv_check_alloc_img (const GpivImage
*image
2069 /*-----------------------------------------------------------------------------
2070 * Check if gpiv_image frames have been allocated
2073 gchar
*err_msg
= NULL
;
2076 g_return_val_if_fail (image
->frame1
!= NULL
,
2077 "gpiv_check_alloc_image: frame1 != NULL");
2078 g_return_val_if_fail (image
->frame2
!= NULL
,
2079 "gpiv_check_alloc_image: frame2 != NULL");
2081 /* g_message ("gpiv_check_alloc_image: sizeof frame = %d", */
2082 /* sizeof (image->frame1)); */
2083 /* g_message ("gpiv_check_alloc_image: sizeof guint16 x nrows x ncolumns = %d x %d x %d = %d", */
2084 /* sizeof (guint16), */
2085 /* image->header->nrows, */
2086 /* image->header->ncolumns, */
2087 /* (sizeof (guint16)) * image->header->nrows * image->header->ncolumns */
2095 gpiv_cp_img (const GpivImage
*image
2097 /*-----------------------------------------------------------------------------
2099 * Duplicates img. The returned image will have to be freed with
2100 * gpiv_free_img when no longer needed.
2103 * image_par: image parameters
2104 * img_src: 2-dim image data arry
2107 * img_dest: 2-dim image data arry
2110 *---------------------------------------------------------------------------*/
2113 GpivImage
*image_dest
= NULL
;
2116 if (image
->frame1
[0] == NULL
) {
2117 gpiv_warning ("gpiv_cp_img: image->frame1 not allocated");
2121 if (image
->header
->x_corr__set
== FALSE
) {
2122 gpiv_warning ("gpiv_cp_img: x_corr not set");
2126 if (image
->header
->x_corr
) {
2127 if (image
->frame2
[0] == NULL
) {
2128 gpiv_warning ("gpiv_cp_img: x_corr && image->frame2 not allocated");
2134 image_dest
= gpiv_alloc_img (image
->header
);
2137 for (i
= 0; i
< image_dest
->header
->nrows
; i
++) {
2138 for (j
= 0; j
< image_dest
->header
->ncolumns
; j
++) {
2139 image_dest
->frame1
[i
][j
] = image
->frame1
[i
][j
];
2143 if (image
->header
->x_corr
) {
2144 for (i
= 0; i
< image_dest
->header
->nrows
; i
++) {
2145 for (j
= 0; j
< image_dest
->header
->ncolumns
; j
++) {
2146 image_dest
->frame2
[i
][j
] = image
->frame2
[i
][j
];
2150 image_dest
->frame2
[0] = image
->frame1
[0];
2160 gpiv_cp_img_data (const GpivImage
*image_src
,
2161 GpivImage
*image_dest
2163 /*-----------------------------------------------------------------------------
2165 * Copies contents of image_src to image_dest. image_src and image_dest
2166 * will have to be allocated with gpiv_alloc_img before and will have to
2167 * be freed with gpiv_free_img when no longer needed.
2170 * image_par: image parameters
2171 * image_src: 2-dim image data arry
2174 * image_dest: 2-dim image data arry
2177 *---------------------------------------------------------------------------*/
2179 gchar
*err_msg
= NULL
;
2183 if (image_src
->frame1
[0] == NULL
) {
2184 err_msg
= "gpiv_cp_img_data: image_src not allocated";
2185 gpiv_warning ("%s", err_msg
);
2189 if (image_dest
->frame1
[0] == NULL
) {
2190 err_msg
= "gpiv_cp_img_data: image_dest not allocated";
2191 gpiv_warning ("%s", err_msg
);
2195 if (image_src
->header
->x_corr__set
== FALSE
) {
2196 err_msg
= "gpiv_cp_img_data: image_src: x_corr not set";
2197 gpiv_warning ("%s", err_msg
);
2201 if (image_dest
->header
->x_corr__set
== FALSE
) {
2202 err_msg
= "gpiv_cp_img_data: image_dest: x_corr not set";
2203 gpiv_warning ("%s", err_msg
);
2207 if ((image_src
->header
->x_corr
== FALSE
2208 && image_dest
->header
->x_corr
== TRUE
)
2209 || (image_src
->header
->x_corr
== TRUE
2210 && image_dest
->header
->x_corr
== FALSE
)) {
2211 err_msg
= "gpiv_cp_img_data: image_src and image_dest: x_corr unequal";
2212 gpiv_warning ("%s", err_msg
);
2216 if (image_src
->header
->nrows
!= image_dest
->header
->nrows
) {
2217 gpiv_warning ("gpiv_cp_img_data: unequal dimensions: image_src->header->nrows = %d image_dest->header->nrows = %d",
2218 image_src
->header
->nrows
,
2219 image_dest
->header
->nrows
);
2220 err_msg
= "gpiv_cp_img_data: unequal dimensions of image_src and image_dest";
2224 if (image_src
->header
->ncolumns
!= image_dest
->header
->ncolumns
) {
2225 gpiv_warning ("gpiv_cp_img_data: unequal dimensions: image_src->header->ncolumns = %d image_dest->header->ncolumns = %d",
2226 image_src
->header
->ncolumns
,
2227 image_dest
->header
->ncolumns
);
2228 err_msg
= "gpiv_cp_img_data: unequal dimensions of image_src and image_dest";
2233 if (image_src
->header
->x_corr
) {
2234 if (image_src
->frame2
[0] == NULL
) {
2235 err_msg
= "gpiv_cp_img_data: x_corr && image_src->frame2 not allocated";
2236 gpiv_warning ("%s", err_msg
);
2240 if (image_dest
->frame2
[0] == NULL
) {
2241 err_msg
= "gpiv_cp_img_data: x_corr && image_dest->frame2 not allocated";
2242 gpiv_warning ("%s", err_msg
);
2249 for (i
= 0; i
< image_src
->header
->nrows
; i
++) {
2250 for (j
= 0; j
< image_src
->header
->ncolumns
; j
++) {
2252 g_message ("gpiv_cp_img_data:: frame1 i = %d j = %d", i
, j
);
2254 image_dest
->frame1
[i
][j
] = image_src
->frame1
[i
][j
];
2258 if (image_src
->header
->x_corr
) {
2259 for (i
= 0; i
< image_src
->header
->nrows
; i
++) {
2260 for (j
= 0; j
< image_src
->header
->ncolumns
; j
++) {
2262 g_message ("gpiv_cp_img_data:: frame2 i = %d j = %d", i
, j
);
2264 image_dest
->frame2
[i
][j
] = image_src
->frame2
[i
][j
];
2276 gpiv_free_img (GpivImage
*image
2278 /*-----------------------------------------------------------------------------
2280 * Frees memory for image
2283 * image_par: image parameters
2284 * img: 2-dim image data arry
2289 *---------------------------------------------------------------------------*/
2291 g_return_if_fail (image
->frame1
[0] != NULL
); /* gpiv_error ("img not allocated"); */
2293 gpiv_free_matrix_guint16 (image
->frame1
);
2294 image
->frame1
= NULL
;
2296 if (image
->header
->x_corr
== TRUE
) {
2297 g_return_if_fail (image
->frame2
[0] != NULL
); /* gpiv_error ("img not allocated"); */
2298 gpiv_free_matrix_guint16 (image
->frame2
);
2299 image
->frame2
= NULL
;
2306 gpiv_img_mpi_bcast_image (GpivImage
*image
,
2307 const gboolean alloc_frame
2309 /*-----------------------------------------------------------------------------
2316 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
2317 gpiv_img_mpi_bcast_imgpar (image
->header
);
2318 if (alloc_frame
&& rank
!= 0) gpiv_alloc_imgframe (image
);
2319 gpiv_img_mpi_bcast_imgframe (image
);
2322 my_utils_write_tmp_image (image
,
2323 g_strdup_printf ("%s%d", "bcast_rank", rank
),
2324 "Writing mpi-bcasted image to: ")
2330 gpiv_img_mpi_bcast_imgframe (GpivImage
*image
2332 /*-----------------------------------------------------------------------------
2333 * Broadcasts image frame data
2336 guint size
= image
->header
->ncolumns
* image
->header
->nrows
;
2339 if (MPI_Bcast(*image
->frame1
, size
, MPI_SHORT
, 0, MPI_COMM_WORLD
)
2342 gpiv_error("@&%#$!, mpi_bcast_img_frame: An error ocurred in MPI_Bcast");
2345 if (image
->header
->x_corr
) {
2346 if (MPI_Bcast(*image
->frame2
, size
, MPI_SHORT
, 0, MPI_COMM_WORLD
)
2348 gpiv_error("@&%#$!, mpi_bcast_img_frame: An error ocurred in MPI_Bcast");
2354 #endif /* ENABLE_MPI */