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

  1. /*****************************************************************************
  2. *              NCSA HDF version 3.10r5
  3. *                 October 24, 1991
  4. *
  5. * NCSA HDF Version 3.10r5 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. #ifdef RCSID
  17. static char RcsId[] = "@(#) $Revision: 3.2 $"
  18. #endif
  19. /*
  20. $Header: /pita/work/HDF/dev/RCS/src/paltohdf.c,v 3.2 1991/10/22 17:56:10 dilg beta $
  21.  
  22. $Log: paltohdf.c,v $
  23.  * Revision 3.2  1991/10/22  17:56:10  dilg
  24.  * 5
  25.  * HDF3.1r5
  26.  *
  27.  * New machine types added:
  28.  *
  29.  *         PC      - IBM PC (DOS)
  30.  *         WIN     - IBM PC (Microsoft Windows 3.0)
  31.  *         IBM6000 - IBM RS/6000 (AIX)
  32.  *         CONVEX  - Convex C-2 (Unix)
  33.  *
  34.  * Bugs fixed in:
  35.  *
  36.  *         scup32.f
  37.  *         cspck32.f
  38.  *         dfpFf.f
  39.  *         dfpF.c
  40.  *         dfsd.c
  41.  *
  42.  * New utility added:
  43.  *
  44.  *         ristosds.c - convert raster images to sds.
  45.  *
  46.  * Also:
  47.  *         All code for the library was modified to conform to the
  48.  *         ANSI C standard.
  49.  *
  50.  * Revision 3.1  1990/07/02  10:58:31  clow
  51.  * some cosmetic modifications
  52.  *
  53. */
  54. /*
  55. *  paltohdf.c
  56. *       Version: 1.0   date: August 1, 1989
  57. *       This utility converts a raw palette to hdf format 
  58. *       The incoming palette is assumed to have 768 bytes:
  59. *          256 red values, 256 greens, and 256 blues.
  60. *          The palette in the HDF file will have the RGB values
  61. *          interlaced: RGB RGB ... (This is standard HDF format.)
  62. *
  63. *  by Mike Folk
  64. *  first version of paltohdf:   8/01/89
  65. *
  66. *  This program is in the public domain
  67. */
  68.  
  69. #include <stdio.h>
  70. #include <hdf/df.h>
  71. #include <hdf/dfp.h>
  72.  
  73. unsigned char palspace[1024],
  74.             reds[256],
  75.             greens[256],
  76.             blues[256];
  77.  
  78.  
  79. #if defined __STDC__ || defined PC
  80. int main(int, char **);
  81. int palconv(char *, char *);
  82. #else
  83. int main();
  84. int palconv();
  85. #endif /* __STDC__ || PC */
  86.  
  87. #if defined __STDC__ || defined PC
  88. main(int argc, char *argv[]) 
  89. #else
  90. main(argc,argv) 
  91. int argc;
  92. char *argv[];
  93. #endif /* __STDC__ || PC */
  94. {
  95.     if (argc < 3) { 
  96.         puts("Usage:");
  97.         printf("   %s rawpalfile hdffile \n\n", argv[0]);
  98.         printf("%s,  version: 1.0   date: August 1, 1989\n\n",argv[0]);
  99.         printf("   This utility converts a raw palette to hdf format \n\n");
  100.         printf("   The incoming palette is assumed to have 768 bytes:\n");
  101.         printf("   256 red values, 256 greens, and 256 blues.\n\n");
  102.         printf("   The palette in the HDF file will have the RGB values\n");
  103.         printf("   interlaced: RGB RGB ... (This is standard HDF format.\n\n");
  104.         exit(1);
  105.     }
  106.  
  107.     palconv( argv[1], argv[2]);
  108. }
  109.  
  110. /*
  111.  *    palconv(palfile, outfile) sets the palette
  112.  */
  113.  
  114. #if defined __STDC__ || defined PC
  115. palconv(char *palfile, char *outfile)
  116. #else
  117. palconv( palfile,outfile)
  118. char *palfile, *outfile;
  119. #endif /* __STDC__ || PC */
  120. {
  121.     unsigned char *p;
  122.     FILE *fp;
  123.     int j,ret;
  124.  
  125.     fp = fopen(palfile,"r");
  126.     if (fp==NULL) {
  127.         printf(" Error opening palette file %s\n", palfile);
  128.         exit(1);
  129.     }
  130.     fread(reds,1,256,fp);
  131.     fread(greens,1,256,fp);
  132.     fread(blues,1,256,fp);
  133.     fclose(fp);
  134.  
  135.     p = palspace;
  136.     for (j=0; j<256; j++) {
  137.         *p++ = reds[j];
  138.         *p++ = greens[j];
  139.         *p++ = blues[j];
  140.     }
  141.  
  142.     ret = DFPaddpal(outfile, palspace);
  143.     if (ret < 0) {
  144.         printf(" Error: %d, in writing palette %s\n",ret, palfile);
  145.         exit(1);
  146.     }
  147.     return(0);
  148. }
  149.  
  150.