2007-03-28 04:17:03 +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. *
|
2007-03-28 04:17:03 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2016-09-28 01:29:16 +08:00
|
|
|
#include <assert.h>
|
2007-03-28 04:17:03 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "hdf5.h"
|
2007-03-29 02:47:15 +08:00
|
|
|
#include "H5IMpublic.h"
|
2007-03-28 04:17:03 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2007-04-12 03:56:49 +08:00
|
|
|
* Program: h52gifgentst
|
2007-03-28 04:17:03 +08:00
|
|
|
*
|
|
|
|
* Purpose: generate files for h52gif testing
|
|
|
|
*
|
2020-08-07 08:58:07 +08:00
|
|
|
* Programmer: Pedro Vicente
|
2007-03-28 04:17:03 +08:00
|
|
|
*
|
|
|
|
* Date: March 15, 2007
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FILENAME "h52giftst.h5"
|
2020-09-30 22:27:10 +08:00
|
|
|
#define WIDTH 400
|
|
|
|
#define HEIGHT 200
|
|
|
|
#define PAL_ENTRIES 256
|
|
|
|
#define IMAGE1_NAME "image"
|
|
|
|
#define PAL_NAME "palette"
|
2007-03-28 04:17:03 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: main
|
|
|
|
*
|
|
|
|
* Purpose: main program
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int
|
|
|
|
main(void)
|
2007-03-28 04:17:03 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fid;
|
|
|
|
int i, j, n, space;
|
2016-09-28 01:29:16 +08:00
|
|
|
unsigned char *buf;
|
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 */
|
|
|
|
hsize_t width = WIDTH;
|
|
|
|
hsize_t height = HEIGHT;
|
2007-03-28 04:17:03 +08:00
|
|
|
|
2016-09-28 01:29:16 +08:00
|
|
|
/* Allocate buffer */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (buf = (unsigned char *)malloc(WIDTH * HEIGHT)))
|
2016-09-30 02:01:23 +08:00
|
|
|
return EXIT_FAILURE;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-03-28 04:17:03 +08:00
|
|
|
/* create a file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_FAILURE;
|
2007-03-28 04:17:03 +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++) {
|
2015-03-25 23:25:59 +08:00
|
|
|
buf[i] = (unsigned char)n;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (j > space) {
|
2007-03-28 04:17:03 +08:00
|
|
|
n++;
|
2020-09-30 22:27:10 +08:00
|
|
|
j = 0;
|
2007-03-28 04:17:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make the image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_image_8bit(fid, IMAGE1_NAME, width, height, buf) < 0)
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_FAILURE;
|
2007-03-28 04:17:03 +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] = (unsigned char)0; /* green */
|
|
|
|
pal[i + 2] = (unsigned char)(255 - n); /* blue */
|
2007-03-28 04:17:03 +08:00
|
|
|
}
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-03-28 04:17:03 +08:00
|
|
|
/* make a palette */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMmake_palette(fid, PAL_NAME, pal_dims, pal) < 0)
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_FAILURE;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2007-03-28 04:17:03 +08:00
|
|
|
/* attach the palette to the image */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5IMlink_palette(fid, IMAGE1_NAME, PAL_NAME) < 0)
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_FAILURE;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(fid) < 0)
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_FAILURE;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2016-09-28 01:29:16 +08:00
|
|
|
free(buf);
|
|
|
|
|
2009-12-25 20:37:55 +08:00
|
|
|
return EXIT_SUCCESS;
|
2007-03-28 04:17:03 +08:00
|
|
|
}
|