[maemo-commits] [maemo-commits] r18676 - in projects/haf/trunk/hildon-thumbnail: . daemon/plugins thumbs
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Jun 9 15:26:07 EEST 2009
- Previous message: [maemo-commits] r18677 - projects/haf/trunk/gtk+/modules/other/gail
- Next message: [maemo-commits] r18678 - projects/haf/trunk/hildon-thumbnail/daemon/plugins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2009-06-09 15:25:56 +0300 (Tue, 09 Jun 2009) New Revision: 18676 Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/plugins/pixbuf-io-loader.c projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c Log: 2009-06-09 Philip Van Hoof <philip at codeminded.be> * daemon/plugins/epeg-plugin.c: * thumbs/hildon-thumbnail-obj.c * daemon/plugins/gdkpixbuf-plugin.c * daemon/plugins/pixbuf-io-loader.c * daemon/plugins/epeg-plugin.c: Cropped sizes. NB#118963 Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog =================================================================== --- projects/haf/trunk/hildon-thumbnail/ChangeLog 2009-06-09 08:59:08 UTC (rev 18675) +++ projects/haf/trunk/hildon-thumbnail/ChangeLog 2009-06-09 12:25:56 UTC (rev 18676) @@ -1,5 +1,9 @@ 2009-06-09 Philip Van Hoof <philip at codeminded.be> + * daemon/plugins/epeg-plugin.c: + * thumbs/hildon-thumbnail-obj.c + * daemon/plugins/gdkpixbuf-plugin.c + * daemon/plugins/pixbuf-io-loader.c * daemon/plugins/epeg-plugin.c: Cropped sizes. NB#118963 2009-06-08 Philip Van Hoof <philip at codeminded.be> Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c 2009-06-09 08:59:08 UTC (rev 18675) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c 2009-06-09 12:25:56 UTC (rev 18676) @@ -379,6 +379,7 @@ guint rowstride; gboolean err_file = FALSE; int ww, wh; + gboolean orig_is_crop = FALSE; file = g_file_new_for_uri (uri); path = g_file_get_path (file); @@ -417,32 +418,23 @@ epeg_size_get (im, &ow, &oh); - wanted_size (ow, oh, 256 , 256, &ww, &wh); + if (ow <= 256 || oh <= 256) { - // printf ("%dx%d -> %dx%d\n", ow, oh, ww, wh); + /* Changed in NB#118963 comment #38 */ - // Only cropped will work with this currently ugly looking, - // often changed exception code + /* For items where either x or y is smaller than 124, + * the image is taken aspect ratio retained by scaling + * the dimension which is greater than 124 to the size + * 124. */ - if (ow <= 124 || oh <= 124) { - - /* Epeg doesn't behave as expected when the destination is larger - * than the source */ - if (ow <= 124 && oh <= 124) { - // If both are smaller, no cropping (crop_resize - // will take care of this one) - - pixbuf_large1 = gdk_pixbuf_new_from_file (path, + pixbuf_large1 = gdk_pixbuf_new_from_file (path, &nerror); } else { - // if one of both is smaller, first upscale for - // both to become larger, then normal crop - pixbuf_large1 = gdk_pixbuf_new_from_file_at_scale (path, - 256, 256, - TRUE, - &nerror); + 124, 124, + TRUE, + &nerror); } epeg_close (im); @@ -451,29 +443,32 @@ pixbuf_large = pixbuf_large1; goto nerror_handler; } + orig_is_crop = TRUE; } else { - // if both are larger, normal crop + /* For items where x and y are both larger than 124, the + * thumbnail is taken from the largest square in the + * middle of the image and scaled down to size 124x124. */ - //gchar *large=NULL, *normal=NULL, *cropped=NULL; + wanted_size (ow, oh, 256 , 256, &ww, &wh); epeg_decode_colorspace_set (im, EPEG_RGB8); epeg_decode_size_set (im, ww, wh); // epeg_quality_set (im, 75); epeg_thumbnail_comments_enable (im, 0); - //hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, - // NULL, NULL, NULL, FALSE); + // hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, + // NULL, NULL, NULL, FALSE); - //epeg_file_output_set (im, large); - //epeg_encode (im); - //epeg_close (im); + // epeg_file_output_set (im, large); + // epeg_encode (im); + // epeg_close (im); - //pixbuf_large = gdk_pixbuf_new_from_file (large, &nerror); + // pixbuf_large = gdk_pixbuf_new_from_file (large, &nerror); - //if (nerror) { + // if (nerror) { // pixbuf_large = pixbuf_large1; - // goto nerror_handler; + // goto nerror_handler; // } data = (guchar *) epeg_pixels_get (im, 0, 0, ww, wh); @@ -517,7 +512,11 @@ if (do_cropped && hildon_thumbnail_outplugins_needs_out (HILDON_THUMBNAIL_PLUGIN_OUTTYPE_CROPPED, mtime, uri, &err_file)) { - pixbuf_cropped = crop_resize (pixbuf_large, 124, 124); + if (orig_is_crop) { + pixbuf_cropped = g_object_ref (pixbuf_large); + } else { + pixbuf_cropped = crop_resize (pixbuf_large, 124, 124); + } rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped); width = gdk_pixbuf_get_width (pixbuf_cropped); Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c 2009-06-09 08:59:08 UTC (rev 18675) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c 2009-06-09 12:25:56 UTC (rev 18676) @@ -47,8 +47,10 @@ #ifdef HAVE_OSSO #define MAX_SIZE (1024*1024*5) +#define MAX_PIX (5000000) #else #define MAX_SIZE (1024*1024*100) +#define MAX_PIX (5000000*(100/5)) #endif GdkPixbuf * @@ -62,6 +64,7 @@ GdkPixbuf * my_gdk_pixbuf_new_from_stream (GInputStream *stream, GCancellable *cancellable, + guint max_pix, GError **error); static gchar **supported = NULL; @@ -255,10 +258,10 @@ #endif if (do_cropped && hildon_thumbnail_outplugins_needs_out (HILDON_THUMBNAIL_PLUGIN_OUTTYPE_CROPPED, mtime, uri, &err_file)) { + int a, b; - GdkPixbuf *pixbuf1 = my_gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), - NULL, - &nerror); + GdkPixbuf *pixbuf1 = my_gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), + NULL, MAX_PIX, &nerror); if (nerror) { if (pixbuf1) @@ -268,10 +271,45 @@ pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf1); - pixbuf_cropped = crop_resize (pixbuf, 124, 124); + g_object_unref (pixbuf1); + a = gdk_pixbuf_get_width (pixbuf); + b = gdk_pixbuf_get_height (pixbuf); + + /* Changed in NB#118963 comment #38 */ + + if (a <= 124 || b <= 124) { + int a_wanted, b_wanted; + + + /* For items where either x or y is smaller than 124, + * the image is taken aspect ratio retained by scaling + * the dimension which is greater than 124 to the size + * 124. */ + + if ((double)b * (double)124 > (double)a * (double)124) { + a_wanted = 0.5 + (double)a * (double)124 / (double)b; + b_wanted = 124; + } else { + b_wanted = 0.5 + (double)b * (double)124 / (double)a; + a_wanted = 124; + } + + pixbuf_cropped = gdk_pixbuf_scale_simple (pixbuf, + a_wanted, + b_wanted, + GDK_INTERP_BILINEAR); + + } else { + + /* For items where x and y are both larger than 124, the + * thumbnail is taken from the largest square in the + * middle of the image and scaled down to size 124x124. */ + + pixbuf_cropped = crop_resize (pixbuf, 124, 124); + } + g_object_unref (pixbuf); - g_object_unref (pixbuf1); rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped); width = gdk_pixbuf_get_width (pixbuf_cropped); Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/pixbuf-io-loader.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/pixbuf-io-loader.c 2009-06-09 08:59:08 UTC (rev 18675) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/pixbuf-io-loader.c 2009-06-09 12:25:56 UTC (rev 18676) @@ -28,13 +28,21 @@ #include <gio/gio.h> #include <gdk-pixbuf/gdk-pixbuf.h> - #define LOAD_BUFFER_SIZE 65536 +typedef struct { + guint max_pix; + gboolean stop; +} LoadInfo; + +#define DEFAULT_ERROR_DOMAIN "HildonThumbnailerGdkPixbuf" +#define DEFAULT_ERROR g_quark_from_static_string (DEFAULT_ERROR_DOMAIN) + static GdkPixbuf * load_from_stream (GdkPixbufLoader *loader, GInputStream *stream, GCancellable *cancellable, + LoadInfo *info, GError **error) { GdkPixbuf *pixbuf; @@ -43,7 +51,7 @@ gboolean res; res = TRUE; - while (1) { + while (!info->stop) { n_read = g_input_stream_read (stream, buffer, sizeof (buffer), @@ -58,6 +66,9 @@ if (n_read == 0) break; + if (info->stop) + break; + if (!gdk_pixbuf_loader_write (loader, buffer, n_read, @@ -73,6 +84,12 @@ error = NULL; } + if (info->stop) { + res = FALSE; + g_set_error (error, DEFAULT_ERROR, 0, + "original image too large"); + } + pixbuf = NULL; if (res) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); @@ -89,7 +106,25 @@ gboolean preserve_aspect_ratio; } AtScaleData; + static void +max_pix_check_cb (GdkPixbufLoader *loader, + int width, + int height, + gpointer data) +{ + LoadInfo *linfo = data; + + if (linfo->max_pix == 0) { + return; + } + + if (width * height > linfo->max_pix) { + linfo->stop = TRUE; + } +} + +static void at_scale_size_prepared_cb (GdkPixbufLoader *loader, int width, int height, @@ -176,17 +211,21 @@ GdkPixbufLoader *loader; GdkPixbuf *pixbuf; AtScaleData info; + LoadInfo linfo; loader = gdk_pixbuf_loader_new (); info.width = width; info.height = height; - info.preserve_aspect_ratio = preserve_aspect_ratio; + info.preserve_aspect_ratio = preserve_aspect_ratio; + linfo.stop = FALSE; + linfo.max_pix = 0; + g_signal_connect (loader, "size-prepared", G_CALLBACK (at_scale_size_prepared_cb), &info); - pixbuf = load_from_stream (loader, stream, cancellable, error); + pixbuf = load_from_stream (loader, stream, cancellable, &linfo, error); g_object_unref (loader); return pixbuf; @@ -218,13 +257,22 @@ GdkPixbuf * my_gdk_pixbuf_new_from_stream (GInputStream *stream, GCancellable *cancellable, + guint max_pix, GError **error) { GdkPixbuf *pixbuf; GdkPixbufLoader *loader; + LoadInfo linfo; loader = gdk_pixbuf_loader_new (); - pixbuf = load_from_stream (loader, stream, cancellable, error); + + g_signal_connect (loader, "size-prepared", + G_CALLBACK (max_pix_check_cb), &linfo); + + linfo.stop = FALSE; + linfo.max_pix = max_pix; + + pixbuf = load_from_stream (loader, stream, cancellable, &linfo, error); g_object_unref (loader); return pixbuf; Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c 2009-06-09 08:59:08 UTC (rev 18675) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-obj.c 2009-06-09 12:25:56 UTC (rev 18676) @@ -61,6 +61,7 @@ GdkPixbuf * my_gdk_pixbuf_new_from_stream (GInputStream *stream, GCancellable *cancellable, + guint max_pix, GError **error); GdkPixbuf * my_gdk_pixbuf_new_from_stream_at_scale (GInputStream *stream,
- Previous message: [maemo-commits] r18677 - projects/haf/trunk/gtk+/modules/other/gail
- Next message: [maemo-commits] r18678 - projects/haf/trunk/hildon-thumbnail/daemon/plugins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]