[Top] [Prev] [Next]

r24_ex1.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);

}

r24_ex1.f

      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

r24_ex2.c

#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);

}

r24_ex2.f

      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

r24_ex3.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);

}

r24_ex3.f

      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

r24_ex4.c

#include "hdf.h"

#define WIDTH 5
#define HEIGHT 6
#define PIXEL_DEPTH 3

main( )
{
	uint8 raster_data[PIXEL_DEPTH][HEIGHT][WIDTH];
	int32 width, height;
	intn interlace, status;

	/* Get the image dimensions from the HDF file. */
	status = DF24getdims("Example2.hdf", &width, &height, 
					&interlace);

	/* 
	* Read raster data if the dimensions are
	* correct.
	*/
	if (width <= WIDTH && height <= HEIGHT)
	  status = DF24getimage("Example2.hdf", (VOIDP)raster_data, 
					width, height);
}

r24_ex4.f

      PROGRAM READ RIS24 

      integer d2gimg, d2gdims, status, width, height, interlace
      integer*4 X_LENGTH, Y_LENGTH, PIXEL_DEPTH
      parameter(X_LENGTH = 5, Y_LENGTH = 6, PIXEL_DEPTH = 3)
      integer raster_data(PIXEL_DEPTH, X_LENGTH, Y_LENGTH)

C     Read the dimensions raster image.
      status = d2gdims(`Example2.hdf', width, height, interlace)

C     Read image data from the HDF file if the dimensions are 
C     correct.
      if (width .eq. X_LENGTH .and. height .eq. Y_LENGTH) then
       status = d2gimg(`Example2.hdf', raster_data, width, height)
      endif

      end



[Top] [Prev] [Next]

hdfhelp@ncsa.uiuc.edu
HDF User's Guide - 05/19/99, NCSA HDF Development Group.