home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 580a.lha / hdf_utilities / src.LZH / src / hdfcomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-11  |  3.8 KB  |  117 lines

  1. /*****************************************************************************
  2. *              NCSA HDF version 3.10r3
  3. *                Dec 6, 1990
  4. *
  5. * NCSA HDF Version 3.10r3 source code and documentation are in the public
  6. * domain.  Specifically, we give to the public domain all rights for future
  7. * licensing of the source code, all resale rights, and all publishing rights.
  8. * We ask, but do not require, that the following message be included in all
  9. * derived works:
  10. * Portions developed at the National Center for Supercomputing Applications at
  11. * the University of Illinois at Urbana-Champaign.
  12. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  13. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  14. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  15. *****************************************************************************/
  16.  
  17. #ifdef RCSID
  18. static char RcsId[] = "@(#)$Revision: 3.1 $";
  19. #endif
  20. /*
  21. $Header: /pita/work/HDF/dev/RCS/src/hdfcomp.c,v 3.1 90/07/02 10:11:49 clow beta $
  22.  
  23. $Log:    hdfcomp.c,v $
  24.  * Revision 3.1  90/07/02  10:11:49  clow
  25.  * some cosmetic modifications
  26.  * 
  27. */
  28.  
  29. /*
  30. *  hdfcomp.c
  31. *  Re-compress Raster-8 HDF file
  32. */
  33.  
  34. #include <hdf/df.h>
  35.  
  36. char *space;
  37. char palette[768];
  38. int32 xdim,ydim, ispal;
  39.  
  40. main(argc,argv) 
  41.     int argc;
  42.     char *argv[];
  43.     {
  44.     int i, ret;
  45.     char *outfile;
  46.     int image=1,compress=0;
  47.     uint16 prevref, writeref=200;
  48.  
  49.     if (argc < 3) { 
  50.         printf("%s,  version: 1.0   date: December 1, 1988\n",argv[0]);
  51.         printf("  This utility will read in raster-8 images from an\n");
  52.         printf("  HDF file and create a new HDF containing the\n");
  53.         printf("  images in a compressed format.  Images will be\n");
  54.         printf("  appended to outfile, if it exists.\n\n");
  55.         puts("Usage:");
  56.         puts(" hdfcomp outfile {[-c],[-r],[-i]} imagefile ...\n");
  57.                 puts("                 {[-c],[-r],[-i]} imagefile\n");
  58.         puts("         -r: Store without compression (default)");
  59.         puts("         -c: Store using RLE compression");
  60.                 puts("         -i: Store using IMCOMP compression");
  61.         exit(1);
  62.     }
  63.  
  64.     outfile = argv[1];
  65.  
  66.     for (i=2; i<argc; i++) {
  67.         if (*argv[i]=='-') {
  68.             switch (argv[i][1]) {
  69.                 case 'r':               /* raster */
  70.                     image=1;
  71.                     compress=0;
  72.                     break;
  73.                 case 'c':               /* RLE */
  74.                     image = 1;
  75.                     compress = DFTAG_RLE;
  76.                     break;
  77.                 case 'i':               /* IMCOMP */
  78.                     image=1;
  79.                     compress=DFTAG_IMC;
  80.                     break;
  81.                 default:
  82.                     printf("Illegal option: %s, skipping....\n",argv[i]);   
  83.                     break;
  84.             }
  85.         }
  86.         else { /* file name */
  87.             while (DFR8getdims(argv[i], &xdim, &ydim, &ispal)>=0) {
  88.                 prevref = DFR8lastref();
  89.                 if (NULL == (space = malloc(xdim*ydim))) {
  90.                     puts("Not enough memory to convert image");
  91.                     exit(1);
  92.                 }
  93.                 if (DFR8getimage(argv[i], space, xdim, ydim, palette)<0) {
  94.                     printf("Error reading image from file %s\n",argv[i]);
  95.                     exit(1);
  96.                 }
  97.                 if (ispal) DFR8setpalette(palette);
  98.                 ret = DFR8writeref(outfile, writeref++);
  99.                 if (DFR8addimage(outfile, space, xdim, ydim, compress)<0) {
  100.                     printf("Error writing image to file %s\n",outfile);
  101.                     exit(1);
  102.                 }
  103.                 ret = DFR8readref(argv[i], prevref);
  104.                         /* sequence past this image */
  105.                 ret = DFR8getdims(argv[i], &xdim, &ydim, &ispal);
  106.             }
  107.         }
  108.     }
  109.  
  110.     return(0);
  111. }
  112.