Commit 22b9d2e
Fix optimized rendering of raster images
Changed files (3)
modifiedlibbirdfont/BackgroundImage.valamodifiedlibbirdfont/ScaledBackgrounds.valamodifiedlibbirdfont/ScaledImage.vala
Diff
@@ -25,9 +25,33 @@ public class BackgroundImage { /** Image position in canvas coordinates. */ public double img_x = 0; public double img_y = 0;++ public double img_scale_x {+ get {+ return img_scale_x_size;+ } - public double img_scale_x = 1;- public double img_scale_y = 1;+ set {+ if (value > 0.0001) {+ img_scale_x_size = value;+ }+ }+ }+ + public double img_scale_y {+ get {+ return img_scale_y_size;+ }+ + set {+ if (value > 0.0001) {+ img_scale_y_size = value;+ }+ }+ }+ + private double img_scale_x_size = 1; + private double img_scale_y_size = 1; public double img_rotation = 0; @@ -458,17 +482,20 @@ public class BackgroundImage { ScaledBackgroundPart part; scaled = backgrounds.get_image (view_zoom * img_scale_x); // FIXME: y-+ double part_offset_x = img_offset_x - view_offset_x;- part_offset_x *= view_zoom;+ part_offset_x /= img_scale_x / scaled.get_scale (); part_offset_x = -part_offset_x; double part_offset_y = img_offset_y - view_offset_y;- part_offset_y *= view_zoom;+ part_offset_y /= img_scale_y / scaled.get_scale (); part_offset_y = -part_offset_y;++ double zoom = 1 / view_zoom;+ zoom /= img_scale_y / scaled.get_scale (); part = scaled.get_part (part_offset_x, part_offset_y, - (int) (allocation.width * view_zoom), (int) (allocation.height * view_zoom)); + (int) (allocation.width * zoom), (int) (allocation.height * zoom)); scale_x = view_zoom * image_scale_x; scale_y = view_zoom * image_scale_y;@@ -57,6 +57,12 @@ public class ScaledBackgrounds : GLib.Object { private ScaledBackground scale (double scale_factor) { ImageSurface scaled_image;+ + if (scale_factor <= 0) {+ warning ("scale_factor <= 0");+ scale_factor = 1;+ }+ int width = (int) (scale_factor * original.get_width ()); int height = (int) (scale_factor * original.get_height ()); scaled_image = new ImageSurface (Format.ARGB32, width, height);@@ -28,6 +28,11 @@ public class ScaledBackground : GLib.Object { double scale; public ScaledBackground (ImageSurface image, double scale) {+ if (scale <= 0) {+ warning ("scale <= 0");+ scale = 1;+ }+ this.image = image; rotated = image; this.scale = scale;@@ -46,7 +51,15 @@ public class ScaledBackground : GLib.Object { part_width = image.get_width () / size; part_height = image.get_height () / size;- + + if (part_width < 1) {+ part_width = 1;+ }++ if (part_height < 1) {+ part_height = 1;+ }+ for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { ImageSurface next_part;@@ -65,6 +78,11 @@ public class ScaledBackground : GLib.Object { } public double get_scale () {+ if (unlikely (scale == 0)) {+ warning ("Zero scale.");+ return 1;+ }+ return scale; } @@ -93,17 +111,30 @@ public class ScaledBackground : GLib.Object { public ScaledBackgroundPart get_part (double offset_x, double offset_y, int width, int height) {- + + if (width <= 0 || height <= 0) {+ warning ("width <= 0 || height <= 0");+ scale = 1;+ }+ double image_width = part_width * size; double image_height = part_height * size; - int start_x = (int) ((offset_x / image_width) * size) - 1;- int start_y = (int) ((offset_y / image_height) * size) - 1;- int stop_x = (int) (((offset_x + width) / image_width) * size) + 2;- int stop_y = (int) (((offset_y + height) / image_height) * size) + 2;+ int start_x = (int) ((offset_x / image_width) * size);+ int start_y = (int) ((offset_y / image_height) * size);+ int stop_x = (int) (((offset_x + width) / image_width) * size) + 1;+ int stop_y = (int) (((offset_y + height) / image_height) * size) + 1; - int assembled_width = (int) ((size + 2) * image_width);- int assembled_height = (int) ((size + 2) * image_height);+ if (start_x < 0) {+ start_x = 0;+ }++ if (start_y < 0) {+ start_y = 0;+ }++ int assembled_width = (int) ((stop_x - start_x) * image_width);+ int assembled_height = (int) ((stop_y - start_y) * image_height); image = new ImageSurface (Format.ARGB32, assembled_width, assembled_height); @@ -112,28 +143,18 @@ public class ScaledBackground : GLib.Object { int start_offset_x = start_x * part_width; int start_offset_y = start_y * part_height; - if (start_offset_x > 0) {- start_x = -1;- start_offset_x = start_x * part_width;- }-- if (start_offset_y > 0) {- start_y = -1;- start_offset_y = start_y * part_height;- }- for (int y = start_y; y < stop_y; y++) { for (int x = start_x; x < stop_x; x++) { ImageSurface? part = get_part_at (x, y); if (part != null) { context.save ();- + context.set_source_surface ((!) part, (x - start_x) * part_width, (y - start_y) * part_height);- context.paint ();+ context.restore (); } }