summaryrefslogtreecommitdiff
path: root/src/util/image.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-07-09 12:10:38 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-07-09 12:10:38 +0200
commit709e2d6f5652ec90c194a4ec2b530bebc6f952cb (patch)
tree496b2f3899e1d5728ee9ae76095cc5056c317447 /src/util/image.vala
parentf1353e9ffd34db5f755c7da0b3f9c10638fbfd38 (diff)
parent5c8be07095cc04a6d8a95204b0504fd7ab030154 (diff)
Merge branch 'release/0.28.3-1'0.28.3-1
Diffstat (limited to 'src/util/image.vala')
-rw-r--r--src/util/image.vala53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/util/image.vala b/src/util/image.vala
index 4adafae..f8646e2 100644
--- a/src/util/image.vala
+++ b/src/util/image.vala
@@ -446,6 +446,59 @@ Gdk.Point derotate_point_arb(Gdk.Point source_point, int img_w, int img_h, doubl
return rotate_point_arb(source_point, img_w, img_h, angle, true);
}
+private static Cairo.Surface background_surface = null;
+
+private Cairo.Surface get_background_surface() {
+ if (background_surface == null) {
+ string color_a;
+ string color_b;
+ var config = Config.Facade.get_instance();
+
+ var type = config.get_transparent_background_type();
+ switch (type) {
+ case "checkered":
+ color_a = "#808080";
+ color_b = "#ccc";
+ break;
+ case "solid":
+ color_a = color_b = config.get_transparent_background_color();
+ break;
+ default:
+ color_a = color_b = "#000";
+ break;
+ }
+
+ background_surface = new Cairo.ImageSurface(Cairo.Format.RGB24, 16, 16);
+ var ctx = new Cairo.Context(background_surface);
+ ctx.set_operator(Cairo.Operator.SOURCE);
+ set_source_color_from_string(ctx, color_a);
+ ctx.rectangle(0,0,8,8);
+ ctx.rectangle(8,8,8,8);
+ ctx.fill();
+ set_source_color_from_string(ctx, color_b);
+ ctx.rectangle(0,8,8,8);
+ ctx.rectangle(8,0,8,8);
+ ctx.fill();
+ }
+
+ return background_surface;
+}
+
+public void invalidate_transparent_background() {
+ background_surface = null;
+}
+
+public void paint_pixmap_with_background (Cairo.Context ctx, Gdk.Pixbuf pixbuf, int x, int y) {
+ if (pixbuf.get_has_alpha()) {
+ ctx.set_source_surface(get_background_surface(), 0, 0);
+ ctx.get_source().set_extend(Cairo.Extend.REPEAT);
+ ctx.rectangle(x, y, pixbuf.width, pixbuf.height);
+ ctx.fill();
+ }
+
+ Gdk.cairo_set_source_pixbuf(ctx, pixbuf, x, y);
+ ctx.paint();
+}
// Force an axially-aligned box to be inside a rotated rectangle.
Box clamp_inside_rotated_image(Box src, int img_w, int img_h, double angle_deg,