Skip to content

Commit

Permalink
use ppm instead of svg for generating qr pixbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Jul 4, 2023
1 parent ab448a3 commit cf02c13
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/remoteauth/remoteauthdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,26 @@ void RemoteAuthDialog::OnFingerprint(const std::string &fingerprint) {
int size = qr.getSize();
const int border = 4;

const auto module_set = "0 0 0";
const auto module_clr = "255 255 255";

std::ostringstream sb;
sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
sb << (size + border * 2) << " " << (size + border * 2) << "\" stroke=\"none\">\n";
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
sb << "\t<path d=\"";
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
sb << "P3\n";
sb << size + border * 2 << " " << size + border * 2 << " 255\n";
for (int y = -border; y < size + border; y++) {
for (int x = -border; x < size + border; x++) {
if (qr.getModule(x, y)) {
if (x != 0 || y != 0)
sb << " ";
sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
sb << module_set << "\n";
} else {
sb << module_clr << "\n";
}
}
}
sb << "\" fill=\"#000000\"/>\n";
sb << "</svg>\n";

const auto svg = sb.str();
const auto img = sb.str();

auto loader = Gdk::PixbufLoader::create();
loader->write(reinterpret_cast<const guint8 *>(svg.data()), svg.size());
loader->write(reinterpret_cast<const guint8 *>(img.data()), img.size());
loader->close();
const auto pb = loader->get_pixbuf()->scale_simple(256, 256, Gdk::INTERP_NEAREST);

Expand Down

0 comments on commit cf02c13

Please sign in to comment.