- raster/BMP/GIF/PCX/TIF: fix dealing with very large data (use
`size_t` as appropriate) - BMP: lessen heap memory usage by only `malloc()`ing a row, not whole file - GIF: lessen heap memory usage by paging (also simplifies some function returns); use standard colour char map - raster: add `raster_malloc()` to fail > 1GB (avoids very large output files that most systems can't handle; also lessens to some degree chances of being victim of OOM killer on Linux) - GUI: printing scale dialog: set maxima on X-dim and resolution to keep scale <= 200
17
ChangeLog
@ -1,6 +1,23 @@
|
|||||||
Version 2.13.0.9 (dev) not released yet
|
Version 2.13.0.9 (dev) not released yet
|
||||||
=======================================
|
=======================================
|
||||||
|
|
||||||
|
**Incompatible changes**
|
||||||
|
------------------------
|
||||||
|
None so far
|
||||||
|
|
||||||
|
Changes
|
||||||
|
-------
|
||||||
|
- BMP: lessen heap memory usage by only `malloc()`ing a row
|
||||||
|
- GIF: lessen heap memory usage by paging; use standard colour char map
|
||||||
|
|
||||||
|
Bugs
|
||||||
|
----
|
||||||
|
- raster/BMP/GIF/PCX/TIF: fix dealing with very large data (use `size_t`)
|
||||||
|
- raster: add `raster_malloc()` to fail > 1GB (avoids very large output files;
|
||||||
|
also lessens to some degree chances of being victim of OOM killer on Linux)
|
||||||
|
- GUI: printing scale dialog: set maxima on X-dim and resolution to keep scale
|
||||||
|
<= 200
|
||||||
|
|
||||||
|
|
||||||
Version 2.13.0 (2023-12-18)
|
Version 2.13.0 (2023-12-18)
|
||||||
===========================
|
===========================
|
||||||
|
111
backend/bmp.c
@ -43,13 +43,10 @@
|
|||||||
|
|
||||||
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) {
|
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) {
|
||||||
int i, row, column;
|
int i, row, column;
|
||||||
int row_size;
|
|
||||||
int bits_per_pixel;
|
int bits_per_pixel;
|
||||||
int colour_count;
|
int colour_count;
|
||||||
int resolution;
|
int resolution;
|
||||||
unsigned int data_offset, data_size, file_size;
|
size_t row_size, data_offset, file_size;
|
||||||
unsigned char *bitmap_file_start, *bmp_posn;
|
|
||||||
unsigned char *bitmap;
|
|
||||||
FILE *bmp_file;
|
FILE *bmp_file;
|
||||||
bitmap_file_header_t file_header;
|
bitmap_file_header_t file_header;
|
||||||
bitmap_info_header_t info_header;
|
bitmap_info_header_t info_header;
|
||||||
@ -59,6 +56,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
int ultra_fg_index = 9;
|
int ultra_fg_index = 9;
|
||||||
unsigned char map[128];
|
unsigned char map[128];
|
||||||
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
|
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
|
||||||
|
unsigned char *rowbuf;
|
||||||
|
|
||||||
(void) out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, NULL /*alpha*/);
|
(void) out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, NULL /*alpha*/);
|
||||||
fg.reserved = 0x00;
|
fg.reserved = 0x00;
|
||||||
@ -86,42 +84,26 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
map['0'] = 0;
|
map['0'] = 0;
|
||||||
map['1'] = 0x80;
|
map['1'] = 0x80;
|
||||||
}
|
}
|
||||||
row_size = 4 * ((bits_per_pixel * symbol->bitmap_width + 31) / 32);
|
row_size = 4 * (((size_t) symbol->bitmap_width * bits_per_pixel + 31) / 32);
|
||||||
data_size = symbol->bitmap_height * row_size;
|
|
||||||
data_offset = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t);
|
data_offset = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t);
|
||||||
data_offset += colour_count * sizeof(color_ref_t);
|
data_offset += sizeof(color_ref_t) * colour_count;
|
||||||
file_size = data_offset + data_size;
|
file_size = data_offset + row_size * symbol->bitmap_height;
|
||||||
|
|
||||||
bitmap_file_start = (unsigned char *) malloc(file_size);
|
/* Must fit in `uint32_t` field in header */
|
||||||
if (bitmap_file_start == NULL) {
|
if (file_size != (uint32_t) file_size) {
|
||||||
strcpy(symbol->errtxt, "602: Insufficient memory for BMP file buffer");
|
strcpy(symbol->errtxt, "606: Output file size too large for BMP header");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
memset(bitmap_file_start, 0, file_size); /* Not required but keeps padding bytes consistent */
|
|
||||||
|
|
||||||
bitmap = bitmap_file_start + data_offset;
|
if (!(rowbuf = (unsigned char *) malloc(row_size))) {
|
||||||
|
strcpy(symbol->errtxt, "602: Insufficient memory for BMP row buffer");
|
||||||
/* Pixel Plotting */
|
return ZINT_ERROR_MEMORY;
|
||||||
if (bits_per_pixel == 4) {
|
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
|
||||||
const unsigned char *pb = pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1));
|
|
||||||
for (column = 0; column < symbol->bitmap_width; column++) {
|
|
||||||
bitmap[(column >> 1) + (row * row_size)] |= map[pb[column]] << (!(column & 1) << 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { /* bits_per_pixel == 1 */
|
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
|
||||||
const unsigned char *pb = pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1));
|
|
||||||
for (column = 0; column < symbol->bitmap_width; column++) {
|
|
||||||
bitmap[(column >> 3) + (row * row_size)] |= map[pb[column]] >> (column & 7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file_header.header_field = 0x4d42; /* "BM" */
|
file_header.header_field = 0x4d42; /* "BM" */
|
||||||
file_header.file_size = file_size;
|
file_header.file_size = (uint32_t) file_size;
|
||||||
file_header.reserved = 0;
|
file_header.reserved = 0;
|
||||||
file_header.data_offset = data_offset;
|
file_header.data_offset = (uint32_t) data_offset;
|
||||||
|
|
||||||
info_header.header_size = sizeof(bitmap_info_header_t);
|
info_header.header_size = sizeof(bitmap_info_header_t);
|
||||||
info_header.width = symbol->bitmap_width;
|
info_header.width = symbol->bitmap_width;
|
||||||
@ -136,34 +118,12 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
info_header.colours = colour_count;
|
info_header.colours = colour_count;
|
||||||
info_header.important_colours = colour_count;
|
info_header.important_colours = colour_count;
|
||||||
|
|
||||||
bmp_posn = bitmap_file_start;
|
|
||||||
memcpy(bitmap_file_start, &file_header, sizeof(bitmap_file_header_t));
|
|
||||||
bmp_posn += sizeof(bitmap_file_header_t);
|
|
||||||
memcpy(bmp_posn, &info_header, sizeof(bitmap_info_header_t));
|
|
||||||
bmp_posn += sizeof(bitmap_info_header_t);
|
|
||||||
|
|
||||||
memcpy(bmp_posn, &bg, sizeof(color_ref_t));
|
|
||||||
bmp_posn += sizeof(color_ref_t);
|
|
||||||
if (bits_per_pixel == 4) {
|
|
||||||
for (i = 0; i < 8; i++) {
|
|
||||||
memcpy(bmp_posn, &palette[i], sizeof(color_ref_t));
|
|
||||||
bmp_posn += sizeof(color_ref_t);
|
|
||||||
}
|
|
||||||
if (ultra_fg_index == 9) {
|
|
||||||
memcpy(bmp_posn, &fg, sizeof(color_ref_t));
|
|
||||||
/* bmp_posn += sizeof(color_ref_t); */ /* Not needed as long as last */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memcpy(bmp_posn, &fg, sizeof(color_ref_t));
|
|
||||||
/* bmp_posn += sizeof(color_ref_t); */ /* Not needed as long as last */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open output file in binary mode */
|
/* Open output file in binary mode */
|
||||||
if (output_to_stdout) {
|
if (output_to_stdout) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
||||||
sprintf(symbol->errtxt, "600: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "600: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
|
||||||
free(bitmap_file_start);
|
free(rowbuf);
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -171,16 +131,50 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
} else {
|
} else {
|
||||||
if (!(bmp_file = out_fopen(symbol->outfile, "wb"))) {
|
if (!(bmp_file = out_fopen(symbol->outfile, "wb"))) {
|
||||||
sprintf(symbol->errtxt, "601: Could not open output file (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "601: Could not open output file (%d: %.30s)", errno, strerror(errno));
|
||||||
free(bitmap_file_start);
|
free(rowbuf);
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(bitmap_file_start, file_header.file_size, 1, bmp_file);
|
fwrite(&file_header, sizeof(bitmap_file_header_t), 1, bmp_file);
|
||||||
|
fwrite(&info_header, sizeof(bitmap_info_header_t), 1, bmp_file);
|
||||||
|
|
||||||
|
fwrite(&bg, sizeof(color_ref_t), 1, bmp_file);
|
||||||
|
if (bits_per_pixel == 4) {
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
fwrite(&palette[i], sizeof(color_ref_t), 1, bmp_file);
|
||||||
|
}
|
||||||
|
if (ultra_fg_index == 9) {
|
||||||
|
fwrite(&fg, sizeof(color_ref_t), 1, bmp_file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fwrite(&fg, sizeof(color_ref_t), 1, bmp_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pixel Plotting */
|
||||||
|
if (bits_per_pixel == 4) {
|
||||||
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
|
const unsigned char *pb = pixelbuf + ((size_t) symbol->bitmap_width * (symbol->bitmap_height - row - 1));
|
||||||
|
memset(rowbuf, 0, row_size);
|
||||||
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
|
rowbuf[column >> 1] |= map[pb[column]] << (!(column & 1) << 2);
|
||||||
|
}
|
||||||
|
fwrite(rowbuf, 1, row_size, bmp_file);
|
||||||
|
}
|
||||||
|
} else { /* bits_per_pixel == 1 */
|
||||||
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
|
const unsigned char *pb = pixelbuf + ((size_t) symbol->bitmap_width * (symbol->bitmap_height - row - 1));
|
||||||
|
memset(rowbuf, 0, row_size);
|
||||||
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
|
rowbuf[column >> 3] |= map[pb[column]] >> (column & 7);
|
||||||
|
}
|
||||||
|
fwrite(rowbuf, 1, row_size, bmp_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(rowbuf);
|
||||||
|
|
||||||
if (ferror(bmp_file)) {
|
if (ferror(bmp_file)) {
|
||||||
sprintf(symbol->errtxt, "603: Incomplete write to output (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "603: Incomplete write to output (%d: %.30s)", errno, strerror(errno));
|
||||||
free(bitmap_file_start);
|
|
||||||
if (!output_to_stdout) {
|
if (!output_to_stdout) {
|
||||||
(void) fclose(bmp_file);
|
(void) fclose(bmp_file);
|
||||||
}
|
}
|
||||||
@ -190,18 +184,15 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
if (output_to_stdout) {
|
if (output_to_stdout) {
|
||||||
if (fflush(bmp_file) != 0) {
|
if (fflush(bmp_file) != 0) {
|
||||||
sprintf(symbol->errtxt, "604: Incomplete flush to output (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "604: Incomplete flush to output (%d: %.30s)", errno, strerror(errno));
|
||||||
free(bitmap_file_start);
|
|
||||||
return ZINT_ERROR_FILE_WRITE;
|
return ZINT_ERROR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fclose(bmp_file) != 0) {
|
if (fclose(bmp_file) != 0) {
|
||||||
sprintf(symbol->errtxt, "605: Failure on closing output file (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "605: Failure on closing output file (%d: %.30s)", errno, strerror(errno));
|
||||||
free(bitmap_file_start);
|
|
||||||
return ZINT_ERROR_FILE_WRITE;
|
return ZINT_ERROR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bitmap_file_start);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
373
backend/gif.c
@ -43,47 +43,35 @@
|
|||||||
#define GIF_LZW_PAGE_SIZE 0x100000 /* Megabyte */
|
#define GIF_LZW_PAGE_SIZE 0x100000 /* Megabyte */
|
||||||
|
|
||||||
typedef struct s_statestruct {
|
typedef struct s_statestruct {
|
||||||
|
FILE *file;
|
||||||
unsigned char *pOut;
|
unsigned char *pOut;
|
||||||
const unsigned char *pIn;
|
const unsigned char *pIn;
|
||||||
unsigned int InLen;
|
const unsigned char *pInEnd;
|
||||||
unsigned int OutLength;
|
size_t OutLength;
|
||||||
unsigned int OutPosCur;
|
size_t OutPosCur;
|
||||||
unsigned int OutByteCountPos;
|
size_t OutByteCountPos;
|
||||||
unsigned short ClearCode;
|
unsigned short ClearCode;
|
||||||
unsigned short FreeCode;
|
unsigned short FreeCode;
|
||||||
char fByteCountByteSet;
|
char fByteCountByteSet;
|
||||||
|
char fOutPaged;
|
||||||
unsigned char OutBitsFree;
|
unsigned char OutBitsFree;
|
||||||
unsigned short NodeAxon[4096];
|
unsigned short NodeAxon[4096];
|
||||||
unsigned short NodeNext[4096];
|
unsigned short NodeNext[4096];
|
||||||
unsigned char NodePix[4096];
|
unsigned char NodePix[4096];
|
||||||
unsigned char colourCode[10];
|
unsigned char map[256];
|
||||||
unsigned char colourPaletteIndex[10];
|
|
||||||
int colourCount;
|
|
||||||
} statestruct;
|
} statestruct;
|
||||||
|
|
||||||
/* Transform a Pixel to a lzw colourmap index and move to next pixel.
|
static void BufferNextByte(statestruct *pState) {
|
||||||
* All colour values are listed in colourCode with corresponding palette index
|
|
||||||
*/
|
|
||||||
static unsigned char NextPaletteIndex(statestruct *pState)
|
|
||||||
{
|
|
||||||
unsigned char pixelColour;
|
|
||||||
int colourIndex;
|
|
||||||
pixelColour = *(pState->pIn);
|
|
||||||
(pState->pIn)++;
|
|
||||||
(pState->InLen)--;
|
|
||||||
for (colourIndex = 0; colourIndex < pState->colourCount; colourIndex++) {
|
|
||||||
if (pixelColour == pState->colourCode[colourIndex])
|
|
||||||
return pState->colourPaletteIndex[colourIndex];
|
|
||||||
|
|
||||||
}
|
|
||||||
return 0; /* Not reached */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int BufferNextByte(statestruct *pState) {
|
|
||||||
(pState->OutPosCur)++;
|
(pState->OutPosCur)++;
|
||||||
|
if (pState->fOutPaged && pState->OutPosCur + 2 >= pState->OutLength) {
|
||||||
|
/* Keep last 256 bytes so `OutByteCountPos` within range */
|
||||||
|
fwrite(pState->pOut, 1, pState->OutPosCur - 256, pState->file);
|
||||||
|
memmove(pState->pOut, pState->pOut + pState->OutPosCur - 256, 256);
|
||||||
|
pState->OutByteCountPos -= pState->OutPosCur - 256;
|
||||||
|
pState->OutPosCur = 256;
|
||||||
|
}
|
||||||
/* Check if this position is a byte count position
|
/* Check if this position is a byte count position
|
||||||
* fg_f_bytecountbyte_set indicates, if byte count position bytes should be
|
* `fByteCountByteSet` indicates, if byte count position bytes should be
|
||||||
* inserted in general.
|
* inserted in general.
|
||||||
* If this is true, and the distance to the last byte count position is 256
|
* If this is true, and the distance to the last byte count position is 256
|
||||||
* (e.g. 255 bytes in between), a byte count byte is inserted, and the value
|
* (e.g. 255 bytes in between), a byte count byte is inserted, and the value
|
||||||
@ -94,34 +82,22 @@ static int BufferNextByte(statestruct *pState) {
|
|||||||
pState->OutByteCountPos = pState->OutPosCur;
|
pState->OutByteCountPos = pState->OutPosCur;
|
||||||
(pState->OutPosCur)++;
|
(pState->OutPosCur)++;
|
||||||
}
|
}
|
||||||
if (pState->OutPosCur >= pState->OutLength) {
|
|
||||||
unsigned char *pOut;
|
|
||||||
pState->OutLength += GIF_LZW_PAGE_SIZE;
|
|
||||||
/* Note pState->pOut not free()d by realloc() on failure */
|
|
||||||
if (!(pOut = (unsigned char *) realloc(pState->pOut, pState->OutLength))) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pState->pOut = pOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
(pState->pOut)[pState->OutPosCur] = 0x00;
|
(pState->pOut)[pState->OutPosCur] = 0x00;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AddCodeToBuffer(statestruct *pState, unsigned short CodeIn, unsigned char CodeBits) {
|
static void AddCodeToBuffer(statestruct *pState, unsigned short CodeIn, unsigned char CodeBits) {
|
||||||
/* Check, if we may fill up the current byte completely */
|
/* Check, if we may fill up the current byte completely */
|
||||||
if (CodeBits >= pState->OutBitsFree) {
|
if (CodeBits >= pState->OutBitsFree) {
|
||||||
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
|
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
|
||||||
if (BufferNextByte(pState))
|
BufferNextByte(pState);
|
||||||
return -1;
|
|
||||||
CodeIn = (unsigned short) (CodeIn >> pState->OutBitsFree);
|
CodeIn = (unsigned short) (CodeIn >> pState->OutBitsFree);
|
||||||
CodeBits -= pState->OutBitsFree;
|
CodeBits -= pState->OutBitsFree;
|
||||||
pState->OutBitsFree = 8;
|
pState->OutBitsFree = 8;
|
||||||
/* Write a full byte if there are at least 8 code bits left */
|
/* Write a full byte if there are at least 8 code bits left */
|
||||||
if (CodeBits >= pState->OutBitsFree) {
|
if (CodeBits >= pState->OutBitsFree) {
|
||||||
(pState->pOut)[pState->OutPosCur] = (unsigned char) CodeIn;
|
(pState->pOut)[pState->OutPosCur] = (unsigned char) CodeIn;
|
||||||
if (BufferNextByte(pState))
|
BufferNextByte(pState);
|
||||||
return -1;
|
|
||||||
CodeIn = (unsigned short) (CodeIn >> 8);
|
CodeIn = (unsigned short) (CodeIn >> 8);
|
||||||
CodeBits -= 8;
|
CodeBits -= 8;
|
||||||
}
|
}
|
||||||
@ -131,7 +107,6 @@ static int AddCodeToBuffer(statestruct *pState, unsigned short CodeIn, unsigned
|
|||||||
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
|
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
|
||||||
pState->OutBitsFree -= CodeBits;
|
pState->OutBitsFree -= CodeBits;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FlushStringTable(statestruct *pState) {
|
static void FlushStringTable(statestruct *pState) {
|
||||||
@ -158,21 +133,22 @@ static int NextCode(statestruct *pState, unsigned char *pPixelValueCur, unsigned
|
|||||||
unsigned short DownNode;
|
unsigned short DownNode;
|
||||||
/* start with the root node for last pixel chain */
|
/* start with the root node for last pixel chain */
|
||||||
UpNode = *pPixelValueCur;
|
UpNode = *pPixelValueCur;
|
||||||
if ((pState->InLen) == 0)
|
if (pState->pIn == pState->pInEnd) {
|
||||||
return AddCodeToBuffer(pState, UpNode, CodeBits);
|
AddCodeToBuffer(pState, UpNode, CodeBits);
|
||||||
|
return 0;
|
||||||
*pPixelValueCur = NextPaletteIndex(pState);
|
}
|
||||||
|
*pPixelValueCur = pState->map[*pState->pIn++];
|
||||||
/* Follow the string table and the data stream to the end of the longest string that has a code */
|
/* Follow the string table and the data stream to the end of the longest string that has a code */
|
||||||
while (0 != (DownNode = FindPixelOutlet(pState, UpNode, *pPixelValueCur))) {
|
while (0 != (DownNode = FindPixelOutlet(pState, UpNode, *pPixelValueCur))) {
|
||||||
UpNode = DownNode;
|
UpNode = DownNode;
|
||||||
if ((pState->InLen) == 0)
|
if (pState->pIn == pState->pInEnd) {
|
||||||
return AddCodeToBuffer(pState, UpNode, CodeBits);
|
AddCodeToBuffer(pState, UpNode, CodeBits);
|
||||||
|
return 0;
|
||||||
*pPixelValueCur = NextPaletteIndex(pState);
|
}
|
||||||
|
*pPixelValueCur = pState->map[*pState->pIn++];
|
||||||
}
|
}
|
||||||
/* Submit 'UpNode' which is the code of the longest string */
|
/* Submit 'UpNode' which is the code of the longest string */
|
||||||
if (AddCodeToBuffer(pState, UpNode, CodeBits))
|
AddCodeToBuffer(pState, UpNode, CodeBits);
|
||||||
return -1;
|
|
||||||
/* ... and extend the string by appending 'PixelValueCur' */
|
/* ... and extend the string by appending 'PixelValueCur' */
|
||||||
/* Create a successor node for 'PixelValueCur' whose code is 'freecode' */
|
/* Create a successor node for 'PixelValueCur' whose code is 'freecode' */
|
||||||
(pState->NodePix)[pState->FreeCode] = *pPixelValueCur;
|
(pState->NodePix)[pState->FreeCode] = *pPixelValueCur;
|
||||||
@ -196,9 +172,9 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
|
|||||||
unsigned short Pos;
|
unsigned short Pos;
|
||||||
|
|
||||||
/* > Get first data byte */
|
/* > Get first data byte */
|
||||||
if (pState->InLen == 0)
|
if (pState->pIn == pState->pInEnd)
|
||||||
return 0;
|
return 0;
|
||||||
PixelValueCur = NextPaletteIndex(pState);
|
PixelValueCur = pState->map[*pState->pIn++];
|
||||||
/* Number of bits per data item (=pixel)
|
/* Number of bits per data item (=pixel)
|
||||||
* We need at least a value of 2, otherwise the cc and eoi code consumes
|
* We need at least a value of 2, otherwise the cc and eoi code consumes
|
||||||
* the whole string table
|
* the whole string table
|
||||||
@ -211,12 +187,9 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
|
|||||||
pState->ClearCode = (1 << paletteBitSize);
|
pState->ClearCode = (1 << paletteBitSize);
|
||||||
pState->FreeCode = pState->ClearCode + 2;
|
pState->FreeCode = pState->ClearCode + 2;
|
||||||
pState->OutBitsFree = 8;
|
pState->OutBitsFree = 8;
|
||||||
pState->OutPosCur = -1;
|
pState->OutPosCur = 0;
|
||||||
pState->fByteCountByteSet = 0;
|
pState->fByteCountByteSet = 0;
|
||||||
|
|
||||||
if (BufferNextByte(pState))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (Pos = 0; Pos < pState->ClearCode; Pos++)
|
for (Pos = 0; Pos < pState->ClearCode; Pos++)
|
||||||
(pState->NodePix)[Pos] = (unsigned char) Pos;
|
(pState->NodePix)[Pos] = (unsigned char) Pos;
|
||||||
|
|
||||||
@ -225,31 +198,21 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
|
|||||||
/* Write what the GIF specification calls the "code size". */
|
/* Write what the GIF specification calls the "code size". */
|
||||||
(pState->pOut)[pState->OutPosCur] = paletteBitSize;
|
(pState->pOut)[pState->OutPosCur] = paletteBitSize;
|
||||||
/* Reserve first bytecount byte */
|
/* Reserve first bytecount byte */
|
||||||
if (BufferNextByte(pState))
|
BufferNextByte(pState);
|
||||||
return 0;
|
|
||||||
pState->OutByteCountPos = pState->OutPosCur;
|
pState->OutByteCountPos = pState->OutPosCur;
|
||||||
if (BufferNextByte(pState))
|
BufferNextByte(pState);
|
||||||
return 0;
|
|
||||||
pState->fByteCountByteSet = 1;
|
pState->fByteCountByteSet = 1;
|
||||||
/* Submit one 'ClearCode' as the first code */
|
/* Submit one 'ClearCode' as the first code */
|
||||||
if (AddCodeToBuffer(pState, pState->ClearCode, CodeBits))
|
AddCodeToBuffer(pState, pState->ClearCode, CodeBits);
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int Res;
|
|
||||||
/* generate and save the next code, which may consist of multiple input pixels. */
|
/* generate and save the next code, which may consist of multiple input pixels. */
|
||||||
Res = NextCode(pState, &PixelValueCur, CodeBits);
|
if (!NextCode(pState, &PixelValueCur, CodeBits)) { /* Check for end of data stream */
|
||||||
if (Res < 0)
|
|
||||||
return 0;
|
|
||||||
/* Check for end of data stream */
|
|
||||||
if (!Res) {
|
|
||||||
/* submit 'eoi' as the last item of the code stream */
|
/* submit 'eoi' as the last item of the code stream */
|
||||||
if (AddCodeToBuffer(pState, (unsigned short) (pState->ClearCode + 1), CodeBits))
|
AddCodeToBuffer(pState, (unsigned short) (pState->ClearCode + 1), CodeBits);
|
||||||
return 0;
|
|
||||||
pState->fByteCountByteSet = 0;
|
pState->fByteCountByteSet = 0;
|
||||||
if (pState->OutBitsFree < 8) {
|
if (pState->OutBitsFree < 8) {
|
||||||
if (BufferNextByte(pState))
|
BufferNextByte(pState);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/* > Update last bytecount byte; */
|
/* > Update last bytecount byte; */
|
||||||
if (pState->OutByteCountPos < pState->OutPosCur) {
|
if (pState->OutByteCountPos < pState->OutPosCur) {
|
||||||
@ -257,17 +220,16 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
|
|||||||
= (unsigned char) (pState->OutPosCur - pState->OutByteCountPos - 1);
|
= (unsigned char) (pState->OutPosCur - pState->OutByteCountPos - 1);
|
||||||
}
|
}
|
||||||
pState->OutPosCur++;
|
pState->OutPosCur++;
|
||||||
return pState->OutPosCur;
|
return 1;
|
||||||
}
|
}
|
||||||
/* Check for currently last code */
|
/* Check for currently last code */
|
||||||
if (pState->FreeCode == (1U << CodeBits))
|
if (pState->FreeCode == (1U << CodeBits))
|
||||||
CodeBits++;
|
CodeBits++;
|
||||||
pState->FreeCode++;
|
pState->FreeCode++;
|
||||||
/* Check for full stringtable */
|
/* Check for full stringtable - for widest compatibility with gif decoders, empty when 0xfff, not 0x1000 */
|
||||||
if (pState->FreeCode == 0xfff) {
|
if (pState->FreeCode == 0xfff) {
|
||||||
FlushStringTable(pState);
|
FlushStringTable(pState);
|
||||||
if (AddCodeToBuffer(pState, pState->ClearCode, CodeBits))
|
AddCodeToBuffer(pState, pState->ClearCode, CodeBits);
|
||||||
return 0;
|
|
||||||
|
|
||||||
CodeBits = (unsigned char) (1 + paletteBitSize);
|
CodeBits = (unsigned char) (1 + paletteBitSize);
|
||||||
pState->FreeCode = (unsigned short) (pState->ClearCode + 2);
|
pState->FreeCode = (unsigned short) (pState->ClearCode + 2);
|
||||||
@ -280,13 +242,9 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
|
|||||||
*/
|
*/
|
||||||
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
|
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
|
||||||
unsigned char outbuf[10];
|
unsigned char outbuf[10];
|
||||||
FILE *gif_file;
|
|
||||||
unsigned short usTemp;
|
unsigned short usTemp;
|
||||||
int byte_out;
|
|
||||||
int colourCount;
|
|
||||||
unsigned char paletteRGB[10][3];
|
unsigned char paletteRGB[10][3];
|
||||||
int paletteCount, paletteCountCur, paletteIndex;
|
int paletteCount, i;
|
||||||
unsigned int pixelIndex;
|
|
||||||
int paletteBitSize;
|
int paletteBitSize;
|
||||||
int paletteSize;
|
int paletteSize;
|
||||||
statestruct State;
|
statestruct State;
|
||||||
@ -294,30 +252,49 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
int bgindex = -1, fgindex = -1;
|
int bgindex = -1, fgindex = -1;
|
||||||
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
|
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
|
||||||
|
|
||||||
unsigned char backgroundColourIndex;
|
static const unsigned char RGBUnused[3] = {0,0,0};
|
||||||
unsigned char RGBCur[3];
|
|
||||||
unsigned char RGBUnused[3] = {0,0,0};
|
|
||||||
unsigned char RGBfg[3];
|
unsigned char RGBfg[3];
|
||||||
unsigned char RGBbg[3];
|
unsigned char RGBbg[3];
|
||||||
unsigned char fgalpha;
|
unsigned char fgalpha;
|
||||||
unsigned char bgalpha;
|
unsigned char bgalpha;
|
||||||
|
|
||||||
int colourIndex;
|
const size_t bitmapSize = (size_t) symbol->bitmap_height * symbol->bitmap_width;
|
||||||
|
|
||||||
int fFound;
|
|
||||||
|
|
||||||
unsigned char pixelColour;
|
|
||||||
unsigned int bitmapSize = symbol->bitmap_height * symbol->bitmap_width;
|
|
||||||
|
|
||||||
/* Allow for overhead of 4 == code size + byte count + overflow byte + zero terminator */
|
|
||||||
unsigned int lzoutbufSize = bitmapSize + 4;
|
|
||||||
if (lzoutbufSize > GIF_LZW_PAGE_SIZE) {
|
|
||||||
lzoutbufSize = GIF_LZW_PAGE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) out_colour_get_rgb(symbol->fgcolour, &RGBfg[0], &RGBfg[1], &RGBfg[2], &fgalpha);
|
(void) out_colour_get_rgb(symbol->fgcolour, &RGBfg[0], &RGBfg[1], &RGBfg[2], &fgalpha);
|
||||||
(void) out_colour_get_rgb(symbol->bgcolour, &RGBbg[0], &RGBbg[1], &RGBbg[2], &bgalpha);
|
(void) out_colour_get_rgb(symbol->bgcolour, &RGBbg[0], &RGBbg[1], &RGBbg[2], &bgalpha);
|
||||||
|
|
||||||
|
/* prepare state array */
|
||||||
|
State.pIn = pixelbuf;
|
||||||
|
State.pInEnd = pixelbuf + bitmapSize;
|
||||||
|
/* Allow for overhead of 4 == code size + byte count + overflow byte + zero terminator */
|
||||||
|
State.OutLength = bitmapSize + 4;
|
||||||
|
State.fOutPaged = State.OutLength > GIF_LZW_PAGE_SIZE;
|
||||||
|
if (State.fOutPaged) {
|
||||||
|
State.OutLength = GIF_LZW_PAGE_SIZE;
|
||||||
|
}
|
||||||
|
if (!(State.pOut = (unsigned char *) malloc(State.OutLength))) {
|
||||||
|
strcpy(symbol->errtxt, "614: Insufficient memory for LZW buffer");
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open output file in binary mode */
|
||||||
|
if (output_to_stdout) {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
||||||
|
sprintf(symbol->errtxt, "610: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
|
||||||
|
free(State.pOut);
|
||||||
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
State.file = stdout;
|
||||||
|
} else {
|
||||||
|
if (!(State.file = out_fopen(symbol->outfile, "wb"))) {
|
||||||
|
sprintf(symbol->errtxt, "611: Could not open output file (%d: %.30s)", errno, strerror(errno));
|
||||||
|
free(State.pOut);
|
||||||
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build a table of the used palette items.
|
* Build a table of the used palette items.
|
||||||
* Currently, there are the following 10 colour codes:
|
* Currently, there are the following 10 colour codes:
|
||||||
@ -332,138 +309,73 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
* 'G': green
|
* 'G': green
|
||||||
* 'K': black
|
* 'K': black
|
||||||
* '0' and '1' may be identical to one of the other values
|
* '0' and '1' may be identical to one of the other values
|
||||||
*
|
|
||||||
* A data structure is set up as follows:
|
|
||||||
* state.colourCode: list of colour codes
|
|
||||||
* paletteIndex: palette index of the corresponding colour code
|
|
||||||
* There are colourCount entries in the upper lists.
|
|
||||||
* paletteRGB: RGB value at the palette position
|
|
||||||
* There are paletteCount entries.
|
|
||||||
* This value is smaller to colourCount, if multiple colour codes have the
|
|
||||||
* same RGB value and point to the same palette value.
|
|
||||||
* Example:
|
|
||||||
* 0 1 W K are present. 0 is equal to white, while 1 is blue
|
|
||||||
* The resulting tables are:
|
|
||||||
* paletteItem: ['0']=0 (white), ['1']=1 (blue), ['W']=0 (white),
|
|
||||||
* ['K']=2 (black)
|
|
||||||
* Thus, there are 4 colour codes and 3 palette entries.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
colourCount = 0;
|
|
||||||
paletteCount = 0;
|
paletteCount = 0;
|
||||||
/* loop over all pixels */
|
memset(State.map, 0, sizeof(State.map));
|
||||||
for (pixelIndex = 0; pixelIndex < bitmapSize; pixelIndex++) {
|
if (symbol->symbology == BARCODE_ULTRA) {
|
||||||
fFound = 0;
|
static const unsigned char ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' };
|
||||||
/* get pixel colour code */
|
for (i = 0; i < 8; i++) {
|
||||||
pixelColour = pixelbuf[pixelIndex];
|
State.map[ultra_chars[i]] = i;
|
||||||
/* look, if colour code is already in colour list */
|
out_colour_char_to_rgb(ultra_chars[i], &paletteRGB[i][0], &paletteRGB[i][1], &paletteRGB[i][2]);
|
||||||
for (colourIndex = 0; colourIndex < colourCount; colourIndex++) {
|
|
||||||
if ((State.colourCode)[colourIndex] == pixelColour) {
|
|
||||||
fFound = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
paletteCount = 8;
|
||||||
/* If colour is already present, go to next colour code */
|
paletteBitSize = 3;
|
||||||
if (fFound)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Colour code not present - add colour code */
|
/* For Ultracode, have foreground only if have bind/box */
|
||||||
/* Get RGB value */
|
if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BIND | BARCODE_BOX | BARCODE_BIND_TOP))) {
|
||||||
switch (pixelColour) {
|
/* Check whether can re-use black */
|
||||||
case '0': /* standard background */
|
if (RGBfg[0] == 0 && RGBfg[1] == 0 && RGBfg[2] == 0) {
|
||||||
RGBCur[0] = RGBbg[0]; RGBCur[1] = RGBbg[1]; RGBCur[2] = RGBbg[2];
|
State.map['1'] = fgindex = 7; /* Re-use black */
|
||||||
break;
|
} else {
|
||||||
case '1': /* standard foreground */
|
State.map['1'] = fgindex = paletteCount;
|
||||||
RGBCur[0] = RGBfg[0]; RGBCur[1] = RGBfg[1]; RGBCur[2] = RGBfg[2];
|
memcpy(paletteRGB[paletteCount++], RGBfg, 3);
|
||||||
break;
|
paletteBitSize = 4;
|
||||||
default: /* Colour or error case */
|
|
||||||
if (!out_colour_char_to_rgb(pixelColour, &RGBCur[0], &RGBCur[1], &RGBCur[2])) {
|
|
||||||
strcpy(symbol->errtxt, "612: unknown pixel colour");
|
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* Search, if RGB value is already present */
|
|
||||||
fFound = 0;
|
|
||||||
for (paletteIndex = 0; paletteIndex < paletteCount; paletteIndex++) {
|
|
||||||
if (RGBCur[0] == paletteRGB[paletteIndex][0]
|
|
||||||
&& RGBCur[1] == paletteRGB[paletteIndex][1]
|
|
||||||
&& RGBCur[2] == paletteRGB[paletteIndex][2])
|
|
||||||
{
|
|
||||||
fFound = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* RGB not present, add it */
|
|
||||||
if (!fFound) {
|
|
||||||
paletteIndex = paletteCount;
|
|
||||||
paletteRGB[paletteIndex][0] = RGBCur[0];
|
|
||||||
paletteRGB[paletteIndex][1] = RGBCur[1];
|
|
||||||
|
|
||||||
paletteRGB[paletteIndex][2] = RGBCur[2];
|
/* For Ultracode, have background only if have whitespace/quiet zones */
|
||||||
|
if (symbol->whitespace_width > 0 || symbol->whitespace_height > 0
|
||||||
paletteCount++;
|
|| ((symbol->output_options & BARCODE_QUIET_ZONES)
|
||||||
|
&& !(symbol->output_options & BARCODE_NO_QUIET_ZONES))) {
|
||||||
if (pixelColour == '0') bgindex = paletteIndex;
|
/* Check whether can re-use white */
|
||||||
if (pixelColour == '1') fgindex = paletteIndex;
|
if (RGBbg[0] == 0xff && RGBbg[1] == 0xff && RGBbg[2] == 0xff && bgalpha == fgalpha) {
|
||||||
|
State.map['0'] = bgindex = 0; /* Re-use white */
|
||||||
|
} else {
|
||||||
|
State.map['0'] = bgindex = paletteCount;
|
||||||
|
memcpy(paletteRGB[paletteCount++], RGBbg, 3);
|
||||||
|
paletteBitSize = 4;
|
||||||
}
|
}
|
||||||
/* Add palette index to current colour code */
|
|
||||||
(State.colourCode)[colourCount] = pixelColour;
|
|
||||||
(State.colourPaletteIndex)[colourCount] = paletteIndex;
|
|
||||||
colourCount++;
|
|
||||||
}
|
}
|
||||||
State.colourCount = colourCount;
|
} else {
|
||||||
|
State.map['0'] = bgindex = 0;
|
||||||
|
memcpy(paletteRGB[bgindex], RGBbg, 3);
|
||||||
|
State.map['1'] = fgindex = 1;
|
||||||
|
memcpy(paletteRGB[fgindex], RGBfg, 3);
|
||||||
|
paletteCount = 2;
|
||||||
|
paletteBitSize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set transparency */
|
/* Set transparency */
|
||||||
/* Note: does not allow both transparent foreground and background -
|
/* Note: does not allow both transparent foreground and background -
|
||||||
* background takes priority */
|
* background takes priority */
|
||||||
transparent_index = -1;
|
transparent_index = -1;
|
||||||
if (bgalpha == 0) {
|
if (bgalpha == 0 && bgindex != -1) {
|
||||||
/* Transparent background */
|
/* Transparent background */
|
||||||
transparent_index = bgindex;
|
transparent_index = bgindex;
|
||||||
} else if (fgalpha == 0) {
|
} else if (fgalpha == 0 && fgindex != -1) {
|
||||||
/* Transparent foreground */
|
/* Transparent foreground */
|
||||||
transparent_index = fgindex;
|
transparent_index = fgindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find palette bit size from palette size*/
|
|
||||||
|
|
||||||
/* 1,2 -> 1, 3,4 ->2, 5,6,7,8->3 */
|
|
||||||
paletteBitSize = 0;
|
|
||||||
paletteCountCur = paletteCount - 1;
|
|
||||||
while (paletteCountCur != 0) {
|
|
||||||
paletteBitSize++;
|
|
||||||
paletteCountCur >>= 1;
|
|
||||||
}
|
|
||||||
/* Minimum is 1 */
|
|
||||||
if (paletteBitSize == 0)
|
|
||||||
paletteBitSize = 1;
|
|
||||||
|
|
||||||
/* palette size 2 ^ bit size */
|
/* palette size 2 ^ bit size */
|
||||||
paletteSize = 1 << paletteBitSize;
|
paletteSize = 1 << paletteBitSize;
|
||||||
|
|
||||||
/* Open output file in binary mode */
|
|
||||||
if (output_to_stdout) {
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
|
||||||
sprintf(symbol->errtxt, "610: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
|
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
gif_file = stdout;
|
|
||||||
} else {
|
|
||||||
if (!(gif_file = out_fopen(symbol->outfile, "wb"))) {
|
|
||||||
sprintf(symbol->errtxt, "611: Could not open output file (%d: %.30s)", errno, strerror(errno));
|
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GIF signature (6) */
|
/* GIF signature (6) */
|
||||||
memcpy(outbuf, "GIF87a", 6);
|
memcpy(outbuf, "GIF87a", 6);
|
||||||
if (transparent_index != -1)
|
if (transparent_index != -1)
|
||||||
outbuf[4] = '9';
|
outbuf[4] = '9';
|
||||||
|
|
||||||
fwrite(outbuf, 6, 1, gif_file);
|
fwrite(outbuf, 1, 6, State.file);
|
||||||
/* Screen Descriptor (7) */
|
/* Screen Descriptor (7) */
|
||||||
/* Screen Width */
|
/* Screen Width */
|
||||||
usTemp = (unsigned short) symbol->bitmap_width;
|
usTemp = (unsigned short) symbol->bitmap_width;
|
||||||
@ -479,7 +391,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
* 1 : Global colour map
|
* 1 : Global colour map
|
||||||
* 111 : 8 bit colour depth of the palette
|
* 111 : 8 bit colour depth of the palette
|
||||||
* 0 : Not ordered in decreasing importance
|
* 0 : Not ordered in decreasing importance
|
||||||
* xxx : palette bit zize - 1
|
* xxx : palette bit size - 1
|
||||||
*/
|
*/
|
||||||
outbuf[4] = (unsigned char) (0xf0 | (0x7 & (paletteBitSize - 1)));
|
outbuf[4] = (unsigned char) (0xf0 | (0x7 & (paletteBitSize - 1)));
|
||||||
|
|
||||||
@ -487,23 +399,15 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
* Background colour index
|
* Background colour index
|
||||||
* Default to 0. If colour code 0 or K is present, it is used as index
|
* Default to 0. If colour code 0 or K is present, it is used as index
|
||||||
*/
|
*/
|
||||||
|
outbuf[5] = bgindex == -1 ? 0 : bgindex;
|
||||||
backgroundColourIndex = 0;
|
|
||||||
for (colourIndex = 0; colourIndex < colourCount; colourIndex++) {
|
|
||||||
if ((State.colourCode)[colourIndex] == '0' || (State.colourCode)[colourIndex] == 'W') {
|
|
||||||
backgroundColourIndex = (State.colourPaletteIndex)[colourIndex];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outbuf[5] = backgroundColourIndex;
|
|
||||||
/* Byte 7 must be 0x00 */
|
/* Byte 7 must be 0x00 */
|
||||||
outbuf[6] = 0x00;
|
outbuf[6] = 0x00;
|
||||||
fwrite(outbuf, 7, 1, gif_file);
|
fwrite(outbuf, 1, 7, State.file);
|
||||||
/* Global Color Table (paletteSize*3) */
|
/* Global Color Table (paletteSize*3) */
|
||||||
fwrite(paletteRGB, 3*paletteCount, 1, gif_file);
|
fwrite(paletteRGB, 1, 3*paletteCount, State.file);
|
||||||
/* add unused palette items to fill palette size */
|
/* add unused palette items to fill palette size */
|
||||||
for (paletteIndex = paletteCount; paletteIndex < paletteSize; paletteIndex++) {
|
for (i = paletteCount; i < paletteSize; i++) {
|
||||||
fwrite(RGBUnused, 3, 1, gif_file);
|
fwrite(RGBUnused, 1, 3, State.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Graphic control extension (8) */
|
/* Graphic control extension (8) */
|
||||||
@ -531,7 +435,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
outbuf[6] = (unsigned char) transparent_index;
|
outbuf[6] = (unsigned char) transparent_index;
|
||||||
/* Block Terminator */
|
/* Block Terminator */
|
||||||
outbuf[7] = 0;
|
outbuf[7] = 0;
|
||||||
fwrite(outbuf, 8, 1, gif_file);
|
fwrite(outbuf, 1, 8, State.file);
|
||||||
}
|
}
|
||||||
/* Image Descriptor */
|
/* Image Descriptor */
|
||||||
/* Image separator character = ',' */
|
/* Image separator character = ',' */
|
||||||
@ -554,51 +458,38 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
* There is no local color table if its most significant bit is reset.
|
* There is no local color table if its most significant bit is reset.
|
||||||
*/
|
*/
|
||||||
outbuf[9] = 0x00;
|
outbuf[9] = 0x00;
|
||||||
fwrite(outbuf, 10, 1, gif_file);
|
fwrite(outbuf, 1, 10, State.file);
|
||||||
|
|
||||||
/* prepare state array */
|
|
||||||
State.pIn = pixelbuf;
|
|
||||||
State.InLen = bitmapSize;
|
|
||||||
if (!(State.pOut = (unsigned char *) malloc(lzoutbufSize))) {
|
|
||||||
if (!output_to_stdout) {
|
|
||||||
(void) fclose(gif_file);
|
|
||||||
}
|
|
||||||
strcpy(symbol->errtxt, "614: Insufficient memory for LZW buffer");
|
|
||||||
return ZINT_ERROR_MEMORY;
|
|
||||||
}
|
|
||||||
State.OutLength = lzoutbufSize;
|
|
||||||
|
|
||||||
/* call lzw encoding */
|
/* call lzw encoding */
|
||||||
byte_out = gif_lzw(&State, paletteBitSize);
|
if (!gif_lzw(&State, paletteBitSize)) {
|
||||||
if (byte_out <= 0) {
|
|
||||||
free(State.pOut);
|
free(State.pOut);
|
||||||
if (!output_to_stdout) {
|
if (!output_to_stdout) {
|
||||||
(void) fclose(gif_file);
|
(void) fclose(State.file);
|
||||||
}
|
}
|
||||||
strcpy(symbol->errtxt, "613: Insufficient memory for LZW buffer");
|
strcpy(symbol->errtxt, "613: Insufficient memory for LZW buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
fwrite((const char *) State.pOut, byte_out, 1, gif_file);
|
fwrite((const char *) State.pOut, 1, State.OutPosCur, State.file);
|
||||||
free(State.pOut);
|
free(State.pOut);
|
||||||
|
|
||||||
/* GIF terminator */
|
/* GIF terminator */
|
||||||
fputc('\x3b', gif_file);
|
fputc('\x3b', State.file);
|
||||||
|
|
||||||
if (ferror(gif_file)) {
|
if (ferror(State.file)) {
|
||||||
sprintf(symbol->errtxt, "615: Incomplete write to output (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "615: Incomplete write to output (%d: %.30s)", errno, strerror(errno));
|
||||||
if (!output_to_stdout) {
|
if (!output_to_stdout) {
|
||||||
(void) fclose(gif_file);
|
(void) fclose(State.file);
|
||||||
}
|
}
|
||||||
return ZINT_ERROR_FILE_WRITE;
|
return ZINT_ERROR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_to_stdout) {
|
if (output_to_stdout) {
|
||||||
if (fflush(gif_file) != 0) {
|
if (fflush(State.file) != 0) {
|
||||||
sprintf(symbol->errtxt, "616: Incomplete flush to output (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "616: Incomplete flush to output (%d: %.30s)", errno, strerror(errno));
|
||||||
return ZINT_ERROR_FILE_WRITE;
|
return ZINT_ERROR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fclose(gif_file) != 0) {
|
if (fclose(State.file) != 0) {
|
||||||
sprintf(symbol->errtxt, "617: Failure on closing output file (%d: %.30s)", errno, strerror(errno));
|
sprintf(symbol->errtxt, "617: Failure on closing output file (%d: %.30s)", errno, strerror(errno));
|
||||||
return ZINT_ERROR_FILE_WRITE;
|
return ZINT_ERROR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,10 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
int run_count;
|
int run_count;
|
||||||
FILE *pcx_file;
|
FILE *pcx_file;
|
||||||
pcx_header_t header;
|
pcx_header_t header;
|
||||||
int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); /* Must be even */
|
|
||||||
unsigned char previous;
|
unsigned char previous;
|
||||||
|
const unsigned char *pb;
|
||||||
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
|
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
|
||||||
|
const int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); /* Must be even */
|
||||||
unsigned char *rle_row = (unsigned char *) z_alloca(bytes_per_line);
|
unsigned char *rle_row = (unsigned char *) z_alloca(bytes_per_line);
|
||||||
|
|
||||||
rle_row[bytes_per_line - 1] = 0; /* Will remain zero if bitmap_width odd */
|
rle_row[bytes_per_line - 1] = 0; /* Will remain zero if bitmap_width odd */
|
||||||
@ -104,8 +105,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
|
|
||||||
fwrite(&header, sizeof(pcx_header_t), 1, pcx_file);
|
fwrite(&header, sizeof(pcx_header_t), 1, pcx_file);
|
||||||
|
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
for (row = 0, pb = pixelbuf; row < symbol->bitmap_height; row++, pb += symbol->bitmap_width) {
|
||||||
const unsigned char *const pb = pixelbuf + row * symbol->bitmap_width;
|
|
||||||
for (colour = 0; colour < header.number_of_planes; colour++) {
|
for (colour = 0; colour < header.number_of_planes; colour++) {
|
||||||
for (column = 0; column < symbol->bitmap_width; column++) {
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
const unsigned char ch = pb[column];
|
const unsigned char ch = pb[column];
|
||||||
|
@ -63,6 +63,17 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
|
|
||||||
static const char ultra_colour[] = "0CBMRYGKW";
|
static const char ultra_colour[] = "0CBMRYGKW";
|
||||||
|
|
||||||
|
/* Wrapper to pre-check `size` on `malloc()` isn't too big (`size2` given if doing X `malloc()`s in a row) */
|
||||||
|
static void *raster_malloc(size_t size, size_t size2) {
|
||||||
|
/* Check for large image `malloc`s, which produce very large files most systems can't handle anyway */
|
||||||
|
/* Also `malloc()` on Linux will (usually) succeed regardless of request, and then get untrappably killed on
|
||||||
|
access by OOM killer if too much, so this is a crude mitigation */
|
||||||
|
if (size + size2 > 0x40000000) { /* 1GB */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) {
|
static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) {
|
||||||
/* Place pixelbuffer into symbol */
|
/* Place pixelbuffer into symbol */
|
||||||
unsigned char alpha[2];
|
unsigned char alpha[2];
|
||||||
@ -80,6 +91,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
|
|||||||
int row;
|
int row;
|
||||||
int plot_alpha = 0;
|
int plot_alpha = 0;
|
||||||
const size_t bm_bitmap_width = (size_t) symbol->bitmap_width * 3;
|
const size_t bm_bitmap_width = (size_t) symbol->bitmap_width * 3;
|
||||||
|
const size_t bm_bitmap_size = bm_bitmap_width * symbol->bitmap_height;
|
||||||
|
|
||||||
if (out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2],
|
if (out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2],
|
||||||
&alpha[0])) {
|
&alpha[0])) {
|
||||||
@ -100,27 +112,28 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
|
|||||||
symbol->alphamap = NULL;
|
symbol->alphamap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
symbol->bitmap = (unsigned char *) malloc(bm_bitmap_width * symbol->bitmap_height);
|
symbol->bitmap = (unsigned char *) raster_malloc(bm_bitmap_size, 0);
|
||||||
if (symbol->bitmap == NULL) {
|
if (symbol->bitmap == NULL) {
|
||||||
strcpy(symbol->errtxt, "661: Insufficient memory for bitmap buffer");
|
strcpy(symbol->errtxt, "661: Insufficient memory for bitmap buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plot_alpha) {
|
if (plot_alpha) {
|
||||||
symbol->alphamap = (unsigned char *) malloc((size_t) symbol->bitmap_width * symbol->bitmap_height);
|
const size_t alpha_size = (size_t) symbol->bitmap_width * symbol->bitmap_height;
|
||||||
|
symbol->alphamap = (unsigned char *) raster_malloc(alpha_size, bm_bitmap_size);
|
||||||
if (symbol->alphamap == NULL) {
|
if (symbol->alphamap == NULL) {
|
||||||
strcpy(symbol->errtxt, "662: Insufficient memory for alphamap buffer");
|
strcpy(symbol->errtxt, "662: Insufficient memory for alphamap buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
int p = row * symbol->bitmap_width;
|
size_t p = (size_t) symbol->bitmap_width * row;
|
||||||
const unsigned char *pb = pixelbuf + p;
|
const unsigned char *pb = pixelbuf + p;
|
||||||
unsigned char *bitmap = symbol->bitmap + p * 3;
|
unsigned char *bitmap = symbol->bitmap + p * 3;
|
||||||
if (row && memcmp(pb, pb - symbol->bitmap_width, symbol->bitmap_width) == 0) {
|
if (row && memcmp(pb, pb - symbol->bitmap_width, symbol->bitmap_width) == 0) {
|
||||||
memcpy(bitmap, bitmap - bm_bitmap_width, bm_bitmap_width);
|
memcpy(bitmap, bitmap - bm_bitmap_width, bm_bitmap_width);
|
||||||
memcpy(symbol->alphamap + p, symbol->alphamap + p - symbol->bitmap_width, symbol->bitmap_width);
|
memcpy(symbol->alphamap + p, symbol->alphamap + p - symbol->bitmap_width, symbol->bitmap_width);
|
||||||
} else {
|
} else {
|
||||||
const int pe = p + symbol->bitmap_width;
|
const size_t pe = p + symbol->bitmap_width;
|
||||||
for (; p < pe; p++, bitmap += 3) {
|
for (; p < pe; p++, bitmap += 3) {
|
||||||
memcpy(bitmap, map[pixelbuf[p]], 3);
|
memcpy(bitmap, map[pixelbuf[p]], 3);
|
||||||
symbol->alphamap[p] = alpha[pixelbuf[p] == DEFAULT_PAPER];
|
symbol->alphamap[p] = alpha[pixelbuf[p] == DEFAULT_PAPER];
|
||||||
@ -129,7 +142,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
const int r = row * symbol->bitmap_width;
|
const size_t r = (size_t) symbol->bitmap_width * row;
|
||||||
const unsigned char *pb = pixelbuf + r;
|
const unsigned char *pb = pixelbuf + r;
|
||||||
unsigned char *bitmap = symbol->bitmap + r * 3;
|
unsigned char *bitmap = symbol->bitmap + r * 3;
|
||||||
if (row && memcmp(pb, pb - symbol->bitmap_width, symbol->bitmap_width) == 0) {
|
if (row && memcmp(pb, pb - symbol->bitmap_width, symbol->bitmap_width) == 0) {
|
||||||
@ -169,7 +182,7 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rotate_angle) {
|
if (rotate_angle) {
|
||||||
if (!(rotated_pixbuf = (unsigned char *) malloc((size_t) image_width * image_height))) {
|
if (!(rotated_pixbuf = (unsigned char *) raster_malloc((size_t) image_width * image_height, 0 /*size2*/))) {
|
||||||
strcpy(symbol->errtxt, "650: Insufficient memory for pixel buffer");
|
strcpy(symbol->errtxt, "650: Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
@ -182,25 +195,28 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image
|
|||||||
break;
|
break;
|
||||||
case 90: /* Plot 90 degrees clockwise */
|
case 90: /* Plot 90 degrees clockwise */
|
||||||
for (row = 0; row < image_width; row++) {
|
for (row = 0; row < image_width; row++) {
|
||||||
|
const size_t h_offset = (size_t) image_height * row;
|
||||||
for (column = 0; column < image_height; column++) {
|
for (column = 0; column < image_height; column++) {
|
||||||
rotated_pixbuf[(row * image_height) + column] =
|
const size_t w_offset = (size_t) image_width * (image_height - column - 1);
|
||||||
*(pixelbuf + (image_width * (image_height - column - 1)) + row);
|
rotated_pixbuf[h_offset + column] = *(pixelbuf + w_offset + row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 180: /* Plot upside down */
|
case 180: /* Plot upside down */
|
||||||
for (row = 0; row < image_height; row++) {
|
for (row = 0; row < image_height; row++) {
|
||||||
|
const size_t w_offset = (size_t) image_width * row;
|
||||||
|
const size_t wh_offset = (size_t) image_width * (image_height - row - 1);
|
||||||
for (column = 0; column < image_width; column++) {
|
for (column = 0; column < image_width; column++) {
|
||||||
rotated_pixbuf[(row * image_width) + column] =
|
rotated_pixbuf[w_offset + column] = *(pixelbuf + wh_offset + (image_width - column - 1));
|
||||||
*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 270: /* Plot 90 degrees anti-clockwise */
|
case 270: /* Plot 90 degrees anti-clockwise */
|
||||||
for (row = 0; row < image_width; row++) {
|
for (row = 0; row < image_width; row++) {
|
||||||
|
const size_t h_offset = (size_t) image_height * row;
|
||||||
for (column = 0; column < image_height; column++) {
|
for (column = 0; column < image_height; column++) {
|
||||||
rotated_pixbuf[(row * image_height) + column] =
|
const size_t w_offset = (size_t) image_width * column;
|
||||||
*(pixelbuf + (image_width * column) + (image_width - row - 1));
|
rotated_pixbuf[h_offset + column] = *(pixelbuf + w_offset + (image_width - row - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -713,12 +729,14 @@ static void draw_bind_box(const struct zint_symbol *symbol, unsigned char *pixel
|
|||||||
static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_angle, const int file_type) {
|
static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_angle, const int file_type) {
|
||||||
int row, column;
|
int row, column;
|
||||||
int image_height, image_width;
|
int image_height, image_width;
|
||||||
|
size_t image_size;
|
||||||
unsigned char *pixelbuf;
|
unsigned char *pixelbuf;
|
||||||
int error_number;
|
int error_number;
|
||||||
float xoffset, yoffset, roffset, boffset;
|
float xoffset, yoffset, roffset, boffset;
|
||||||
float scaler = symbol->scale;
|
float scaler = symbol->scale;
|
||||||
unsigned char *scaled_hexagon;
|
unsigned char *scaled_hexagon;
|
||||||
int hex_width, hex_height;
|
int hex_width, hex_height;
|
||||||
|
size_t hex_size;
|
||||||
int hx_start, hy_start, hx_end, hy_end;
|
int hx_start, hy_start, hx_end, hy_end;
|
||||||
int hex_image_width, hex_image_height;
|
int hex_image_width, hex_image_height;
|
||||||
int yposn_offset;
|
int yposn_offset;
|
||||||
@ -758,19 +776,21 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang
|
|||||||
image_width = (int) ceilf(hex_image_width + xoffset_si + roffset_si);
|
image_width = (int) ceilf(hex_image_width + xoffset_si + roffset_si);
|
||||||
image_height = (int) ceilf(hex_image_height + yoffset_si + boffset_si);
|
image_height = (int) ceilf(hex_image_height + yoffset_si + boffset_si);
|
||||||
assert(image_width && image_height);
|
assert(image_width && image_height);
|
||||||
|
image_size = (size_t) image_width * image_height;
|
||||||
|
|
||||||
if (!(pixelbuf = (unsigned char *) malloc((size_t) image_width * image_height))) {
|
if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*size*/))) {
|
||||||
strcpy(symbol->errtxt, "655: Insufficient memory for pixel buffer");
|
strcpy(symbol->errtxt, "655: Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
memset(pixelbuf, DEFAULT_PAPER, (size_t) image_width * image_height);
|
memset(pixelbuf, DEFAULT_PAPER, image_size);
|
||||||
|
|
||||||
if (!(scaled_hexagon = (unsigned char *) malloc((size_t) hex_width * hex_height))) {
|
hex_size = (size_t) hex_width * hex_height;
|
||||||
|
if (!(scaled_hexagon = (unsigned char *) raster_malloc(hex_size, image_size))) {
|
||||||
strcpy(symbol->errtxt, "656: Insufficient memory for pixel buffer");
|
strcpy(symbol->errtxt, "656: Insufficient memory for pixel buffer");
|
||||||
free(pixelbuf);
|
free(pixelbuf);
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
memset(scaled_hexagon, DEFAULT_PAPER, (size_t) hex_width * hex_height);
|
memset(scaled_hexagon, DEFAULT_PAPER, hex_size);
|
||||||
|
|
||||||
plot_hexagon(scaled_hexagon, hex_width, hex_height, hx_start, hy_start, hx_end, hy_end);
|
plot_hexagon(scaled_hexagon, hex_width, hex_height, hx_start, hy_start, hx_end, hy_end);
|
||||||
|
|
||||||
@ -814,6 +834,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
|
|||||||
unsigned char *scaled_pixelbuf;
|
unsigned char *scaled_pixelbuf;
|
||||||
int r, i;
|
int r, i;
|
||||||
int scale_width, scale_height;
|
int scale_width, scale_height;
|
||||||
|
size_t scale_size;
|
||||||
int error_number = 0;
|
int error_number = 0;
|
||||||
float xoffset, yoffset, roffset, boffset;
|
float xoffset, yoffset, roffset, boffset;
|
||||||
float dot_offset_s;
|
float dot_offset_s;
|
||||||
@ -848,13 +869,14 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
|
|||||||
|
|
||||||
scale_width = (int) (symbol->width * scaler + xoffset_si + roffset_si + dot_overspill_si);
|
scale_width = (int) (symbol->width * scaler + xoffset_si + roffset_si + dot_overspill_si);
|
||||||
scale_height = (int) (symbol_height_si + yoffset_si + boffset_si + dot_overspill_si);
|
scale_height = (int) (symbol_height_si + yoffset_si + boffset_si + dot_overspill_si);
|
||||||
|
scale_size = (size_t) scale_width * scale_height;
|
||||||
|
|
||||||
/* Apply scale options by creating another pixel buffer */
|
/* Apply scale options by creating pixel buffer */
|
||||||
if (!(scaled_pixelbuf = (unsigned char *) malloc((size_t) scale_width * scale_height))) {
|
if (!(scaled_pixelbuf = (unsigned char *) raster_malloc(scale_size, 0 /*size2*/))) {
|
||||||
strcpy(symbol->errtxt, "657: Insufficient memory for pixel buffer");
|
strcpy(symbol->errtxt, "657: Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
memset(scaled_pixelbuf, DEFAULT_PAPER, (size_t) scale_width * scale_height);
|
memset(scaled_pixelbuf, DEFAULT_PAPER, scale_size);
|
||||||
|
|
||||||
/* Plot the body of the symbol to the pixel buffer */
|
/* Plot the body of the symbol to the pixel buffer */
|
||||||
for (r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
@ -946,6 +968,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
|
|||||||
int row_heights_si[200];
|
int row_heights_si[200];
|
||||||
int symbol_height_si;
|
int symbol_height_si;
|
||||||
int image_width, image_height;
|
int image_width, image_height;
|
||||||
|
size_t image_size;
|
||||||
unsigned char *pixelbuf;
|
unsigned char *pixelbuf;
|
||||||
float scaler = symbol->scale;
|
float scaler = symbol->scale;
|
||||||
int si;
|
int si;
|
||||||
@ -1013,12 +1036,13 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
|
|||||||
|
|
||||||
image_height = symbol_height_si + (int) ceilf(textoffset * si) + yoffset_si + boffset_si;
|
image_height = symbol_height_si + (int) ceilf(textoffset * si) + yoffset_si + boffset_si;
|
||||||
assert(image_width && image_height);
|
assert(image_width && image_height);
|
||||||
|
image_size = (size_t) image_width * image_height;
|
||||||
|
|
||||||
if (!(pixelbuf = (unsigned char *) malloc((size_t) image_width * image_height))) {
|
if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*size2*/))) {
|
||||||
strcpy(symbol->errtxt, "658: Insufficient memory for pixel buffer");
|
strcpy(symbol->errtxt, "658: Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
memset(pixelbuf, DEFAULT_PAPER, (size_t) image_width * image_height);
|
memset(pixelbuf, DEFAULT_PAPER, image_size);
|
||||||
|
|
||||||
yposn_si = yoffset_si;
|
yposn_si = yoffset_si;
|
||||||
|
|
||||||
@ -1341,7 +1365,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
|
|||||||
const int scale_height = (int) stripf(image_height * scaler);
|
const int scale_height = (int) stripf(image_height * scaler);
|
||||||
|
|
||||||
/* Apply scale options by creating another pixel buffer */
|
/* Apply scale options by creating another pixel buffer */
|
||||||
if (!(scaled_pixelbuf = (unsigned char *) malloc((size_t) scale_width * scale_height))) {
|
if (!(scaled_pixelbuf = (unsigned char *) raster_malloc((size_t) scale_width * scale_height, image_size))) {
|
||||||
free(pixelbuf);
|
free(pixelbuf);
|
||||||
strcpy(symbol->errtxt, "659: Insufficient memory for scaled pixel buffer");
|
strcpy(symbol->errtxt, "659: Insufficient memory for scaled pixel buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
@ -1350,7 +1374,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
|
|||||||
|
|
||||||
/* Interpolate */
|
/* Interpolate */
|
||||||
for (r = 0; r < scale_height; r++) {
|
for (r = 0; r < scale_height; r++) {
|
||||||
size_t scaled_row = r * scale_width;
|
size_t scaled_row = (size_t) scale_width * r;
|
||||||
size_t image_row = (size_t) stripf(r / scaler) * image_width;
|
size_t image_row = (size_t) stripf(r / scaler) * image_width;
|
||||||
if (r && (image_row == prev_image_row
|
if (r && (image_row == prev_image_row
|
||||||
|| memcmp(pixelbuf + image_row, pixelbuf + prev_image_row, image_width) == 0)) {
|
|| memcmp(pixelbuf + image_row, pixelbuf + prev_image_row, image_width) == 0)) {
|
||||||
|
Before Width: | Height: | Size: 162 B After Width: | Height: | Size: 162 B |
Before Width: | Height: | Size: 548 B After Width: | Height: | Size: 548 B |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 330 B After Width: | Height: | Size: 359 B |
BIN
backend/tests/data/gif/ultra_fgbg_hvwsp1_box1_bgfgtrans.gif
Normal file
After Width: | Height: | Size: 367 B |
BIN
backend/tests/data/gif/ultra_fgbg_hvwsp1_box1_bgtrans.gif
Normal file
After Width: | Height: | Size: 367 B |
BIN
backend/tests/data/gif/ultra_fgbg_hvwsp1_box1_fgtrans.gif
Normal file
After Width: | Height: | Size: 367 B |
Before Width: | Height: | Size: 255 B After Width: | Height: | Size: 255 B |
@ -1,5 +1,5 @@
|
|||||||
%!PS-Adobe-3.0 EPSF-3.0
|
%!PS-Adobe-3.0 EPSF-3.0
|
||||||
%%Creator: Zint 2.12.0.9
|
%%Creator: Zint 2.13.0.9
|
||||||
%%Title: Zint Generated Symbol
|
%%Title: Zint Generated Symbol
|
||||||
%%Pages: 0
|
%%Pages: 0
|
||||||
%%BoundingBox: 0 0 136 117
|
%%BoundingBox: 0 0 136 117
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
%!PS-Adobe-3.0 EPSF-3.0
|
%!PS-Adobe-3.0 EPSF-3.0
|
||||||
%%Creator: Zint 2.12.0.9
|
%%Creator: Zint 2.13.0.9
|
||||||
%%Title: Zint Generated Symbol
|
%%Title: Zint Generated Symbol
|
||||||
%%Pages: 0
|
%%Pages: 0
|
||||||
%%BoundingBox: 0 0 42 42
|
%%BoundingBox: 0 0 42 42
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
%!PS-Adobe-3.0 EPSF-3.0
|
%!PS-Adobe-3.0 EPSF-3.0
|
||||||
%%Creator: Zint 2.12.0.9
|
%%Creator: Zint 2.13.0.9
|
||||||
%%Title: Zint Generated Symbol
|
%%Title: Zint Generated Symbol
|
||||||
%%Pages: 0
|
%%Pages: 0
|
||||||
%%BoundingBox: 0 0 26 26
|
%%BoundingBox: 0 0 26 26
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B |
Before Width: | Height: | Size: 216 B After Width: | Height: | Size: 216 B |
@ -37,6 +37,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
int debug = p_ctx->debug;
|
int debug = p_ctx->debug;
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
|
int symbology;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
char *pattern;
|
char *pattern;
|
||||||
@ -45,21 +46,21 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
};
|
};
|
||||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||||
struct item data[] = {
|
struct item data[] = {
|
||||||
/* 0*/ { 1, 1, "1", 0, 0 },
|
/* 0*/ { BARCODE_CODE128, 1, 1, "1", 0, 0 },
|
||||||
/* 1*/ { 2, 1, "11", 0, 0 },
|
/* 1*/ { BARCODE_CODE128, 2, 1, "11", 0, 0 },
|
||||||
/* 2*/ { 3, 1, "101", 0, 0 },
|
/* 2*/ { BARCODE_CODE128, 3, 1, "101", 0, 0 },
|
||||||
/* 3*/ { 4, 1, "1010", 0, 0 },
|
/* 3*/ { BARCODE_CODE128, 4, 1, "1010", 0, 0 },
|
||||||
/* 4*/ { 5, 1, "10101", 0, 0 },
|
/* 4*/ { BARCODE_CODE128, 5, 1, "10101", 0, 0 },
|
||||||
/* 5*/ { 3, 2, "101010", 0, 0 },
|
/* 5*/ { BARCODE_CODE128, 3, 2, "101010", 0, 0 },
|
||||||
/* 6*/ { 3, 3, "101010101", 0, 0 },
|
/* 6*/ { BARCODE_CODE128, 3, 3, "101010101", 0, 0 },
|
||||||
/* 7*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0, 0 },
|
/* 7*/ { BARCODE_ULTRA, 8, 2, "CBMWKRYGGYRKWMBC", 0, 0 },
|
||||||
/* 8*/ { 20, 30, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWKCKBKMKRKYKGKK", 1, 0 }, /* Single LZW block, size 255 */
|
/* 8*/ { BARCODE_ULTRA, 20, 30, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWKCKBKMKRKYKGKK", 1, 0 }, /* Single LZW block, size 255 */
|
||||||
/* 9*/ { 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1, 0 }, /* Two LZW blocks, last size 1 */
|
/* 9*/ { BARCODE_ULTRA, 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1, 0 }, /* Two LZW blocks, last size 1 */
|
||||||
/* 10*/ { 1, 1, "D", 0, ZINT_ERROR_INVALID_DATA },
|
/* 10*/ { BARCODE_ULTRA, 1, 1, "D", 0, 0 }, /* This used to fail, now just maps unknown codes to 0 (1st colour index) */
|
||||||
};
|
};
|
||||||
int data_size = ARRAY_SIZE(data);
|
int data_size = ARRAY_SIZE(data);
|
||||||
int i, ret;
|
int i, ret;
|
||||||
struct zint_symbol *symbol;
|
struct zint_symbol *symbol = NULL;
|
||||||
|
|
||||||
char *gif = "out.gif";
|
char *gif = "out.gif";
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
|
|
||||||
strcpy(symbol->outfile, gif);
|
strcpy(symbol->outfile, gif);
|
||||||
|
|
||||||
|
symbol->symbology = data[i].symbology;
|
||||||
symbol->bitmap_width = data[i].width;
|
symbol->bitmap_width = data[i].width;
|
||||||
symbol->bitmap_height = data[i].height;
|
symbol->bitmap_height = data[i].height;
|
||||||
symbol->debug |= debug;
|
symbol->debug |= debug;
|
||||||
@ -103,7 +105,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
ret = testUtilVerifyIdentify(have_identify, symbol->outfile, debug);
|
ret = testUtilVerifyIdentify(have_identify, symbol->outfile, debug);
|
||||||
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
|
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
|
||||||
}
|
}
|
||||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */
|
||||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -168,18 +170,21 @@ static void test_print(const testCtx *const p_ctx) {
|
|||||||
/* 23*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "000000", "FFFFFF00", "12", "dotcode_bgtrans.gif", "" },
|
/* 23*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "000000", "FFFFFF00", "12", "dotcode_bgtrans.gif", "" },
|
||||||
/* 24*/ { BARCODE_DOTCODE, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "71,0,40,44", "", "12", "dotcode_cmyk_fg.gif", "" },
|
/* 24*/ { BARCODE_DOTCODE, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "71,0,40,44", "", "12", "dotcode_cmyk_fg.gif", "" },
|
||||||
/* 25*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF", "FF0000", "12", "ultra_fgbg_hvwsp1_box1.gif", "" },
|
/* 25*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF", "FF0000", "12", "ultra_fgbg_hvwsp1_box1.gif", "" },
|
||||||
/* 26*/ { BARCODE_ITF14, 4, BARCODE_BIND, 24, -1, -1, -1, 61.8, 3, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height61.8_bind4_wsp24_3.gif", "#204 ARM-Cortex crash" },
|
/* 26*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF00", "FF000000", "12", "ultra_fgbg_hvwsp1_box1_bgfgtrans.gif", "" },
|
||||||
/* 27*/ { BARCODE_ITF14, 0, BARCODE_BIND, -1, -1, -1, -1, 0.5, 0.5, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_box0_0.5.gif", "No box, no text" },
|
/* 27*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF", "FF000000", "12", "ultra_fgbg_hvwsp1_box1_bgtrans.gif", "" },
|
||||||
/* 28*/ { BARCODE_ITF14, -1, -1, -1, -1, -1, -1, 0.5, 1.1, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_1.1.gif", "" },
|
/* 28*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF00", "FF0000", "12", "ultra_fgbg_hvwsp1_box1_fgtrans.gif", "" },
|
||||||
/* 29*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 0.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height0.5_wsp3_vwsp5.gif", "Separator covers bars" },
|
/* 29*/ { BARCODE_ITF14, 4, BARCODE_BIND, 24, -1, -1, -1, 61.8, 3, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height61.8_bind4_wsp24_3.gif", "#204 ARM-Cortex crash" },
|
||||||
/* 30*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 1.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height1.5_wsp3_vwsp5.gif", "" },
|
/* 30*/ { BARCODE_ITF14, 0, BARCODE_BIND, -1, -1, -1, -1, 0.5, 0.5, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_box0_0.5.gif", "No box, no text" },
|
||||||
/* 31*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 2, 9, "001002" }, "", "", "1234567890", "datamatrix_seq2of9.gif", "" },
|
/* 31*/ { BARCODE_ITF14, -1, -1, -1, -1, -1, -1, 0.5, 1.1, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_1.1.gif", "" },
|
||||||
/* 32*/ { BARCODE_ULTRA, -1, -1, 1, -1, -1, 2, 0, 0, 0, { 0, 0, "" }, "", "", "12", "ultra_rev2.gif", "Revision 2" },
|
/* 32*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 0.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height0.5_wsp3_vwsp5.gif", "Separator covers bars" },
|
||||||
/* 33*/ { BARCODE_DPD, -1, BARCODE_QUIET_ZONES | COMPLIANT_HEIGHT, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "", "", "008182709980000020028101276", "dpd_compliant.gif", "Now with bind top 3X default" },
|
/* 33*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 1.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height1.5_wsp3_vwsp5.gif", "" },
|
||||||
|
/* 34*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 2, 9, "001002" }, "", "", "1234567890", "datamatrix_seq2of9.gif", "" },
|
||||||
|
/* 35*/ { BARCODE_ULTRA, -1, -1, 1, -1, -1, 2, 0, 0, 0, { 0, 0, "" }, "", "", "12", "ultra_rev2.gif", "Revision 2" },
|
||||||
|
/* 36*/ { BARCODE_DPD, -1, BARCODE_QUIET_ZONES | COMPLIANT_HEIGHT, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "", "", "008182709980000020028101276", "dpd_compliant.gif", "Now with bind top 3X default" },
|
||||||
};
|
};
|
||||||
int data_size = ARRAY_SIZE(data);
|
int data_size = ARRAY_SIZE(data);
|
||||||
int i, length, ret;
|
int i, length, ret;
|
||||||
struct zint_symbol *symbol;
|
struct zint_symbol *symbol = NULL;
|
||||||
|
|
||||||
const char *data_dir = "/backend/tests/data/gif";
|
const char *data_dir = "/backend/tests/data/gif";
|
||||||
const char *gif = "out.gif";
|
const char *gif = "out.gif";
|
||||||
@ -189,7 +194,7 @@ static void test_print(const testCtx *const p_ctx) {
|
|||||||
|
|
||||||
const char *const have_identify = testUtilHaveIdentify();
|
const char *const have_identify = testUtilHaveIdentify();
|
||||||
|
|
||||||
testStart("test_print");
|
testStartSymbol("test_print", &symbol);
|
||||||
|
|
||||||
if (p_ctx->generate) {
|
if (p_ctx->generate) {
|
||||||
char data_dir_path[1024];
|
char data_dir_path[1024];
|
||||||
@ -319,13 +324,11 @@ static void test_large_scale(const testCtx *const p_ctx) {
|
|||||||
|
|
||||||
length = (int) strlen(data);
|
length = (int) strlen(data);
|
||||||
|
|
||||||
|
ZBarcode_Reset(&symbol);
|
||||||
symbol.symbology = BARCODE_ITF14;
|
symbol.symbology = BARCODE_ITF14;
|
||||||
strcpy(symbol.fgcolour, "000000");
|
|
||||||
strcpy(symbol.bgcolour, "ffffff");
|
|
||||||
strcpy(symbol.outfile, "out.gif");
|
strcpy(symbol.outfile, "out.gif");
|
||||||
/* X-dimension 0.27mm * 95 = 25.65 ~ 25 pixels so 12.5 gives 95 dpmm (2400 dpi) */
|
/* X-dimension 0.27mm * 95 = 25.65 ~ 25 pixels so 12.5 gives 95 dpmm (2400 dpi) */
|
||||||
symbol.scale = 12.5f; /* 70.0f would cause re-alloc as LZW > 1MB but very slow */
|
symbol.scale = 12.5f; /* 70.0f would cause paging as LZW > 1MB but very slow */
|
||||||
symbol.dot_size = 4.0f / 5.0f;
|
|
||||||
|
|
||||||
ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/);
|
ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/);
|
||||||
assert_zero(ret, "%s ZBarcode_Encode_and_Print ret %d != 0 %s\n", testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt);
|
assert_zero(ret, "%s ZBarcode_Encode_and_Print ret %d != 0 %s\n", testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt);
|
||||||
@ -340,6 +343,35 @@ static void test_large_scale(const testCtx *const p_ctx) {
|
|||||||
testFinish();
|
testFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_too_big(const testCtx *const p_ctx) {
|
||||||
|
int debug = p_ctx->debug;
|
||||||
|
|
||||||
|
int length, ret;
|
||||||
|
struct zint_symbol symbol = {0};
|
||||||
|
char data[] = "12345";
|
||||||
|
|
||||||
|
(void)debug;
|
||||||
|
|
||||||
|
testStart("test_too_big");
|
||||||
|
|
||||||
|
length = (int) strlen(data);
|
||||||
|
|
||||||
|
ZBarcode_Reset(&symbol);
|
||||||
|
symbol.symbology = BARCODE_EANX;
|
||||||
|
strcpy(symbol.outfile, "out.gif");
|
||||||
|
symbol.scale = 200.0f;
|
||||||
|
symbol.whitespace_width = 32;
|
||||||
|
|
||||||
|
/* Fails in `plot_raster_default()` with `image_size` 0x4029C800 > 1GB */
|
||||||
|
ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/);
|
||||||
|
assert_equal(ret, ZINT_ERROR_MEMORY, "%s ZBarcode_Encode_and_Print ret %d != ZINT_ERROR_MEMORY %s\n",
|
||||||
|
testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt);
|
||||||
|
|
||||||
|
ZBarcode_Clear(&symbol);
|
||||||
|
|
||||||
|
testFinish();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
testFunction funcs[] = { /* name, func */
|
testFunction funcs[] = { /* name, func */
|
||||||
@ -347,6 +379,7 @@ int main(int argc, char *argv[]) {
|
|||||||
{ "test_print", test_print },
|
{ "test_print", test_print },
|
||||||
{ "test_outfile", test_outfile },
|
{ "test_outfile", test_outfile },
|
||||||
{ "test_large_scale", test_large_scale },
|
{ "test_large_scale", test_large_scale },
|
||||||
|
{ "test_too_big", test_too_big },
|
||||||
};
|
};
|
||||||
|
|
||||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||||
|
@ -65,7 +65,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
|
|
||||||
const char *const have_identify = testUtilHaveIdentify();
|
const char *const have_identify = testUtilHaveIdentify();
|
||||||
|
|
||||||
testStartSymbol("test_pixel_plot", &symbol);
|
testStart("test_pixel_plot");
|
||||||
|
|
||||||
for (i = 0; i < data_size; i++) {
|
for (i = 0; i < data_size; i++) {
|
||||||
int size;
|
int size;
|
||||||
|
@ -98,7 +98,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
|
|||||||
int have_tiffinfo = testUtilHaveTiffInfo();
|
int have_tiffinfo = testUtilHaveTiffInfo();
|
||||||
const char *const have_identify = testUtilHaveIdentify();
|
const char *const have_identify = testUtilHaveIdentify();
|
||||||
|
|
||||||
testStartSymbol("test_pixel_plot", &symbol);
|
testStart("test_pixel_plot");
|
||||||
|
|
||||||
symbol = ZBarcode_Create();
|
symbol = ZBarcode_Create();
|
||||||
assert_nonnull(symbol, "Symbol not created\n");
|
assert_nonnull(symbol, "Symbol not created\n");
|
||||||
|
@ -92,7 +92,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
unsigned char palette[32][5];
|
unsigned char palette[32][5];
|
||||||
int color_map_size = 0;
|
int color_map_size = 0;
|
||||||
int extra_samples = 0;
|
int extra_samples = 0;
|
||||||
uint32_t free_memory;
|
size_t free_memory;
|
||||||
int row, column, strip;
|
int row, column, strip;
|
||||||
int strip_row;
|
int strip_row;
|
||||||
unsigned int bytes_put;
|
unsigned int bytes_put;
|
||||||
@ -291,7 +291,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
free_memory = sizeof(tiff_header_t);
|
free_memory = sizeof(tiff_header_t);
|
||||||
|
|
||||||
for (i = 0; i < strip_count; i++) {
|
for (i = 0; i < strip_count; i++) {
|
||||||
strip_offset[i] = free_memory;
|
strip_offset[i] = (uint32_t) free_memory;
|
||||||
if (i != (strip_count - 1)) {
|
if (i != (strip_count - 1)) {
|
||||||
strip_bytes[i] = bytes_per_strip;
|
strip_bytes[i] = bytes_per_strip;
|
||||||
} else {
|
} else {
|
||||||
@ -339,7 +339,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
header.byte_order = 0x4949; /* "II" little-endian */
|
header.byte_order = 0x4949; /* "II" little-endian */
|
||||||
}
|
}
|
||||||
header.identity = 42;
|
header.identity = 42;
|
||||||
header.offset = free_memory;
|
header.offset = (uint32_t) free_memory;
|
||||||
|
|
||||||
fwrite(&header, sizeof(tiff_header_t), 1, tif_file);
|
fwrite(&header, sizeof(tiff_header_t), 1, tif_file);
|
||||||
total_bytes_put = sizeof(tiff_header_t);
|
total_bytes_put = sizeof(tiff_header_t);
|
||||||
@ -425,7 +425,16 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
file_pos = ftell(tif_file);
|
file_pos = ftell(tif_file);
|
||||||
fseek(tif_file, 4, SEEK_SET);
|
fseek(tif_file, 4, SEEK_SET);
|
||||||
free_memory = file_pos;
|
free_memory = file_pos;
|
||||||
fwrite(&free_memory, 4, 1, tif_file);
|
temp32 = (uint32_t) free_memory;
|
||||||
|
/* Shouldn't happen as `free_memory` checked above to be <= 0xffff0000 & should only decrease */
|
||||||
|
if (free_memory != temp32 || (long) free_memory != file_pos) {
|
||||||
|
strcpy(symbol->errtxt, "982: Output file size too big");
|
||||||
|
if (!output_to_stdout) {
|
||||||
|
(void) fclose(tif_file);
|
||||||
|
}
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
|
fwrite(&temp32, 4, 1, tif_file);
|
||||||
fseek(tif_file, file_pos, SEEK_SET);
|
fseek(tif_file, file_pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +459,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
tags[entries++].offset = (bits_per_sample << 16) | bits_per_sample;
|
tags[entries++].offset = (bits_per_sample << 16) | bits_per_sample;
|
||||||
} else {
|
} else {
|
||||||
update_offsets[offsets++] = entries;
|
update_offsets[offsets++] = entries;
|
||||||
tags[entries++].offset = free_memory;
|
tags[entries++].offset = (uint32_t) free_memory;
|
||||||
free_memory += samples_per_pixel * 2;
|
free_memory += samples_per_pixel * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,7 +481,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
tags[entries++].offset = strip_offset[0];
|
tags[entries++].offset = strip_offset[0];
|
||||||
} else {
|
} else {
|
||||||
update_offsets[offsets++] = entries;
|
update_offsets[offsets++] = entries;
|
||||||
tags[entries++].offset = free_memory;
|
tags[entries++].offset = (uint32_t) free_memory;
|
||||||
free_memory += strip_count * 4;
|
free_memory += strip_count * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +536,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix
|
|||||||
tags[entries].type = 3; /* SHORT */
|
tags[entries].type = 3; /* SHORT */
|
||||||
tags[entries].count = color_map_size * 3;
|
tags[entries].count = color_map_size * 3;
|
||||||
update_offsets[offsets++] = entries;
|
update_offsets[offsets++] = entries;
|
||||||
tags[entries++].offset = free_memory;
|
tags[entries++].offset = (uint32_t) free_memory;
|
||||||
/* free_memory += color_map_size * 3 * 2; Unnecessary as long as last use */
|
/* free_memory += color_map_size * 3 * 2; Unnecessary as long as last use */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
<double>0.001000000000000</double>
|
<double>0.001000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>100.000000000000000</double>
|
<double>10.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="singleStep">
|
<property name="singleStep">
|
||||||
<double>0.010000000000000</double>
|
<double>0.010000000000000</double>
|
||||||
@ -140,7 +140,7 @@
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>9999</number>
|
<number>1000</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
|
@ -2008,7 +2008,7 @@ the barcode in X-dimensions</string>
|
|||||||
<double>0.100000000000000</double>
|
<double>0.100000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>100.000000000000000</double>
|
<double>200.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="singleStep">
|
<property name="singleStep">
|
||||||
<double>0.500000000000000</double>
|
<double>0.500000000000000</double>
|
||||||
|
@ -86,6 +86,7 @@ ScaleWindow::ScaleWindow(BarcodeItem *bc, Zint::QZintXdimDpVars *vars, double or
|
|||||||
} else {
|
} else {
|
||||||
spnResolution->setSingleStep(1);
|
spnResolution->setSingleStep(1);
|
||||||
}
|
}
|
||||||
|
set_maxima();
|
||||||
|
|
||||||
size_msg_ui_set();
|
size_msg_ui_set();
|
||||||
|
|
||||||
@ -179,6 +180,7 @@ void ScaleWindow::update_scale()
|
|||||||
emit scaleChanged(scale);
|
emit scaleChanged(scale);
|
||||||
m_unset = false;
|
m_unset = false;
|
||||||
btnScaleUnset->setEnabled(true);
|
btnScaleUnset->setEnabled(true);
|
||||||
|
set_maxima();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +250,22 @@ const char *ScaleWindow::getFileType() const
|
|||||||
return filetypes[std::max(std::min(cmbFileType->currentIndex(), 2), 0)];
|
return filetypes[std::max(std::min(cmbFileType->currentIndex(), 2), 0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScaleWindow::set_maxima()
|
||||||
|
{
|
||||||
|
float maxXdim = m_bc->bc.getXdimDpFromScale(200.0f, get_dpmm(), getFileType());
|
||||||
|
if (cmbXdimUnits->currentIndex() == 1) { // Inches
|
||||||
|
spnXdim->setMaximum(maxXdim / 25.4);
|
||||||
|
} else {
|
||||||
|
spnXdim->setMaximum(maxXdim);
|
||||||
|
}
|
||||||
|
float maxRes = m_bc->bc.getXdimDpFromScale(200.0f, get_x_dim_mm(), getFileType());
|
||||||
|
if (cmbResolutionUnits->currentIndex() == 1) { // Inches
|
||||||
|
spnResolution->setMaximum(maxRes * 25.4);
|
||||||
|
} else {
|
||||||
|
spnResolution->setMaximum(maxRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double ScaleWindow::update_vars()
|
double ScaleWindow::update_vars()
|
||||||
{
|
{
|
||||||
double scale = (double) m_bc->bc.getScaleFromXdimDp(get_x_dim_mm(), get_dpmm(), getFileType());
|
double scale = (double) m_bc->bc.getScaleFromXdimDp(get_x_dim_mm(), get_dpmm(), getFileType());
|
||||||
|
@ -57,6 +57,7 @@ private:
|
|||||||
float get_x_dim_mm() const;
|
float get_x_dim_mm() const;
|
||||||
float get_dpmm() const;
|
float get_dpmm() const;
|
||||||
const char *getFileType() const;
|
const char *getFileType() const;
|
||||||
|
void set_maxima();
|
||||||
double update_vars();
|
double update_vars();
|
||||||
double m_originalScale;
|
double m_originalScale;
|
||||||
bool m_unset;
|
bool m_unset;
|
||||||
|