File: tdfr8.c

package info (click to toggle)
libhdf4 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,384 kB
  • sloc: ansic: 128,700; sh: 15,015; fortran: 12,444; java: 5,863; xml: 1,205; makefile: 794; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (224 lines) | stat: -rw-r--r-- 10,078 bytes parent folder | download | duplicates (2)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF.  The full HDF copyright notice, including       *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/************************************************************************
 * tdfr8.c - test file for images of DFR8 API
 *************************************************************************/

#include "hdf.h"
#include "tproto.h" /* for utility macros */

/************************************************************************
   Name: test_GRgetcomptype() - test GRgetcomptype for hmap project

   Description:
        This routine uses DFR8 API to create the following images:
        + Name image0 with no compression and no palette
        + Name image1 with no compression and no palette
        + Name image2 with no compression and with palette
        + Name image3 with no compression and with palette
        + Name image4 with RLE compression and with palette
        + Name image5 with RLE compression and with palette
        + Name image6 with IMCOMP compression and with palette
        + Name image7 with IMCOMP compression and with palette
        * Name image8 with JPEG compression and with palette
        + Name image9 with JPEG compression and with palette
        + Name image10 with RLE compression and with palette
        + Name image11 with RLE compression and with palette
        All have same data in rasters and in palette (when used)
        Note: This part of the test was adopted from Ruth's test program.

        The function GRgetcomptype will be call on each image and the returned
        compression type will be verified against the list of compressions used.
   BMR - Mar 12, 2011
**************************************************************************/
#define FILE_NAME    "tGRgetcomptype.hdf"
#define HEIGHT       3
#define WIDTH        8
#define N_IMAGES     12
#define N_ENTRIES    256
#define N_COMPONENTS 3

void
test_GRgetcomptype()
{
    intn         ii;
    int          row, col;
    int          entry, component;
    uint8        raster[HEIGHT][WIDTH];
    uint8        palette[N_ENTRIES * N_COMPONENTS], temp_pal[N_ENTRIES][N_COMPONENTS];
    int32        file_id, gr_id, ri_id;
    int32        num_images = 0, num_fattrs = 0;
    intn         status;
    comp_coder_t comp_type;
    comp_info    compress_info;

    /* used to verify the compression type of the images */
    comp_coder_t check_comp[N_IMAGES] = {COMP_CODE_NONE, COMP_CODE_NONE, COMP_CODE_NONE,   COMP_CODE_NONE,
                                         COMP_CODE_RLE,  COMP_CODE_RLE,  COMP_CODE_IMCOMP, COMP_CODE_IMCOMP,
                                         COMP_CODE_JPEG, COMP_CODE_JPEG, COMP_CODE_RLE,    COMP_CODE_RLE};

    /* used to verify whether an image should be mapped */
    intn maplist[N_IMAGES] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE};

    /* Initialize the raster image array */
    for (row = 0; row < HEIGHT; row++) {
        for (col = 0; col < WIDTH; col++) {
            raster[row][col] =
                (uint8)(row * 10 + col); /* row and col are too small to overflow an 8-bit int */
        }
    }

    /*
     * Initialize the palette array (256 entries of RGB components)
     * We want our test case to be easy to see, so only turn
     * on colors for values we have in raster image.
     * Red for first row; Green for second row; Blue for third row
     * -RA
     */
    for (entry = 0; entry < N_ENTRIES; entry++) {
        for (component = 0; component < N_COMPONENTS; component++) {
            if ((0 <= entry) && (entry <= 7)) { /* values in first row of raster */
                temp_pal[entry][0] = 255;       /* Red */
                temp_pal[entry][1] = 0;         /* Green */
                temp_pal[entry][2] = 0;         /* Blue */
            }
            else if ((10 <= entry) && (entry <= 17)) { /* values in second row of raster */
                temp_pal[entry][0] = 0;                /* Red */
                temp_pal[entry][1] = 255;              /* Green */
                temp_pal[entry][2] = 0;                /* Blue */
            }
            else if ((20 <= entry) && (entry <= 27)) { /* values in third row of raster */
                temp_pal[entry][0] = 0;                /* Red */
                temp_pal[entry][1] = 0;                /* Green */
                temp_pal[entry][2] = 255;              /* Blue */
            }
            else {                      /* all else (don't expect) will be black */
                temp_pal[entry][0] = 0; /* Red */
                temp_pal[entry][1] = 0; /* Green */
                temp_pal[entry][2] = 0; /* Blue */
            }
        }
    }

    /* Work around to pass "palette" into DFR8setpalette w/o compiler warning.*/
    memcpy(palette, temp_pal, N_ENTRIES * N_COMPONENTS);

    /* Write image0 to the HDF4 file with no compression and no palette
     * Note that the order of args 3 and 4 is width then height.  */
    status = DFR8putimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_NONE);
    CHECK_VOID(status, FAIL, "DFR8putimage");

    /* Write image1 to the HDF4 file with no compression and no palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_NONE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Set the palette */
    status = DFR8setpalette(palette);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image2 with no compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_NONE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image3 with no compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_NONE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image4 with RLE compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_RLE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image5 with RLE compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_RLE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image6 with IMCOMP compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_IMCOMP);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image7 with IMCOMP compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_IMCOMP);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image8 with JPEG compression and with palette */
    compress_info.jpeg.quality        = 60;
    compress_info.jpeg.force_baseline = 1;
    status                            = DFR8setcompress(COMP_JPEG, &compress_info);
    CHECK_VOID(status, FAIL, "DFR8setcompress");

    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_JPEG);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image9 with JPEG compression and with palette */
    compress_info.jpeg.quality        = 60;
    compress_info.jpeg.force_baseline = 1;
    status                            = DFR8setcompress(COMP_JPEG, &compress_info);
    CHECK_VOID(status, FAIL, "DFR8setcompress");

    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_JPEG);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image10 with RLE compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_RLE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Write image11 with RLE compression and with palette */
    status = DFR8addimage(FILE_NAME, raster, WIDTH, HEIGHT, COMP_RLE);
    CHECK_VOID(status, FAIL, "DFR8addimage");

    /* Open the file in GR interface and verify the compression type of each
        image in the file */

    /* Open the file and initialize the GR interface */
    file_id = Hopen(FILE_NAME, DFACC_READ, 0);
    CHECK_VOID(file_id, FAIL, "Hopen");
    gr_id = GRstart(file_id);
    CHECK_VOID(gr_id, FAIL, "GRstart");

    /* Get the number of images in the file */
    status = GRfileinfo(gr_id, &num_images, &num_fattrs);
    CHECK_VOID(status, FAIL, "GRfileinfo");

    /* Verify compression type of each image */
    for (ii = 0; ii < num_images; ii++) {
        intn is_mappedable;  /* TRUE if the image is mapped-able (hmap project)*/
        intn name_generated; /* TRUE if the image has name generated by lib */

        ri_id = GRselect(gr_id, ii);
        CHECK_VOID(ri_id, FAIL, "GRselect");

        /* Get image's compression type */
        status = GRgetcomptype(ri_id, &comp_type);
        CHECK_VOID(status, FAIL, "GRgetcomptype");

        /* Test GR2bmapped on this image (For hmap project only) */
        status = GR2bmapped(ri_id, &is_mappedable, &name_generated);
        CHECK_VOID(status, FAIL, "GR2bmapped");
        VERIFY_VOID(is_mappedable, maplist[ii], "GR2bmapped");
        VERIFY_VOID(name_generated, TRUE, "GR2bmapped");

        /* Verify compression type */
        if (comp_type != check_comp[ii])
            VERIFY_VOID(check_comp[ii], comp_type, "GRgetcomptype");

        status = GRendaccess(ri_id);
        CHECK_VOID(status, FAIL, "GRendaccess");
    }

    /* Terminate access to the file */
    status = GRend(gr_id);
    CHECK_VOID(status, FAIL, "GRend");
    status = Hclose(file_id);
    CHECK_VOID(status, FAIL, "Hclose");

} /* test_GRgetcomptype */