home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / paltohdf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-02  |  4.1 KB  |  157 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/paltohdf.c,v 1.2 1992/07/15 21:48:48 sxu beta koziol $
  30.  
  31. $Log: paltohdf.c,v $
  32.  * Revision 1.2  1992/07/15  21:48:48  sxu
  33.  * No change.
  34.  *
  35.  * Revision 1.1  1992/07/01  20:50:03  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:58:31  clow
  66.  * some cosmetic modifications
  67.  *
  68. */
  69. /*
  70. *  paltohdf.c
  71. *       Version: 1.0   date: August 1, 1989
  72. *       This utility converts a raw palette to hdf format 
  73. *       The incoming palette is assumed to have 768 bytes:
  74. *          256 red values, 256 greens, and 256 blues.
  75. *          The palette in the HDF file will have the RGB values
  76. *          interlaced: RGB RGB ... (This is standard HDF format.)
  77. *
  78. *  by Mike Folk
  79. *  first version of paltohdf:   8/01/89
  80. *
  81. *  This program is in the public domain
  82. */
  83.  
  84. #include "hdf.h"
  85.  
  86. #ifdef PROTOTYPE
  87. int main(int argc, char *argv[]);
  88. int palconv(char *palfile, char *outfile);
  89. #else
  90. int main();
  91. int palconv();
  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 rawpalfile hdffile \n\n", argv[0]);
  105.             printf("%s,  version: 1.1   date: July 1, 1992\n\n", argv[0]);
  106.             printf("\tThis utility converts a raw palette to hdf format \n\n");
  107.             printf("\tThe incoming palette is assumed to have 768 bytes:\n");
  108.             printf("\t256 red values, 256 greens, and 256 blues.\n\n");
  109.             printf("\tThe palette in the HDF file will have the RGB values\n");
  110.             printf("\tinterlaced: RGB RGB ... (standard HDF format).\n\n");
  111.         exit(1);
  112.     }
  113.  
  114.     palconv(argv[1], argv[2]);
  115. }
  116.  
  117. /*
  118.  *    palconv(palfile, outfile) sets the palette
  119.  */
  120.  
  121. #ifdef PROTOTYPE
  122. palconv(char *palfile, char *outfile)
  123. #else
  124. palconv(palfile, outfile)
  125. char *palfile, *outfile;
  126. #endif /* PROTOTYPE */
  127. {
  128.     unsigned char palspace[1024], reds[256], greens[256], blues[256], *p;
  129.     FILE *fp;
  130.     int j, ret;
  131.  
  132.     fp = fopen(palfile, "r");
  133.     if (fp == NULL) {
  134.         printf(" Error opening palette file %s\n", palfile);
  135.         exit(1);
  136.     }
  137.     fread(reds, 1, 256, fp);
  138.     fread(greens, 1, 256, fp);
  139.     fread(blues, 1, 256, fp);
  140.     fclose(fp);
  141.  
  142.     p = palspace;
  143.     for (j = 0; j < 256; j++) {
  144.         *p++ = reds[j];
  145.         *p++ = greens[j];
  146.         *p++ = blues[j];
  147.     }
  148.  
  149.     ret = DFPaddpal(outfile, (VOIDP)palspace);
  150.     if (ret < 0) {
  151.         printf(" Error: %d, in writing palette %s\n", ret, palfile);
  152.         exit(1);
  153.     }
  154.     return(0);
  155. }
  156.  
  157.