Module gtkimageview :: Class PixbufDrawCache
[frames] | no frames]

Class PixbufDrawCache

Cache that ensures fast redraws by storing the last draw operation. For example, when resizing an ImageView, it will receive an expose event and must redraw the damaged region. Unless fitting is True, most of the pixels it should draw are indentical to the ones drawn the previous time. Redrawing them is wasteful because scaling and especially bilinear scaling is very slow. Therefore, PixbufDrawCache objectifies the drawing process and adds a cache with the last draw from which pixels can be fetched.

This class is present purely to ensure optimal speed. An IImageTool that is asked to redraw a part of the image view widget could either do it manually with something like this:

def paint_image(self, draw_opts, drawable):
    zoom_rect = draw_opts.zoom_rect
    scaled = draw_opts.pixbuf.scale(0, 0,
                                    zoom_rect.width, zoom_rect.height,
                                    -zoom_rect.x, -zoom_rect.y,
                                    draw_opts.zoom,
                                    draw_opts.interp,
                                    zoom_rect.x, zoom_rect.y,
                                    16,
                                    draw_opts.check_color1,
                                    draw_opts.check_color2)
    drawable.draw_pixbuf(NULL, scaled,
                         0, 0,
                         draw_opts.widget_x, draw_opts.widget_y,
                         zoom_rect.width, zoom_rect.height,
                         gtk.gdk.RGB_DITHER_MAX,
                         draw_opts.widget_x, draw_opts.widget_y)
Instance Methods
 
__init__(self)
Create a new pixbuf draw cache.
 
invalidate(self)
Force the draw cache to scale the pixbuf at the next draw.
 
draw(self, draw_opts, drawable)
Draw on the drawable using the specified draw options.
Class Methods
 
get_method(cls, last_opts, new_opts)
Get the fastest method to draw the specified draw options.
Method Details

invalidate(self)

 

Force the draw cache to scale the pixbuf at the next draw.

PixbufDrawCache tries to minimize the number of scale operations needed by caching the last drawn pixbuf. It would be inefficient to check the individual pixels inside the pixbuf so it assumes that if the memory address of the pixbuf has not changed, then the cache is good to use.

However, when the image data is modified, this assumtion breaks, which is why this method must be used to tell draw cache about it.

draw(self, draw_opts, drawable)

 
Draw on the drawable using the specified draw options.
Parameters:
  • draw_opts - PixbufDrawOpts to use in this draw.
  • drawable - a gdk.Drawable to draw on.

get_method(cls, last_opts, new_opts)
Class Method

 

Get the fastest method to draw the specified draw options. last_opts is assumed to be the last PixbufDrawOpts used and new_opts is the one to use this time.

This function returns one of the three constants DRAW_METHOD_CONTAINS, DRAW_METHOD_SCROLL or DRAW_METHOD_SCALE.

Parameters:
  • last_opts - the last draw options used
  • new_opts - the current draw options
Returns:
the best draw method to use to draw