1 /******************************************************************************
2 * $Id: clr.c,v 1.2 2003-01-07 10:59:52 dron Exp $
4 * Project: Library fo reading EPPL7 file format
5 * Purpose: Read palette from the EPPL7 file
7 ******************************************************************************
9 * Copyright (C) 1997, Victor Wagner <vitus@ice.ru>
10 * Copyright (C) 2003, Andrey Kiselev <dron@remotesensing.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 *****************************************************************************
34 static int defarray[]={
37 PALETTE default_palette=defarray;
38 PALETTE read_palette(FILE *f)
39 /* Read palette from the EPPL7 file */
42 pal=memcpy(malloc(256*sizeof(long int)),default_palette,256*sizeof(long int));
44 if (fscanf(f,"%d %d %d %d\n",&index,&r,&g,&b)!=4) break;
45 if (index>255) continue;
46 pal[index]=(r*255/1000)<<16|(g*255/1000)<<8|(b*255/1000);
51 char *ppm_pixel(PALETTE palette,int index)
53 static char buffer[24];
54 if(index>=0&&index<255)
56 else value=palette[255];
57 sprintf(buffer,"%d %d %d ",value>>16,(value>>8)&0xFF,value & 0xFF);
61 /* char *Xcolor_string(PALETTE palette,int index)
63 static char buffer[24];
64 if(index>=0&&index<255)
65 value=palette[index]; else value=palette[255];
66 sprintf(buffer,"#%06x",value);
70 XColor Xcolor_struct(PALETTE palette,int index)
73 if (index>=0&&index<255)
74 value=palette[index]; else value=palette[255];
76 buffer.green=(value>>8)&0xFF;
77 buffer.blue=value&0xFF;
78 buffer.flags=DoRed|DoGreen|DoBlue;