From fa3c150610dc53da1a7cf7807571580b54f9dd76 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 11 Feb 2018 13:01:43 +0000 Subject: [PATCH] Force TIFF to always use more than one strip --- backend/tif.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/backend/tif.c b/backend/tif.c index 70dc498c..31e06a82 100644 --- a/backend/tif.c +++ b/backend/tif.c @@ -55,7 +55,7 @@ int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { int i; int rows_per_strip, strip_count; int free_memory; - int row, column; + int row, column, strip, bytes_put; FILE *tif_file; #ifdef _MSC_VER uint32_t* strip_offset; @@ -83,7 +83,16 @@ int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { if ((symbol->bitmap_height % rows_per_strip) != 0) { strip_count++; } - + + if (rows_per_strip > symbol->bitmap_height) { + rows_per_strip = symbol->bitmap_height; + } + + if (strip_count == 1) { + rows_per_strip = (rows_per_strip / 2) + 1; + strip_count++; + } + #ifndef _MSC_VER uint32_t strip_offset[strip_count]; uint32_t strip_bytes[strip_count]; @@ -142,8 +151,10 @@ int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { fwrite(&header, sizeof(tiff_header_t), 1, tif_file); free_memory += sizeof(tiff_ifd_t); - + /* Pixel data */ + strip = 0; + bytes_put = 0; for (row = 0; row < symbol->bitmap_height; row++) { for (column = 0; column < symbol->bitmap_width; column++) { if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') { @@ -155,13 +166,16 @@ int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { putc(bggrn, tif_file); putc(bgblu, tif_file); } + bytes_put += 3; } - if (((row + 1) % rows_per_strip) == 0) { - /* End of a strip */ - if ((strip_bytes[0] % 2) == 1) { - /* Add end-of strip pad */ + + if ((bytes_put + 3) >= strip_bytes[strip]) { + // End of strip, pad if strip length is odd + if (strip_bytes[strip] % 2 == 1) { putc(0, tif_file); } + strip++; + bytes_put = 0; } }