blob: 0e3c8d89d49b5875b786f67b13ae3f8e79d32ef1 (
plain)
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
|
/* Copyright (c) 2004 Russ Cox, see README for licence details */
#include <stdio.h>
#include <signal.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "dat.h"
#include "fns.h"
unsigned long
colorpixel(Display *dpy, int depth, unsigned long rgb)
{
int r, g, b;
r = rgb>>16;
g = (rgb>>8)&0xFF;
b = rgb&0xFF;
switch(depth){
case 1:
case 2:
case 4:
case 8:
default:
/* not going to waste color map entries */
if(rgb == 0xFFFFFF)
return WhitePixel(dpy, DefaultScreen(dpy));
return BlackPixel(dpy, DefaultScreen(dpy));
case 15:
r >>= 3;
g >>= 3;
b >>= 3;
return (r<<10) | (g<<5) | b;
case 16:
r >>= 3;
g >>= 2;
b >>= 3;
return (r<<11) | (g<<5) | b;
case 24:
case 32:
return rgb;
}
}
|