summaryrefslogtreecommitdiffstats
path: root/hl/examples/ex_image1.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2006-03-06 16:11:11 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2006-03-06 16:11:11 (GMT)
commita83d815631e9981f3a89f4347d6a481e0fb7c62d (patch)
treedb77b10d8c5c6247f59d0352a747bcc4a70babcd /hl/examples/ex_image1.c
parent0f8fa98da0b4b61173cc82f3123c736c1eec1552 (diff)
downloadhdf5-a83d815631e9981f3a89f4347d6a481e0fb7c62d.zip
hdf5-a83d815631e9981f3a89f4347d6a481e0fb7c62d.tar.gz
hdf5-a83d815631e9981f3a89f4347d6a481e0fb7c62d.tar.bz2
[svn-r12009] Purpose:
add examples Description: add examples for HL (image, table and dimension scales) Solution: Platforms tested: linux Misc. update:
Diffstat (limited to 'hl/examples/ex_image1.c')
-rw-r--r--hl/examples/ex_image1.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/hl/examples/ex_image1.c b/hl/examples/ex_image1.c
new file mode 100644
index 0000000..0535cbc
--- /dev/null
+++ b/hl/examples/ex_image1.c
@@ -0,0 +1,70 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#include "H5IM.h"
+
+#define WIDTH (hsize_t)400
+#define HEIGHT (hsize_t)200
+#define PAL_ENTRIES 9
+unsigned char buf [ WIDTH*HEIGHT ];
+
+int main( void )
+{
+ hid_t file_id;
+ herr_t status;
+ hsize_t pal_dims[] = {PAL_ENTRIES,3};
+ hsize_t i, j;
+ int n, space;
+ unsigned char pal[PAL_ENTRIES*3] = { /* create a palette with 9 colors */
+ 0,0,168, /* dark blue */
+ 0,0,252, /* blue */
+ 0,168,252, /* ocean blue */
+ 84,252,252, /* light blue */
+ 168,252,168, /* light green */
+ 0,252,168, /* green */
+ 252,252,84, /* yellow */
+ 252,168,0, /* orange */
+ 252,0,0}; /* red */
+
+ /* create an image of 9 values divided evenly by the array */
+ space = WIDTH*HEIGHT / PAL_ENTRIES;
+ for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ )
+ {
+ buf[i] = n;
+ if ( j > space )
+ {
+ n++;
+ j=0;
+ }
+ if (n>PAL_ENTRIES-1) n=0;
+ }
+
+ /* create a new HDF5 file using default properties. */
+ file_id = H5Fcreate( "ex_image1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
+
+ /* make the image */
+ status = H5IMmake_image_8bit( file_id, "image1", WIDTH, HEIGHT, buf );
+
+ /* make a palette */
+ status = H5IMmake_palette( file_id, "pallete", pal_dims, pal );
+
+ /* attach the palette to the image */
+ status = H5IMlink_palette( file_id, "image1", "pallete" );
+
+ /* close the file. */
+ status = H5Fclose( file_id );
+
+ return 0;
+
+}