C: status = DF24putimage(filename, image, width, height); FORTRAN: status = d2pimg(filename, image, width, height)
C: status = DF24addimage(filename, image, width, height); FORTRAN: status = d2aimg(filename, image, width, height)
DF24putimage and DF24addimage write a 24-bit raster images to the HDF file specified by the filename parameter. When given a new file name, DF24putimage and DF24addimage create a new file and write the raster image as the first raster image in the file. If a file with the specified filename exists, DF24putimage overwrites the previous contents of the file whereas DF24addimage appends data to the end of the file.
TABLE 7D DF24putimage and DF24addimage Parameter List
C:
#include "hdf.h" #define WIDTH 5 #define HEIGHT 6 #define PIXEL_DEPTH 3 main( ) { /* Initialize the image array. */ static uint8 raster_data[HEIGHT][WIDTH][PIXEL_DEPTH] = { 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 }; intn status; /* Write the 24-bit raster image to the HDF file. */ status = DF24addimage("Example1.hdf", (VOIDP)raster_data, WIDTH, \ HEIGHT); }
PROGRAM WRITE RIS24 integer status, d2aimg integer*4 WIDTH, HEIGHT, PIXEL_DEPTH parameter (WIDTH = 5, + HEIGHT = 6, + PIXEL_DEPTH = 3) character raster_data(PIXEL_DEPTH, WIDTH, HEIGHT) C Initialize the image array. data raster_data + / 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 / C Write the 24-bit raster image to the file. status = d2aimg('Example1.hdf', raster_data, WIDTH, + HEIGHT) end
7.4.2 Setting the Interlace Format: DF24setil
DF24setil indicates the interlace format to be used for all subsequent write operations. DF24setil changes the default setting from pixel interlacing to the selected format. When the format is set, it acts as the default until it is reset by another call to DF24setil. To change the default interlace format , the calling program must contain the following routines:
C: status = DF24setil(il); status = DF24addimage(filename, image, width, height);
FORTRAN: status = d2setil(il) status = d2aimg(filename, image, width, height)
DF24setil takes il as its only parameter. Valid values for il are DFIL_PIXEL, DFIL_LINE, and DFIL_PLANE. The parameters for DF24setil are further defined below. (See Table 7E on page 192.)
EXAMPLE 2. Writing 24-Bit Raster Images Using Scan-plane Interlacing
In the following examples, DF24addimage is used to write a 24-bit image to an HDF file called "Example2.hdf". The DF24setil function used here to change the default format setting from pixel interlacing to scan-plane interlacing.
#include "hdf.h" #include "hcomp.h" #define WIDTH 5 #define HEIGHT 6 #define PIXEL_DEPTH 3 main( ) { /* Initialize the image array. */ static uint8 raster_data[HEIGHT][WIDTH][PIXEL_DEPTH] = { 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 }; intn status; /* Change interlace from pixel to scan-plane. */ status = DF24setil(DFIL_PLANE); /* Write the 24-bit image data to file. */ status = DF24addimage("Example2.hdf", (VOIDP)raster_data, WIDTH, HEIGHT); }
PROGRAM CHANGE INTERLACE integer status, d2aimg, d2setil integer*4 WIDTH, HEIGHT, PIXEL_DEPTH, DFIL_PLANE parameter (WIDTH = 5, + HEIGHT = 6, + PIXEL_DEPTH = 3, + DFIL_PLANE = 2) integer raster_data(PIXEL_DEPTH, WIDTH, HEIGHT) C Initialize the image array. data raster_data + / 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 / C Change interlace from pixel to scan plane. status = d2setil(DFIL_PLANE) C Write the 24-bit raster image to the file. status = d2aimg('Example2.hdf', raster_data, WIDTH, + HEIGHT) end
7.4.3 Compressing Image Data: DF24setcompress and d2sjpeg
DF24setcompress invokes JPEG compression and sets the JPEG quality and baseline options. To store a 24-bit raster image using JPEG compression, the calling program must contain the following function calls:
C: status = DF24setcompress(type, c_info); status = DF24addimage(filename, image, width, height);
FORTRAN: status = d2scomp(type) OR status = d2sjpeg(quality, baseline) status = d2aimg(filename, image, width, height, compress)
Notice that the calling sequence for C is different from the calling sequence for Fortran-77. Once it is set, the parameter type in the DF24setcompress routine, or d2scomp in Fortran-77, routine specifies the compression method that will be used to store the raster images. However, the c_info parameter in DF24setcompress is missing from d2scomp which is a pointer to a structure that contains information specific to the compression method indicated by the type parameter. Because data structures of variable size are not supported in Fortran-77, a second compression-specific routine (d2sjpeg) is required in the Fortran-77 calling sequence.
TABLE 7E DF24setil and DF24setcompress Parameter List
C:
#include "hdf.h" #include "hcomp.h" #define WIDTH 3 #define HEIGHT 5 #define PIXEL_DEPTH 3 main( ) { /* Initialize the image array. */ static uint8 raster_data[HEIGHT][WIDTH][PIXEL_DEPTH] = { 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 }; static comp_info compress_info; intn status; /* Initialize JPEG compression structure. */ compress_info.jpeg.quality = 60; compress_info.jpeg.force_baseline = 1; /* Set JPEG compression for storing the image. */ status = DF24setcompress(COMP_JPEG, &compress_info); /* Write the 24-bit image data to file. */ status = DF24addimage("Example2.hdf", (VOIDP)raster_data, WIDTH, HEIGHT); }
PROGRAM COMPRESS RIS24 integer d2aimg, d2scomp, d2sjpeg, status integer*4 WIDTH, HEIGHT, PIXEL_DEPTH parameter(WIDTH = 3, + HEIGHT = 5, + PIXEL_DEPTH = 3) character raster_data(PIXEL_DEPTH, WIDTH, HEIGHT) C Initialize the image array. data raster_data + / 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 / C Set compression. status = d2scomp(COMP_JPEG) C Set JPEG parameters to quality = 60, and turn compatibility on. status = d2sjpeg(60, 1) C Write the 24-bit image data to the HDF file. status = d2aimg('Example2.hdf', raster_data, WIDTH, HEIGHT) end