home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / hdftopal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  4.1 KB  |  161 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/hdftopal.c,v 1.2 1992/07/15 21:48:48 sxu beta koziol $
  30.  
  31. $Log: hdftopal.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:50:03  mlivin
  36.  * Initial revision
  37.  *
  38.  * Revision 3.1  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.0  1990/02/02  20:31:12  clow
  66.  * *** empty log message ***
  67.  *
  68. */
  69. /*
  70. *  hdftopal.c
  71. *       Version: 1.0   date: August 1, 1989
  72. *       This utility converts a palette from an HDF file
  73. *       to a raw palette in a raw palette file.
  74. *       The outgoing palette will have 768 bytes: First
  75. *       256 red values, then 256 greens, then 256 blues.
  76. *
  77. *  by Mike Folk
  78. *  first version of hdftopal:   8/01/89
  79. *
  80. *  This program is in the public domain
  81. *
  82. */
  83.  
  84. #include "hdf.h"
  85.  
  86. #ifdef PROTOTYPE
  87. int main(int argc, char *argv[]);
  88. int rawpalconv(char *hdffile, char *rawpalfile);
  89. #else
  90. int main();
  91. int rawpalconv();
  92. #endif /* PROTOTYPE */
  93.  
  94. #ifdef PROTOTYPE
  95. main(int argc, char *argv[]) 
  96. #else
  97. main(argc,argv) 
  98. int argc;
  99. char *argv[];
  100. #endif /* PROTOTYPE */
  101. {
  102.     if (argc != 3) { 
  103.         printf("Usage:\n");
  104.         printf("   %s hdffile rawpalfile \n\n", argv[0]);
  105.         printf("%s,  version: 1.1   date: July 1, 1992\n\n",argv[0]);
  106.         printf("   This utility converts a palette from an HDF file \n");
  107.         printf("   to a raw palette in a raw palette file.\n\n");
  108.         printf("   The outgoing palette will have 768 bytes: First \n");
  109.         printf("   256 red values, then 256 greens, then 256 blues.\n\n");
  110.         exit(1);
  111.     }
  112.  
  113.     rawpalconv(argv[1], argv[2]);
  114. }
  115.  
  116. /*
  117.  *      rawpalconv(palfile, outfile) sets the palette
  118.  */
  119.  
  120. #ifdef PROTOTYPE
  121. rawpalconv(char *hdffile, char *rawpalfile)
  122. #else
  123. rawpalconv(hdffile, rawpalfile)
  124. char *hdffile, *rawpalfile;
  125. #endif /* PROTOTYPE */
  126. {
  127.     uint8 palspace[1024], reds[256], greens[256], blues[256], *p;
  128.     FILE *fp;
  129.     int j, ret;
  130.  
  131.     ret = DFPgetpal(hdffile, (char *) palspace);
  132.     if (ret < 0) {
  133.         printf("Error in reading file %s\n", hdffile);
  134.         exit(1);
  135.     }
  136.  
  137.     p = palspace;
  138.     for (j = 0; j < 256; j++) {
  139.         reds[j]   = *p++;
  140.         greens[j] = *p++;
  141.         blues[j]  = *p++;
  142.     }
  143.  
  144. #ifdef PC
  145.     fp = fopen(rawpalfile, "wb");    /* open in binary mode on PC */
  146. #else
  147.     fp = fopen(rawpalfile, "w");
  148. #endif
  149.     if (fp == NULL) {
  150.         printf("Error opening raw palette file %s\n", rawpalfile);
  151.         exit(1);
  152.     }
  153.  
  154.     fwrite(reds, 1, 256, fp);
  155.     fwrite(greens, 1, 256, fp);
  156.     fwrite(blues, 1, 256, fp);
  157.     fclose(fp);
  158.     return(0);
  159. }
  160.  
  161.