mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-20 02:05:11 -04:00
Performance improvement
Simplifies the QR code and improves performance Adds a new --dump option to output binary to stdout With thanks to Ismael Luceno
This commit is contained in:
parent
2300a76a07
commit
93c678e1cf
4 changed files with 103 additions and 293 deletions
|
@ -200,6 +200,36 @@ void error_tag(char error_string[], int error_number)
|
|||
}
|
||||
}
|
||||
|
||||
int dump_plot(struct zint_symbol *symbol)
|
||||
{
|
||||
FILE *f;
|
||||
int i, r;
|
||||
|
||||
if(symbol->output_options & BARCODE_STDOUT) {
|
||||
f = stdout;
|
||||
} else {
|
||||
f = fopen(symbol->outfile, "w");
|
||||
if(!f) {
|
||||
strcpy(symbol->errtxt, "Could not open output file");
|
||||
return ERROR_FILE_ACCESS;
|
||||
}
|
||||
}
|
||||
|
||||
fputs("[\n", f);
|
||||
for (r = 0; r < symbol->rows; r++) {
|
||||
fputs(" [ ", f);
|
||||
for (i = 0; i < symbol->width; i++) {
|
||||
fputs(module_is_set(symbol, r, i) ? "1 " : "0 ", f);
|
||||
}
|
||||
fputs("]\n", f);
|
||||
}
|
||||
fputs("]\n", f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int counter, error_number, i;
|
||||
|
@ -692,22 +722,22 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
|
|||
if(!(strcmp(output, "PNG"))) {
|
||||
if(symbol->scale < 1.0) { symbol->text[0] = '\0'; }
|
||||
error_number = png_handle(symbol, rotate_angle);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
if(!(strcmp(output, "EPS"))) {
|
||||
error_number = ps_plot(symbol);
|
||||
} else {
|
||||
if(!(strcmp(output, "SVG"))) {
|
||||
error_number = svg_plot(symbol);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "Unknown output format");
|
||||
error_tag(symbol->errtxt, ERROR_INVALID_OPTION);
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
}
|
||||
#ifndef NO_PNG
|
||||
if(!(strcmp(output, "TXT"))) {
|
||||
error_number = dump_plot(symbol);
|
||||
} else
|
||||
if(!(strcmp(output, "EPS"))) {
|
||||
error_number = ps_plot(symbol);
|
||||
} else
|
||||
if(!(strcmp(output, "SVG"))) {
|
||||
error_number = svg_plot(symbol);
|
||||
} else
|
||||
{
|
||||
strcpy(symbol->errtxt, "Unknown output format");
|
||||
error_tag(symbol->errtxt, ERROR_INVALID_OPTION);
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "Unknown output format");
|
||||
error_tag(symbol->errtxt, ERROR_INVALID_OPTION);
|
||||
|
@ -777,22 +807,27 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
|
|||
unsigned int nRead = 0, n = 0;
|
||||
int ret;
|
||||
|
||||
file = fopen(filename, "rb");
|
||||
if (!file) {
|
||||
strcpy(symbol->errtxt, "Unable to read input file");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
if (!strcmp(filename, "-")) {
|
||||
file = stdin;
|
||||
fileLen = 7100;
|
||||
} else {
|
||||
file = fopen(filename, "rb");
|
||||
if (!file) {
|
||||
strcpy(symbol->errtxt, "Unable to read input file");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Get file length */
|
||||
fseek(file, 0, SEEK_END);
|
||||
fileLen = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
/* Get file length */
|
||||
fseek(file, 0, SEEK_END);
|
||||
fileLen = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
if(fileLen > 7100) {
|
||||
/* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */
|
||||
strcpy(symbol->errtxt, "Input file too long");
|
||||
fclose(file);
|
||||
return ERROR_INVALID_DATA;
|
||||
if(fileLen > 7100) {
|
||||
/* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */
|
||||
strcpy(symbol->errtxt, "Input file too long");
|
||||
fclose(file);
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue