Force TIFF to always use more than one strip

This commit is contained in:
Robin Stuart 2018-02-11 13:01:43 +00:00
parent 78d85bd72e
commit fa3c150610

View File

@ -55,7 +55,7 @@ int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
int i; int i;
int rows_per_strip, strip_count; int rows_per_strip, strip_count;
int free_memory; int free_memory;
int row, column; int row, column, strip, bytes_put;
FILE *tif_file; FILE *tif_file;
#ifdef _MSC_VER #ifdef _MSC_VER
uint32_t* strip_offset; 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) { if ((symbol->bitmap_height % rows_per_strip) != 0) {
strip_count++; 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 #ifndef _MSC_VER
uint32_t strip_offset[strip_count]; uint32_t strip_offset[strip_count];
uint32_t strip_bytes[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); fwrite(&header, sizeof(tiff_header_t), 1, tif_file);
free_memory += sizeof(tiff_ifd_t); free_memory += sizeof(tiff_ifd_t);
/* Pixel data */ /* Pixel data */
strip = 0;
bytes_put = 0;
for (row = 0; row < symbol->bitmap_height; row++) { for (row = 0; row < symbol->bitmap_height; row++) {
for (column = 0; column < symbol->bitmap_width; column++) { for (column = 0; column < symbol->bitmap_width; column++) {
if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') { 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(bggrn, tif_file);
putc(bgblu, tif_file); putc(bgblu, tif_file);
} }
bytes_put += 3;
} }
if (((row + 1) % rows_per_strip) == 0) {
/* End of a strip */ if ((bytes_put + 3) >= strip_bytes[strip]) {
if ((strip_bytes[0] % 2) == 1) { // End of strip, pad if strip length is odd
/* Add end-of strip pad */ if (strip_bytes[strip] % 2 == 1) {
putc(0, tif_file); putc(0, tif_file);
} }
strip++;
bytes_put = 0;
} }
} }