home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / ris8 / putim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-09  |  2.9 KB  |  109 lines

  1. /*****************************************************************
  2. *
  3. *  Program for creating an image and storing it in an HDF file
  4. *
  5. *
  6. *  If "row order" is selected the image created, with it's palette,
  7. *  should display as an increasingly dark gray scale going from top
  8. *  to bottom, up to 256 rows, then repeating.  If "column order" is
  9. *  chosen, this pattern will be transposed.
  10. *
  11. *  User supplies filename, height, width, compression, and whether
  12. *  to store image in row or column order.
  13. *
  14. *****************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include <ctype.h>
  18. #define TRUE    1
  19. #define FALSE   0
  20. char *malloc();
  21.  
  22. main(argc,argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.     int          Height, Width;
  27.     int       Color;
  28.     int       Compress;
  29.     int       ReturnCode;
  30.     int       Index1, Index2, Index3;
  31.     char      Image[307200];
  32.     char      Palette[768];
  33.     char      Order='R';
  34.     char      Filename[65];
  35.  
  36.     if (argc != 6) {
  37.         printf("Usage: %s outfile height width compress order\n", argv[0]);
  38.         printf("\tHeight Value: 1-480\n");
  39.         printf("\tWidth Value: 1-640\n");
  40.         printf("\tCompression Code: 0=None, 11=Run Length, 12=IMCOMP\n");
  41.         printf("\tOrder: R (row major), C (column major)\n");
  42.         exit(1);
  43.     }
  44.     printf("HDFTEST - Generate HDF Test File\n");
  45.  
  46.     strcpy(Filename, argv[1]);
  47.     Height = atoi(argv[2]);
  48.     Width  = atoi(argv[3]);
  49.     
  50.  
  51.     if (Height>480)  {
  52.         printf( "Error in command line\n\tHeight Value: 1-480\n");
  53.         exit(1);
  54.     }
  55.     if (Width>640)  {
  56.         printf( "Error in command line\n\tWidth Value: 1-640\n");
  57.         exit(1);
  58.     }
  59.  
  60.  
  61.     Compress = atoi(argv[4]);
  62.     if ( (Compress != 0) && (Compress!=11) && (Compress!=12) ) { 
  63.         printf( "Error in command line:\n");
  64.         printf("\tCompression Code: 0=None, 11=Run Length, 12=IMCOMP\n");
  65.         exit(1);
  66.     }
  67.  
  68.     Order = argv[5][0];
  69.     if ((Order=='C') || (Order == 'c')){
  70.        for (Index1=1; Index1<Height; Index1++) {
  71.            Color=0;
  72.            for (Index2=1; Index2<Width; Index2++) {
  73.                Image[((Index1*Width)-Width)+Index2] = (char) Color;
  74.                Color = (Color+1) %256;
  75.            }
  76.        }
  77.     } 
  78.     else {
  79.     for (Index1=1; Index1<Width; Index1++) {
  80.             Color=0;
  81.             for (Index2=1; Index2<Height; Index2++) {
  82.                 Image[((Index2*Width)-Width)+Index1] = (char) Color;
  83.                 Color = (Color+1) %256;
  84.         }
  85.        }
  86.     }
  87.  
  88.     Color=255;
  89.     for (Index3=0; Index3 < 768; Index3 += 3) {
  90.        Palette[Index3+0]=(char) Color;
  91.        Palette[Index3+1]=(char) Color;
  92.        Palette[Index3+2]=(char) Color;
  93.        Color--;
  94.        if (Color < 0)
  95.           Color=255;
  96.     }
  97.  
  98.     ReturnCode = DFR8setpalette(Palette);
  99.     if (ReturnCode != 0) 
  100.        printf("Error calling DFR8setpalette\n");
  101.  
  102.     ReturnCode=DFR8putimage(Filename,Image,Width,Height,Compress);
  103.     if (ReturnCode != 0) 
  104.        printf("Error calling DFR8putimage\n");
  105.  
  106.     printf("HDFTEST - Finished\n");
  107. }
  108.  
  109.