From 87ec997436fe0c1599869b1bccbf3cb75515030b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 25 Feb 2014 20:12:03 +0100 Subject: do the meta stuff only if any meta data is requested --- lib/libcqrlogo.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/libcqrlogo.c b/lib/libcqrlogo.c index e1b7a8e..5a83515 100644 --- a/lib/libcqrlogo.c +++ b/lib/libcqrlogo.c @@ -75,38 +75,40 @@ struct png_t * generate_png (struct bitmap_t *bitmap, const uint8_t meta, const png_text *pngtext = NULL; char *curi = NULL, *libsstr = NULL, *qrver; - if (meta & CQR_COMMENT) - pngtext = add_png_text(pngtext, &textcount, "comment", COMMENTSTR); + if (meta) { + if (meta & CQR_COMMENT) + pngtext = add_png_text(pngtext, &textcount, "comment", COMMENTSTR); - if (meta & CQR_REFERER) { - curi = strdup(uri); + if (meta & CQR_REFERER) { + curi = strdup(uri); - /* text in png file may have a max length of 79 chars */ - if (strlen(curi) > 79) - sprintf(curi + 76, "..."); + /* text in png file may have a max length of 79 chars */ + if (strlen(curi) > 79) + sprintf(curi + 76, "..."); - pngtext = add_png_text(pngtext, &textcount, "referer", curi); - } + pngtext = add_png_text(pngtext, &textcount, "referer", curi); + } - if (meta & CQR_VERSION) - pngtext = add_png_text(pngtext, &textcount, "version", VERSIONSTR); + if (meta & CQR_VERSION) + pngtext = add_png_text(pngtext, &textcount, "version", VERSIONSTR); - if (meta & CQR_LIBVERSION) { - qrver = QRcode_APIVersionString(); + if (meta & CQR_LIBVERSION) { + qrver = QRcode_APIVersionString(); - libsstr = malloc(sizeof(LIBSSTR) + strlen(qrver) + strlen(png_libpng_ver) + strlen(zlib_version)); - sprintf(libsstr, LIBSSTR, qrver, png_libpng_ver, zlib_version); + libsstr = malloc(sizeof(LIBSSTR) + strlen(qrver) + strlen(png_libpng_ver) + strlen(zlib_version)); + sprintf(libsstr, LIBSSTR, qrver, png_libpng_ver, zlib_version); - pngtext = add_png_text(pngtext, &textcount, "libs", libsstr); - } + pngtext = add_png_text(pngtext, &textcount, "libs", libsstr); + } - png_set_text(png_ptr, info_ptr, pngtext, textcount); - png_free (png_ptr, pngtext); + png_set_text(png_ptr, info_ptr, pngtext, textcount); + png_free (png_ptr, pngtext); - if (curi) - free(curi); - if (libsstr) - free(libsstr); + if (curi) + free(curi); + if (libsstr) + free(libsstr); + } #endif row_pointers = png_malloc (png_ptr, bitmap->height * sizeof (png_byte *)); -- cgit v1.2.3-70-g09d2