mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-24 03:12:05 +03:00
Make scaled bitmap plotting much faster by only scaling the portion of the bitmap we need to plot.
svn path=/trunk/netsurf/; revision=10320
This commit is contained in:
parent
291b4480f1
commit
9d38a66299
@ -320,7 +320,7 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int x0, y0, x1, y1;
|
int x0, y0, x1, y1;
|
||||||
int dx, dy, dwidth, dheight;
|
int dsrcx, dsrcy, dwidth, dheight;
|
||||||
|
|
||||||
/* Bail early if we can */
|
/* Bail early if we can */
|
||||||
if (width == 0 || height == 0)
|
if (width == 0 || height == 0)
|
||||||
@ -341,20 +341,20 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
|
|||||||
y1 = (y + height) - (cliprect.y + cliprect.height);
|
y1 = (y + height) - (cliprect.y + cliprect.height);
|
||||||
|
|
||||||
/* Set initial draw geometry */
|
/* Set initial draw geometry */
|
||||||
dx = dy = 0;
|
dsrcx = dsrcy = 0;
|
||||||
dwidth = width;
|
dwidth = width;
|
||||||
dheight = height;
|
dheight = height;
|
||||||
|
|
||||||
/* Manually clip draw coordinates to area of image to be rendered */
|
/* Manually clip draw coordinates to area of image to be rendered */
|
||||||
if (x0 > 0) {
|
if (x0 > 0) {
|
||||||
/* Clip left */
|
/* Clip left */
|
||||||
dx = x0;
|
dsrcx = x0;
|
||||||
x += x0;
|
x += x0;
|
||||||
dwidth -= x0;
|
dwidth -= x0;
|
||||||
}
|
}
|
||||||
if (y0 > 0) {
|
if (y0 > 0) {
|
||||||
/* Clip top */
|
/* Clip top */
|
||||||
dy = y0;
|
dsrcy = y0;
|
||||||
y += y0;
|
y += y0;
|
||||||
dheight -= y0;
|
dheight -= y0;
|
||||||
}
|
}
|
||||||
@ -367,32 +367,41 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
|
|||||||
dheight -= y1;
|
dheight -= y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dwidth == 0 || dheight == 0)
|
||||||
|
/* Nothing to plot */
|
||||||
|
return true;
|
||||||
|
|
||||||
/* Render the bitmap */
|
/* Render the bitmap */
|
||||||
if (gdk_pixbuf_get_width(pixbuf) == width &&
|
if (gdk_pixbuf_get_width(pixbuf) == width &&
|
||||||
gdk_pixbuf_get_height(pixbuf) == height) {
|
gdk_pixbuf_get_height(pixbuf) == height) {
|
||||||
/* Bitmap is not scaled */
|
/* Bitmap is not scaled */
|
||||||
/* Plot the bitmap */
|
/* Plot the bitmap */
|
||||||
gdk_draw_pixbuf(current_drawable, current_gc, pixbuf,
|
gdk_draw_pixbuf(current_drawable, current_gc, pixbuf,
|
||||||
dx, dy, x, y, dwidth, dheight,
|
dsrcx, dsrcy, x, y, dwidth, dheight,
|
||||||
GDK_RGB_DITHER_MAX, 0, 0);
|
GDK_RGB_DITHER_MAX, 0, 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Bitmap is scaled */
|
/* Bitmap is scaled */
|
||||||
GdkPixbuf *scaled;
|
/* Get scale factors */
|
||||||
|
double sx = (double)width / gdk_pixbuf_get_width(pixbuf);
|
||||||
|
double sy = (double)height / gdk_pixbuf_get_height(pixbuf);
|
||||||
|
|
||||||
/* Create scaled bitmap
|
/* Create bitmap for scaled image */
|
||||||
* VERY SLOW */
|
GdkPixbuf *scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8,
|
||||||
scaled = gdk_pixbuf_scale_simple(pixbuf,
|
dwidth, dheight);
|
||||||
width, height,
|
/* Only scale up the portion of the bitmap that we are
|
||||||
option_render_resample ?
|
* interested in rendering */
|
||||||
GDK_INTERP_BILINEAR :
|
gdk_pixbuf_scale(pixbuf, scaled,
|
||||||
GDK_INTERP_NEAREST);
|
0, 0, dwidth, dheight,
|
||||||
|
-dsrcx, -dsrcy, sx, sy,
|
||||||
|
option_render_resample ? GDK_INTERP_BILINEAR :
|
||||||
|
GDK_INTERP_NEAREST);
|
||||||
if (!scaled)
|
if (!scaled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Plot the scaled bitmap */
|
/* Plot the scaled bitmap */
|
||||||
gdk_draw_pixbuf(current_drawable, current_gc, scaled,
|
gdk_draw_pixbuf(current_drawable, current_gc, scaled,
|
||||||
dx, dy, x, y, dwidth, dheight,
|
0, 0, x, y, dwidth, dheight,
|
||||||
GDK_RGB_DITHER_MAX, 0, 0);
|
GDK_RGB_DITHER_MAX, 0, 0);
|
||||||
|
|
||||||
g_object_unref(scaled);
|
g_object_unref(scaled);
|
||||||
|
Loading…
Reference in New Issue
Block a user