OMEMO QR code: Switch to paintable, fix css

This commit is contained in:
fiaxh 2022-09-16 11:23:18 +02:00
parent b8e84c8326
commit 7ad52d9335
3 changed files with 8 additions and 9 deletions

View file

@ -386,6 +386,6 @@ box.dino-input-error .chat-input-status.input-status-highlight-once {
box-shadow: 0 0 2px 0 rgba(0,0,0,0.5);
}
.qrcode-container {
.qrcode-container > contents {
background: white; /* Color of the quiet zone. MUST have the same "reflectance" as light modules of the QR code. */
}

View file

@ -104,9 +104,9 @@ public class ContactDetailsDialog : Gtk.Dialog {
const int QUIET_ZONE_MODULES = 4; // MUST be at least 4
const int MODULE_SIZE_PX = 4; // arbitrary
var qr_pixbuf = new QRcode(iri, 2)
.to_pixbuf(MODULE_SIZE_PX * qrcode_image.scale_factor);
qrcode_image.set_from_pixbuf(qr_pixbuf);
var qr_paintable = new QRcode(iri, 2)
.to_paintable(MODULE_SIZE_PX * qrcode_image.scale_factor);
qrcode_image.paintable = qr_paintable;
qrcode_image.margin_top = qrcode_image.margin_end =
qrcode_image.margin_bottom = qrcode_image.margin_start = QUIET_ZONE_MODULES*MODULE_SIZE_PX;
qrcode_popover.add_css_class("qrcode-container");

View file

@ -1,5 +1,3 @@
using Gdk;
[CCode (cheader_filename = "qrencode.h")]
namespace Qrencode {
@ -36,13 +34,14 @@ namespace Qrencode {
[CCode (cname = "QRcode_encodeString")]
public QRcode (string str, int version = 0, ECLevel level = ECLevel.L, EncodeMode hint = EncodeMode.EIGHT_BIT, bool casesensitive = true);
public Pixbuf to_pixbuf(int module_size) {
public Gdk.Paintable to_paintable(int module_size) {
GLib.assert(module_size > 0);
var dst_width = width*module_size;
var dst_data = new uint8[dst_width*dst_width*3];
expand_and_upsample(data,width,width, dst_data,dst_width,dst_width);
return new Pixbuf.from_data(dst_data,
Colorspace.RGB, false, 8, dst_width, dst_width, dst_width*3);
return new Gdk.MemoryTexture(dst_width, dst_width, Gdk.MemoryFormat.R8G8B8,
new GLib.Bytes.take((owned) dst_data), dst_width*3);
}
/** Does 2D nearest-neighbor upsampling of an array of single-byte