~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/glut/fbdev/colormap.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * Written by Sean D'Epagnier (c) 2006
25
25
 */
26
26
 
 
27
#include <stdio.h>
27
28
#include <stdlib.h>
28
29
 
29
30
#include <linux/fb.h>
37
38
#define TORMAP(x)(unsigned short)((x<0?0:x>1?1:x)*(GLfloat)(REVERSECMAPSIZE-1))
38
39
#define FROMCMAP(x) (GLfloat)x / (GLfloat)((1<<16) - 1)
39
40
 
40
 
static struct fb_cmap ColorMap;
 
41
static struct fb_cmap ColorMap, OriginalColorMap;
41
42
 
42
43
unsigned short RedColorMap[256], GreenColorMap[256], BlueColorMap[256];
43
44
 
91
92
 
92
93
void RestoreColorMap(void)
93
94
{
 
95
   if(FixedInfo.visual == FB_VISUAL_TRUECOLOR)
 
96
      return;
 
97
 
94
98
   if (ioctl(FrameBufferFD, FBIOPUTCMAP, (void *) &ColorMap) < 0)
95
99
      sprintf(exiterror, "ioctl(FBIOPUTCMAP) failed!\n");
96
100
}
97
101
 
98
102
void LoadColorMap(void)
99
103
{
100
 
   /* we're assuming 256 entries here */
101
 
   int i;
 
104
   if(FixedInfo.visual == FB_VISUAL_TRUECOLOR)
 
105
      return;
102
106
 
103
107
   ColorMap.start = 0;
104
 
   ColorMap.len = 256;
105
108
   ColorMap.red   = RedColorMap;
106
109
   ColorMap.green = GreenColorMap;
107
110
   ColorMap.blue  = BlueColorMap;
108
111
   ColorMap.transp = NULL;
109
112
 
110
 
   if (ioctl(FrameBufferFD, FBIOGETCMAP, (void *) &ColorMap) < 0)
111
 
      sprintf(exiterror, "ioctl(FBIOGETCMAP) failed!\n");
112
 
 
113
 
   switch(VarInfo.bits_per_pixel) {
114
 
   case 15:
115
 
      for(i=0; i<32; i++)
116
 
         RedColorMap[i] = GreenColorMap[i] = BlueColorMap[i] = i*65535/31;
117
 
      break;
118
 
   case 16:
119
 
      for(i=0; i<32; i++) 
120
 
         RedColorMap[i] = BlueColorMap[i] = i*65535/31;
121
 
      for(i=0; i<64; i++) 
122
 
         GreenColorMap[i] = i*65535/63;
123
 
      break;
124
 
   case 24:
125
 
   case 32:
126
 
      for(i=0; i<256; i++)
127
 
         RedColorMap[i] = GreenColorMap[i] = BlueColorMap[i] = i*257;
128
 
      break;
129
 
   }
130
 
 
131
 
   RestoreColorMap();
132
 
 
133
 
   if(DisplayMode & GLUT_INDEX)
 
113
   if(DisplayMode & GLUT_INDEX) {
 
114
      ColorMap.len = 256;
 
115
 
 
116
      if (ioctl(FrameBufferFD, FBIOGETCMAP, (void *) &ColorMap) < 0)
 
117
         sprintf(exiterror, "ioctl(FBIOGETCMAP) failed!\n");
 
118
 
134
119
      FillReverseColorMap();
 
120
   } else {
 
121
      int rcols = 1 << VarInfo.red.length;
 
122
      int gcols = 1 << VarInfo.green.length;
 
123
      int bcols = 1 << VarInfo.blue.length;
 
124
 
 
125
      int i;
 
126
 
 
127
      ColorMap.len = gcols;
 
128
 
 
129
      for (i = 0; i < rcols ; i++) 
 
130
         RedColorMap[i] = (65536/(rcols-1)) * i;
 
131
      
 
132
      for (i = 0; i < gcols ; i++) 
 
133
         GreenColorMap[i] = (65536/(gcols-1)) * i;
 
134
      
 
135
      for (i = 0; i < bcols ; i++) 
 
136
         BlueColorMap[i] = (65536/(bcols-1)) * i;  
 
137
 
 
138
      RestoreColorMap();
 
139
   }
135
140
}
136
141
 
137
142
void glutSetColor(int cell, GLfloat red, GLfloat green, GLfloat blue)