diff --git a/src/common/parse-uri.c b/src/common/parse-uri.c index 1cd7715..94e977a 100644 --- a/src/common/parse-uri.c +++ b/src/common/parse-uri.c @@ -176,13 +176,11 @@ parse_parameters (const gchar *modified_uri, gchar *escaped_issuer_and_label = g_uri_unescape_string (tokens[0], NULL); gchar *mod_uri_copy_utf8 = g_utf8_offset_to_pointer (cleaned_uri, g_utf8_strlen (tokens[0], -1) + 1); g_strfreev (tokens); - g_free (cleaned_uri); tokens = g_strsplit (escaped_issuer_and_label, ":", -1); if (tokens[0] && tokens[1]) { otp->issuer = g_strdup (g_strstrip (tokens[0])); otp->account_name = g_strdup (g_strstrip (tokens[1])); - } else { otp->account_name = g_strdup (g_strstrip (tokens[0])); } @@ -226,6 +224,7 @@ parse_parameters (const gchar *modified_uri, i++; } g_strfreev (tokens); + g_free (cleaned_uri); } @@ -237,4 +236,4 @@ remove_null_encoding (const gchar *uri) g_regex_unref (regex); return cleaned_uri; -} \ No newline at end of file +} diff --git a/src/gui/qrcode-parser.c b/src/gui/qrcode-parser.c index bdd02f8..b8c81f3 100644 --- a/src/gui/qrcode-parser.c +++ b/src/gui/qrcode-parser.c @@ -17,17 +17,29 @@ parse_qrcode (const gchar *png_path, gint width = gdk_pixbuf_get_width (pbuf); gint height = gdk_pixbuf_get_height (pbuf); guchar *raw_data = gdk_pixbuf_get_pixels (pbuf); + gint rowstride = gdk_pixbuf_get_rowstride (pbuf); + gint n_channels = gdk_pixbuf_get_n_channels (pbuf); + + guchar *gray_data = g_malloc0 (width * height); + + // we need to convert RGB data to grayscale, otherwise QR parsing will fail + for (gint y = 0; y < height; y++) { + for (gint x = 0; x < width; x++) { + guchar *p = raw_data + y * rowstride + x * n_channels; + gray_data[y * width + x] = (p[0] * 0.299) + (p[1] * 0.587) + (p[2] * 0.114); + } + } + g_object_unref (pbuf); zbar_image_t *image = zbar_image_create (); zbar_image_set_format (image, zbar_fourcc ('Y','8','0','0')); zbar_image_set_size (image, width, height); - zbar_image_set_data (image, raw_data, width * height, zbar_image_free_data); + zbar_image_set_data (image, gray_data, width * height, zbar_image_free_data); gint n = zbar_scan_image (scanner, image); if (n < 1) { zbar_image_destroy (image); zbar_image_scanner_destroy (scanner); - g_object_unref (pbuf); return g_strdup ("Couldn't find a valid qrcode"); } @@ -41,7 +53,5 @@ parse_qrcode (const gchar *png_path, zbar_image_destroy (image); zbar_image_scanner_destroy (scanner); - g_object_unref (pbuf); - return NULL; -} \ No newline at end of file +}