1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* hdftopal.c
* Version: 1.0 date: August 1, 1989
* This utility converts a palette from an HDF file
* to a raw palette in a raw palette file.
* The outgoing palette will have 768 bytes: First
* 256 red values, then 256 greens, then 256 blues.
*
* by Mike Folk
* first version of hdftopal: 8/01/89
*
* This program is in the public domain
*
*/
#include <stdlib.h>
#include "hdf.h"
int main(int argc, char *argv[]);
int rawpalconv(char *hdffile, char *rawpalfile);
int
main(int argc, char *argv[])
{
if (argc != 3) {
printf("Usage:\n");
printf(" %s hdffile rawpalfile \n\n", argv[0]);
printf("%s, version: 1.1 date: July 1, 1992\n\n", argv[0]);
printf(" This utility converts a palette from an HDF file \n");
printf(" to a raw palette in a raw palette file.\n\n");
printf(" The outgoing palette will have 768 bytes: First \n");
printf(" 256 red values, then 256 greens, then 256 blues.\n\n");
exit(1);
}
rawpalconv(argv[1], argv[2]);
return (0);
}
/*
* rawpalconv(palfile, outfile) sets the palette
*/
int
rawpalconv(char *hdffile, char *rawpalfile)
{
uint8 palspace[1024], reds[256], greens[256], blues[256], *p;
FILE *fp;
int j, ret;
ret = DFPgetpal(hdffile, (char *)palspace);
if (ret < 0) {
printf("Error in reading file %s\n", hdffile);
exit(1);
}
p = palspace;
for (j = 0; j < 256; j++) {
reds[j] = *p++;
greens[j] = *p++;
blues[j] = *p++;
}
fp = fopen(rawpalfile, "wb");
if (fp == NULL) {
printf("Error opening raw palette file %s\n", rawpalfile);
exit(1);
}
fwrite(reds, 1, 256, fp);
fwrite(greens, 1, 256, fp);
fwrite(blues, 1, 256, fp);
fclose(fp);
return (0);
}
|