2005-10-12 00:55:29 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2020-09-30 22:27:10 +08:00
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2020-09-30 22:27:10 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2004-11-23 03:17:36 +08:00
|
|
|
|
2006-04-29 14:20:50 +08:00
|
|
|
#include "h5hltest.h"
|
2010-03-18 20:23:04 +08:00
|
|
|
#include "H5srcdir.h"
|
2006-04-29 14:20:50 +08:00
|
|
|
#include "H5LTpublic.h"
|
|
|
|
#include "H5IMpublic.h"
|
|
|
|
#include "pal_rgb.h"
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
#define FILE_NAME "test_image1.h5"
|
2005-03-28 23:24:10 +08:00
|
|
|
#define FILE2 "test_image2.h5"
|
|
|
|
#define FILE3 "test_image3.h5"
|
|
|
|
#define DATA_FILE1 "image8.txt"
|
|
|
|
#define DATA_FILE2 "image24pixel.txt"
|
|
|
|
#define DATA_FILE3 "image24plane.txt"
|
|
|
|
#define DATA_FILE4 "usa.wri"
|
2005-03-30 05:47:53 +08:00
|
|
|
#define PAL2_FILE "sepia.pal"
|
|
|
|
#define PAL3_FILE "earth.pal"
|
2005-03-28 23:24:10 +08:00
|
|
|
#define IMAGE1_NAME "image8bit"
|
|
|
|
#define IMAGE2_NAME "image24bitpixel"
|
|
|
|
#define IMAGE3_NAME "image24bitplane"
|
2007-04-10 02:25:18 +08:00
|
|
|
#define PAL_NAME "palette"
|
2005-03-30 05:47:53 +08:00
|
|
|
#define PAL1_NAME "rainbow"
|
|
|
|
#define PAL2_NAME "sepia"
|
|
|
|
#define PAL3_NAME "earth"
|
2005-05-17 03:08:41 +08:00
|
|
|
#define PAL4_NAME "blue-red"
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define WIDTH 400
|
|
|
|
#define HEIGHT 200
|
|
|
|
#define PAL_ENTRIES 256
|
2005-03-30 05:47:53 +08:00
|
|
|
|
|
|
|
/* struct to store RGB values read from a .pal file */
|
|
|
|
typedef struct rgb_t {
|
2005-04-06 04:26:26 +08:00
|
|
|
unsigned char r;
|
2005-03-30 05:47:53 +08:00
|
|
|
unsigned char g;
|
|
|
|
unsigned char b;
|
|
|
|
} rgb_t;
|
|
|
|
|
2005-03-28 23:24:10 +08:00
|
|
|
/* prototypes */
|
|
|
|
static int test_simple(void);
|
|
|
|
static int test_data(void);
|
|
|
|
static int test_generate(void);
|
2020-09-30 22:27:10 +08:00
|
|
|
static int read_data(const char *file_name, hsize_t *width, hsize_t *height);
|
|
|
|
static int read_palette(const char *file_name, rgb_t *palette, size_t palette_size);
|
2005-03-30 05:47:53 +08:00
|
|
|
|
2005-03-28 23:24:10 +08:00
|
|
|
/* globals */
|
2005-08-14 04:53:35 +08:00
|
|
|
unsigned char *image_data = NULL;
|
2004-11-23 03:17:36 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* the main program
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int
|
|
|
|
main(void)
|
2004-11-23 03:17:36 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int nerrors = 0;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
nerrors += test_simple() < 0 ? 1 : 0;
|
|
|
|
nerrors += test_data() < 0 ? 1 : 0;
|
|
|
|
nerrors += test_generate() < 0 ? 1 : 0;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nerrors)
|
|
|
|
goto error;
|
2019-08-25 03:07:19 +08:00
|
|
|
HDprintf("All image tests passed.\n");
|
2007-04-10 02:25:18 +08:00
|
|
|
return 0;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2005-03-28 23:24:10 +08:00
|
|
|
error:
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("***** %d IMAGE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S");
|
2007-04-10 02:25:18 +08:00
|
|
|
return 1;
|
2005-03-28 23:24:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* a simple test that generates images and palettes
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static int
|
|
|
|
test_simple(void)
|
2005-03-28 23:24:10 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t width = WIDTH;
|
|
|
|
hsize_t height = HEIGHT;
|
|
|
|
hsize_t planes;
|
|
|
|
hid_t fid;
|
|
|
|
int i, j, n, space;
|
|
|
|
hsize_t u;
|
|
|
|
char interlace[20];
|
|
|
|
hssize_t npals;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* 8-bit image */
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
unsigned char *buf1 = NULL;
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned char pal[PAL_ENTRIES * 3]; /* palette array */
|
|
|
|
hsize_t pal_dims[2] = {PAL_ENTRIES, 3}; /* palette dimensions */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* 24-bit image */
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
unsigned char *buf2 = NULL;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read data */
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
unsigned char *buf1_out = NULL;
|
|
|
|
unsigned char *buf2_out = NULL;
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned char pal_out[PAL_ENTRIES * 3]; /* palette array */
|
|
|
|
hsize_t pal_dims_out[2]; /* palette dimensions */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Allocate image buffers */
|
|
|
|
buf1 = (unsigned char *)HDmalloc(WIDTH * HEIGHT);
|
|
|
|
HDassert(buf1);
|
2020-09-30 22:27:10 +08:00
|
|
|
buf2 = (unsigned char *)HDmalloc(WIDTH * HEIGHT * 3);
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDassert(buf2);
|
|
|
|
buf1_out = (unsigned char *)HDmalloc(WIDTH * HEIGHT);
|
|
|
|
HDassert(buf1_out);
|
2020-09-30 22:27:10 +08:00
|
|
|
buf2_out = (unsigned char *)HDmalloc(WIDTH * HEIGHT * 3);
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDassert(buf2_out);
|
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* create an image */
|
2020-09-30 22:27:10 +08:00
|
|
|
space = WIDTH * HEIGHT / PAL_ENTRIES;
|
|
|
|
for (i = 0, j = 0, n = 0; i < WIDTH * HEIGHT; i++, j++) {
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
buf1[i] = (unsigned char)n;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (j > space) {
|
2007-04-10 02:25:18 +08:00
|
|
|
n++;
|
2020-09-30 22:27:10 +08:00
|
|
|
j = 0;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* create an image */
|
2020-09-30 22:27:10 +08:00
|
|
|
space = WIDTH * HEIGHT / 256;
|
|
|
|
for (i = 0, j = 0, n = 0; i < WIDTH * HEIGHT * 3; i += 3, j++) {
|
|
|
|
buf2[i] = (unsigned char)n;
|
|
|
|
buf2[i + 1] = 0;
|
|
|
|
buf2[i + 2] = (unsigned char)(255 - n);
|
|
|
|
if (j > space) {
|
2007-04-10 02:25:18 +08:00
|
|
|
n++;
|
2020-09-30 22:27:10 +08:00
|
|
|
j = 0;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* define a palette, blue to red tones
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
for (i = 0, n = 0; i < PAL_ENTRIES * 3; i += 3, n++) {
|
|
|
|
pal[i] = (unsigned char)n; /* red */
|
|
|
|
pal[i + 1] = 0; /* green */
|
|
|
|
pal[i + 2] = (unsigned char)(255 - n); /* blue */
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Create a new HDF5 file using default properties. */
|
2020-09-30 22:27:10 +08:00
|
|
|
fid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* Indexed image test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("indexed image");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Write image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_image_8bit(fid, IMAGE1_NAME, width, height, buf1) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL_NAME, pal_dims, pal) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Attach a palette to the image dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Read image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMget_image_info(fid, IMAGE1_NAME, &width, &height, &planes, interlace, &npals) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMread_image(fid, IMAGE1_NAME, buf1_out) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (u = 0; u < height * width * planes; u++) {
|
|
|
|
if (buf1[u] != buf1_out[u])
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* True color image test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("true color image");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Write image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_image_24bit(fid, IMAGE2_NAME, width, height, "INTERLACE_PIXEL", buf2))
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Read image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMget_image_info(fid, IMAGE2_NAME, &width, &height, &planes, interlace, &npals) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMread_image(fid, IMAGE2_NAME, buf2_out) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (u = 0; u < height * width * planes; u++) {
|
|
|
|
if (buf2[u] != buf2_out[u])
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* H5IMget_npalettes test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("pallete functions");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMget_npalettes(fid, IMAGE1_NAME, &npals) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* H5IMget_palette_info test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMget_palette_info(fid, IMAGE1_NAME, 0, pal_dims_out) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (pal_dims[i] != pal_dims_out[i])
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* H5IMget_palette test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMget_palette(fid, IMAGE1_NAME, 0, pal_out) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < PAL_ENTRIES * 3; i++) {
|
|
|
|
if (pal[i] != pal_out[i])
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* H5IMis_image test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMis_image(fid, IMAGE1_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMis_image(fid, IMAGE2_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* H5IMis_palette test
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMis_palette(fid, PAL_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* end tests
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf1)
|
2013-05-15 21:38:41 +08:00
|
|
|
HDfree(buf1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf2)
|
2013-05-15 21:38:41 +08:00
|
|
|
HDfree(buf2);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf1_out)
|
2013-05-15 21:38:41 +08:00
|
|
|
HDfree(buf1_out);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf2_out)
|
2013-05-15 21:38:41 +08:00
|
|
|
HDfree(buf2_out);
|
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Close the file. */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(fid) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* error zone, gracefully close */
|
2005-03-28 23:24:10 +08:00
|
|
|
out:
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf1)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(buf1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf2)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(buf2);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf1_out)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(buf1_out);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf2_out)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(buf2_out);
|
2021-03-17 23:25:39 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
H5Fclose(fid);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_END_TRY;
|
2007-04-10 02:25:18 +08:00
|
|
|
H5_FAILED();
|
|
|
|
return FAIL;
|
2005-03-28 23:24:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read sample realistic image data from ASCII files
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static int
|
|
|
|
test_data(void)
|
2005-03-28 23:24:10 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fid;
|
|
|
|
hsize_t pal_dims[2];
|
|
|
|
hsize_t width;
|
|
|
|
hsize_t height;
|
|
|
|
unsigned char pal[256 * 3]; /* buffer to hold an HDF5 palette */
|
|
|
|
rgb_t rgb[256]; /* buffer to hold a .pal file palette */
|
|
|
|
int i, n;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* create a file using default properties */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-25 03:07:19 +08:00
|
|
|
HDprintf("Testing read ascii image data and generate images\n");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read 8bit image data
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make indexed image");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read first data file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (read_data(DATA_FILE1, &width, &height) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make an image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_image_8bit(fid, IMAGE1_NAME, width, height, image_data) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("attaching palettes");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* palette #1. rainbow palette. data is contained in "pal_rgb.h"
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* initialize the palette data */
|
|
|
|
pal_dims[0] = 256;
|
|
|
|
pal_dims[1] = 3;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL1_NAME, pal_dims, pal_rgb) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* attach a palette to the image dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL1_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* palette #2. sepia palette.
|
|
|
|
* read a PAL file and attach the palette to the HDF5 file
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read a PAL file */
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
if (read_palette(PAL2_FILE, rgb, (sizeof(rgb) / sizeof(rgb[0]))) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* transfer to the HDF5 buffer */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0, n = 0; i < 256 * 3; i += 3, n++) {
|
|
|
|
pal[i] = rgb[n].r;
|
|
|
|
pal[i + 1] = rgb[n].g;
|
|
|
|
pal[i + 2] = rgb[n].b;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL2_NAME, pal_dims, pal) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* attach the palette to the image dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL2_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* palette #3. earth palette.
|
|
|
|
* read a PAL file and attach the palette to the HDF5 file
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read a PAL file */
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
if (read_palette(PAL3_FILE, rgb, (sizeof(rgb) / sizeof(rgb[0]))) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* transfer to the HDF5 buffer */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0, n = 0; i < 256 * 3; i += 3, n++) {
|
|
|
|
pal[i] = rgb[n].r;
|
|
|
|
pal[i + 1] = rgb[n].g;
|
|
|
|
pal[i + 2] = rgb[n].b;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL3_NAME, pal_dims, pal) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* attach the palette to the image dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL3_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* palette #4. blue-red
|
|
|
|
* make a palette whith blue to red colors
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
for (i = 0, n = 0; i < 256 * 3; i += 3, n++) {
|
|
|
|
pal[i] = (unsigned char)n;
|
|
|
|
pal[i + 1] = 0;
|
|
|
|
pal[i + 2] = (unsigned char)(255 - n);
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL4_NAME, pal_dims, pal) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* attach the palette to the image dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL4_NAME) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* true color image example with pixel interlace
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make true color image with pixel interlace");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read second data file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((read_data(DATA_FILE2, &width, &height)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_image_24bit(fid, IMAGE2_NAME, width, height, "INTERLACE_PIXEL", image_data)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* True color image example with plane interlace
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make true color image with plane interlace");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* read third data file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((read_data(DATA_FILE3, &width, &height)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_image_24bit(fid, IMAGE3_NAME, width, height, "INTERLACE_PLANE", image_data)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* close
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
if (H5Fclose(fid) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Release memory buffer */
|
|
|
|
HDfree(image_data);
|
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
return 0;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* error zone, gracefully close */
|
2005-03-28 23:24:10 +08:00
|
|
|
out:
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Release memory buffer */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (image_data)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(image_data);
|
|
|
|
|
2021-03-17 23:25:39 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
H5Fclose(fid);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_END_TRY;
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
H5_FAILED();
|
|
|
|
return FAIL;
|
2005-03-28 23:24:10 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*
|
|
|
|
The following test provides an examples of how to generate HDF5 image data from
|
|
|
|
floating point data. In the example we use real life topographic data
|
|
|
|
(from the North American hemisphere). In the dataset sea values are represented
|
|
|
|
as negative numbers and land values are represented as positive numbers.
|
|
|
|
The example generates 3 HDF5 images, one that generates an image from all the values,
|
|
|
|
another that generates an image from the land values and another that generates an
|
|
|
|
image from the sea values.
|
|
|
|
For the example we used data from MODB, the Mediterranean Oceanic Data Base
|
|
|
|
http://modb.oce.ulg.ac.be/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2005-03-28 23:24:10 +08:00
|
|
|
*/
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static int
|
|
|
|
test_generate(void)
|
2005-03-28 23:24:10 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fid;
|
|
|
|
hsize_t pal_dims[2] = {256, 3};
|
|
|
|
float * data = NULL;
|
|
|
|
int imax, jmax, kmax;
|
|
|
|
int n_elements;
|
|
|
|
float valex, xmin, xmax, value;
|
|
|
|
FILE * f = NULL;
|
2010-03-18 05:38:20 +08:00
|
|
|
const char *data_file = H5_get_srcdir_filename(DATA_FILE4);
|
2020-09-30 22:27:10 +08:00
|
|
|
int i;
|
|
|
|
int retval = FAIL;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* create a file using default properties */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fcreate(FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-25 03:07:19 +08:00
|
|
|
HDprintf("Testing read and process data and make indexed images\n");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read data; the file data format is described below
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
f = HDfopen(data_file, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
HDprintf("Could not find file %s. Try set $srcdir \n", data_file);
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2005-03-28 23:24:10 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*
|
|
|
|
!The first line of the ASCII file contains the dimension of the array :
|
|
|
|
! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5.
|
|
|
|
!The second line contains the exclusion value, the minimum and the maximum value of this
|
|
|
|
! file. These numbers are stored with the FORTRAN format E12.5.
|
|
|
|
! The remaining lines contains the data of the array, with 5 numbers per line
|
|
|
|
! (except the last line for each I-line).
|
|
|
|
! The array is stored in horizontal slices from sea surface to sea bottom and from
|
|
|
|
! north to south. So the indexes go from :
|
|
|
|
!
|
|
|
|
! DO K = KMAX to 1
|
|
|
|
! DO J = JMAX to 1
|
|
|
|
! DO I = 1 to IMAX
|
|
|
|
! read
|
|
|
|
! OD
|
|
|
|
! OD
|
|
|
|
! OD
|
|
|
|
!
|
|
|
|
! ____________________________
|
|
|
|
! / /| (imax,jmax,kmax)
|
|
|
|
! / sea surface / |
|
|
|
|
! / / |
|
|
|
|
! /__________________________ / |
|
|
|
|
! | | |
|
|
|
|
! | | | (imax,jmax,1) n
|
|
|
|
! | | / /
|
|
|
|
! | | / /
|
|
|
|
! ^ j | | / w <-----o-----> e
|
|
|
|
! k | / |__________________________|/ /
|
|
|
|
! | / (imax,1,1) /
|
|
|
|
! |----------> s
|
|
|
|
! i
|
|
|
|
!
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%d %d %d", &imax, &jmax, &kmax) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%f %f %f", &valex, &xmin, &xmax) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Sanity check on scanned-in values */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (imax < 1 || jmax < 1 || kmax < 1)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Test product for integer overflow */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (imax > INT_MAX / jmax)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (imax * jmax > INT_MAX / kmax)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
n_elements = imax * jmax * kmax;
|
|
|
|
|
|
|
|
/* Test buffer sizes for overflow */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (n_elements > INT_MAX / (int)sizeof(unsigned char))
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (n_elements > INT_MAX / (int)sizeof(float))
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2019-08-17 02:23:29 +08:00
|
|
|
|
2014-03-16 12:44:13 +08:00
|
|
|
data = (float *)HDmalloc((size_t)n_elements * sizeof(float));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == data)
|
2014-03-16 12:44:13 +08:00
|
|
|
goto out;
|
|
|
|
image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == image_data)
|
2014-03-16 12:44:13 +08:00
|
|
|
goto out;
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < n_elements; i++) {
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%f ", &value) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2007-04-10 02:25:18 +08:00
|
|
|
data[i] = value;
|
|
|
|
}
|
2014-03-23 14:27:57 +08:00
|
|
|
HDfclose(f);
|
|
|
|
f = NULL;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* transform the data from floating point to unsigned char
|
|
|
|
* we are processing all the data here
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make indexed image from all the data");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < n_elements; i++)
|
|
|
|
image_data[i] = (unsigned char)((255 * (data[i] - xmin)) / (xmax - xmin));
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* Make the image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_image_8bit(fid, "All data", (hsize_t)imax, (hsize_t)jmax, image_data)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* transform the data from floating point to unsigned char
|
|
|
|
* here we just process the land data
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make indexed image from land data");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < n_elements; i++) {
|
2021-05-03 23:22:53 +08:00
|
|
|
if (data[i] < 0.0f)
|
2007-04-10 02:25:18 +08:00
|
|
|
image_data[i] = 0;
|
|
|
|
else
|
2021-05-03 23:22:53 +08:00
|
|
|
image_data[i] = (unsigned char)((255 * data[i]) / xmax);
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make the image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_image_8bit(fid, "Land data", (hsize_t)imax, (hsize_t)jmax, image_data)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* transform the data from floating point to unsigned char
|
|
|
|
* here we just process the sea data
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("make indexed image from sea data");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < n_elements; i++) {
|
2021-05-03 23:22:53 +08:00
|
|
|
if (data[i] > 0.0f)
|
2007-04-10 02:25:18 +08:00
|
|
|
image_data[i] = 0;
|
2021-05-03 23:22:53 +08:00
|
|
|
else {
|
|
|
|
image_data[i] = (unsigned char)((255.0f * (data[i] - xmin)) / (xmax - xmin));
|
|
|
|
}
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make the image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_image_8bit(fid, "Sea data", (hsize_t)imax, (hsize_t)jmax, image_data)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* make a palette and attach it to the datasets
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
HL_TESTING2("attaching palettes");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMmake_palette(fid, PAL1_NAME, pal_dims, pal_rgb)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* attach the palette to the image datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMlink_palette(fid, "All data", PAL1_NAME)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMlink_palette(fid, "Land data", PAL1_NAME)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5IMlink_palette(fid, "Sea data", PAL1_NAME)) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
PASSED();
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* close
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
if (H5Fclose(fid) < 0)
|
2007-04-10 02:25:18 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Release memory buffers */
|
|
|
|
HDfree(data);
|
|
|
|
HDfree(image_data);
|
|
|
|
|
2012-08-09 07:01:20 +08:00
|
|
|
/* Indicate success */
|
2012-09-27 04:06:08 +08:00
|
|
|
return 0;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-04-10 02:25:18 +08:00
|
|
|
/* error zone, gracefully close */
|
2004-11-23 03:17:36 +08:00
|
|
|
out:
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Release memory buffers */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (data)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(data);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (image_data)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(image_data);
|
|
|
|
|
2021-03-17 23:25:39 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
H5Fclose(fid);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_END_TRY;
|
|
|
|
if (f)
|
2014-03-23 14:27:57 +08:00
|
|
|
HDfclose(f);
|
2007-04-10 02:25:18 +08:00
|
|
|
H5_FAILED();
|
2012-08-09 07:01:20 +08:00
|
|
|
return retval;
|
2005-03-28 23:24:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read_data
|
|
|
|
* utility function to read ASCII image data
|
|
|
|
* the files have a header of the type
|
|
|
|
*
|
|
|
|
* components
|
|
|
|
* n
|
|
|
|
* height
|
|
|
|
* n
|
|
|
|
* width
|
|
|
|
* n
|
|
|
|
*
|
|
|
|
* followed by the image data
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_data(const char *fname, /*IN*/
|
|
|
|
hsize_t * width, /*OUT*/
|
|
|
|
hsize_t * height /*OUT*/)
|
2005-03-28 23:24:10 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int i, n;
|
|
|
|
int color_planes;
|
|
|
|
char str[20];
|
|
|
|
FILE * f = NULL;
|
|
|
|
int w, h;
|
|
|
|
int n_elements;
|
2010-03-18 05:38:20 +08:00
|
|
|
const char *data_file = H5_get_srcdir_filename(fname);
|
2020-09-30 22:27:10 +08:00
|
|
|
int ret_val = -1;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2009-04-10 03:56:54 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (f = HDfopen(data_file, "r"))) {
|
|
|
|
HDprintf("Could not open file %s. Try set $srcdir \n", data_file);
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2007-04-10 02:25:18 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%d", &color_planes) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2019-08-17 02:23:29 +08:00
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%d", &h) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%d", &w) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Check product for overflow */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (w < 1 || h < 1 || color_planes < 1)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (w > INT_MAX / h)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (w * h > INT_MAX / color_planes)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Compute buffer size */
|
|
|
|
n_elements = w * h * color_planes;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Check buffer size for overflow */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (n_elements > INT_MAX / (int)sizeof(unsigned char))
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Release the buffer, if it was previously allocated */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (image_data)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfree(image_data);
|
|
|
|
|
|
|
|
/* Allocate the image data buffer */
|
|
|
|
image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == image_data)
|
2014-03-16 12:44:13 +08:00
|
|
|
goto out;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
*width = (hsize_t)w;
|
2014-03-16 12:44:13 +08:00
|
|
|
*height = (hsize_t)h;
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
|
|
|
|
/* Read data elements */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < n_elements; i++) {
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(f, "%d", &n) < 0 && HDferror(f)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
HDprintf("fscanf error in file %s.\n", data_file);
|
2016-06-15 07:07:03 +08:00
|
|
|
goto out;
|
|
|
|
} /* end if */
|
2007-04-10 02:25:18 +08:00
|
|
|
image_data[i] = (unsigned char)n;
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
} /* end for */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
/* Indicate success */
|
|
|
|
ret_val = 1;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2019-08-17 02:23:29 +08:00
|
|
|
out:
|
2020-09-30 22:27:10 +08:00
|
|
|
if (f)
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
HDfclose(f);
|
2005-03-30 05:47:53 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
return ret_val;
|
|
|
|
} /* end read_data() */
|
2005-03-30 05:47:53 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read_palette
|
|
|
|
* Read an ASCII palette file .PAL into an array
|
|
|
|
* the files have a header of the type
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* fname - name of file to read.
|
|
|
|
* palette - array of rgb_t to store the read palette.
|
|
|
|
* palette_size - number of elements in 'palette' array
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-03-30 05:47:53 +08:00
|
|
|
|
|
|
|
#define STRING_JASC "JASC-PAL"
|
|
|
|
#define VERSION_JASC "0100"
|
|
|
|
#define STRING_CWPAL "CWPAL"
|
|
|
|
#define VERSION_CWPAL "100"
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static int
|
|
|
|
read_palette(const char *fname, rgb_t *palette, size_t palette_size)
|
2005-03-30 05:47:53 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
FILE * file;
|
|
|
|
char buffer[80];
|
|
|
|
unsigned u;
|
|
|
|
unsigned int red;
|
|
|
|
unsigned int green;
|
|
|
|
unsigned int blue;
|
|
|
|
unsigned nentries;
|
|
|
|
const char * data_file = H5_get_srcdir_filename(fname);
|
2009-04-10 03:56:54 +08:00
|
|
|
|
|
|
|
/* ensure the given palette is valid */
|
|
|
|
if (!palette)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* open the input file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (!(file = HDfopen(data_file, "r"))) {
|
|
|
|
HDprintf("Could not open file %s. Try set $srcdir \n", data_file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the file ident string */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDfgets(buffer, sizeof(buffer), file) == NULL) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure it matches the palette file ident string */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 &&
|
|
|
|
HDstrncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the version string */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDfgets(buffer, sizeof(buffer), file) == NULL) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure it matches the palette file version string */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 &&
|
|
|
|
HDstrncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the number of colors */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDfgets(buffer, sizeof(buffer), file) == NULL) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract the number of colors.
|
2005-04-06 04:26:26 +08:00
|
|
|
check for missing version or number of colors
|
|
|
|
in this case it reads the first entry
|
2005-03-30 05:47:53 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrlen(buffer) > 4) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDsscanf(buffer, "%u", &nentries) != 1) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure there are a sensible number of colors in the palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((nentries > 256) || (nentries > palette_size)) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2020-09-30 22:27:10 +08:00
|
|
|
return (-1);
|
2009-04-10 03:56:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read the palette entries */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (u = 0; u < nentries; u++) {
|
2009-04-10 03:56:54 +08:00
|
|
|
/* extract the red, green and blue color components. */
|
2021-06-29 12:59:25 +08:00
|
|
|
if (HDfscanf(file, "%u %u %u", &red, &green, &blue) != 3) {
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* store this palette entry */
|
|
|
|
palette[u].r = (unsigned char)red;
|
|
|
|
palette[u].g = (unsigned char)green;
|
|
|
|
palette[u].b = (unsigned char)blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close file */
|
2012-03-05 22:17:14 +08:00
|
|
|
HDfclose(file);
|
2009-04-10 03:56:54 +08:00
|
|
|
|
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!)
Merge changes from Coverity branch back to trunk:
r20684:
Fix for coverity bug #1721 which was due to the fix for coverity bug #943.
r20685:
Use HDstrncpy. --gh
r20761:
Purpose: Fix valgrind issues
Description:
Free image_data and data as appropriate in test_image.
r20762:
Purpose: Fix coverity issue 600
Description:
Add check for return value of H5O_close in H5Ocopy. Also cleaned up various
warnings.
r20763:
Purpose: Fix valgrind issues with h5stat
Description:
Modified h5stat to free "iter" before exit, and free "hand" before exit if
parse_command_line exits directly.
r20764:
fixed coverity issues:
69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80
r20765:
Fixed coverity bug 668
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1.
I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program.
r20766:
Fixed coverity bug 667
Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning.
No actual integer overflow tests are performed since it's just a test program.
Tested on:
Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN
(h5committest upcoming)
2013-05-11 23:59:48 +08:00
|
|
|
return (int)nentries;
|
2005-03-30 05:47:53 +08:00
|
|
|
}
|