Enlightenment CVS committal

Author  : gilbertt
Project : misc
Module  : scrot

Dir     : misc/scrot/src


Modified Files:
        main.c options.c options.h scrot.h 


Log Message:

Wed Mar 12 13:20:11 GMT 2003  Tom Gilbert <[EMAIL PROTECTED]>

  * Patch from Claes Nasten <[EMAIL PROTECTED]>
  * Enhances thumbnail related options:
  "First, specifying -t would break the $f param to -exec.
   Second, the thumbnail and the screenshot got different timestamps.
   Third, one weren't able to specify geometry with -t.
  
   I fixed those and added, $m ( mini, instead of $t as it was taken ) so
   that one can do.
  
   $ scrot -t 91x0 -e 'echo $f,$m'
   2003-03-08-104735_800x600_scrot.png,2003-03-08-104735_91x68_scrot-thumb.png`
  
   About the geometry, having either the width or height set to 0 makes it
   fill in the other pertaining the aspect ratio.
  "
  * Once I update the docs I'll release 0.8


===================================================================
RCS file: /cvsroot/enlightenment/misc/scrot/src/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- main.c      25 Feb 2003 13:14:22 -0000      1.15
+++ main.c      12 Mar 2003 13:23:14 -0000      1.16
@@ -33,7 +33,10 @@
   Imlib_Image image;
   Imlib_Image thumbnail;
   Imlib_Load_Error err;
-  char *filename;
+  char *filename_im = NULL, *filename_thumb = NULL;
+
+  time_t t;
+  struct tm *tm;
 
   init_parse_options(argc, argv);
 
@@ -59,33 +62,64 @@
   if (!image)
     gib_eprintf("no image grabbed");
 
+  time(&t); /* Get the time directly after the screenshot */
+  tm = localtime(&t);
+
   imlib_context_set_image(image);
   imlib_image_attach_data_value("quality", NULL, opt.quality, NULL);
 
-  filename = im_printf(opt.output_file, NULL, image);
-  gib_imlib_save_image_with_error_return(image, filename, &err);
+  filename_im = im_printf(opt.output_file, tm, NULL, NULL, image);
+  gib_imlib_save_image_with_error_return(image, filename_im, &err);
   if (err)
-    gib_eprintf("Saving to file %s failed\n", filename);
-  if (opt.thumb) {
+    gib_eprintf("Saving to file %s failed\n", filename_im);
+  if (opt.thumb)
+  {
     int cwidth, cheight;
+    int twidth, theight;
 
     cwidth = gib_imlib_image_get_width(image);
     cheight = gib_imlib_image_get_height(image);
+
+    /* Geometry based thumb size */
+    if (opt.thumb_width || opt.thumb_height)
+    {
+      if (!opt.thumb_width)
+      {
+        twidth = cwidth * opt.thumb_height / cheight;
+        theight = opt.thumb_height;
+      }
+      else if (!opt.thumb_height)
+      {
+        twidth = opt.thumb_width;
+        theight = cheight * opt.thumb_width / cwidth;
+      }
+      else
+      {
+        twidth = opt.thumb_width;
+        theight = opt.thumb_height;
+      }
+    }
+    else
+    {
+      twidth = cwidth * opt.thumb / 100;
+      theight = cheight * opt.thumb / 100;
+    }
+
     thumbnail =
       gib_imlib_create_cropped_scaled_image(image, 0, 0, cwidth, cheight,
-                                            cwidth * opt.thumb / 100,
-                                            cheight * opt.thumb / 100, 1);
+                                            twidth, theight, 1);
     if (thumbnail == NULL)
       gib_eprintf("Unable to create scaled Image\n");
-    else {
-      filename = im_printf(opt.thumb_file, NULL, thumbnail);
-      gib_imlib_save_image_with_error_return(thumbnail, filename, &err);
+    else
+    {
+      filename_thumb = im_printf(opt.thumb_file, tm, NULL, NULL, thumbnail);
+      gib_imlib_save_image_with_error_return(thumbnail, filename_thumb, &err);
       if (err)
-        gib_eprintf("Saving thumbnail %s failed\n", filename);
+        gib_eprintf("Saving thumbnail %s failed\n", filename_thumb);
     }
   }
   if (opt.exec)
-    scrot_exec_app(image, filename);
+    scrot_exec_app(image, tm, filename_im, filename_thumb);
   gib_imlib_free_image_and_decache(image);
 
   return 0;
@@ -126,12 +160,12 @@
 }
 
 void
-scrot_exec_app(Imlib_Image im,
-               char *filename)
+scrot_exec_app(Imlib_Image image, struct tm *tm,
+               char *filename_im, char *filename_thumb)
 {
   char *execstr;
 
-  execstr = im_printf(opt.exec, filename, im);
+  execstr = im_printf(opt.exec, tm, filename_im, filename_thumb, image);
   system(execstr);
   exit(0);
 }
@@ -371,8 +405,9 @@
 
 
 char *
-im_printf(char *str,
-          char *filename,
+im_printf(char *str, struct tm *tm,
+          char *filename_im,
+          char *filename_thumb,
           Imlib_Image im)
 {
   char *c;
@@ -381,12 +416,8 @@
   char strf[4096];
   char *tmp;
   struct stat st;
-  time_t t;
-  struct tm *tm;
 
   ret[0] = '\0';
-  time(&t);
-  tm = localtime(&t);
   strftime(strf, 4095, str, tm);
 
   for (c = strf; *c != '\0'; c++) {
@@ -394,16 +425,20 @@
       c++;
       switch (*c) {
         case 'f':
-          if (filename)
-            strcat(ret, filename);
+          if (filename_im)
+            strcat(ret, filename_im);
+          break;
+        case 'm': /* t was allready taken, so m as in mini */
+          if (filename_thumb)
+            strcat(ret, filename_thumb);
           break;
         case 'n':
-          if (filename) {
-            tmp = strrchr(filename, '/');
+          if (filename_im) {
+            tmp = strrchr(filename_im, '/');
             if (tmp)
               strcat(ret, tmp + 1);
             else
-              strcat(ret, filename);
+              strcat(ret, filename_im);
           }
           break;
         case 'w':
@@ -415,8 +450,8 @@
           strcat(ret, buf);
           break;
         case 's':
-          if (filename) {
-            if (!stat(filename, &st)) {
+          if (filename_im) {
+            if (!stat(filename_im, &st)) {
               int size;
 
               size = st.st_size;
@@ -446,7 +481,7 @@
       c++;
       switch (*c) {
         case 'n':
-          if (filename)
+          if (filename_im)
             strcat(ret, "\n");
           break;
         default:
===================================================================
RCS file: /cvsroot/enlightenment/misc/scrot/src/options.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- options.c   25 Feb 2003 13:14:23 -0000      1.19
+++ options.c   12 Mar 2003 13:23:15 -0000      1.20
@@ -102,11 +102,7 @@
            opt.countdown = 1;
            break;
         case 't':
-           opt.thumb = atoi(optarg);
-           if (opt.thumb < 1)
-              opt.thumb = 1;
-           if (opt.thumb > 100)
-              opt.thumb = 100;
+           options_parse_thumbnail(optarg);
            break;
         default:
            break;
@@ -159,6 +155,42 @@
       sprintf(new_title, "%s-thumb", name);
 
    return new_title;
+}
+
+void
+options_parse_thumbnail(char *optarg)
+{
+   char *tok;
+
+   if (strchr(optarg, 'x')) /* We want to specify the geometry */
+   {
+     tok = strtok(optarg, "x");
+     opt.thumb_width = atoi(tok);
+     tok = strtok(NULL, "x");
+     if (tok)
+     {
+       opt.thumb_width = atoi(optarg);
+       opt.thumb_height = atoi(tok);
+
+       if (opt.thumb_width < 0)
+         opt.thumb_width = 1;
+       if (opt.thumb_height < 0)
+         opt.thumb_height = 1;
+
+       if (!opt.thumb_width && !opt.thumb_height)
+         opt.thumb = 0;
+       else
+         opt.thumb = 1;
+     }
+   }
+   else
+   {
+     opt.thumb = atoi(optarg);
+     if (opt.thumb < 1)
+       opt.thumb = 1;
+     else if (opt.thumb > 100)
+       opt.thumb = 100;
+   }
 }
 
 void
===================================================================
RCS file: /cvsroot/enlightenment/misc/scrot/src/options.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- options.h   11 Jan 2001 17:44:55 -0000      1.10
+++ options.h   12 Mar 2003 13:23:15 -0000      1.11
@@ -36,14 +36,16 @@
    int border;
    int multidisp;
    int thumb;
-
+   int thumb_width;
+   int thumb_height;
    char *output_file;
    char *thumb_file;
    char *exec;
 };
 
 void init_parse_options(int argc, char **argv);
-char *name_thumbnail(char *);
+char *name_thumbnail(char *name);
+void options_parse_thumbnail(char *optarg);
 extern scrotoptions opt;
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/scrot/src/scrot.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- scrot.h     29 Aug 2001 18:43:07 -0000      1.12
+++ scrot.h     12 Mar 2003 13:23:15 -0000      1.13
@@ -68,7 +68,8 @@
 void init_x_and_imlib(char *dispstr, int screen_num);
 char *chop_file_from_full_path(char *str);
 Imlib_Image scrot_grab_shot(void);
-void scrot_exec_app(Imlib_Image im, char *filename);
+void scrot_exec_app(Imlib_Image image, struct tm *tm,
+                    char *filename_im, char *filename_thumb);
 void scrot_do_delay(void);
 Imlib_Image scrot_sel_and_grab_image(void);
 void scrot_sel_area(int *x, int *y, int *w, int *h);
@@ -76,7 +77,9 @@
 Window scrot_get_client_window(Display * display, Window target);
 Window scrot_find_window_by_property(Display * display, const Window window,
                                      const Atom property);
-char *im_printf(char *str, char *filename, Imlib_Image im);
+char *im_printf(char *str, struct tm *tm,
+                char *filename_im, char *filename_thumb,
+                Imlib_Image im);
 Imlib_Image scrot_grab_shot_multi(void);
 Imlib_Image stalk_image_concat(gib_list *images);
 




-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to