cf8 avatar cf8 committed 0c3ff94

initial

Comments (0)

Files changed (2)

+## getcolor
+
+
+A simple utility to get a color of certain pixel on the screen.
+
+## Compiling
+
+Just run :
+
+    gcc -Wall gc.c -o gc -lX11
+
+and you are done.
+
+## Usage
+
+    $ ./gc 1 1 
+    #262626
+#include <X11/Xlib.h>
+#include <stdio.h>
+
+void get_pixel_color (Display *display, int x, int y, XColor *color)
+{
+  XImage *image;
+  image = XGetImage (display, DefaultRootWindow (display), x, y, 1, 1, AllPlanes, XYPixmap);
+  color->pixel = XGetPixel (image, 0, 0);
+  XFree (image);
+  XQueryColor (display, DefaultColormap(display, DefaultScreen (display)), color);
+}
+
+int main(int argc, char *argv[]) {
+  XColor c;
+  Display *d;
+  d = XOpenDisplay(NULL);
+  int x,y,r,g,b;
+
+  if (d == NULL) {
+    fprintf (stderr, "Can't open display!\n");
+    return -1;
+  }
+
+  if ( argc < 2 ) {
+    fprintf (stderr, "Shoo shoo! You must input X and Y!\n");
+    return -1;
+  }
+
+  x = atoi(argv[1]);
+  y = atoi(argv[2]);
+
+  get_pixel_color(d, x, y, &c);
+
+  r=(c.red >> 8);
+  g=(c.green >> 8);
+  b=(c.blue >> 8);
+
+  printf ("#%02x%02x%02x\n", r, g, b);
+  return 1;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.