mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-24 15:29:45 +03:00
Various gtk thumbnailing fixes. Don't make intermediate buffer bigger than it needs to be. Don't pass clip rect that's larger than render area. Don't plot blank background before setting the clip rect. Scale initial content render appropriately. Simplify and fix scale calc for thumbnail resampling.
svn path=/trunk/netsurf/; revision=11697
This commit is contained in:
parent
daf23b0860
commit
120005e04b
@ -57,28 +57,28 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
|
|||||||
gint depth;
|
gint depth;
|
||||||
GdkPixmap *pixmap;
|
GdkPixmap *pixmap;
|
||||||
GdkPixbuf *big;
|
GdkPixbuf *big;
|
||||||
|
float plot_scale;
|
||||||
|
double scale;
|
||||||
|
|
||||||
assert(content);
|
assert(content);
|
||||||
assert(bitmap);
|
assert(bitmap);
|
||||||
|
|
||||||
clip.x0 = 0;
|
/* Get details of final thumbnail image */
|
||||||
clip.y0 = 0;
|
|
||||||
clip.x1 = content_get_width(content);
|
|
||||||
clip.y1 = content_get_width(content);
|
|
||||||
|
|
||||||
cwidth = min(content_get_width(content), 1024);
|
|
||||||
cheight = min(content_get_height(content), 768);
|
|
||||||
|
|
||||||
pixbuf = gtk_bitmap_get_primary(bitmap);
|
pixbuf = gtk_bitmap_get_primary(bitmap);
|
||||||
width = gdk_pixbuf_get_width(pixbuf);
|
width = gdk_pixbuf_get_width(pixbuf);
|
||||||
height = gdk_pixbuf_get_height(pixbuf);
|
height = gdk_pixbuf_get_height(pixbuf);
|
||||||
depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
||||||
|
|
||||||
|
/* Calculate size of buffer to render the content into */
|
||||||
|
cwidth = min(content_get_width(content), 1024);
|
||||||
|
cheight = ((cwidth * height) + (width / 2)) / width;
|
||||||
|
|
||||||
LOG(("Trying to create a thumbnail pixmap for a content of %dx%d@%d",
|
LOG(("Trying to create a thumbnail pixmap for a content of %dx%d@%d",
|
||||||
content_get_width(content), content_get_height(content),
|
content_get_width(content), content_get_height(content),
|
||||||
depth));
|
depth));
|
||||||
|
|
||||||
pixmap = gdk_pixmap_new(NULL, cwidth, cwidth, depth);
|
/* Create buffer to render into */
|
||||||
|
pixmap = gdk_pixmap_new(NULL, cwidth, cheight, depth);
|
||||||
|
|
||||||
if (pixmap == NULL) {
|
if (pixmap == NULL) {
|
||||||
/* the creation failed for some reason: most likely because
|
/* the creation failed for some reason: most likely because
|
||||||
@ -95,8 +95,8 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
|
|||||||
/* set the plotting functions up */
|
/* set the plotting functions up */
|
||||||
plot = nsgtk_plotters;
|
plot = nsgtk_plotters;
|
||||||
|
|
||||||
nsgtk_plot_set_scale((double) cwidth /
|
plot_scale = (float)cwidth / (float)content_get_width(content);
|
||||||
(double) content_get_width(content));
|
nsgtk_plot_set_scale(plot_scale);
|
||||||
|
|
||||||
/* set to plot to pixmap */
|
/* set to plot to pixmap */
|
||||||
current_drawable = pixmap;
|
current_drawable = pixmap;
|
||||||
@ -104,23 +104,30 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
|
|||||||
#ifdef CAIRO_VERSION
|
#ifdef CAIRO_VERSION
|
||||||
current_cr = gdk_cairo_create(current_drawable);
|
current_cr = gdk_cairo_create(current_drawable);
|
||||||
#endif
|
#endif
|
||||||
plot.rectangle(0, 0, cwidth, cwidth, plot_style_fill_white);
|
|
||||||
|
/* Set up clip rect */
|
||||||
|
clip.x0 = 0;
|
||||||
|
clip.y0 = 0;
|
||||||
|
clip.x1 = cwidth;
|
||||||
|
clip.y1 = cheight;
|
||||||
|
|
||||||
plot.clip(&clip);
|
plot.clip(&clip);
|
||||||
|
|
||||||
|
/* blank the background */
|
||||||
|
plot.rectangle(0, 0, cwidth, cheight, plot_style_fill_white);
|
||||||
|
|
||||||
/* render the content */
|
/* render the content */
|
||||||
content_redraw(content, 0, 0, content_get_width(content),
|
content_redraw(content, 0, 0, cwidth, cheight,
|
||||||
content_get_width(content),
|
&clip, plot_scale, 0xFFFFFF);
|
||||||
&clip, 1.0, 0xFFFFFF);
|
|
||||||
|
/* get the pixbuf we rendered the content into */
|
||||||
|
big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
|
||||||
|
cwidth, cheight);
|
||||||
|
|
||||||
/* resample the large plot down to the size of our thumbnail */
|
/* resample the large plot down to the size of our thumbnail */
|
||||||
big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
|
scale = (double)width / (double)cwidth;
|
||||||
cwidth, cwidth);
|
|
||||||
|
|
||||||
gdk_pixbuf_scale(big, pixbuf, 0, 0, width, height, 0, 0,
|
gdk_pixbuf_scale(big, pixbuf, 0, 0, width, height, 0, 0,
|
||||||
(double)width / (double)cwidth,
|
scale, scale, GDK_INTERP_TILES);
|
||||||
(double)height / (double)cwidth,
|
|
||||||
GDK_INTERP_TILES);
|
|
||||||
|
|
||||||
/* As a debugging aid, try this to dump out a copy of the thumbnail as
|
/* As a debugging aid, try this to dump out a copy of the thumbnail as
|
||||||
* a PNG: gdk_pixbuf_save(pixbuf, "thumbnail.png", "png", NULL, NULL);
|
* a PNG: gdk_pixbuf_save(pixbuf, "thumbnail.png", "png", NULL, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user