http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / webcollage-helper.c
index 99bd78292b5637315165057467270e6c06af0ea3..a661b3a41f278b0d78a84aa8ea2297a134ee6d39 100644 (file)
@@ -1,5 +1,5 @@
 /* webcollage-helper --- scales and pastes one image into another
- * xscreensaver, Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 2002, 2003 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -33,6 +33,31 @@ static int verbose_p = 0;
 static void add_jpeg_comment (struct jpeg_compress_struct *cinfo);
 static void write_pixbuf (GdkPixbuf *pb, const char *file);
 
+static GdkPixbuf *
+load_pixbuf (const char *file)
+{
+  GdkPixbuf *pb;
+#ifdef HAVE_GTK2
+  GError *err = NULL;
+
+  pb = gdk_pixbuf_new_from_file (file, &err);
+#else  /* !HAVE_GTK2 */
+  pb = gdk_pixbuf_new_from_file (file);
+#endif /* HAVE_GTK2 */
+
+  if (!pb)
+    {
+#ifdef HAVE_GTK2
+      fprintf (stderr, "%s: %s\n", progname, err->message);
+      g_error_free (err);
+#else  /* !HAVE_GTK2 */
+      fprintf (stderr, "%s: unable to load %s\n", progname, file);
+#endif /* !HAVE_GTK2 */
+      exit (1);
+    }
+
+  return pb;
+}
 
 static void
 paste (const char *paste_file,
@@ -48,20 +73,8 @@ paste (const char *paste_file,
   int paste_w, paste_h;
   int base_w, base_h;
 
-  paste_pb = gdk_pixbuf_new_from_file (paste_file);
-
-  if (!paste_pb)
-    {
-      fprintf (stderr, "%s: unable to load %s\n", progname, paste_file);
-      exit (1);
-    }
-
-  base_pb = gdk_pixbuf_new_from_file (base_file);
-  if (!base_pb)
-    {
-      fprintf (stderr, "%s: unable to load %s\n", progname, base_file);
-      exit (1);
-    }
+  paste_pb = load_pixbuf (paste_file);
+  base_pb  = load_pixbuf (base_file);
 
   paste_w = gdk_pixbuf_get_width (paste_pb);
   paste_h = gdk_pixbuf_get_height (paste_pb);
@@ -210,7 +223,7 @@ write_pixbuf (GdkPixbuf *pb, const char *file)
 
   if (channels != 3)
     {
-      fprintf (stderr, "%s: %d channels?\n", progname);
+      fprintf (stderr, "%s: %d channels?\n", progname, channels);
       exit (1);
     }
 
@@ -266,7 +279,7 @@ write_pixbuf (GdkPixbuf *pb, const char *file)
           perror (buf);
           exit (1);
         }
-      fprintf (stderr, " %dK\n", (st.st_size + 1023) / 1024);
+      fprintf (stderr, " %luK\n", (st.st_size + 1023) / 1024);
     }
 
   fclose (out);
@@ -289,7 +302,9 @@ add_jpeg_comment (struct jpeg_compress_struct *cinfo)
     "\r\n";
   char comment[sizeof(fmt) + 100];
   strftime (comment, sizeof(comment)-1, fmt, tm);
-  jpeg_write_marker (cinfo, JPEG_COM, comment, strlen (comment));
+  jpeg_write_marker (cinfo, JPEG_COM,
+                     (unsigned char *) comment,
+                     strlen (comment));
 }
 
 
@@ -350,6 +365,10 @@ main (int argc, char **argv)
   if (w < 0) usage();
   if (h < 0) usage();
 
+#ifdef HAVE_GTK2
+  g_type_init ();
+#endif /* HAVE_GTK2 */
+
   paste (paste_file, base_file,
          from_scale, opacity,
          from_x, from_y, to_x, to_y,