Revision: 56740
          http://sourceforge.net/p/brlcad/code/56740
Author:   mohitdaga
Date:     2013-08-11 10:34:18 +0000 (Sun, 11 Aug 2013)
Log Message:
-----------
Improvise bwrect utility to work correctly for input arguments. This will 
become a model for incorporating libicv in other image processing utilities.

Modified Paths:
--------------
    brlcad/trunk/src/util/bwrect.c

Modified: brlcad/trunk/src/util/bwrect.c
===================================================================
--- brlcad/trunk/src/util/bwrect.c      2013-08-10 16:40:42 UTC (rev 56739)
+++ brlcad/trunk/src/util/bwrect.c      2013-08-11 10:34:18 UTC (rev 56740)
@@ -32,12 +32,15 @@
 #include "bu.h"
 #include "icv.h"
 
+#define __ICV_DEBUG__ bu_log("bwrect : %d\n",__LINE__);
+
 int outx=0, outy=0;            /* Number of pixels in new map */
 int xorig=0, yorig=0;          /* Bottom left corner to extract from */
 int inx=512, iny=512;
 char *out_file = NULL;
 char *in_file = NULL;
 
+
 char usage[] = "\
 Usage: bwcrop [-s squaresize] [-w width] [-n height] [-W out_width ] [-N 
out_height] \n\
                        [-x xorig] [-y yorig] [-S out_squaresize] [-o 
out_file.bw] [file.bw] > [out_file.bw]\n";
@@ -81,27 +84,42 @@
            iny = inx = 1024;
            break;
            default : /* '?' */
-           bu_log("%s", usage);
            return 0;
        }
     }
-    if (bu_optind < argc) {
-       if ((isatty(fileno(stdin)))) {
-           in_file = argv[bu_optind];
-           return 1;
+    if (bu_optind >= argc) {
+       if (isatty(fileno(stdin))){
+           return 0;
        }
+    } else {
+        in_file = argv[bu_optind];
+        bu_optind++;
+        return 1;
     }
-    return 1;          /* OK */
+  
+
+    if (!isatty(fileno(stdout)) && out_file!=NULL){
+       return 0;
+    }
+
+    if (argc > ++bu_optind) {
+       fprintf(stderr, "bwfilter: excess argument(s) ignored\n");
+    }
+
+    return 1;  
 }
 
 int
 main(int argc, char **argv)
 {
     icv_image_t *img;
-    if(!get_args(argc, argv))
-       return 1;
+    if(!get_args(argc, argv)) {
+        bu_log("%s", usage);
+        return 1;
+    }
 
-    img = icv_load(in_file, ICV_IMAGE_BW, inx, iny);
+    if((img = icv_load(in_file, ICV_IMAGE_BW, inx, iny))==NULL)
+        return 1;
     icv_rect(img, xorig, yorig, outx, outy);
     icv_save(img, out_file , ICV_IMAGE_BW);
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to