mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
test_tif: fix, use tiffinfo if available (big speedup)
This commit is contained in:
parent
2d962c6321
commit
6dc8a242df
@ -42,11 +42,13 @@ static void test_print(int index, int generate, int debug) {
|
|||||||
int have_libreoffice = 0;
|
int have_libreoffice = 0;
|
||||||
int have_ghostscript = 0;
|
int have_ghostscript = 0;
|
||||||
int have_vnu = 0;
|
int have_vnu = 0;
|
||||||
|
int have_tiffinfo = 0;
|
||||||
if (generate) {
|
if (generate) {
|
||||||
have_identify = testUtilHaveIdentify();
|
have_identify = testUtilHaveIdentify();
|
||||||
have_libreoffice = testUtilHaveLibreOffice();
|
have_libreoffice = testUtilHaveLibreOffice();
|
||||||
have_ghostscript = testUtilHaveGhostscript();
|
have_ghostscript = testUtilHaveGhostscript();
|
||||||
have_vnu = testUtilHaveVnu();
|
have_vnu = testUtilHaveVnu();
|
||||||
|
have_tiffinfo = testUtilHaveTiffInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@ -153,6 +155,9 @@ static void test_print(int index, int generate, int debug) {
|
|||||||
ret = testUtilVerifyVnu(expected_file, debug); // Very slow
|
ret = testUtilVerifyVnu(expected_file, debug); // Very slow
|
||||||
assert_zero(ret, "i:%d %s vnu %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
|
assert_zero(ret, "i:%d %s vnu %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(exts[j], "tif") == 0 && have_tiffinfo) { // Much faster (and better) than identify
|
||||||
|
ret = testUtilVerifyTiffInfo(expected_file, debug);
|
||||||
|
assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
|
||||||
} else if (strcmp(exts[j], "txt") != 0) { // I.e. rasters
|
} else if (strcmp(exts[j], "txt") != 0) { // I.e. rasters
|
||||||
if (have_identify) {
|
if (have_identify) {
|
||||||
ret = testUtilVerifyIdentify(expected_file, debug);
|
ret = testUtilVerifyIdentify(expected_file, debug);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -39,10 +39,8 @@ static void test_pixel_plot(int index, int debug) {
|
|||||||
|
|
||||||
testStart("");
|
testStart("");
|
||||||
|
|
||||||
if (!testUtilHaveIdentify()) {
|
int have_tiffinfo = testUtilHaveTiffInfo();
|
||||||
testSkip("ImageMagick identify not available");
|
int have_identify = testUtilHaveIdentify();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
struct item {
|
struct item {
|
||||||
@ -50,37 +48,38 @@ static void test_pixel_plot(int index, int debug) {
|
|||||||
int height;
|
int height;
|
||||||
char *pattern;
|
char *pattern;
|
||||||
int repeat;
|
int repeat;
|
||||||
|
int no_identify; // identify fails for some valid TIFFs (eg. RGB with LZW and large rows)
|
||||||
};
|
};
|
||||||
// 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*/ { 1, 1, "1", 0, 0 },
|
||||||
/* 1*/ { 2, 1, "11", 0 },
|
/* 1*/ { 2, 1, "11", 0, 0 },
|
||||||
/* 2*/ { 1, 2, "11", 0 },
|
/* 2*/ { 1, 2, "11", 0, 0 },
|
||||||
/* 3*/ { 2, 2, "10", 1 },
|
/* 3*/ { 2, 2, "10", 1, 0 },
|
||||||
/* 4*/ { 3, 1, "101", 0 },
|
/* 4*/ { 3, 1, "101", 0, 0 },
|
||||||
/* 5*/ { 1, 3, "101", 0 },
|
/* 5*/ { 1, 3, "101", 0, 0 },
|
||||||
/* 6*/ { 4, 1, "1010", 0 },
|
/* 6*/ { 4, 1, "1010", 0, 0 },
|
||||||
/* 7*/ { 1, 4, "1010", 0 },
|
/* 7*/ { 1, 4, "1010", 0, 0 },
|
||||||
/* 8*/ { 5, 1, "10101", 0 },
|
/* 8*/ { 5, 1, "10101", 0, 0 },
|
||||||
/* 9*/ { 1, 5, "10101", 0 },
|
/* 9*/ { 1, 5, "10101", 0, 0 },
|
||||||
/* 10*/ { 3, 2, "101", 1 },
|
/* 10*/ { 3, 2, "101", 1, 0 },
|
||||||
/* 11*/ { 100, 2, "10", 1 },
|
/* 11*/ { 100, 2, "10", 1, 0 },
|
||||||
/* 12*/ { 2, 100, "10", 1 },
|
/* 12*/ { 2, 100, "10", 1, 0 },
|
||||||
/* 13*/ { 3, 3, "101010101", 0 },
|
/* 13*/ { 3, 3, "101010101", 0, 0 },
|
||||||
/* 14*/ { 4, 3, "10", 1 },
|
/* 14*/ { 4, 3, "10", 1, 0 },
|
||||||
/* 15*/ { 3, 4, "10", 1 },
|
/* 15*/ { 3, 4, "10", 1, 0 },
|
||||||
/* 16*/ { 45, 44, "10", 1 }, // Strip Count 1, Rows Per Strip 44 (45 * 44 * 4 == 7920)
|
/* 16*/ { 45, 44, "10", 1, 0 }, // Strip Count 1, Rows Per Strip 44 (45 * 44 * 4 == 7920)
|
||||||
/* 17*/ { 45, 45, "10", 1 }, // Strip Count 1, Rows Per Strip 45 (45 * 45 * 4 == 8100)
|
/* 17*/ { 45, 45, "10", 1, 0 }, // Strip Count 1, Rows Per Strip 45 (45 * 45 * 4 == 8100)
|
||||||
/* 18*/ { 46, 45, "10", 1 }, // Strip Count 2, Rows Per Strip 44 (46 * 45 * 4 == 8280)
|
/* 18*/ { 46, 45, "10", 1, 0 }, // Strip Count 2, Rows Per Strip 44 (46 * 45 * 4 == 8280)
|
||||||
/* 19*/ { 46, 46, "10", 1 }, // Strip Count 2, Rows Per Strip 44
|
/* 19*/ { 46, 46, "10", 1, 0 }, // Strip Count 2, Rows Per Strip 44
|
||||||
/* 20*/ { 2048, 1, "10", 1 }, // Strip Count 1, Rows Per Strip 1 (2048 * 4 == 8192)
|
/* 20*/ { 2048, 1, "10", 1, 1 }, // Strip Count 1, Rows Per Strip 1 (2048 * 4 == 8192)
|
||||||
/* 21*/ { 1, 2048, "10", 1 }, // Strip Count 1, Rows Per Strip 2048
|
/* 21*/ { 1, 2048, "10", 1, 0 }, // Strip Count 1, Rows Per Strip 2048
|
||||||
/* 22*/ { 2048, 2, "10", 1 }, // Strip Count 2, Rows Per Strip 1
|
/* 22*/ { 2048, 2, "10", 1, 1 }, // Strip Count 2, Rows Per Strip 1
|
||||||
/* 23*/ { 2, 2048, "10", 1 }, // Strip Count 2, Rows Per Strip 1024 (2 * 1024 * 4 == 8192)
|
/* 23*/ { 2, 2048, "10", 1, 0 }, // Strip Count 2, Rows Per Strip 1024 (2 * 1024 * 4 == 8192)
|
||||||
/* 24*/ { 2048, 3, "10", 1 }, // Strip Count 3, Rows Per Strip 1
|
/* 24*/ { 2048, 3, "10", 1, 1 }, // Strip Count 3, Rows Per Strip 1
|
||||||
/* 25*/ { 3, 2048, "10", 1 }, // Strip Count 4, Rows Per Strip 682 ((3 * 682 + 2) * 4 == 8192)
|
/* 25*/ { 3, 2048, "10", 1, 0 }, // Strip Count 4, Rows Per Strip 682 ((3 * 682 + 2) * 4 == 8192)
|
||||||
/* 26*/ { 2049, 4, "10", 1 }, // Strip Count 4, Rows Per Strip 1 (2049 * 1 * 4 == 8196) - large rows in 1 strip, even if > 8192
|
/* 26*/ { 2049, 4, "10", 1, 1 }, // Strip Count 4, Rows Per Strip 1 (2049 * 1 * 4 == 8196) - large rows in 1 strip, even if > 8192
|
||||||
/* 27*/ { 4, 2049, "10", 1 }, // Strip Count 5, Rows Per Strip 512 ((4 * 512 + 1) * 4 == 8196)
|
/* 27*/ { 4, 2049, "10", 1, 0 }, // Strip Count 5, Rows Per Strip 512 ((4 * 512 + 1) * 4 == 8196)
|
||||||
};
|
};
|
||||||
int data_size = ARRAY_SIZE(data);
|
int data_size = ARRAY_SIZE(data);
|
||||||
|
|
||||||
@ -88,18 +87,19 @@ static void test_pixel_plot(int index, int debug) {
|
|||||||
|
|
||||||
char data_buf[65536];
|
char data_buf[65536];
|
||||||
|
|
||||||
|
struct zint_symbol *symbol = ZBarcode_Create();
|
||||||
|
assert_nonnull(symbol, "Symbol not created\n");
|
||||||
|
|
||||||
for (int i = 0; i < data_size; i++) {
|
for (int i = 0; i < data_size; i++) {
|
||||||
|
|
||||||
if (index != -1 && i != index) continue;
|
if (index != -1 && i != index) continue;
|
||||||
|
|
||||||
struct zint_symbol *symbol = ZBarcode_Create();
|
|
||||||
assert_nonnull(symbol, "Symbol not created\n");
|
|
||||||
|
|
||||||
strcpy(symbol->outfile, tif);
|
strcpy(symbol->outfile, tif);
|
||||||
|
|
||||||
symbol->bitmap_width = data[i].width;
|
symbol->bitmap_width = data[i].width;
|
||||||
symbol->bitmap_height = data[i].height;
|
symbol->bitmap_height = data[i].height;
|
||||||
strcpy(symbol->bgcolour, "FFFFFFEE"); // Use alpha background to force RGB
|
symbol->symbology = BARCODE_ULTRA; // Use ULTRA with alpha background to force RGB
|
||||||
|
strcpy(symbol->bgcolour, "FFFFFFEE");
|
||||||
symbol->debug |= debug;
|
symbol->debug |= debug;
|
||||||
|
|
||||||
int size = data[i].width * data[i].height;
|
int size = data[i].width * data[i].height;
|
||||||
@ -117,18 +117,23 @@ static void test_pixel_plot(int index, int debug) {
|
|||||||
ret = tif_pixel_plot(symbol, (unsigned char *) data_buf);
|
ret = tif_pixel_plot(symbol, (unsigned char *) data_buf);
|
||||||
assert_zero(ret, "i:%d tif_pixel_plot ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
|
assert_zero(ret, "i:%d tif_pixel_plot ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
|
||||||
|
|
||||||
ret = testUtilVerifyIdentify(symbol->outfile, debug);
|
if (have_tiffinfo) {
|
||||||
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
|
ret = testUtilVerifyTiffInfo(symbol->outfile, debug);
|
||||||
|
assert_zero(ret, "i:%d tiffinfo %s ret %d != 0\n", i, symbol->outfile, ret);
|
||||||
|
} else if (have_identify && !data[i].no_identify) {
|
||||||
|
ret = testUtilVerifyIdentify(symbol->outfile, debug);
|
||||||
|
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)) {
|
||||||
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
|
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
symbol->bitmap = NULL;
|
symbol->bitmap = NULL;
|
||||||
|
|
||||||
ZBarcode_Delete(symbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZBarcode_Delete(symbol);
|
||||||
|
|
||||||
testFinish();
|
testFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +141,7 @@ static void test_print(int index, int generate, int debug) {
|
|||||||
|
|
||||||
testStart("");
|
testStart("");
|
||||||
|
|
||||||
|
int have_tiffinfo = testUtilHaveTiffInfo();
|
||||||
int have_identify = testUtilHaveIdentify();
|
int have_identify = testUtilHaveIdentify();
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@ -240,7 +246,10 @@ static void test_print(int index, int generate, int debug) {
|
|||||||
testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].composite, data[i].expected_file, data[i].comment);
|
testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].composite, data[i].expected_file, data[i].comment);
|
||||||
ret = rename(symbol->outfile, data[i].expected_file);
|
ret = rename(symbol->outfile, data[i].expected_file);
|
||||||
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
|
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
|
||||||
if (have_identify) {
|
if (have_tiffinfo) {
|
||||||
|
ret = testUtilVerifyTiffInfo(data[i].expected_file, debug);
|
||||||
|
assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
|
||||||
|
} else if (have_identify) {
|
||||||
ret = testUtilVerifyIdentify(data[i].expected_file, debug);
|
ret = testUtilVerifyIdentify(data[i].expected_file, debug);
|
||||||
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
|
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
|
||||||
}
|
}
|
||||||
|
@ -1681,7 +1681,7 @@ int testUtilVerifyGhostscript(char *filename, int debug) {
|
|||||||
/* v.Nu https://github.com/validator/validator
|
/* v.Nu https://github.com/validator/validator
|
||||||
* Needs "$INSTALL_DIR/vnu-runtime-image/bin" in PATH */
|
* Needs "$INSTALL_DIR/vnu-runtime-image/bin" in PATH */
|
||||||
int testUtilHaveVnu() {
|
int testUtilHaveVnu() {
|
||||||
return system("vnu --version > /dev/null") == 0;
|
return system("vnu --version > /dev/null 2>&1") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int testUtilVerifyVnu(char *filename, int debug) {
|
int testUtilVerifyVnu(char *filename, int debug) {
|
||||||
@ -1700,6 +1700,26 @@ int testUtilVerifyVnu(char *filename, int debug) {
|
|||||||
return system(buf);
|
return system(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Requires libtiff 4.2.0 http://www.libtiff.org to be installed */
|
||||||
|
int testUtilHaveTiffInfo() {
|
||||||
|
return system("tiffinfo -h > /dev/null") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int testUtilVerifyTiffInfo(char *filename, int debug) {
|
||||||
|
char cmd[512 + 128];
|
||||||
|
|
||||||
|
if (strlen(filename) > 512) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (debug & ZINT_DEBUG_TEST_PRINT) {
|
||||||
|
sprintf(cmd, "tiffinfo -D %s", filename);
|
||||||
|
} else {
|
||||||
|
sprintf(cmd, "tiffinfo -D %s > /dev/null 2>&1", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return system(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *testUtilBwippName(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug, int *linear_row_height, int *gs1_cvt) {
|
static const char *testUtilBwippName(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug, int *linear_row_height, int *gs1_cvt) {
|
||||||
struct item {
|
struct item {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -119,6 +119,8 @@ int testUtilHaveGhostscript();
|
|||||||
int testUtilVerifyGhostscript(char *filename, int debug);
|
int testUtilVerifyGhostscript(char *filename, int debug);
|
||||||
int testUtilHaveVnu();
|
int testUtilHaveVnu();
|
||||||
int testUtilVerifyVnu(char *filename, int debug);
|
int testUtilVerifyVnu(char *filename, int debug);
|
||||||
|
int testUtilHaveTiffInfo();
|
||||||
|
int testUtilVerifyTiffInfo(char *filename, int debug);
|
||||||
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug);
|
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug);
|
||||||
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size);
|
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size);
|
||||||
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected);
|
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected);
|
||||||
|
@ -290,8 +290,9 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
|
|||||||
assert(strip_count > 0); /* Suppress clang-analyzer-core.UndefinedBinaryOperatorResult */
|
assert(strip_count > 0); /* Suppress clang-analyzer-core.UndefinedBinaryOperatorResult */
|
||||||
|
|
||||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||||
printf("TIFF (%dx%d) Strip Count %d, Rows Per Strip %d\n", symbol->bitmap_width, symbol->bitmap_height,
|
printf("TIFF (%dx%d) Strip Count %d, Rows Per Strip %d, Pixels Per Sample %d, Samples Per Pixel %d, PMI %d\n",
|
||||||
strip_count, rows_per_strip);
|
symbol->bitmap_width, symbol->bitmap_height, strip_count, rows_per_strip, pixels_per_sample,
|
||||||
|
samples_per_pixel, pmi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes_per_strip = rows_per_strip * ((symbol->bitmap_width + pixels_per_sample - 1) / pixels_per_sample)
|
bytes_per_strip = rows_per_strip * ((symbol->bitmap_width + pixels_per_sample - 1) / pixels_per_sample)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* zint.h - definitions for libzint
|
/* zint.h - definitions for libzint
|
||||||
|
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009-2020 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
Loading…
Reference in New Issue
Block a user