- request.handle = server.FetchThumbnail (movie.title, movie.year.to_string (), "movie");
- request.movie = movie;
- request.callback = callback;
- request.width = (int) width;
- request.height = (int) height;
- requests.append (request);
+ if (!cropped && (pixbuf.width == width || pixbuf.height == height))
+ return pixbuf;
+
+ if (!download_posters ||
+ (pixbuf.width >= width && pixbuf.height >= height) ||
+ (pixbuf.width >= Poster.SMALL_WIDTH && pixbuf.height >= Poster.SMALL_HEIGHT)) {
+ // Scale to fit
+ return scale_to_fit (pixbuf, width, height, cropped);
+
+ }
+ }
+
+ return null;
+ }
+
+ private Gdk.Pixbuf scale_to_fit (Gdk.Pixbuf source, int width, int height, bool cropped) {
+ Gdk.InterpType interp_type;
+
+ if (width > source.width && height > source.height)
+ interp_type = Gdk.InterpType.HYPER;
+ else
+ interp_type = Gdk.InterpType.BILINEAR;
+
+ if (cropped) {
+ double xscale = (double) width / (double) source.width;
+ double yscale = (double) height / (double) source.height;
+ double scale;
+ int ofs_x = 0;
+ int ofs_y = 0;
+ if (xscale > yscale) {
+ scale = xscale;
+ ofs_y = (int) (height - source.height * scale) / 2;
+ } else {
+ scale = yscale;
+ ofs_x = (int) (width - source.width * scale) / 2;
+ }
+
+ var dest = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, width, height);
+ source.scale (dest, 0, 0, width, height, ofs_x, ofs_y, scale, scale, interp_type);
+
+ return dest;
+ } else {
+ width = int.min (width,
+ (source.width * height + source.height / 2) / source.height);
+ height = int.min ((source.height * width + source.width / 2) / source.width,
+ height);
+
+ return source.scale_simple (width, height, interp_type);