X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fwebcollage-helper.c;h=19786ba129f3204bdc08e5a293bc0fec631a9801;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=7c686db94c08d0e65f53a193195b1a7d763cb8db;hpb=9c9d475ff889ed8be02e8ce8c17da28b93278fca;p=xscreensaver diff --git a/hacks/webcollage-helper.c b/hacks/webcollage-helper.c index 7c686db9..19786ba1 100644 --- a/hacks/webcollage-helper.c +++ b/hacks/webcollage-helper.c @@ -1,5 +1,5 @@ /* webcollage-helper --- scales and pastes one image into another - * xscreensaver, Copyright (c) 2002, 2003, 2004 Jamie Zawinski + * xscreensaver, Copyright (c) 2002-2005 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -10,6 +10,10 @@ * implied warranty. */ +/* This is the GDK + JPEGlib implementation. See webcollage-helper-cocoa.m + for the Cocoa implementation. + */ + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -24,6 +28,7 @@ #include #include +#undef HAVE_STDLIB_H /* stupid jconfig.h! */ #include #include @@ -66,17 +71,21 @@ bevel_image (GdkPixbuf **pbP, int bevel_pct, int x, int y, int w, int h) { GdkPixbuf *pb = *pbP; + int small_size = (w > h ? h : w); - int bevel_size = (w > h ? h : w) * (bevel_pct / 100.0); + int bevel_size = small_size * (bevel_pct / 100.0); - if (bevel_size < 10) /* too small to bother */ + /* Use a proportionally larger bevel size for especially small images. */ + if (bevel_size < 20 && small_size > 40) bevel_size = 20; + else if (bevel_size < 10 && small_size > 20) bevel_size = 10; + else if (bevel_size < 5) /* too small to bother bevelling */ return; /* Ensure the pixbuf has an alpha channel. */ if (! gdk_pixbuf_get_has_alpha (pb)) { GdkPixbuf *pb2 = gdk_pixbuf_add_alpha (pb, FALSE, 0, 0, 0); - gdk_pixbuf_unref (pb); + g_object_unref (pb); pb = pb2; } @@ -127,25 +136,24 @@ bevel_image (GdkPixbuf **pbP, int bevel_pct, if (r != 1) p[ch-1] *= r; - /* p[0]=p[1]=p[2]=0; / * #### */ - p += ch; } line += rs; } #if 0 /* show the ramp */ - for (xx = 0; xx < bevel_size * 2; xx++) + line = data + (rs * y); + for (yy = 0; yy < h; yy++) { - int ii = (256 * (xx >= bevel_size ? 1 : ramp[xx])); - int yy; - for (yy = 0; yy < ii; yy++) + guchar *p = line + (x * ch); + for (xx = 0; xx < w; xx++) { - data [((y + (256-yy)) * rs) + ((x + xx) * ch) + 0] = 0; - data [((y + (256-yy)) * rs) + ((x + xx) * ch) + 1] = 0; - data [((y + (256-yy)) * rs) + ((x + xx) * ch) + 2] = 0; - data [((y + (256-yy)) * rs) + ((x + xx) * ch) + 3] = 255; + int cc = 0; + for (cc = 0; cc < ch-1; cc++) + p[cc] = 255; + p += ch; } + line += rs; } #endif @@ -197,7 +205,7 @@ paste (const char *paste_file, int new_h = paste_h * from_scale; GdkPixbuf *new_pb = gdk_pixbuf_scale_simple (paste_pb, new_w, new_h, GDK_INTERP_HYPER); - gdk_pixbuf_unref (paste_pb); + g_object_unref (paste_pb); paste_pb = new_pb; paste_w = gdk_pixbuf_get_width (paste_pb); paste_h = gdk_pixbuf_get_height (paste_pb); @@ -294,20 +302,30 @@ paste (const char *paste_file, base_pb, to_x, to_y); else - gdk_pixbuf_composite (paste_pb, base_pb, - to_x, to_y, w, h, - to_x - from_x, to_y - from_y, - 1.0, 1.0, - GDK_INTERP_HYPER, - opacity * 255); + { + from_x++; /* gdk_pixbuf_composite gets confused about the bevel: */ + from_y++; /* it leaves a stripe on the top and left if we try to */ + to_x++; /* start at 0,0, so pull it right and down by 1 pixel. */ + to_y++; /* (problem seen in gtk2-2.4.14-2.fc3) */ + w--; + h--; + + if (w > 0 && h > 0) + gdk_pixbuf_composite (paste_pb, base_pb, + to_x, to_y, w, h, + to_x - from_x, to_y - from_y, + 1.0, 1.0, + GDK_INTERP_HYPER, + opacity * 255); + } if (verbose_p) fprintf (stderr, "%s: pasted %dx%d from %d,%d to %d,%d\n", progname, paste_w, paste_h, from_x, from_y, to_x, to_y); - gdk_pixbuf_unref (paste_pb); + g_object_unref (paste_pb); write_pixbuf (base_pb, base_file); - gdk_pixbuf_unref (base_pb); + g_object_unref (base_pb); } @@ -384,7 +402,7 @@ write_pixbuf (GdkPixbuf *pb, const char *file) perror (buf); exit (1); } - fprintf (stderr, " %luK\n", (st.st_size + 1023) / 1024); + fprintf (stderr, " %luK\n", ((unsigned long) st.st_size + 1023) / 1024); } fclose (out); @@ -401,7 +419,7 @@ add_jpeg_comment (struct jpeg_compress_struct *cinfo) " Generated by WebCollage: Exterminate All Rational Thought. \r\n" " Copyright (c) 1999-%Y by Jamie Zawinski \r\n" "\r\n" - " http://www.jwz.org/webcollage/ \r\n" + " https://www.jwz.org/webcollage/ \r\n" "\r\n" " This is what the web looked like on %d %b %Y at %I:%M:%S %p %Z. \r\n" "\r\n"; @@ -473,7 +491,9 @@ main (int argc, char **argv) if (h < 0) usage(); #ifdef HAVE_GTK2 +#if !GLIB_CHECK_VERSION(2, 36 ,0) g_type_init (); +#endif #endif /* HAVE_GTK2 */ paste (paste_file, base_file,