home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / hdfcomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  5.2 KB  |  175 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/util/RCS/hdfcomp.c,v 1.2 1992/07/15 21:48:48 sxu beta koziol $
  30.  
  31. $Log: hdfcomp.c,v $
  32.  * Revision 1.2  1992/07/15  21:48:48  sxu
  33.  * Added changes for CONVEX
  34.  *
  35.  * Revision 1.1  1992/07/01  20:14:53  mlivin
  36.  * Initial revision
  37.  *
  38.  * Revision 3.2  1991/10/22  17:56:10  dilg
  39.  * 5
  40.  * HDF3.1r5
  41.  *
  42.  * New machine types added:
  43.  *
  44.  *         PC      - IBM PC (DOS)
  45.  *         WIN     - IBM PC (Microsoft Windows 3.0)
  46.  *         IBM6000 - IBM RS/6000 (AIX)
  47.  *         CONVEX  - Convex C-2 (Unix)
  48.  *
  49.  * Bugs fixed in:
  50.  *
  51.  *         scup32.f
  52.  *         cspck32.f
  53.  *         dfpFf.f
  54.  *         dfpF.c
  55.  *         dfsd.c
  56.  *
  57.  * New utility added:
  58.  *
  59.  *         ristosds.c - convert raster images to sds.
  60.  *
  61.  * Also:
  62.  *         All code for the library was modified to conform to the
  63.  *         ANSI C standard.
  64.  *
  65.  * Revision 3.1  1990/07/02  10:11:49  clow
  66.  * some cosmetic modifications
  67.  *
  68. */
  69.  
  70. /*
  71. *  hdfcomp.c
  72. *  Re-compress Raster-8 HDF file
  73. */
  74.  
  75. #include "hdf.h"
  76.  
  77. uint8 *space;
  78. uint8 palette[768];
  79. int32 xdim, ydim;
  80. int ispal;
  81.  
  82. #ifdef PROTOTYPE
  83. int main(int argc, char *argv[]);
  84. #else
  85. int main();
  86. #endif /* PROTOTYPE */
  87.  
  88. #ifdef PROTOTYPE
  89. main(int argc, char *argv[]) 
  90. #else
  91. main(argc,argv) 
  92.     int argc;
  93.     char *argv[];
  94. #endif /* PROTOTYPE */
  95.     {
  96.     int i, ret;
  97.     char *outfile;
  98.     int image = 1;
  99.     uint16 prevref, writeref = 200, compress = (uint16) 0;
  100.  
  101.     if (argc < 3) { 
  102.         printf("%s,  version: 1.1   date: July 1, 1992\n", argv[0]);
  103.         printf("  This utility will read in raster-8 images from an\n");
  104.         printf("  HDF file and create a new HDF containing the\n");
  105.         printf("  images in a compressed format.  Images will be\n");
  106.         printf("  appended to outfile, if it exists.\n\n");
  107.         printf("Usage:\n");
  108.         printf(" hdfcomp outfile {[-c],[-r],[-i]} imagefile ...\n");
  109.         printf("                 {[-c],[-r],[-i]} imagefile\n");
  110.         printf("         -r: Store without compression (default)\n");
  111.         printf("         -c: Store using RLE compression\n");
  112.         printf("         -i: Store using IMCOMP compression (requires a");
  113.         printf(" palette in the HDF file)\n");
  114.         exit(1);
  115.     }
  116.  
  117.     outfile = argv[1];
  118.  
  119.     for (i = 2; i < argc; i++) {
  120.         if (*argv[i] == '-') {
  121.             switch (argv[i][1]) {
  122.                 case 'r':               /* raster */
  123.                     image = 1;
  124.                     compress = (uint16) 0;
  125.                     break;
  126.                 case 'c':               /* RLE */
  127.                     image = 1;
  128.                     compress = DFTAG_RLE;
  129.                     break;
  130.                 case 'i':               /* IMCOMP */
  131.                     image = 1;
  132.                     compress = DFTAG_IMC;
  133.                     break;
  134.                 default:
  135.                     printf("Illegal option: %s, skipping....\n", argv[i]);   
  136.                     break;
  137.             }
  138.         }
  139.         else { /* file name */
  140.             while (DFR8getdims(argv[i], &xdim, &ydim, &ispal) >= 0) {
  141.                 prevref = DFR8lastref();
  142.                 if ((space = (uint8 *) HDgetspace(xdim * ydim)) == NULL) {
  143.                     printf("Not enough memory to convert image");
  144.                     exit(1);
  145.                 }
  146.  
  147.                 if (DFR8getimage(argv[i], space, xdim, ydim, palette) < 0) {
  148.                     printf("Error reading image from file %s\n", argv[i]);
  149.                     exit(1);
  150.                 }
  151.                 if (ispal) DFR8setpalette((uint8 *) palette);
  152.                 else if (compress == DFTAG_IMC) {
  153.                     printf("Couldn't find palette for IMCOMP compression\n");
  154.                     exit(1);
  155.                 }
  156.                 ret = DFR8writeref(outfile, writeref++);
  157.  
  158.                 if (DFR8addimage(outfile, (VOIDP) space, 
  159.                           xdim, ydim, compress)<0) {
  160.                     printf("Error writing image to file %s\n", outfile);
  161.                     exit(1);
  162.                 }
  163.  
  164.                 /* sequence past this image */
  165.                 ret = DFR8readref(argv[i], prevref);
  166.                 ret = DFR8getdims(argv[i], &xdim, &ydim, &ispal);
  167.  
  168.         HDfreespace(space);
  169.             }
  170.         }
  171.     }
  172.  
  173.     return(0);
  174. }
  175.