Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Re #142: Only scale an image when necessary
Browse files Browse the repository at this point in the history
If the image is already right (image isn't bigger than "small" size)
then don't waste time creating a scaled clone surface.
  • Loading branch information
IBBoard committed Aug 22, 2020
1 parent c9ca95e commit 10d7df8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/CbMediaImageWidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,21 @@ cb_media_image_widget_new (CbMedia *media, GdkRectangle *max_dimensions)
gtk_image_set_from_animation (GTK_IMAGE (self->image), media->animation);
}
else {
self->image_surface = cairo_image_surface_create(cairo_image_surface_get_format(media->surface), media->width, media->height);
cairo_t *ct = cairo_create(self->image_surface);
cairo_scale(ct, media->width * 1.0 / media->thumb_width, media->height * 1.0 / media->thumb_height);
cairo_set_source_surface (ct, media->surface, 0, 0);
cairo_paint(ct);
gtk_image_set_from_surface (GTK_IMAGE (self->image), self->image_surface);
double scale_width = media->width * 1.0 / media->thumb_width;
double scale_height = media->height * 1.0 / media->thumb_height;

if (scale_width != 1 || scale_height != 1) {
self->image_surface = cairo_image_surface_create(cairo_image_surface_get_format(media->surface), media->width, media->height);
cairo_t *ct = cairo_create(self->image_surface);
cairo_scale(ct, scale_width, scale_height);
cairo_set_source_surface (ct, media->surface, 0, 0);
cairo_paint(ct);
gtk_image_set_from_surface (GTK_IMAGE (self->image), self->image_surface);

}
else {
gtk_image_set_from_surface (GTK_IMAGE (self->image), media->surface);
}
}

win_width = media->width;
Expand Down

0 comments on commit 10d7df8

Please sign in to comment.