From 1542cf56806f7b484d1c5fcb85e8ae2dc08128c1 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Thu, 22 Oct 2009 22:02:02 +0000 Subject: [PATCH] Patches from tgotic --- backend/png.c | 10 ++++++++++ backend/qr.c | 51 +++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/backend/png.c b/backend/png.c index f9d30c5c..42004945 100644 --- a/backend/png.c +++ b/backend/png.c @@ -20,6 +20,10 @@ */ #include +#ifdef _MSC_VER +#include +#include +#endif #include #include #include "common.h" @@ -124,6 +128,12 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c /* Open output file in binary mode */ if((symbol->output_options & BARCODE_STDOUT) != 0) { +#ifdef _MSC_VER + if (-1 == _setmode(_fileno(stdout), _O_BINARY)) { + strcpy(symbol->errtxt, "Can't open output file"); + return ERROR_FILE_ACCESS; + } +#endif graphic->outfile = stdout; } else { if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) { diff --git a/backend/qr.c b/backend/qr.c index 5c44891f..be87a1a7 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -114,40 +114,43 @@ int estimate_binary_length(char mode[], int length) char current = 0; int a_count = 0; int n_count = 0; - - switch(mode[0]) { - case 'K': count = 12 + 4; current = 'K'; break; - case 'B': count = 16 + 4; current = 'B'; break; - case 'A': count = 13 + 4; current = 'A'; break; - case 'N': count = 14 + 4; current = 'N'; break; - } - + for(i = 0; i < length; i++) { if(mode[i] != current) { - if(current == 'N') { - switch(n_count) { - case 1: count += 4; break; - case 2: count += 7; break; - } - } - switch(mode[i]) { case 'K': count += 12 + 4; current = 'K'; break; case 'B': count += 16 + 4; current = 'B'; break; - case 'A': count += 13 + 4; current = 'A'; break; - case 'N': count += 14 + 4; current = 'N'; break; + case 'A': count += 13 + 4; current = 'A'; a_count = 0; break; + case 'N': count += 14 + 4; current = 'N'; n_count = 0; break; } } - + switch(mode[i]) { - case 'K': count += 13; break; - case 'B': count += 8; break; - case 'A': a_count++; if((a_count % 2) == 0) { count += 11; a_count = 0; } break; - case 'N': n_count++; if((n_count % 3) == 0) { count += 10; n_count = 0; } break; + case 'K': count += 13; break; + case 'B': count += 8; break; + case 'A': + a_count++; + if((a_count % 2) == 0) { + count += 5; // 11 in total + a_count = 0; + } + else + count += 6; + break; + case 'N': + n_count++; + if((n_count % 3) == 0) { + count += 3; // 10 in total + n_count = 0; + } + else if ((n_count % 2) == 0) + count += 3; // 7 in total + else + count += 4; + break; } - } - + return count; }