384 |
|
{ |
385 |
|
if (cmap[0] && cmap[1]) { |
386 |
|
int num = 256; |
387 |
< |
if (xdepth == 15) |
388 |
< |
num = 32; |
389 |
< |
else if (xdepth == 16) |
390 |
< |
num = 64; |
387 |
> |
if (vis->c_class == DirectColor && VideoMonitor.mode.depth == VDEPTH_16BIT) |
388 |
> |
num = vis->map_entries; |
389 |
|
XStoreColors(x_display, cmap[0], palette, num); |
390 |
|
XStoreColors(x_display, cmap[1], palette, num); |
391 |
|
} |
1162 |
|
case 16: |
1163 |
|
case 24: |
1164 |
|
case 32: // Try DirectColor first, as this will allow gamma correction |
1165 |
< |
if (!XMatchVisualInfo(x_display, screen, xdepth, DirectColor, &visualInfo)) |
1165 |
> |
color_class = DirectColor; |
1166 |
> |
if (!XMatchVisualInfo(x_display, screen, xdepth, color_class, &visualInfo)) |
1167 |
|
color_class = TrueColor; |
1168 |
|
break; |
1169 |
|
default: |
1184 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
1185 |
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1186 |
|
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1187 |
+ |
|
1188 |
+ |
// Preset pixel members for gamma table |
1189 |
+ |
if (color_class == DirectColor) { |
1190 |
+ |
int num = vis->map_entries; |
1191 |
+ |
uint32 rmask = vis->red_mask, gmask = vis->green_mask, bmask = vis->blue_mask; |
1192 |
+ |
uint32 mask; |
1193 |
+ |
int rloss = 8, rshift = 0; |
1194 |
+ |
for (mask=rmask; !(mask&1); mask>>=1) |
1195 |
+ |
++rshift; |
1196 |
+ |
for (; mask&1; mask>>=1) |
1197 |
+ |
--rloss; |
1198 |
+ |
int gloss = 8, gshift = 0; |
1199 |
+ |
for (mask=gmask; !(mask&1); mask>>=1) |
1200 |
+ |
++gshift; |
1201 |
+ |
for (; mask&1; mask>>=1) |
1202 |
+ |
--gloss; |
1203 |
+ |
int bloss = 8, bshift = 0; |
1204 |
+ |
for (mask=bmask; !(mask&1); mask>>=1) |
1205 |
+ |
++bshift; |
1206 |
+ |
for (; mask&1; mask>>=1) |
1207 |
+ |
--bloss; |
1208 |
+ |
for (int i=0; i<num; i++) { |
1209 |
+ |
int c = (i * 256) / num; |
1210 |
+ |
palette[i].pixel = ((c >> rloss) << rshift) | ((c >> gloss) << gshift) | ((c >> bloss) << bshift); |
1211 |
+ |
} |
1212 |
+ |
} |
1213 |
|
} |
1214 |
|
|
1215 |
|
// Get screen mode from preferences |
1391 |
|
LOCK_PALETTE; |
1392 |
|
|
1393 |
|
// Convert colors to XColor array |
1394 |
< |
for (int i=0; i<256; i++) { |
1395 |
< |
palette[i].red = pal[i*3] * 0x0101; |
1396 |
< |
palette[i].green = pal[i*3+1] * 0x0101; |
1397 |
< |
palette[i].blue = pal[i*3+2] * 0x0101; |
1398 |
< |
palette[i].pixel = i; |
1399 |
< |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1394 |
> |
int num_in = 256, num_out = 256; |
1395 |
> |
if (VideoMonitor.mode.depth == VDEPTH_16BIT) { |
1396 |
> |
num_in = 32; |
1397 |
> |
// If X is in 565 mode we have to stretch the palette from 32 to 64 entries |
1398 |
> |
if (vis->c_class == DirectColor) |
1399 |
> |
num_out = vis->map_entries; |
1400 |
> |
} |
1401 |
> |
XColor *p = palette; |
1402 |
> |
for (int i=0; i<num_out; i++) { |
1403 |
> |
int c = (i * num_in) / num_out; |
1404 |
> |
p->red = pal[c*3 + 0] * 0x0101; |
1405 |
> |
p->green = pal[c*3 + 1] * 0x0101; |
1406 |
> |
p->blue = pal[c*3 + 2] * 0x0101; |
1407 |
> |
if (!IsDirectMode(VideoMonitor.mode)) |
1408 |
> |
p->pixel = i; |
1409 |
> |
p->flags = DoRed | DoGreen | DoBlue; |
1410 |
> |
p++; |
1411 |
|
} |
1412 |
|
|
1413 |
|
// Tell redraw thread to change palette |