Sean, H.S.Rai,

Attached is my patch to bench/pixcmp.c which adds the option of adding the parameter so that one could check the number of pixels which are "off by a certain value". The default value is still 1. I've tested for a few cases and they were fine but I want to be absolutely sure before I can commit it to the trunk.

Usage is as follows:
brlcad-build → bin/pixcmp -d4 ../brlcad/pix/moss.pix ../brlcad/pix/moss_new.pix
pixcmp pixels: 262140 matching, 4 off by 4, 0 off by many

brlcad-build → bin/pixcmp -d2 ../brlcad/pix/moss.pix ../brlcad/pix/moss.pix
pixcmp pixels: 262144 matching, 0 off by 2, 0 off by many

brlcad-build → bin/pixcmp -d2 ../brlcad/pix/moss.pix ../brlcad/pix/moss_new.pix
pixcmp pixels: 262140 matching, 4 off by 2, 0 off by many

brlcad-build → bin/pixcmp -d1 ../brlcad/pix/moss.pix ../brlcad/pix/moss_new.pix
pixcmp pixels: 262140 matching, 2 off by 1, 2 off by many

brlcad-build → bin/pixcmp ../brlcad/pix/moss.pix ../brlcad/pix/moss_new.pix
pixcmp pixels: 262140 matching, 2 off by 1, 2 off by many

Could you please check if that is what I was expected to rewrite?

Thank you,

--
Regards,
Suryajith Chillara.

Index: bench/pixcmp.c
===================================================================
--- bench/pixcmp.c	(revision 50621)
+++ bench/pixcmp.c	(working copy)
@@ -45,7 +45,7 @@
 
 /* exit codes for normal operation */
 #define OFF_BY_NONE 0
-#define OFF_BY_ONE  1
+#define OFF_BY_VAL  1
 #define OFF_BY_MANY 2
 
 
@@ -61,6 +61,7 @@
 	   "Compare two PIX image files pixel by pixel.\n\n"
 	   "  -l   List pixel numbers and values for all pixels that differ.\n"
 	   "  -b   Output and process by bytes instead of pixels.\n"
+	   "  -d<param>  Set the parameter param to check the off-by-param value.\n"
 	   "  -i SKIP\n"
 	   "       Skip the first SKIP pixels of input (for FILE1 and FILE2)\n");
     bu_log("  -i SKIP1:SKIP2\n"
@@ -120,10 +121,12 @@
     FILE *f2 = NULL;
 
     long matching = 0;
-    long off1 = 0;
+    long offval = 0;
     long offmany = 0;
-
+    
     int c;
+    int count = 0;
+    int param = 1;
     int list_pixel_values = 0;
     int print_bytes = 0;
     int silent = 0;
@@ -133,7 +136,7 @@
     long int bytes = 0;
 
     /* process opts */
-    while ((c = bu_getopt(argc, argv, "lbi:s")) != -1) {
+    while ((c = bu_getopt(argc, argv, "lbd:i:s")) != -1) {
 	switch (c) {
 	    case 'l':
 		list_pixel_values = 1;
@@ -147,12 +150,16 @@
 	    case 's':
 		silent = 1;
 		break;
+	    case 'd':
+		param = atoi(bu_optarg);
+		break;
 	    default:
 		bu_log("\n");
 		usage(argv[0]);
 		exit(OPTS_ERROR);
 	}
     }
+
     argc -= bu_optind;
     argv += bu_optind;
 
@@ -245,39 +252,32 @@
 	    bytes++;
 	}
 
-	if ((r1 == r2) && (g1 == g2) && (b1 == b2)) {
-	    matching++;
-	    continue;
-	}
-
-	/* tabulate differing pixels */
-	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) {
-		    offmany++;
+	/* Handle each of the possible cases in a tree like walk.*/
+	if (r1 == r2) {
+	    if (g1 == g2) {
+		if (b1 == b2){
+		    matching++;
+		    continue;
 		} else {
-		    off1++;
+		    count = (b1 > b2 ? b1 - b2 : b2 - b1);
 		}
-	    } else if (g1 != g2) {
-		if ((g1 > g2 ? g1 - g2 : g2 - g1) > 1) {
-		    offmany++;
-		} else {
-		    off1++;
-		}
-	    } else if (b1 != b2) {
-		if ((b1 > b2 ? b1 - b2 : b2 - b1) > 1) {
-		    offmany++;
-		} else {
-		    off1++;
-		}
+	    } else {
+		count = (g1 > g2 ? g1 - g2 : g2 - g1);
+		if (b1 != b2)
+		    count += (b1 > b2 ? b1 - b2 : b2 - b1);
 	    }
 	} else {
-	    /* off by many */
+	    count = (r1 > r2 ? r1 - r2 : r2 - r1);
+	    if (g1 != g2)
+		count += (g1 > g2 ? g1 - g2 : g2 - g1);
+	    if (b1 != b2)
+		count += (b1 > b2 ? b1 - b2 : b2 - b1);
+	}
+	
+	if (count > param)
 	    offmany++;
-	}
+	else
+	    offval++;
 
 	/* they're different, so print something */
 	if (list_pixel_values) {
@@ -291,11 +291,11 @@
 
     /* print summary */
     if (!silent) {
-	printf("pixcmp %s: %8ld matching, %8ld off by 1, %8ld off by many\n",
+	printf("pixcmp %s: %8ld matching, %8ld off by %d, %8ld off by many\n",
 	       print_bytes?"bytes":"pixels",
-	       matching, off1, offmany);
+	       matching, offval, param, offmany);
     }
-
+    
     /* check for errors */
     if (ferror(f1) || ferror(f2)) {
 	perror("pixcmp file error");
@@ -311,8 +311,8 @@
     if (offmany) {
 	return OFF_BY_MANY;
     }
-    if (off1) {
-	return OFF_BY_ONE;
+    if (offval) {
+	return OFF_BY_VAL;
     }
 
     /* Success! */
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to