/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 * * 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://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "H5IM.h" #define FILE_NAME "test_image.h5" #define WIDTH 400 #define HEIGHT 200 #define PAL_ENTRIES 256 #define IMAGE1_NAME "image1" #define IMAGE2_NAME "image2" #define PAL_NAME "palette" /*------------------------------------------------------------------------- * the main program *------------------------------------------------------------------------- */ int main( void ) { hsize_t width = WIDTH; hsize_t height = HEIGHT; hsize_t planes; hid_t fid; int i, j, n, space; char interlace[20]; hssize_t npals; /* 8-bit image */ unsigned char buf1 [ WIDTH*HEIGHT ]; unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */ hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */ /* 24-bit image */ unsigned char buf2 [ WIDTH*HEIGHT*3 ]; /* read data */ unsigned char buf1_out [ WIDTH*HEIGHT ]; unsigned char buf2_out [ WIDTH*HEIGHT*3 ]; unsigned char pal_out[ PAL_ENTRIES * 3 ]; /* palette array */ hsize_t pal_dims_out[2]; /* palette dimensions */ /* create an image */ space = WIDTH*HEIGHT / PAL_ENTRIES; for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ ) { buf1[i] = n; if ( j > space ) { n++; j=0; } } /* create an image */ space = WIDTH*HEIGHT / 256; for (i=0, j=0, n=0; i < WIDTH*HEIGHT*3; i+=3, j++ ) { unsigned char r, g, b; r = n; g = 0; b = 255-n; buf2[i] = r; buf2[i+1] = g; buf2[i+2] = b; if ( j > space ) { n++; j=0; } } /*------------------------------------------------------------------------- * define a palette, blue to red tones *------------------------------------------------------------------------- */ for ( i=0, n=0; i