Revision: 56814
http://sourceforge.net/p/brlcad/code/56814
Author: mohitdaga
Date: 2013-08-13 21:25:08 +0000 (Tue, 13 Aug 2013)
Log Message:
-----------
pixrect modified to use icv api. It now no longer supports bytes_per pixel
option and assumes 3 bytes for .pix files. Also prompting has been removed.
Supports only command line arguments.
Modified Paths:
--------------
brlcad/trunk/src/util/CMakeLists.txt
brlcad/trunk/src/util/pixrect.c
Modified: brlcad/trunk/src/util/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/util/CMakeLists.txt 2013-08-13 21:22:59 UTC (rev
56813)
+++ brlcad/trunk/src/util/CMakeLists.txt 2013-08-13 21:25:08 UTC (rev
56814)
@@ -131,7 +131,7 @@
BRLCAD_ADDEXEC(pixmerge pixmerge.c libbu)
BRLCAD_ADDEXEC(pixmorph pixmorph.c "libfb;libbu;${M_LIBRARY}")
BRLCAD_ADDEXEC(pixpaste pixpaste.c "libfb;libbu")
-BRLCAD_ADDEXEC(pixrect pixrect.c libbu)
+BRLCAD_ADDEXEC(pixrect pixrect.c "libbu;libicv")
BRLCAD_ADDEXEC(pixrot pixrot.c libbu)
BRLCAD_ADDEXEC(pixsaturate pixsaturate.c libbu)
BRLCAD_ADDEXEC(pixscale pixscale.c libbu)
Modified: brlcad/trunk/src/util/pixrect.c
===================================================================
--- brlcad/trunk/src/util/pixrect.c 2013-08-13 21:22:59 UTC (rev 56813)
+++ brlcad/trunk/src/util/pixrect.c 2013-08-13 21:25:08 UTC (rev 56814)
@@ -30,189 +30,101 @@
#include "bio.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;
-#define INTERACTIVE 0
-#define COMMAND_LINE 1
-FILE *ifp, *ofp; /* input and output file pointers */
+char usage[] = "\
+Usage: pixrect [-h] [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";
-static char *file_name;
-static int linelen; /* input width input file */
-static int xorig = 0; /* Bottom left corner to extract from */
-static int yorig = 0; /* Default at (0, 0) pixels */
-static int xnum = 0;
-static int ynum = 0;
-static int bytes_per_pixel = 3; /* Default for RGB */
-
-static const char usage[] = "\
-Usage: pixrect -w in_width -n in_height -W out_width -N out_height\n\
- [-x xoffset] [-y yoffset] [-# bytes] [infile.pix]\n\
- or pixrect [-# bytes] infile outfile (I prompt!)\n";
-
-
-int
+static int
get_args(int argc, char **argv)
{
int c;
- int inputmode = INTERACTIVE;
- int ret;
- /* Get info from command line arguments */
- while ((c = bu_getopt(argc, argv, "s:w:n:x:y:X:Y:S:W:N:#:")) != -1) {
+ while ((c = bu_getopt(argc, argv, "s:w:n:S:W:N:x:y:o:#:h?")) != -1) {
switch (c) {
case 's':
- linelen = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
+ inx = iny = atoi(bu_optarg);
+ break;
+ case 'W':
+ outx = atoi(bu_optarg);
+ break;
case 'w':
- linelen = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
+ inx = atoi(bu_optarg);
+ break;
+ case 'N':
+ outy = atoi(bu_optarg);
+ break;
case 'n':
- inputmode = COMMAND_LINE;
- break;
+ iny = atoi(bu_optarg);
+ break;
+ case 'S':
+ outy = outx = atoi(bu_optarg);
+ break;
case 'x':
- xorig = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
+ xorig = atoi(bu_optarg);
+ break;
case 'y':
- yorig = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
- case 'X':
- inputmode = COMMAND_LINE;
- break;
- case 'Y':
- inputmode = COMMAND_LINE;
- break;
- case 'S':
- xnum = ynum = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
- case 'W':
- xnum = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
- case 'N':
- ynum = atoi(bu_optarg);
- inputmode = COMMAND_LINE;
- break;
- case '#':
- bytes_per_pixel = atoi(bu_optarg);
- break;
- default: /* '?' */
- return 0;
+ yorig = atoi(bu_optarg);
+ break;
+ case 'o':
+ out_file = bu_optarg;
+ break;
+ case 'h' :
+ iny = inx = 1024;
+ break;
+ case '#' :
+ bu_log("pixrect: bytes per pixel is not supported.\n");
+ return 0;
+ default : /* '?' */
+ return 0;
}
}
-
- /* If parameters (i.e. xnum, etc.) are not entered on */
- /* command line, obtain input in the same style as */
- /* the original version of pixrect.c */
-
- if (inputmode == INTERACTIVE) {
- if (argc != 4 && argc != 3)
+ if (bu_optind >= argc) {
+ if (isatty(fileno(stdin))){
return 0;
-
- /* Obtain file pointers */
- if ((ifp = fopen(argv[argc-2], "r")) == NULL) {
- fprintf(stderr, "%s", usage);
- bu_exit(2, "pixrect: can't open %s\n", argv[argc-1]);
}
- if ((ofp = fopen(argv[argc-1], "w")) == NULL) {
- fprintf(stderr, "%s", usage);
- bu_exit(3, "pixrect: can't open %s\n", argv[argc]);
- }
+ } else {
+ in_file = argv[bu_optind];
+ bu_optind++;
+ return 1;
+ }
- /* Get info */
- printf("Area to extract (x, y) in pixels ");
- ret = scanf("%d%d", &xnum, &ynum);
- if (ret != 2)
- perror("scanf");
- printf("Origin to extract from (0, 0 is lower left) ");
- ret = scanf("%d%d", &xorig, &yorig);
- if (ret != 2)
- perror("scanf");
-
- printf("Scan line length of input file ");
- ret = scanf("%d", &linelen);
- if (ret != 1)
- perror("scanf");
+ if (!isatty(fileno(stdout)) && out_file!=NULL){
+ return 0;
}
- /* Make sure necessary variables set */
- if (linelen <= 0 || xnum <= 0 || ynum <= 0) {
- fprintf(stderr, "%s", usage);
- bu_exit(1, "pixrect: args for -w -W -N [-S] must be > 0\n");
+ if (argc > ++bu_optind) {
+ fprintf(stderr, "pixrect: excess argument(s) ignored\n");
}
- if (inputmode == COMMAND_LINE) {
- /* Obtain file pointers */
- ofp = stdout;
- if (bu_optind >= argc) {
- if (isatty(fileno(stdin))) {
- fprintf(stderr,
- "pixrect: input from stdin\n");
- return 0;
- }
- ifp = stdin;
- } else {
- file_name = argv[bu_optind];
- if ((ifp = fopen(file_name, "r")) == NULL) {
- fprintf(stderr,
- "pixrect: cannot open \"%s\" for reading\n",
- file_name);
- return 0;
- }
- }
-
- if (isatty(fileno(stdout))) {
- fprintf(stderr, "pixrect: output to stdout\n\n");
- return 0;
- }
- }
-
- return 1; /* OK */
+ return 1;
}
-
-/* ======================================================================= */
-
-char *buf; /* output scanline buffer, malloc'd */
-int outbytes;
-
int
main(int argc, char **argv)
{
- int row;
- off_t offset;
- size_t ret;
-
- if (!get_args(argc, argv)) {
- bu_exit(1, "%s", usage);
+ icv_image_t *img;
+ if(!get_args(argc, argv)) {
+ bu_log("%s", usage);
+ return 1;
}
- outbytes = xnum * bytes_per_pixel;
+ if((img = icv_read(in_file, ICV_IMAGE_PIX, inx, iny))==NULL)
+ return 1;
+ icv_rect(img, xorig, yorig, outx, outy);
+ icv_write(img, out_file , ICV_IMAGE_PIX);
- if ((buf = (char *)malloc(outbytes)) == NULL) {
- fprintf(stderr, "pixrect: malloc failed!\n");
- bu_exit (1, NULL);
- }
-
- /* Move all points */
- for (row = 0 + yorig; row < ynum + yorig; row++) {
- offset = (row * linelen + xorig) * bytes_per_pixel;
- bu_fseek(ifp, offset, 0);
- ret = fread(buf, sizeof(*buf), outbytes, ifp);
- if (ret < (size_t)outbytes)
- perror("fread");
- ret = fwrite(buf, sizeof(*buf), outbytes, ofp);
- if (ret < (size_t)outbytes)
- perror("fwrite");
- }
-
+ icv_destroy(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