1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/****************************************************************************
* NCSA HDF *
* Scientific Data Technologies *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING f. *
* *
****************************************************************************/
#include "H5IM.h"
#define FILE_NAME "test_image.h5"
#define WIDTH (hsize_t)500
#define HEIGHT (hsize_t)200
unsigned char image_in1 [ WIDTH*HEIGHT ];
unsigned char image_out1[ WIDTH*HEIGHT ];
unsigned char image_in2 [ WIDTH*HEIGHT*3 ];
unsigned char image_out2[ WIDTH*HEIGHT*3 ];
/*-------------------------------------------------------------------------
* the main program
*-------------------------------------------------------------------------
*/
int main( void )
{
hid_t file_id;
hsize_t width, height, planes;
hsize_t pal_dims[] = {9,3};
hsize_t pal_dims_out[2];
hsize_t i;
char interlace[20];
hssize_t npals;
unsigned char pal_data_out[9*3];
/* create a 9 entry grey palette */
unsigned char pal_data_in[9*3] = {0,0,0,
25,25,25,
50,50,50,
75,75,75,
100,100,100,
125,125,125,
150,150,150,
175,175,175,
200,200,200};
for (i = 0; i < WIDTH*HEIGHT; i++ )
image_in1[i] = (unsigned char)i;
for (i = 0; i < WIDTH*HEIGHT*3; i++)
image_in2[i] = (unsigned char)i;
/* Create a new HDF5 file using default properties. */
file_id = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
/*-------------------------------------------------------------------------
* Indexed image test
*-------------------------------------------------------------------------
*/
TESTING("indexed image");
/* Write image */
if ( H5IMmake_image_8bit( file_id, "Image1", WIDTH, HEIGHT, image_in1 ) < 0 )
goto out;
/* Make a palette */
if ( H5IMmake_palette( file_id, "Pallete", pal_dims, pal_data_in ) < 0 )
goto out;
/* Attach a palette to the image dataset */
if ( H5IMlink_palette( file_id, "Image1", "Pallete" ) < 0 )
goto out;
/* Read image */
if ( H5IMget_image_info( file_id, "Image1", &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
if ( H5IMread_image( file_id, "Image1", image_out1 ) < 0 )
goto out;
for (i = 0; i < height*width*planes; i++) {
if ( image_in1[i] != image_out1[i] ) {
goto out;
}
}
PASSED();
/*-------------------------------------------------------------------------
* True color image test
*-------------------------------------------------------------------------
*/
TESTING("true color image");
/* Write image */
if ( H5IMmake_image_24bit( file_id, "Image2", WIDTH, HEIGHT, "INTERLACE_PIXEL", image_in2 ) )
goto out;
/* Read image */
if ( H5IMget_image_info( file_id, "Image2", &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
if ( H5IMread_image( file_id, "Image2", image_out2 ) < 0 )
goto out;
for (i = 0; i < height*width*planes; i++) {
if ( image_in2[i] != image_out2[i] ) {
goto out;
}
}
PASSED();
/*-------------------------------------------------------------------------
* H5IMget_npalettes test
*-------------------------------------------------------------------------
*/
TESTING("pallete functions");
if ( H5IMget_npalettes( file_id, "Image1", &npals ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* H5IMget_palette_info test
*-------------------------------------------------------------------------
*/
if ( H5IMget_palette_info( file_id, "Image1", 0, pal_dims_out ) < 0 )
goto out;
for (i = 0; i < 2; i++) {
if ( pal_dims[i] != pal_dims_out[i] ) {
goto out;
}
}
/*-------------------------------------------------------------------------
* H5IMget_palette test
*-------------------------------------------------------------------------
*/
if ( H5IMget_palette( file_id, "Image1", 0, pal_data_out ) < 0 )
goto out;
for (i = 0; i < 9*3; i++) {
if ( pal_data_in[i] != pal_data_out[i] ) {
goto out;
}
}
/*-------------------------------------------------------------------------
* H5IMis_image test
*-------------------------------------------------------------------------
*/
if ( H5IMis_image( file_id, "Image1" ) < 0 )
goto out;
if ( H5IMis_image( file_id, "Image2" ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* H5IMis_palette test
*-------------------------------------------------------------------------
*/
if ( H5IMis_palette( file_id, "Pallete" ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* end tests
*-------------------------------------------------------------------------
*/
/* Close the file. */
if(H5Fclose( file_id ) < 0) goto out;
PASSED();
return 0;
out:
H5_FAILED();
return 1;
}
|