Revision: 57082
http://sourceforge.net/p/brlcad/code/57082
Author: mohitdaga
Date: 2013-08-22 21:04:13 +0000 (Thu, 22 Aug 2013)
Log Message:
-----------
Update bw-pix to use libicv. Also this imporves the usability of bw-pix.
Modified Paths:
--------------
brlcad/trunk/src/util/CMakeLists.txt
brlcad/trunk/src/util/bw-pix.c
Modified: brlcad/trunk/src/util/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/util/CMakeLists.txt 2013-08-22 21:01:05 UTC (rev
57081)
+++ brlcad/trunk/src/util/CMakeLists.txt 2013-08-22 21:04:13 UTC (rev
57082)
@@ -52,7 +52,7 @@
BRLCAD_ADDEXEC(buffer buffer.c libbu)
BRLCAD_ADDEXEC(bw-a bw-a.c "libfb;libbu")
BRLCAD_ADDEXEC(bw-imp bw-imp.c libbu)
-BRLCAD_ADDEXEC(bw-pix bw-pix.c libbu)
+BRLCAD_ADDEXEC(bw-pix bw-pix.c "libbu;libicv")
BRLCAD_ADDEXEC(bw-png bw-png.c "libfb;libbu;${PNG_LIBRARY}")
BRLCAD_ADDEXEC(bw-ps bw-ps.c libbu)
BRLCAD_ADDEXEC(bw-rle "bw-rle.c;rle_args.c" "libbu;libsysv;${UTAHRLE_LIBRARY}")
Modified: brlcad/trunk/src/util/bw-pix.c
===================================================================
--- brlcad/trunk/src/util/bw-pix.c 2013-08-22 21:01:05 UTC (rev 57081)
+++ brlcad/trunk/src/util/bw-pix.c 2013-08-22 21:04:13 UTC (rev 57082)
@@ -23,67 +23,86 @@
* color one by replicating each value three times.
*
*/
-
#include "common.h"
-
#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
+#include <stdio.h>
#include "bio.h"
-
+#include "icv.h"
#include "bu.h"
-void
-printusage(void) {
- bu_exit(3, "Usage: bw-pix [in.bw] [out.pix]\n");
-}
+char usage[] = "\
+Usage: bw-pix [-h] [-s squaresize] [-w width] [-n height] \n\
+ [-o out_file.pix] [file.pix] > [out_file.pix]\n";
+int inx=512, iny=512;
+char *out_file = NULL;
+char *in_file = NULL;
+
int
-main(int argc, char **argv)
+get_args(int argc, char **argv)
{
- unsigned char ibuf[1024], obuf[3*1024];
- size_t in, out, num;
- FILE *finp, *foutp;
+ int c;
- if ( BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?") )
- printusage();
-
- /* check for input file */
- if (argc > 1) {
- if ((finp = fopen(argv[1], "rb")) == NULL) {
- bu_exit(1, "bw-pix: can't open \"%s\" for reading\n", argv[1]);
+ while ((c = bu_getopt(argc, argv, "s:w:n:o:h?")) != -1) {
+ switch (c) {
+ case 's':
+ inx = iny = atoi(bu_optarg);
+ break;
+ case 'w':
+ inx = atoi(bu_optarg);
+ break;
+ case 'n':
+ iny = atoi(bu_optarg);
+ break;
+ case 'o':
+ out_file = bu_optarg;
+ break;
+ case 'h':
+ default: /* '?' */
+ return 0;
}
- } else
- finp = stdin;
+ }
- /* check for output file */
- if (argc > 2) {
- if ((foutp = fopen(argv[2], "wb")) == NULL) {
- bu_exit(2, "bw-pix: can't open \"%s\" for writing\n", argv[2]);
+ if (bu_optind >= argc) {
+ if (isatty(fileno(stdin))) {
+ return 0;
}
- } else
- foutp = stdout;
+ } else {
+ in_file = argv[bu_optind];
+ bu_optind++;
+ return 1;
+ }
- if (argc > 3 || isatty(fileno(finp)) || isatty(fileno(foutp)))
- printusage();
- while ((num = fread(ibuf, sizeof(char), 1024, finp)) > 0) {
- size_t ret;
- for (in = out = 0; in < num; in++, out += 3) {
- obuf[out] = ibuf[in];
- obuf[out+1] = ibuf[in];
- obuf[out+2] = ibuf[in];
- }
- ret = fwrite(obuf, sizeof(char), 3*num, foutp);
- if (ret == 0) {
- perror("fwrite");
- break;
- }
+ if (!isatty(fileno(stdout)) && out_file!=NULL) {
+ return 0;
}
+
+ if (argc > ++bu_optind) {
+ bu_log("bw-pix: excess argument(s) ignored\n");
+ }
+
+ return 1; /* OK */
+}
+
+int
+main(int argc, char **argv)
+{
+ icv_image_t *img;
+ if (!get_args(argc, argv)) {
+ bu_log("%s", usage);
+ return 1;
+ }
+
+ img = icv_read(in_file, ICV_IMAGE_BW, inx, iny);
+ if (img == NULL)
+ return 1;
+ icv_gray2rgb(img);
+ icv_write(img, out_file, ICV_IMAGE_PIX);
+ icv_destroy(img);
return 0;
}
-
/*
* Local Variables:
* mode: C
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits