Revision: 77339
http://sourceforge.net/p/brlcad/code/77339
Author: brlcad
Date: 2020-10-06 13:13:34 +0000 (Tue, 06 Oct 2020)
Log Message:
-----------
implement support for comparing images with different sizes. instead of
globbing the extra pixels in as off by many, currently printing them separately
as a missing count
Modified Paths:
--------------
brlcad/trunk/bench/pixcmp.c
Modified: brlcad/trunk/bench/pixcmp.c
===================================================================
--- brlcad/trunk/bench/pixcmp.c 2020-10-06 03:26:48 UTC (rev 77338)
+++ brlcad/trunk/bench/pixcmp.c 2020-10-06 13:13:34 UTC (rev 77339)
@@ -127,6 +127,7 @@
size_t matching = 0;
size_t off1 = 0;
size_t offmany = 0;
+ size_t missing = 0;
int c;
int list_pixel_values = 0;
@@ -202,6 +203,7 @@
perror(argv[0]);
exit(FILE_ERROR);
}
+
if ((argc < 2) || BU_STR_EQUAL(argv[1], "-")) {
f2 = stdin;
} else if ((f2 = fopen(argv[1], "rb")) == NULL) {
@@ -225,7 +227,6 @@
bu_log("\t%s: %7llu pixels (%8llu bytes, skipping %7llu)\n",
argv[1], (unsigned long long)((sf2.st_size - f2_skip)/3),
(unsigned long long)sf2.st_size, (unsigned long long)f2_skip);
}
- bu_exit(1, "ERROR: Cannot pixcmp due to different images sizes
(unimplemented).\n");
}
/* skip requested pixels/bytes in FILE1 */
@@ -249,35 +250,40 @@
}
/* iterate over the pixels/bytes in the files */
- while ((!feof(f1) && !feof(f2)) &&
- (!ferror(f1) && !ferror(f2))) {
+ while ((!feof(f1) || !feof(f2)) &&
+ (!ferror(f1) || !ferror(f2))) {
register int r1, r2, g1, g2, b1, b2;
r1 = r2 = g1 = g2 = b1 = b2 = -1;
r1 = fgetc(f1);
r2 = fgetc(f2);
- if (feof(f1) || feof(f2)) break;
+ if (feof(f1) && feof(f2))
+ break;
bytes++;
if (!print_bytes) {
g1 = fgetc(f1);
g2 = fgetc(f2);
- if (feof(f1) || feof(f2)) break;
+ if (feof(f1) && feof(f2))
+ break;
bytes++;
b1 = fgetc(f1);
b2 = fgetc(f2);
- if (feof(f1) || feof(f2)) break;
+ if (feof(f1) && feof(f2))
+ break;
bytes++;
}
- if ((r1 == r2) && (g1 == g2) && (b1 == b2)) {
+ if ((r1 == r2 && r1 != -1 && r2 != -1) && (g1 == g2 && g1 != -1 && g2
!= -1) && (b1 == b2 && b1 != -1 && b2 != -1)) {
matching++;
continue;
}
/* tabulate differing pixels */
- if (((r1 != r2) && (g1 == g2) && (b1 == b2)) ||
- ((r1 == r2) && (g1 != g2) && (b1 == b2)) ||
- ((r1 == r2) && (g1 == g2) && (b1 != b2))) {
+ if (r1 == -1 || r2 == -1 || g1 == -1 || g2 == -1 || b1 == -1 || b2 ==
-1) {
+ missing++;
+ } else if (((r1 != r2) && (g1 == g2) && (b1 == b2)) ||
+ ((r1 == r2) && (g1 != g2) && (b1 == b2)) ||
+ ((r1 == r2) && (g1 == g2) && (b1 != b2))) {
/* off by one channel */
if (r1 != r2) {
if ((r1 > r2 ? r1 - r2 : r2 - r1) > 1) {
@@ -315,9 +321,13 @@
/* print summary */
if (!silent) {
- printf("pixcmp %s: %8zd matching, %8zd off by 1, %8zd off by many\n",
- print_bytes?"bytes":"pixels",
- matching, off1, offmany);
+ printf("pixcmp %s: %8zd matching, %8zd off by 1, %8zd off by many",
+ print_bytes?"bytes":"pixels", matching, off1, offmany);
+ if (missing) {
+ printf(", %8zd missing\n", missing);
+ } else {
+ printf("\n");
+ }
}
/* check for errors */
@@ -326,13 +336,8 @@
return FILE_ERROR;
}
- /* if files were of different lengths, consider it an error */
- if (feof(f1) != feof(f2)) {
- return FILE_ERROR;
- }
-
/* indicate how many differences there were overall */
- if (offmany) {
+ if (offmany || missing) {
return OFF_BY_MANY;
}
if (off1) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits