]> www.wagner.pp.ru Git - oss/fgis.git/blob - lib/clr.c
*** empty log message ***
[oss/fgis.git] / lib / clr.c
1 /******************************************************************************
2  * $Id: clr.c,v 1.2 2003-01-07 10:59:52 dron Exp $
3  *
4  * Project:  Library fo reading EPPL7 file format
5  * Purpose:  Read palette from the EPPL7 file
6  *
7  ******************************************************************************
8  *
9  * Copyright (C) 1997, Victor Wagner <vitus@ice.ru>
10  * Copyright (C) 2003, Andrey Kiselev <dron@remotesensing.org>
11  *
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)
15  * any later version.
16  *
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.
21  *
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,
25  * USA.
26  *****************************************************************************
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include "eppl_ut.h"
32 #include <clr.h>
33 #include <X11/Xlib.h>
34 static int defarray[]={
35 #include "defpal.h"
36 };
37 PALETTE default_palette=defarray;
38 PALETTE read_palette(FILE *f)
39 /* Read palette from the EPPL7 file */
40 { PALETTE pal;
41   int index,r,g,b;
42   pal=memcpy(malloc(256*sizeof(long int)),default_palette,256*sizeof(long int));
43   do {
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);
47   } while (!feof(f));
48   return pal;
49 }
50
51 char *ppm_pixel(PALETTE palette,int index)
52 { int value;
53   static char buffer[24];
54   if(index>=0&&index<255)
55   value=palette[index];
56   else value=palette[255];
57   sprintf(buffer,"%d %d %d ",value>>16,(value>>8)&0xFF,value & 0xFF);
58   return buffer;
59 }
60
61 /* char *Xcolor_string(PALETTE palette,int index)
62 { int value;
63   static char buffer[24];
64   if(index>=0&&index<255)
65   value=palette[index]; else value=palette[255];
66   sprintf(buffer,"#%06x",value);
67   return buffer;
68 }*/
69
70 XColor Xcolor_struct(PALETTE palette,int index)
71 { int value;
72   XColor buffer;
73   if (index>=0&&index<255)
74    value=palette[index]; else value=palette[255];
75   buffer.red=value>>16;
76   buffer.green=(value>>8)&0xFF;
77   buffer.blue=value&0xFF;
78   buffer.flags=DoRed|DoGreen|DoBlue;
79   return buffer;
80 }
81