Revision: 56732
          http://sourceforge.net/p/brlcad/code/56732
Author:   mohitdaga
Date:     2013-08-10 01:22:15 +0000 (Sat, 10 Aug 2013)
Log Message:
-----------
Use libicv in bwrect utility. Also modify the usage criterio of bwrect. This 
utility now accepts command line arguments instead of prompt based user inputs. 
Also it can read from stdin and save in stdout.

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

Modified: brlcad/trunk/src/util/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/util/CMakeLists.txt        2013-08-10 01:05:00 UTC (rev 
56731)
+++ brlcad/trunk/src/util/CMakeLists.txt        2013-08-10 01:22:15 UTC (rev 
56732)
@@ -63,7 +63,7 @@
 BRLCAD_ADDEXEC(bwhist bwhist.c libfb)
 BRLCAD_ADDEXEC(bwhisteq bwhisteq.c libbu)
 BRLCAD_ADDEXEC(bwmod bwmod.c "libbu;${M_LIBRARY}")
-BRLCAD_ADDEXEC(bwrect bwrect.c libbu)
+BRLCAD_ADDEXEC(bwrect bwrect.c "libbu;libicv")
 BRLCAD_ADDEXEC(bwrot bwrot.c "libbu;${M_LIBRARY}")
 BRLCAD_ADDEXEC(bwscale bwscale.c libbu)
 BRLCAD_ADDEXEC(bwshrink bwshrink.c libbu)

Modified: brlcad/trunk/src/util/bwrect.c
===================================================================
--- brlcad/trunk/src/util/bwrect.c      2013-08-10 01:05:00 UTC (rev 56731)
+++ brlcad/trunk/src/util/bwrect.c      2013-08-10 01:22:15 UTC (rev 56732)
@@ -27,70 +27,85 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include "bu.h"
+#include "icv.h"
 
+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;
 
-int xnum, ynum;                /* Number of pixels in new map */
-int xorig, yorig;              /* Bottom left corner to extract from */
-int linelen;
-char *buf;                     /* output scanline buffer, malloc'd */
+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";
 
 
-int
-main(int argc, char **argv)
+static int
+get_args(int argc, char **argv)
 {
-    FILE *ifp, *ofp;
-    int row;
-    off_t offset;
-    size_t ret;
+    int c;
 
-    if (argc < 3) {
-       bu_exit(1, "Usage: bwrect infile outfile (I prompt!)\n");
+    while ((c = bu_getopt(argc, argv, "s:w:n:S:W:N:x:y:o:h?")) != -1) {
+       switch (c) {
+           case 's':
+           inx = iny = atoi(bu_optarg);
+           break;
+           case 'W':
+           outx = atoi(bu_optarg);
+           break;
+           case 'w':
+           inx = atoi(bu_optarg);
+           break;
+           case 'N':
+           outy = atoi(bu_optarg);
+           break;
+           case 'n':
+           iny = atoi(bu_optarg);
+           break;
+           case 'S':
+           outy = outx = atoi(bu_optarg);
+           break;
+           case 'x':
+           xorig = atoi(bu_optarg);
+           break;
+           case 'y':
+           yorig = atoi(bu_optarg);
+           break;
+           case 'o':
+           out_file = bu_optarg;
+           break;
+           case 'h' :
+           iny = inx = 1024;
+           break;
+           default : /* '?' */
+           bu_log("%s", usage);
+           return 0;
+       }
     }
-    if ((ifp = fopen(argv[1], "r")) == NULL) {
-       bu_exit(2, "bwrect: can't open %s for reading\n", argv[1]);
+    if (bu_optind < argc) {
+       if ((isatty(fileno(stdin)))) {
+           in_file = argv[bu_optind];
+           return 1;
+       }
     }
-    if ((ofp = fopen(argv[2], "w")) == NULL) {
-       bu_exit(3, "bwrect: can't open %s for writing\n", argv[2]);
-    }
+    return 1;          /* OK */
+}
 
-    /* Get info */
-    printf("Area to extract (x, y) in pixels ");
-    ret = scanf("%d%d", &xnum, &ynum);
-    if (ret != 2)
-       perror("scanf");
+int
+main(int argc, char **argv)
+{
+    icv_image_t *img;
+    if(!get_args(argc, argv))
+       return 1;
 
-    printf("Origin to extract from (0, 0 is lower left) ");
-    ret = scanf("%d%d", &xorig, &yorig);
-    if (ret != 2)
-       perror("scanf");
+    img = icv_load(in_file, ICV_IMAGE_BW, inx, iny);
+    icv_rect(img, xorig, yorig, outx, outy);
+    icv_save(img, out_file , ICV_IMAGE_BW);
 
-    printf("Scan line length of input file ");
-    ret = scanf("%d", &linelen);
-    if (ret != 1)
-       perror("scanf");
-
-    buf = (char *)bu_malloc(xnum, "buffer");
-
-    /* Move all points */
-    for (row = 0+yorig; row < ynum+yorig; row++) {
-       offset = row * linelen + xorig;
-       bu_fseek(ifp, offset, 0);
-       ret = fread(buf, sizeof(*buf), xnum, ifp);
-       if (ret == 0) {
-           perror("fread");
-           break;
-       }
-
-       ret = fwrite(buf, sizeof(*buf), xnum, ofp);
-       if (ret == 0) {
-           perror("fwrite");
-           break;
-       }
-    }
-
-    bu_free(buf, "buffer");
+    icv_free(img);
     return 0;
 }
 

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