summaryrefslogtreecommitdiff
path: root/xlib_api.c
diff options
context:
space:
mode:
authorStephane Marchesin <stephane.marchesin@gmail.com>2010-05-06 20:18:46 -0700
committerStephane Marchesin <stephane.marchesin@gmail.com>2010-05-06 20:18:46 -0700
commite206b83d96d7c247c19df36e1083b69588f7473a (patch)
tree5a682b71764cffeb9cb02f118295e83701ef251e /xlib_api.c
parentb296bdd13c2e326096d5ef777cb933ed91f20556 (diff)
Start implementing XParseColor
Diffstat (limited to 'xlib_api.c')
-rw-r--r--xlib_api.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/xlib_api.c b/xlib_api.c
index 351d058..67f13c5 100644
--- a/xlib_api.c
+++ b/xlib_api.c
@@ -3,7 +3,9 @@
#include "window.h"
#include "display.h"
#include "damage.h"
+#include "render.h"
#include "draw.h"
+#include "util.h"
Status XAllocColor(
Display* display,
@@ -190,7 +192,42 @@ Status XParseColor(
XColor* exact_def_return
)
{
- printf("parse color ok\n");
+ unsigned short r,g,b;
+ if (!spec)
+ return BadValue;
+ if (spec[0] == '#')
+ {
+ switch(strlen(spec))
+ {
+ case 4:
+ r = hexval(spec[1]) << 12;
+ g = hexval(spec[2]) << 12;
+ b = hexval(spec[3]) << 12;
+ break;
+ case 7:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 );
+ g = ( hexval(spec[3]) << 12 ) + ( hexval(spec[4]) << 8 );
+ b = ( hexval(spec[5]) << 12 ) + ( hexval(spec[6]) << 8 );
+ break;
+ case 10:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 ) + ( hexval(spec[3]) << 4 );
+ g = ( hexval(spec[4]) << 12 ) + ( hexval(spec[5]) << 8 ) + ( hexval(spec[6]) << 4 );
+ b = ( hexval(spec[7]) << 12 ) + ( hexval(spec[8]) << 8 ) + ( hexval(spec[9]) << 4 );
+ break;
+ case 13:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 ) + ( hexval(spec[3]) << 4 ) + hexval(spec[4]);
+ g = ( hexval(spec[5]) << 12 ) + ( hexval(spec[6]) << 8 ) + ( hexval(spec[7]) << 4 ) + hexval(spec[8]);
+ b = ( hexval(spec[9]) << 12 ) + ( hexval(spec[10]) << 8 ) + ( hexval(spec[11]) << 4 ) + hexval(spec[12]);
+ break;
+ default:
+ return BadValue;
+ }
+ printf("parse color ok %x-%x-%x\n",r>>8,g>>8,b>>8);
+ }
+ else
+ {
+ return BadValue;
+ }
}
int XPutImage(
@@ -216,7 +253,7 @@ int XPutImage(
handle = dlopen("/usr/lib/libX11.so.6", RTLD_LAZY);
if (!handle)
printf("can't open libX11\n");
- typedef GC (* XPutImagefunc) (Display*, Drawable, GC, XImage*, int, int, int, int, unsigned, unsigned);
+ typedef int (* XPutImagefunc) (Display*, Drawable, GC, XImage*, int, int, int, int, unsigned, unsigned);
XPutImagefunc XPutImagereal = dlsym(handle, "XPutImage");
return XPutImagereal(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height);
}