Enlightenment CVS committal

Author  : kwo
Project : e17
Module  : libs/imlib2

Dir     : e17/libs/imlib2/src/bin


Modified Files:
        imlib2_grab.c 


Log Message:
Add some options:
 -id <drawable> to grab other than root window.
 -w/width       set output image width.
 -h/height      set output image height.
 -noshape       do not use window shape.
 -help          show usage.
 -v             show info about the grabbed drawable.

===================================================================
RCS file: /cvs/e/e17/libs/imlib2/src/bin/imlib2_grab.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- imlib2_grab.c       28 Jul 2005 04:15:11 -0000      1.1
+++ imlib2_grab.c       18 May 2006 20:59:17 -0000      1.2
@@ -20,18 +20,87 @@
 int                 depth;
 int                 image_width = 0, image_height = 0;
 
+static void
+usage(void)
+{
+   printf("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] 
[-height <height>] [-noshape] <output file>\n");
+}
+
 int
 main(int argc, char **argv)
 {
+   char               *s;
    Imlib_Image        *im = NULL;
    char               *file = NULL;
-   int                 no = 1;
+   int                 verbose;
+   int                 get_alpha;
    const char         *display_name = getenv("DISPLAY");
+   Drawable            draw;
+   int                 x, y;
+   unsigned int        w, h, bw, depth;
+   unsigned int        wo, ho;
+   Window              rr;
 
-   if (argc < 2)
-      return 1;
+   verbose = 0;
+   get_alpha = 1;
+   draw = None;
+   wo = ho = 0;
+
+   for (;;)
+     {
+        argc--;
+        argv++;
+        if (argc <= 0)
+           break;
+        s = argv[0];
+        if (*s++ != '-')
+           break;
+        if (!strcmp(s, "id"))
+          {
+             argc--;
+             argv++;
+             if (argc <= 1)
+                break;
+             draw = strtoul(argv[0], NULL, 0);
+          }
+        else if (!strcmp(s, "w") || !strcmp(s, "width"))
+          {
+             argc--;
+             argv++;
+             if (argc <= 1)
+                break;
+             wo = strtoul(argv[0], NULL, 0);
+          }
+        else if (!strcmp(s, "h") || !strcmp(s, "height"))
+          {
+             argc--;
+             argv++;
+             if (argc <= 1)
+                break;
+             ho = strtoul(argv[0], NULL, 0);
+          }
+        else if (!strcmp(s, "noshape"))
+          {
+             get_alpha = 0;
+          }
+        else if (!strcmp(s, "v"))
+          {
+             verbose = 1;
+          }
+        else if (!strcmp(s, "help"))
+          {
+             usage();
+             return 0;
+          }
+     }
+   if (argc <= 0)
+     {
+        usage();
+        return 1;
+     }
+
+   file = argv[0];
 
-   file = argv[no];
    if (display_name == NULL)
        display_name = ":0";
    disp = XOpenDisplay(display_name);
@@ -40,26 +109,44 @@
        fprintf(stderr, "Can't open display %s\n", display_name);
        return 1;
      }
+
    vis = DefaultVisual(disp, DefaultScreen(disp));
    depth = DefaultDepth(disp, DefaultScreen(disp));
    cm = DefaultColormap(disp, DefaultScreen(disp));
    imlib_context_set_display(disp);
    imlib_context_set_visual(vis);
    imlib_context_set_colormap(cm);
-   imlib_context_set_drawable(DefaultRootWindow(disp));
-   im = imlib_create_image_from_drawable(0, 0, 0, 
-                                        DisplayWidth(disp, 
DefaultScreen(disp)),
-                                        DisplayHeight(disp, 
DefaultScreen(disp)),
-                                        1);
+
+   if (draw == None)
+      draw = DefaultRootWindow(disp);
+   imlib_context_set_drawable(draw);
+
+   XGetGeometry(disp, draw, &rr, &x, &y, &w, &h, &bw, &depth);
+   if (wo == 0)
+     wo = w;
+   if (ho == 0)
+     ho = h;
+   if (verbose)
+     {
+        printf("Drawable: %#lx: x,y: %d,%d  wxh=%ux%u  bw=%u  depth=%u\n",
+               draw, x, y, w, h, bw, depth);
+        if ((wo != w) || (ho != h))
+           printf("Output  : wxh=%ux%u\n", wo, ho);
+     }
+
+   if ((wo != w) || (ho != h))
+      im = imlib_create_scaled_image_from_drawable(None, 0, 0, w, h, wo, ho, 1,
+                                                   (get_alpha) ? 1 : 0);
+   else
+      im = imlib_create_image_from_drawable((get_alpha) ? 1 : 0, 0, 0, w, h, 
1);
    if (!im)
      {
         fprintf(stderr, "Cannot grab image!\n");
         exit(0);
      }
-   if (argc > 1)
-     {
-       imlib_context_set_image(im);
-       imlib_save_image(argv[1]);
-     }
+
+   imlib_context_set_image(im);
+   imlib_save_image(file);
+
    return 0;
 }




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to