swfdec-gnome r223 - trunk/thumbnailer
- From: otte svn gnome org
- To: svn-commits-list gnome org
- Subject: swfdec-gnome r223 - trunk/thumbnailer
- Date: Wed, 30 Jul 2008 12:05:03 +0000 (UTC)
Author: otte
Date: Wed Jul 30 12:05:03 2008
New Revision: 223
URL: http://svn.gnome.org/viewvc/swfdec-gnome?rev=223&view=rev
Log:
create images in same aspect ratio as Flash file
original patch from James Bowes
Modified:
trunk/thumbnailer/Makefile.am
trunk/thumbnailer/swfdec-thumbnailer.c
Modified: trunk/thumbnailer/Makefile.am
==============================================================================
--- trunk/thumbnailer/Makefile.am (original)
+++ trunk/thumbnailer/Makefile.am Wed Jul 30 12:05:03 2008
@@ -3,7 +3,7 @@
swfdec_thumbnailer_SOURCES = swfdec-thumbnailer.c
INCLUDES = $(GLOBAL_CFLAGS) $(THUMBNAILER_CFLAGS)
-swfdec_thumbnailer_LDFLAGS = $(THUMBNAILER_LIBS)
+swfdec_thumbnailer_LDFLAGS = $(THUMBNAILER_LIBS) -lm
schemas_in_files = swfdec-thumbnailer.schemas.in
schemasdir = $(GCONF_SCHEMA_FILE_DIR)
Modified: trunk/thumbnailer/swfdec-thumbnailer.c
==============================================================================
--- trunk/thumbnailer/swfdec-thumbnailer.c (original)
+++ trunk/thumbnailer/swfdec-thumbnailer.c Wed Jul 30 12:05:03 2008
@@ -24,6 +24,7 @@
#endif
#include <swfdec/swfdec.h>
+#include <math.h>
#define BORING_IMAGE_VARIANCE 256.0 /* Tweak this if necessary */
@@ -103,7 +104,7 @@
SwfdecPlayer *player;
SwfdecURL *url;
guint width, height;
- double scale, scaled_size, x, y, w, h;
+ double scale, x, y, w, h;
guint try;
cairo_surface_t *surface;
cairo_t *cr;
@@ -154,18 +155,19 @@
/* Cheat: We do this in one call so that the max runtime kicks in */
time_left = advance (player, timer, 10 * 1000);
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
- cr = cairo_create (surface);
-
// get image size
swfdec_player_get_default_size (player, &width, &height);
if (width == 0 || height == 0) {
- /* force a size if the player doesn't have a default one */
+ /* Force a size if the player doesn't have a default one. Note that we
+ * don't set a default size because this would result in images that
+ * are scaled way wrong for small thumbnails, if the Flash file has
+ * "noScale" set and resizes itself.
+ */
swfdec_player_set_size (player, size, size);
width = height = size;
}
- // determine amount of scaling to apply
+ // determine amount of scaling to apply and scale
if (width > 2 * height) {
scale = 0.5 * size / height;
} else if (height > 2 * width) {
@@ -173,23 +175,20 @@
} else {
scale = (double) size / MAX (width, height);
}
+ width = ceil (scale * width);
+ height = ceil (scale * height);
// determine necessary translation to get image centered
- scaled_size = size / scale;
- x = (width - scaled_size) / 2;
- y = (height - scaled_size) / 2;
- cairo_scale (cr, scale, scale);
- cairo_translate (cr, -x, -y);
+ x = width > size ? (width - size) / 2 : 0;
+ y = height > size ? (height - size) / 2 : 0;
- // compute part to render
- x = MAX (x, 0);
- y = MAX (y, 0);
- w = MIN (width, scaled_size);
- h = MIN (height, scaled_size);
+ // create the image
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, MIN (size, width), MIN (size, height));
+ cr = cairo_create (surface);
+ cairo_translate (cr, -x, -y);
+ cairo_scale (cr, scale, scale);
// render the image
- cairo_rectangle (cr, x, y, w, h);
- cairo_clip (cr);
swfdec_player_render (player, cr);
for (try = 0; try < 10 && time_left; try++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]