1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 #include "hdf5.h"
15 #include "hdf5_hl.h"
16
17 #define WIDTH 400
18 #define HEIGHT 200
19 #define PAL_ENTRIES 9
20 unsigned char buf [ WIDTH*HEIGHT ];
21
main(void)22 int main( void )
23 {
24 hid_t file_id;
25 hsize_t pal_dims[] = {PAL_ENTRIES,3};
26 size_t i, j;
27 int n, space;
28 unsigned char pal[PAL_ENTRIES*3] = { /* create a palette with 9 colors */
29 0,0,168, /* dark blue */
30 0,0,252, /* blue */
31 0,168,252, /* ocean blue */
32 84,252,252, /* light blue */
33 168,252,168, /* light green */
34 0,252,168, /* green */
35 252,252,84, /* yellow */
36 252,168,0, /* orange */
37 252,0,0}; /* red */
38
39 /* create an image of 9 values divided evenly by the array */
40 space = WIDTH*HEIGHT / PAL_ENTRIES;
41 for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ )
42 {
43 buf[i] = n;
44 if ( j > space )
45 {
46 n++;
47 j=0;
48 }
49 if (n>PAL_ENTRIES-1) n=0;
50 }
51
52 /* create a new HDF5 file using default properties. */
53 file_id = H5Fcreate( "ex_image1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
54
55 /* make the image */
56 H5IMmake_image_8bit( file_id, "image1", (hsize_t)WIDTH, (hsize_t)HEIGHT, buf );
57
58 /* make a palette */
59 H5IMmake_palette( file_id, "pallete", pal_dims, pal );
60
61 /* attach the palette to the image */
62 H5IMlink_palette( file_id, "image1", "pallete" );
63
64 /* close the file. */
65 H5Fclose( file_id );
66
67 return 0;
68
69 }
70