Thread: [brlcad-commits] SF.net SVN: brlcad:[62964] brlcad/trunk/src/util (Page 4)
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2014-09-24 16:13:50
|
Revision: 62964 http://sourceforge.net/p/brlcad/code/62964 Author: starseeker Date: 2014-09-24 16:13:42 +0000 (Wed, 24 Sep 2014) Log Message: ----------- update comments Modified Paths: -------------- brlcad/trunk/src/util/admin-db.cpp brlcad/trunk/src/util/bu_arg_parse_private.h Modified: brlcad/trunk/src/util/admin-db.cpp =================================================================== --- brlcad/trunk/src/util/admin-db.cpp 2014-09-24 15:41:51 UTC (rev 62963) +++ brlcad/trunk/src/util/admin-db.cpp 2014-09-24 16:13:42 UTC (rev 62964) @@ -6,7 +6,7 @@ #include <sys/stat.h> #include "bio.h" -#include "bu_arg_parse.h" // includes bu.h +#include "bu_arg_parse.h" #include "raytrace.h" using namespace std; Modified: brlcad/trunk/src/util/bu_arg_parse_private.h =================================================================== --- brlcad/trunk/src/util/bu_arg_parse_private.h 2014-09-24 15:41:51 UTC (rev 62963) +++ brlcad/trunk/src/util/bu_arg_parse_private.h 2014-09-24 16:13:42 UTC (rev 62964) @@ -25,7 +25,7 @@ /* local customizations of TCLAP MUST follow the above header */ /* get common data from the C world */ -#include "bu_arg_parse.h" /* includes bu.h */ +#include "bu_arg_parse.h" // some customization of TCLAP classes class BRLCAD_StdOutput : public TCLAP::StdOutput This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-01-13 18:52:59
|
Revision: 63942 http://sourceforge.net/p/brlcad/code/63942 Author: carlmoore Date: 2015-01-13 18:52:56 +0000 (Tue, 13 Jan 2015) Log Message: ----------- in 2 utilities, implement h? for help; this necessitated ending a -h for high-res Modified Paths: -------------- brlcad/trunk/src/util/pixembed.c brlcad/trunk/src/util/pixmerge.c Modified: brlcad/trunk/src/util/pixembed.c =================================================================== --- brlcad/trunk/src/util/pixembed.c 2015-01-13 18:41:10 UTC (rev 63941) +++ brlcad/trunk/src/util/pixembed.c 2015-01-13 18:52:56 UTC (rev 63942) @@ -51,7 +51,7 @@ void load_buffer(void), write_buffer(void); static char usage[] = "\ -Usage: pixembed [-h] [-b border_inset] \n\ +Usage: pixembed [-b border_inset] \n\ [-s squareinsize] [-w inwidth] [-n inheight]\n\ [-S squareoutsize] [-W outwidth] [-N outheight] [in.pix] > out.pix\n"; @@ -62,15 +62,11 @@ { int c; - while ((c = bu_getopt(argc, argv, "b:hs:w:n:S:W:N:")) != -1) { + while ((c = bu_getopt(argc, argv, "b:s:w:n:S:W:N:h?")) != -1) { switch (c) { case 'b': border_inset = atoi(bu_optarg); break; - case 'h': - /* high-res */ - xin = yin = 1024; - break; case 'S': /* square size */ xout = yout = atoi(bu_optarg); @@ -92,7 +88,7 @@ yin = atoi(bu_optarg); break; - default: /* '?' */ + default: /* 'h' '?' */ return 0; } } Modified: brlcad/trunk/src/util/pixmerge.c =================================================================== --- brlcad/trunk/src/util/pixmerge.c 2015-01-13 18:41:10 UTC (rev 63941) +++ brlcad/trunk/src/util/pixmerge.c 2015-01-13 18:52:56 UTC (rev 63942) @@ -75,7 +75,7 @@ { int c; - while ((c = bu_getopt(argc, argv, "glenw:C:c:")) != -1) { + while ((c = bu_getopt(argc, argv, "glenw:C:c:h?")) != -1) { switch (c) { case 'g': wanted |= GT; @@ -114,7 +114,7 @@ seen_const = 1; break; - default: /* '?' */ + default: /* 'h' '?' */ return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-01-23 21:02:14
|
Revision: 64044 http://sourceforge.net/p/brlcad/code/64044 Author: carlmoore Date: 2015-01-23 21:02:10 +0000 (Fri, 23 Jan 2015) Log Message: ----------- various fixes regarding h,? in src/util files; in buffer.c , removed a bu_log argument which wasn't needed Modified Paths: -------------- brlcad/trunk/src/util/buffer.c brlcad/trunk/src/util/bw-pix.c brlcad/trunk/src/util/terrain.c brlcad/trunk/src/util/texturescale.c brlcad/trunk/src/util/wavelet.c brlcad/trunk/src/util/yuv-pix.c Modified: brlcad/trunk/src/util/buffer.c =================================================================== --- brlcad/trunk/src/util/buffer.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/buffer.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -61,7 +61,7 @@ if (argc > 1) { bu_log("%s: unrecognized argument(s)\n", argv[0]); - bu_log(" Program continues running:\n", argv[0]); + bu_log(" Program continues running:\n"); } if ((count = bu_mread(0, buf, sizeof(buf))) < (long)sizeof(buf)) { Modified: brlcad/trunk/src/util/bw-pix.c =================================================================== --- brlcad/trunk/src/util/bw-pix.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/bw-pix.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -62,8 +62,7 @@ case 'n' : iny = atoi(bu_optarg); break; - case 'h': - default: /* '?' */ + default: /* '?' 'h' */ return 0; } } Modified: brlcad/trunk/src/util/terrain.c =================================================================== --- brlcad/trunk/src/util/terrain.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/terrain.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -51,7 +51,7 @@ /* declarations to support use of bu_getopt() system call */ -char *options = "w:n:s:L:H:O:S:V:D:f:co:v"; +char *options = "w:n:s:L:H:O:S:V:D:f:co:vh?"; int do_convert = 1; char *progname = "(noname)"; @@ -569,6 +569,7 @@ /* get all the option flags from the command line */ while ((c = bu_getopt(ac, av, options)) != -1) { + if (bu_optopt == '?') c='h'; switch (c) { case 'v': debug = !debug; @@ -651,11 +652,12 @@ break; } break; - case '?': case 'h': - default : - usage("Bad or help flag specified\n"); + usage(""); break; + default: + usage("Bad flag specified\n"); + break; } } Modified: brlcad/trunk/src/util/texturescale.c =================================================================== --- brlcad/trunk/src/util/texturescale.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/texturescale.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -59,7 +59,7 @@ fflush(stderr) static char usage[] = "\ Usage: texturescale [-T 'r1 r2' | -S]\n\ - [-ah] [-s squaresize] [-w file_width] [-n file_height]\n\ + [-a] [-s squaresize] [-w file_width] [-n file_height]\n\ [file.pix]\n"; /* @@ -98,14 +98,11 @@ int c; while ((c = bu_getopt(argc, argv, OPT_STRING)) != -1) { + if (bu_optopt == '?') c='h'; switch (c) { case 'a': autosize = 1; break; - case 'h': - file_height = file_width = 1024L; - autosize = 0; - break; case 'n': file_height = atol(bu_optarg); autosize = 0; @@ -129,7 +126,7 @@ } solid_type = TORUS; break; - case '?': + case 'h': (void) fputs(usage, stderr); bu_exit (0, NULL); default: Modified: brlcad/trunk/src/util/wavelet.c =================================================================== --- brlcad/trunk/src/util/wavelet.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/wavelet.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -63,7 +63,7 @@ #define RECONSTRUCT -1 /* declarations to support use of bu_getopt() system call */ -char *options = "W:S:s:w:n:t:#:D:12drR:"; +char *options = "W:S:s:w:n:t:#:D:12drR:h?"; char *progname = "(noname)"; int img_space=1; @@ -108,6 +108,7 @@ /* get all the option flags from the command line */ while ((c=bu_getopt(ac, av, options)) != -1) + if (bu_optopt == '?') c='h'; switch (c) { case '1': img_space=1; break; case '2': img_space=2; break; @@ -147,11 +148,12 @@ case 's': width = height = atoi(bu_optarg); break; case 'W': limit = atoi(bu_optarg); break; case 'S': limit = atoi(bu_optarg); break; - case '?': case 'h': - default : fprintf(stderr, "Bad or help flag specified %c\n", c); usage(""); break; + default: fprintf(stderr, "Bad flag specified %c\n", bu_optopt); + usage(""); + break; } return bu_optind; Modified: brlcad/trunk/src/util/yuv-pix.c =================================================================== --- brlcad/trunk/src/util/yuv-pix.c 2015-01-23 20:55:01 UTC (rev 64043) +++ brlcad/trunk/src/util/yuv-pix.c 2015-01-23 21:02:10 UTC (rev 64044) @@ -60,11 +60,10 @@ void ab_yuv_to_rgb(unsigned char *rgb_buf, unsigned char *yuv_buf, long int len); static const char usage[] = - "Usage: yuv-pix [-h] [-a]\n" - " [-s squaresize] [-w file_width] [-n file_height] [file.yuv] > file.pix\n" + "Usage: yuv-pix [-a] [-s squaresize] [-w file_width] [-n file_height] [file.yuv] > file.pix\n" ; -static const char optstring[] = "ahs:w:n:"; +static const char optstring[] = "as:w:n:h?"; int get_args(int argc, char **argv) @@ -76,11 +75,6 @@ case 'a': autosize = 1; break; - case 'h': - /* high-res */ - file_height = file_width = 1024L; - autosize = 0; - break; case 's': /* square file size */ file_height = file_width = atol(bu_optarg); @@ -95,7 +89,7 @@ autosize = 0; break; - default: /* '?' */ + default: /* '?' 'h' */ return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-04-01 18:05:11
|
Revision: 64552 http://sourceforge.net/p/brlcad/code/64552 Author: carlmoore Date: 2015-04-01 18:05:08 +0000 (Wed, 01 Apr 2015) Log Message: ----------- adjust the remark alongside 'default:' Modified Paths: -------------- brlcad/trunk/src/util/bw-png.c brlcad/trunk/src/util/pix-png.c Modified: brlcad/trunk/src/util/bw-png.c =================================================================== --- brlcad/trunk/src/util/bw-png.c 2015-04-01 17:27:08 UTC (rev 64551) +++ brlcad/trunk/src/util/bw-png.c 2015-04-01 18:05:08 UTC (rev 64552) @@ -78,7 +78,7 @@ autosize = 0; break; - default: /* '?' */ + default: /* 'h' '?' */ return 0; } } Modified: brlcad/trunk/src/util/pix-png.c =================================================================== --- brlcad/trunk/src/util/pix-png.c 2015-04-01 17:27:08 UTC (rev 64551) +++ brlcad/trunk/src/util/pix-png.c 2015-04-01 18:05:08 UTC (rev 64552) @@ -95,7 +95,7 @@ break; } - default: /* help */ + default: /* 'h' '?' */ return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-04-06 19:59:37
|
Revision: 64577 http://sourceforge.net/p/brlcad/code/64577 Author: carlmoore Date: 2015-04-06 19:59:29 +0000 (Mon, 06 Apr 2015) Log Message: ----------- make the Usage statements look more alike (removing blank lines) Modified Paths: -------------- brlcad/trunk/src/util/bw-png.c brlcad/trunk/src/util/pix-png.c Modified: brlcad/trunk/src/util/bw-png.c =================================================================== --- brlcad/trunk/src/util/bw-png.c 2015-04-06 19:56:05 UTC (rev 64576) +++ brlcad/trunk/src/util/bw-png.c 2015-04-06 19:59:29 UTC (rev 64577) @@ -50,8 +50,7 @@ #define ROWSIZE (file_width * BYTESPERPIXEL) #define SIZE (file_height * ROWSIZE) -static char usage[] = "\ -Usage: bw-png [-a] [-w file_width] [-n file_height]\n\ +static char usage[] = "Usage: bw-png [-a] [-w file_width] [-n file_height]\n\ [-s square_file_size] [file.bw]\n"; int Modified: brlcad/trunk/src/util/pix-png.c =================================================================== --- brlcad/trunk/src/util/pix-png.c 2015-04-06 19:56:05 UTC (rev 64576) +++ brlcad/trunk/src/util/pix-png.c 2015-04-06 19:59:29 UTC (rev 64577) @@ -205,7 +205,8 @@ outfp = stdout; if (!get_args(argc, argv, &file_width, &file_height, &infp, &outfp)) { - bu_exit(1, "%s\n", usage); + (void)fputs(usage, stderr); + bu_exit(1, NULL); } /* autosize input? */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-05-04 20:34:38
|
Revision: 64850 http://sourceforge.net/p/brlcad/code/64850 Author: carlmoore Date: 2015-05-04 20:34:35 +0000 (Mon, 04 May 2015) Log Message: ----------- change an error message in pixmatte so we specify pixmatte Modified Paths: -------------- brlcad/trunk/src/util/pixmatte.c brlcad/trunk/src/util/pixmerge.c Modified: brlcad/trunk/src/util/pixmatte.c =================================================================== --- brlcad/trunk/src/util/pixmatte.c 2015-05-04 20:21:42 UTC (rev 64849) +++ brlcad/trunk/src/util/pixmatte.c 2015-05-04 20:34:35 UTC (rev 64850) @@ -175,7 +175,7 @@ case 'w': c = atoi(bu_optarg); if (c < 1 || c >= EL_WIDTH) - usage("Illegal width specified\n", 1); + usage("pixmatte: illegal width specified\n", 1); width = c; break; default: /* '?' 'h' */ Modified: brlcad/trunk/src/util/pixmerge.c =================================================================== --- brlcad/trunk/src/util/pixmerge.c 2015-05-04 20:21:42 UTC (rev 64849) +++ brlcad/trunk/src/util/pixmerge.c 2015-05-04 20:34:35 UTC (rev 64850) @@ -40,6 +40,7 @@ #include "bu/str.h" #include "bu/log.h" +static int width = 3; static char *f1_name; static char *f2_name; @@ -50,12 +51,14 @@ #define EQ 2 #define GT 4 #define NE 8 -static int wanted; /* LT|EQ|GT conditions to pick fb */ +static int wanted = 0; /* LT|EQ|GT conditions to pick fb */ +static long fg_cnt = 0; +static long bg_cnt = 0; + static int seen_const = 0; static int seen_formula = 0; -static int width = 3; static unsigned char pconst[32]; #define CHUNK 1024 @@ -63,9 +66,6 @@ static char *b2; /* bg input buffer */ static char *b3; /* output buffer */ -static long fg_cnt; -static long bg_cnt; - static char usage[] = "\ Usage: pixmerge [-g -l -e -n] [-w bytes_wide] [-C r/g/b]\n\ foreground.pix background.pix > out.pix\n"; @@ -114,7 +114,7 @@ seen_const = 1; break; - default: /* 'h' '?' */ + default: /* '?' 'h' */ return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2015-05-30 19:42:05
|
Revision: 65120 http://sourceforge.net/p/brlcad/code/65120 Author: starseeker Date: 2015-05-30 19:42:02 +0000 (Sat, 30 May 2015) Log Message: ----------- Add an example of dsp_add_opt.c using the experimental libbu opt API. Looks a bit too simple to make a really good test - should probably experiment with rt for a real stress test. Modified Paths: -------------- brlcad/trunk/src/util/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/util/dsp_add_opt.c Modified: brlcad/trunk/src/util/CMakeLists.txt =================================================================== --- brlcad/trunk/src/util/CMakeLists.txt 2015-05-30 19:40:21 UTC (rev 65119) +++ brlcad/trunk/src/util/CMakeLists.txt 2015-05-30 19:42:02 UTC (rev 65120) @@ -93,6 +93,9 @@ # ignore it for now CMAKEFILES(test_bu_arg_parse.c) +# LIBBU advance option handling test +BRLCAD_ADDEXEC(dsp_add_opt dsp_add_opt.c libbu NO_INSTALL) + # a new admin file BRLCAD_ADDEXEC(admin-db "admin-db.cpp;bu_arg_parse.cpp" "libbu;librt" NO_INSTALL) Added: brlcad/trunk/src/util/dsp_add_opt.c =================================================================== --- brlcad/trunk/src/util/dsp_add_opt.c (rev 0) +++ brlcad/trunk/src/util/dsp_add_opt.c 2015-05-30 19:42:02 UTC (rev 65120) @@ -0,0 +1,319 @@ +/* D S P _ A D D . C + * BRL-CAD + * + * Copyright (c) 2004-2014 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file util/dsp_add.c + * + * add 2 files of network unsigned shorts + * + * Options + * h help + */ + +#include "common.h" + +#include <stdlib.h> +#include <sys/stat.h> +#include "bio.h" + +#include "vmath.h" +#include "bu/getopt.h" +#include "bu/malloc.h" +#include "bu/log.h" +#include "bu/opt.h" +#include "bu/cv.h" +#include "bn.h" + + +/* declarations to support use of bu_getopt() system call */ +static const char usage[] = "Usage: dsp_add [opts] dsp_1 dsp_2 > dsp_3\n"; + +enum dsp_add_enums {DSP_HELP}; +struct bu_opt_desc dsp_opt_desc[3] = { + {DSP_HELP, 0, 0, "h", "help", NULL, "-h", "--help", "Print help and exit"}, + {DSP_HELP, 0, 0, "?", "", NULL, "-?", "", ""}, + BU_OPT_DESC_NULL +}; + +/* purpose: combine two dsp files + * + * description: Combines two dsp files (which are binary files + * comprised of network unsigned shorts). The two files must be of + * identical size. The result, written to stdout, is a file where + * each cell's height is the total of the heights of the same cell + * in the input files. + * + * See the BRL-CAD wiki for a tutorial on using dsp's. + * + * see_also: dsp(5) asc2dsp(1) cv(1) + * + * opt: -h brief help + * + * opt: -? brief help + * + */ + +#define ADD_STYLE_INT 0 +#define ADD_STYLE_FLOAT 1 + +static int style = ADD_STYLE_INT; + +/* + * tell user how to invoke this program, then exit + */ +static void +print_usage() +{ + const char *help = bu_opt_describe(dsp_opt_desc, NULL); + bu_log(usage); + bu_log("Options:\n%s\n", help); + bu_free((char *)help, "help str"); + bu_exit (1, NULL); +} + + +/* + * Parse command line flags + */ +struct bu_ptbl * +parse_args(int ac, char *av[]) +{ + size_t i = 0; + struct bu_ptbl *results; + (void)bu_opt_parse(&results, NULL, ac, (const char **)av, dsp_opt_desc); + bu_opt_compact(results); + + for (i = 0; i < BU_PTBL_LEN(results); i++) { + struct bu_opt_data *d = (struct bu_opt_data *)BU_PTBL_GET(results, i); + if (!d->valid || !d->name || !d->desc) continue; + switch(d->desc->shortopt[0]) { + default: + bu_opt_data_free_tbl(results); + print_usage(); + } + } + + return results; +} + + +static void +swap_bytes(unsigned short *buf, unsigned long count) +{ + unsigned short *p; + + for (p = &buf[count-1]; p >= buf; p--) + *p = ((*p << 8) & 0x0ff00) | (*p >> 8); +} + + +/* + * Perform floating point addition and re-normalization of the data. + */ +static void +add_float(unsigned short *buf1, unsigned short *buf2, unsigned long count) +{ + unsigned short *p, *q, *e; + double *dbuf, *d; + double min, max, k; + + dbuf = (double *)bu_malloc(sizeof(double) * count, "buffer of double"); + + min = MAX_FASTF; + max = -MAX_FASTF; + e = &buf1[count]; + + /* add everything, keeping track of the min/max values found */ + for (d = dbuf, p = buf1, q = buf2; p < e; p++, q++, d++) { + *d = *p + *q; + if (*d > max) max = *d; + if (*d < min) min = *d; + } + + /* now we convert back to unsigned shorts in the range 1 .. 65535 */ + + k = 65534.0 / (max - min); + + bu_log("min: %g scale: %g\n", min - k, k); + + for (d = dbuf, p = buf1, q = buf2; p < e; p++, q++, d++) + *p = (unsigned short) ((*d - min) * k) + 1; + + bu_free(dbuf, "buffer of double"); +} + + +/* + * Perform simple integer addition to the input streams. + * Issue warning on overflow. + * + * Result: buf1 contents modified + */ +static void +add_int(unsigned short *buf1, unsigned short *buf2, unsigned long count) +{ + int int_value; + unsigned long i; + unsigned short s; + + for (i = 0; i < count; i++) { + int_value = buf1[i] + buf2[i]; + s = (unsigned short)int_value; + + if (s != int_value) { + bu_log("overflow (%d+%d) == %d at %lu\n", + buf1[i], buf2[i], int_value, i); + } + buf1[i] = s; + } + +} + + +/* + * Call parse_args to handle command line arguments first, then + * process input. + */ +int +main(int ac, char *av[]) +{ + struct bu_opt_data *non_opts; + struct bu_ptbl *results; + FILE *in1, *in2; + unsigned short *buf1, *buf2; + size_t count; + int in_cookie, out_cookie; + int conv; + struct stat sb; + size_t ret; + const char *f1, *f2; + + if (ac < 2) + print_usage(); + + if (isatty(fileno(stdout))) { + bu_log("Error: Must redirect standard output\n"); + print_usage(); + } + + results = parse_args(ac, av); + non_opts = bu_opt_find(BU_NON_OPTS, results); + + if (!non_opts->args || BU_PTBL_LEN(non_opts->args) < 2) { + bu_log("Error: No files specified\n"); + print_usage(); + } + + /* Open the files */ + f1 = bu_opt_data_arg(non_opts, 0); + f2 = bu_opt_data_arg(non_opts, 1); + + in1 = fopen(f1, "r"); + if (!in1) { + perror(f1); + return -1; + } + + if (fstat(fileno(in1), &sb)) { + perror(f1); + fclose(in1); + return -1; + } + + count = sb.st_size; + buf1 = (unsigned short *)bu_malloc((size_t)sb.st_size, "buf1"); + + in2 = fopen(f2, "r"); + if (!in2) { + perror(f2); + fclose(in1); + return -1; + } + + if (fstat(fileno(in2), &sb)) { + perror(f2); + fclose(in1); + fclose(in2); + return -1; + } + + if ((size_t)sb.st_size != count) { + fclose(in1); + fclose(in2); + bu_exit(EXIT_FAILURE, "**** ERROR **** file size mis-match\n"); + } + + buf2 = (unsigned short *)bu_malloc((size_t)sb.st_size, "buf2"); + + count = count >> 1; /* convert count of char to count of short */ + + /* Read the terrain data */ + ret = fread(buf1, sizeof(short), count, in1); + if (ret < count) + perror("fread"); + fclose(in1); + + ret = fread(buf2, sizeof(short), count, in2); + if (ret < count) + perror("fread"); + fclose(in2); + + /* Convert from network to host format */ + in_cookie = bu_cv_cookie("nus"); + out_cookie = bu_cv_cookie("hus"); + conv = (bu_cv_optimize(in_cookie) != bu_cv_optimize(out_cookie)); + + if (conv) { + swap_bytes(buf1, count); + swap_bytes(buf2, count); + } + + /* add the two datasets together */ + switch (style) { + case ADD_STYLE_FLOAT : add_float(buf1, buf2, count); break; + case ADD_STYLE_INT : add_int(buf1, buf2, count); break; + default : bu_log("Error: Unknown add style\n"); + break; + } + + /* convert back to network format & write out */ + if (conv) { + swap_bytes(buf1, count); + swap_bytes(buf2, count); + } + + if (fwrite(buf1, sizeof(short), count, stdout) != count) { + bu_log("Error writing data\n"); + return -1; + } + + bu_opt_data_free_tbl(results); + + return 0; +} + + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/util/dsp_add_opt.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-06-19 18:13:00
|
Revision: 65415 http://sourceforge.net/p/brlcad/code/65415 Author: carlmoore Date: 2015-06-19 18:12:57 +0000 (Fri, 19 Jun 2015) Log Message: ----------- more shifting of routines: init_buffer and get_args placed just ahead of main, then place binterp behind (not in front of) ninterp Modified Paths: -------------- brlcad/trunk/src/util/bwcrop.c brlcad/trunk/src/util/bwscale.c Modified: brlcad/trunk/src/util/bwcrop.c =================================================================== --- brlcad/trunk/src/util/bwcrop.c 2015-06-19 17:45:02 UTC (rev 65414) +++ brlcad/trunk/src/util/bwcrop.c 2015-06-19 18:12:57 UTC (rev 65415) @@ -88,6 +88,7 @@ buflines = scanlen; buffer = (unsigned char *)bu_malloc(buflines * len, "buffer"); +fprintf(stderr,"in bwcrop.c , int_buffer: (int)buflines, len %d %d\n",(int)buflines,len); } @@ -100,6 +101,7 @@ { size_t ret; +fprintf(stderr,"bwcrop: reached fill_buffer\n"); buf_start = y - buflines/2; if (buf_start < 0) buf_start = 0; @@ -265,6 +267,7 @@ /* Make sure we are in the buffer */ yindex = round(y) - buf_start; +fprintf(stderr,"yindex,round(y),buf_start %f %i %f\n",(float)yindex,round(y),(float)buf_start); if (yindex >= buflines) { fill_buffer(round(y)); yindex = round(y) - buf_start; Modified: brlcad/trunk/src/util/bwscale.c =================================================================== --- brlcad/trunk/src/util/bwscale.c 2015-06-19 17:45:02 UTC (rev 65414) +++ brlcad/trunk/src/util/bwscale.c 2015-06-19 18:12:57 UTC (rev 65415) @@ -97,126 +97,24 @@ /* - * Determine max number of lines to buffer. - * and malloc space for it. - * XXX - CHECK FILE SIZE - */ -void -init_buffer(size_t len) -{ - int max; - - /* See how many we could buffer */ - max = MAXBUFBYTES / len; - - /* - * XXX We really should see how big - * the input file is to decide if we should buffer - * less than our max. - */ - if (max > 4096) max = 4096; - - if (max < iny) - buflines = max; - else - buflines = iny; - - buf_start = (-buflines); - buffer = (unsigned char *)bu_calloc(buflines, len, "buffer"); -} - -static int -get_args(int argc, char **argv) -{ - int c; - - while ((c = bu_getopt(argc, argv, "rs:w:n:S:W:N:h?")) != -1) { - switch (c) { - case 'r': - /* pixel replication */ - rflag = 1; - break; - case 'S': - /* square size */ - outx = outy = atoi(bu_optarg); - break; - case 's': - /* square size */ - 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; - - default: /* 'h' , '?' */ - return 0; - } - } - - /* XXX - backward compatibility hack */ - if (bu_optind+5 == argc) { - file_name = argv[bu_optind++]; - if ((buffp = fopen(file_name, "r")) == NULL) { - bu_log("bwscale: cannot open \"%s\" for reading\n",file_name); - return 0; - } - inx = atoi(argv[bu_optind++]); - iny = atoi(argv[bu_optind++]); - outx = atoi(argv[bu_optind++]); - outy = atoi(argv[bu_optind++]); - return 1; - } - if ((bu_optind >= argc) || - (argv[bu_optind][0] == '-' && argv[bu_optind][1] == '\n')) { - - /* input presumably from standard input */ - if (isatty(fileno(stdin))) { - return 0; - } - file_name = hyphen; - buffp = stdin; - } else { - file_name = argv[bu_optind]; - if ((buffp = fopen(file_name, "r")) == NULL) { - bu_log("bwscale: cannot open \"%s\" for reading\n", file_name); - return 0; - } - } - - if (argc > ++bu_optind) - fprintf(stderr, "bwscale: excess argument(s) ignored\n"); - - return 1; /* OK */ -} - -/* - * Bilinear Interpolate a file of pixels. + * Nearest Neighbor Interpolate a file of pixels. * * This version preserves the outside pixels and interps inside only. */ void -binterp(FILE *ofp, int ix, int iy, int ox, int oy) +ninterp(FILE *ofp, int ix, int iy, int ox, int oy) { int i, j; - double x, y, dx, dy, mid1, mid2; + double x, y; double xstep, ystep; - unsigned char *op, *up, *lp; + unsigned char *op, *lp; + size_t ret; xstep = (double)(ix - 1) / (double)ox - 1.0e-6; ystep = (double)(iy - 1) / (double)oy - 1.0e-6; /* For each output pixel */ for (j = 0; j < oy; j++) { - size_t ret; y = j * ystep; /* * Make sure we have this row (and the one after it) @@ -232,18 +130,8 @@ for (i = 0; i < ox; i++) { x = i * xstep; - dx = x - (int)x; - dy = y - (int)y; - - /* Note: (1-a)*foo + a*bar = foo + a*(bar-foo) */ - lp = &buffer[bufy*scanlen+(int)x]; - up = &buffer[(bufy+1)*scanlen+(int)x]; - - mid1 = lp[0] + dx * ((double)lp[1] - (double)lp[0]); - mid2 = up[0] + dx * ((double)up[1] - (double)up[0]); - - *op++ = mid1 + dy * (mid2 - mid1); + *op++ = lp[0]; } ret = fwrite(outbuf, 1, ox, ofp); @@ -252,26 +140,25 @@ } } - /* - * Nearest Neighbor Interpolate a file of pixels. + * Bilinear Interpolate a file of pixels. * * This version preserves the outside pixels and interps inside only. */ void -ninterp(FILE *ofp, int ix, int iy, int ox, int oy) +binterp(FILE *ofp, int ix, int iy, int ox, int oy) { int i, j; - double x, y; + double x, y, dx, dy, mid1, mid2; double xstep, ystep; - unsigned char *op, *lp; - size_t ret; + unsigned char *op, *up, *lp; xstep = (double)(ix - 1) / (double)ox - 1.0e-6; ystep = (double)(iy - 1) / (double)oy - 1.0e-6; /* For each output pixel */ for (j = 0; j < oy; j++) { + size_t ret; y = j * ystep; /* * Make sure we have this row (and the one after it) @@ -287,8 +174,18 @@ for (i = 0; i < ox; i++) { x = i * xstep; + dx = x - (int)x; + dy = y - (int)y; + + /* Note: (1-a)*foo + a*bar = foo + a*(bar-foo) */ + lp = &buffer[bufy*scanlen+(int)x]; - *op++ = lp[0]; + up = &buffer[(bufy+1)*scanlen+(int)x]; + + mid1 = lp[0] + dx * ((double)lp[1] - (double)lp[0]); + mid2 = up[0] + dx * ((double)up[1] - (double)up[0]); + + *op++ = mid1 + dy * (mid2 - mid1); } ret = fwrite(outbuf, 1, ox, ofp); @@ -297,7 +194,6 @@ } } - /* * Scale a file of pixels to a different size. * @@ -386,7 +282,108 @@ return 1; } +/* + * Determine max number of lines to buffer. + * and malloc space for it. + * XXX - CHECK FILE SIZE + */ +void +init_buffer(size_t len) +{ + int max; + /* See how many we could buffer */ + max = MAXBUFBYTES / len; + + /* + * XXX We really should see how big + * the input file is to decide if we should buffer + * less than our max. + */ + if (max > 4096) max = 4096; + + if (max < iny) + buflines = max; + else + buflines = iny; + + buf_start = (-buflines); + buffer = (unsigned char *)bu_calloc(buflines, len, "buffer"); +} + +static int +get_args(int argc, char **argv) +{ + int c; + + while ((c = bu_getopt(argc, argv, "rs:w:n:S:W:N:h?")) != -1) { + switch (c) { + case 'r': + /* pixel replication */ + rflag = 1; + break; + case 'S': + /* square size */ + outx = outy = atoi(bu_optarg); + break; + case 's': + /* square size */ + 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; + + default: /* 'h' , '?' */ + return 0; + } + } + + /* XXX - backward compatibility hack */ + if (bu_optind+5 == argc) { + file_name = argv[bu_optind++]; + if ((buffp = fopen(file_name, "r")) == NULL) { + bu_log("bwscale: cannot open \"%s\" for reading\n",file_name); + return 0; + } + inx = atoi(argv[bu_optind++]); + iny = atoi(argv[bu_optind++]); + outx = atoi(argv[bu_optind++]); + outy = atoi(argv[bu_optind++]); + return 1; + } + if ((bu_optind >= argc) || + (argv[bu_optind][0] == '-' && argv[bu_optind][1] == '\n')) { + + /* input presumably from standard input */ + if (isatty(fileno(stdin))) { + return 0; + } + file_name = hyphen; + buffp = stdin; + } else { + file_name = argv[bu_optind]; + if ((buffp = fopen(file_name, "r")) == NULL) { + bu_log("bwscale: cannot open \"%s\" for reading\n", file_name); + return 0; + } + } + + if (argc > ++bu_optind) + fprintf(stderr, "bwscale: excess argument(s) ignored\n"); + + return 1; /* OK */ +} + int main(int argc, char **argv) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-06-30 20:38:47
|
Revision: 65503 http://sourceforge.net/p/brlcad/code/65503 Author: carlmoore Date: 2015-06-30 20:38:44 +0000 (Tue, 30 Jun 2015) Log Message: ----------- simplify init_buffer because we don't need to pass argument when a global is available Modified Paths: -------------- brlcad/trunk/src/util/bwscale.c brlcad/trunk/src/util/pixscale.c Modified: brlcad/trunk/src/util/bwscale.c =================================================================== --- brlcad/trunk/src/util/bwscale.c 2015-06-30 20:30:57 UTC (rev 65502) +++ brlcad/trunk/src/util/bwscale.c 2015-06-30 20:38:44 UTC (rev 65503) @@ -292,12 +292,12 @@ * XXX - CHECK FILE SIZE */ void -init_buffer(size_t len) +init_buffer() { - int max; + ssize_t max; /* See how many we could buffer */ - max = MAXBUFBYTES / len; + max = MAXBUFBYTES / scanlen; /* * XXX We really should see how big @@ -312,7 +312,7 @@ buflines = iny; buf_start = (-buflines); - buffer = (unsigned char *)bu_calloc(buflines, len, "buffer"); + buffer = (unsigned char *)bu_calloc(buflines, scanlen, "buffer"); } static int @@ -405,7 +405,7 @@ /* See how many lines we can buffer */ scanlen = inx; - init_buffer(scanlen); + init_buffer(); i = (inx < outx) ? outx : inx; outbuf = (unsigned char *)bu_malloc(i, "outbuf"); Modified: brlcad/trunk/src/util/pixscale.c =================================================================== --- brlcad/trunk/src/util/pixscale.c 2015-06-30 20:30:57 UTC (rev 65502) +++ brlcad/trunk/src/util/pixscale.c 2015-06-30 20:38:44 UTC (rev 65503) @@ -318,12 +318,12 @@ * XXX - CHECK FILE SIZE */ void -init_buffer(int len) +init_buffer() { - int max; + ssize_t max; /* See how many we could buffer */ - max = MAXBUFBYTES / len; + max = MAXBUFBYTES / scanlen; /* * Do a max of 512. We really should see how big @@ -338,7 +338,7 @@ buflines = iny; buf_start = (-buflines); - buffer = (unsigned char *)bu_malloc(buflines * len, "buffer"); + buffer = (unsigned char *)bu_malloc(buflines * scanlen, "buffer"); } @@ -428,7 +428,7 @@ /* See how many lines we can buffer */ scanlen = 3 * inx; - init_buffer(scanlen); + init_buffer(); if (inx < outx) i = outx * 3; else i = inx * 3; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-07-27 20:27:36
|
Revision: 65701 http://sourceforge.net/p/brlcad/code/65701 Author: carlmoore Date: 2015-07-27 20:27:33 +0000 (Mon, 27 Jul 2015) Log Message: ----------- make cosmetic changes to bw-ps.c and pix-ps.c so that they look more alike Modified Paths: -------------- brlcad/trunk/src/util/bw-ps.c brlcad/trunk/src/util/pix-ps.c Modified: brlcad/trunk/src/util/bw-ps.c =================================================================== --- brlcad/trunk/src/util/bw-ps.c 2015-07-27 20:17:40 UTC (rev 65700) +++ brlcad/trunk/src/util/bw-ps.c 2015-07-27 20:27:33 UTC (rev 65701) @@ -27,23 +27,22 @@ #include <stdlib.h> /* for atof() */ #include <math.h> -#include <time.h> /* for ctime() */ +#include <time.h> /* for ctime() */ #include "bio.h" - #include "bu/getopt.h" #include "bu/log.h" -#define DEFAULT_SIZE 6.75 /* default output size in inches */ +#define DEFAULT_SIZE 6.75 /* default output size in inches */ #define MAX_BYTES (64*128) /* max bytes per image chunk */ static int encapsulated = 0; /* encapsulated postscript */ static int center = 0; /* center output on 8.5 x 11 page */ -static int landscape = 0; /* landscape mode */ +static int landscape = 0; /* landscape mode */ static size_t width = 512; /* input size in pixels */ static size_t height = 512; -static double outwidth; /* output image size in inches */ -static double outheight; +static double outwidth = DEFAULT_SIZE; /* output image size in inches */ +static double outheight = DEFAULT_SIZE; static size_t xpoints; /* output image size in points */ static size_t ypoints; static size_t pagewidth = 612; /* page size in points - 8.5 inches */ @@ -99,7 +98,7 @@ outheight = atof(bu_optarg); break; - default: /* '?' */ + default: /* 'h' '?' */ return 0; } } @@ -135,8 +134,6 @@ size_t scans_per_patch, bytes_per_patch; size_t y; - outwidth = outheight = DEFAULT_SIZE; - if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pix-ps.c =================================================================== --- brlcad/trunk/src/util/pix-ps.c 2015-07-27 20:17:40 UTC (rev 65700) +++ brlcad/trunk/src/util/pix-ps.c 2015-07-27 20:27:33 UTC (rev 65701) @@ -32,7 +32,6 @@ #include "bu/getopt.h" #include "bu/log.h" - #define DEFAULT_SIZE 6.75 /* default output size in inches */ #define MAX_BYTES (3*64*128) /* max bytes per image chunk */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-07-28 16:25:56
|
Revision: 65720 http://sourceforge.net/p/brlcad/code/65720 Author: carlmoore Date: 2015-07-28 16:25:53 +0000 (Tue, 28 Jul 2015) Log Message: ----------- cosmetic changes for bw-ps.c and pix-ps.c to look more alike (bw-ps.c has had the placement of 2 routines shifted) Modified Paths: -------------- brlcad/trunk/src/util/bw-ps.c brlcad/trunk/src/util/pix-ps.c Modified: brlcad/trunk/src/util/bw-ps.c =================================================================== --- brlcad/trunk/src/util/bw-ps.c 2015-07-28 15:54:05 UTC (rev 65719) +++ brlcad/trunk/src/util/bw-ps.c 2015-07-28 16:25:53 UTC (rev 65720) @@ -52,14 +52,65 @@ static char *file_name; static FILE *infp; -void prolog(FILE *fp, char *name, int w, int h); -void postlog(FILE *fp); - static char usage[] = "\ Usage: bw-ps [-e] [-c] [-L]\n\ [-s input_squaresize] [-w input_width] [-n input_height]\n\ [-S inches_square] [-W inches_width] [-N inches_height] [file.bw]\n"; +void +prolog(FILE *fp, char *name, int w, int h) + + +/* in points */ +{ + time_t ltime; + + ltime = time(0); + + if (encapsulated) { + fputs("%!PS-Adobe-2.0 EPSF-1.2\n", fp); + fprintf(fp, "%%%%Title: %s\n", name); + fputs("%%Creator: BRL-CAD bw-ps\n", fp); + fprintf(fp, "%%%%CreationDate: %s", ctime(<ime)); + fputs("%%Pages: 0\n", fp); + } else { + fputs("%!PS-Adobe-1.0\n", fp); + fputs("%begin(plot)\n", fp); + fprintf(fp, "%%%%Title: %s\n", name); + fputs("%%Creator: BRL-CAD bw-ps\n", fp); + fprintf(fp, "%%%%CreationDate: %s", ctime(<ime)); + } + fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", w, h); + fputs("%%EndComments\n\n", fp); + + if (!encapsulated && landscape) { + int tmp; + tmp = pagewidth; + pagewidth = pageheight; + pageheight = tmp; + fprintf(fp, "90 rotate\n"); + fprintf(fp, "0 -%lu translate\n", (unsigned long)pageheight); + } + if (!encapsulated && center) { + int xtrans, ytrans; + xtrans = (pagewidth - w)/2.0; + ytrans = (pageheight - h)/2.0; + fprintf(fp, "%d %d translate\n", xtrans, ytrans); + } + fprintf(fp, "%d %d scale\n\n", w, h); +} + + +void +postlog(FILE *fp) +{ + if (!encapsulated) + fputs("%end(plot)\n", fp); + + fputs("\nshowpage\n", fp); +} + + int get_args(int argc, char **argv) { @@ -179,60 +230,6 @@ } -void -prolog(FILE *fp, char *name, int w, int h) - - -/* in points */ -{ - time_t ltime; - - ltime = time(0); - - if (encapsulated) { - fputs("%!PS-Adobe-2.0 EPSF-1.2\n", fp); - fprintf(fp, "%%%%Title: %s\n", name); - fputs("%%Creator: BRL-CAD bw-ps\n", fp); - fprintf(fp, "%%%%CreationDate: %s", ctime(<ime)); - fputs("%%Pages: 0\n", fp); - } else { - fputs("%!PS-Adobe-1.0\n", fp); - fputs("%begin(plot)\n", fp); - fprintf(fp, "%%%%Title: %s\n", name); - fputs("%%Creator: BRL-CAD bw-ps\n", fp); - fprintf(fp, "%%%%CreationDate: %s", ctime(<ime)); - } - fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", w, h); - fputs("%%EndComments\n\n", fp); - - if (!encapsulated && landscape) { - int tmp; - tmp = pagewidth; - pagewidth = pageheight; - pageheight = tmp; - fprintf(fp, "90 rotate\n"); - fprintf(fp, "0 -%lu translate\n", (unsigned long)pageheight); - } - if (!encapsulated && center) { - int xtrans, ytrans; - xtrans = (pagewidth - w)/2.0; - ytrans = (pageheight - h)/2.0; - fprintf(fp, "%d %d translate\n", xtrans, ytrans); - } - fprintf(fp, "%d %d scale\n\n", w, h); -} - - -void -postlog(FILE *fp) -{ - if (!encapsulated) - fputs("%end(plot)\n", fp); - - fputs("\nshowpage\n", fp); -} - - /* * Local Variables: * mode: C Modified: brlcad/trunk/src/util/pix-ps.c =================================================================== --- brlcad/trunk/src/util/pix-ps.c 2015-07-28 15:54:05 UTC (rev 65719) +++ brlcad/trunk/src/util/pix-ps.c 2015-07-28 16:25:53 UTC (rev 65720) @@ -51,13 +51,11 @@ static char *file_name; static FILE *infp; - static char usage[] = "\ Usage: pix-ps [-e] [-c|-l] [-L]\n\ [-s input_squaresize] [-w input_width] [-n input_height]\n\ [-S inches_square] [-W inches_width] [-N inches_height] [<] input.pix > output.ps\n"; - void prolog(FILE *fp, char *name, size_t w, size_t h) @@ -264,7 +262,6 @@ } postlog(ofp); - return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-08-07 22:18:02
|
Revision: 65858 http://sourceforge.net/p/brlcad/code/65858 Author: carlmoore Date: 2015-08-07 22:17:59 +0000 (Fri, 07 Aug 2015) Log Message: ----------- cosmetic changes so the files look more alike Modified Paths: -------------- brlcad/trunk/src/util/bwstat.c brlcad/trunk/src/util/pixstat.c Modified: brlcad/trunk/src/util/bwstat.c =================================================================== --- brlcad/trunk/src/util/bwstat.c 2015-08-07 21:27:45 UTC (rev 65857) +++ brlcad/trunk/src/util/bwstat.c 2015-08-07 22:17:59 UTC (rev 65858) @@ -89,7 +89,7 @@ argc--; } - /* look for optional input file */ + /* check for optional input file */ if (argc > 1) { if ((fp = fopen(argv[1], "r")) == 0) { bu_exit(1, "bwstat: can't open \"%s\"\n", argv[1]); Modified: brlcad/trunk/src/util/pixstat.c =================================================================== --- brlcad/trunk/src/util/pixstat.c 2015-08-07 21:27:45 UTC (rev 65857) +++ brlcad/trunk/src/util/pixstat.c 2015-08-07 22:17:59 UTC (rev 65858) @@ -35,8 +35,8 @@ #include "common.h" +#include <stdlib.h> #include <string.h> -#include <stdlib.h> #include <math.h> #include "bio.h" @@ -80,7 +80,7 @@ { int i, n, num; double d; - long num_pixels; + long num_pixels = 0L ; unsigned char *bp; FILE *fp; @@ -107,9 +107,8 @@ } /* - * Build the histogram. + * Build the histogram. (num_pixels initialized to 0) */ - num_pixels = 0; while ((n = fread(&buf[0], sizeof(*buf), IBUFSIZE, fp)) > 0) { num = n/3; num_pixels += num; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-08-10 22:46:31
|
Revision: 65869 http://sourceforge.net/p/brlcad/code/65869 Author: carlmoore Date: 2015-08-10 22:46:28 +0000 (Mon, 10 Aug 2015) Log Message: ----------- cosmetic changes to make 2 source files look more alike Modified Paths: -------------- brlcad/trunk/src/util/bw-png.c brlcad/trunk/src/util/pix-png.c Modified: brlcad/trunk/src/util/bw-png.c =================================================================== --- brlcad/trunk/src/util/bw-png.c 2015-08-10 20:03:40 UTC (rev 65868) +++ brlcad/trunk/src/util/bw-png.c 2015-08-10 22:46:28 UTC (rev 65869) @@ -32,12 +32,16 @@ #include "vmath.h" #include "bu/getopt.h" +#include "bu/log.h" #include "bu/malloc.h" -#include "bu/log.h" #include "bn.h" #include "fb.h" +#define BYTESPERPIXEL 1 +#define ROWSIZE (file_width * BYTESPERPIXEL) +#define SIZE (file_height * ROWSIZE) + static long int file_width = 512; /* default input width */ static long int file_height = 512; /* default input height */ static int autosize = 0; /* !0 to autosize input */ @@ -45,11 +49,6 @@ static char *file_name; static FILE *infp; -#define BYTESPERPIXEL 1 - -#define ROWSIZE (file_width * BYTESPERPIXEL) -#define SIZE (file_height * ROWSIZE) - static char usage[] = "Usage: bw-png [-a] [-w file_width] [-n file_height]\n\ [-s square_file_size] [file.bw]\n"; @@ -77,7 +76,7 @@ autosize = 0; break; - default: /* 'h' '?' */ + default: /* 'h' '?' */ return 0; } } Modified: brlcad/trunk/src/util/pix-png.c =================================================================== --- brlcad/trunk/src/util/pix-png.c 2015-08-10 20:03:40 UTC (rev 65868) +++ brlcad/trunk/src/util/pix-png.c 2015-08-10 22:46:28 UTC (rev 65869) @@ -49,6 +49,8 @@ #define ROWSIZE (file_width * BYTESPERPIXEL) #define SIZE (file_height * ROWSIZE) +size_t file_width = 512; /* default input width */ +size_t file_height = 512; /* default input height */ static int autosize = 0; /* !0 to autosize input */ static int fileinput = 0; /* file of pipe on input? */ static char *file_name = (char *)NULL; @@ -189,9 +191,6 @@ FILE *infp = (FILE *)NULL; FILE *outfp = (FILE *)NULL; - size_t file_width = 512; /* default input width */ - size_t file_height = 512; /* default input height */ - char usage[] = "Usage: pix-png [-a] [-w file_width] [-n file_height] [-g gamma]\n\ [-s square_file_size] [-o file.png] [file.pix] [> file.png]\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2015-08-11 21:45:51
|
Revision: 65877 http://sourceforge.net/p/brlcad/code/65877 Author: carlmoore Date: 2015-08-11 21:45:48 +0000 (Tue, 11 Aug 2015) Log Message: ----------- fix comment for sake of uniformity Modified Paths: -------------- brlcad/trunk/src/util/bwfilter.c brlcad/trunk/src/util/pixfilter.c Modified: brlcad/trunk/src/util/bwfilter.c =================================================================== --- brlcad/trunk/src/util/bwfilter.c 2015-08-11 21:39:00 UTC (rev 65876) +++ brlcad/trunk/src/util/bwfilter.c 2015-08-11 21:45:48 UTC (rev 65877) @@ -58,9 +58,9 @@ { NULL, NULL, {0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, ICV_FILTER_NULL }, }; +int *kern; int kerndiv; int kernoffset; -int *kern; ICV_FILTER filter_type; int kernel_index; int inx = 512; @@ -152,7 +152,7 @@ case 's': inx = iny = atoi(bu_optarg); break; - default: /* '?' */ + default: /* 'h' '?' */ return 0; } } Modified: brlcad/trunk/src/util/pixfilter.c =================================================================== --- brlcad/trunk/src/util/pixfilter.c 2015-08-11 21:39:00 UTC (rev 65876) +++ brlcad/trunk/src/util/pixfilter.c 2015-08-11 21:45:48 UTC (rev 65877) @@ -109,7 +109,7 @@ case 's': width = height = atoi(bu_optarg); break; - default: /* '?' 'h' */ + default: /* 'h' '?' */ return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2015-11-25 22:50:23
|
Revision: 66708 http://sourceforge.net/p/brlcad/code/66708 Author: starseeker Date: 2015-11-25 22:50:20 +0000 (Wed, 25 Nov 2015) Log Message: ----------- Stub in an icv image conversion tool. Modified Paths: -------------- brlcad/trunk/src/util/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/util/icv.cpp Modified: brlcad/trunk/src/util/CMakeLists.txt =================================================================== --- brlcad/trunk/src/util/CMakeLists.txt 2015-11-25 21:32:13 UTC (rev 66707) +++ brlcad/trunk/src/util/CMakeLists.txt 2015-11-25 22:50:20 UTC (rev 66708) @@ -114,6 +114,10 @@ BRLCAD_ADDEXEC(fix_polysolids fix_polysolids.c "librt;libbu") BRLCAD_ADDEXEC(gencolor gencolor.c libbu) BRLCAD_ADDEXEC(hex hex.c libbu) + +# This is intended to replace all of the img-img utils eventually +BRLCAD_ADDEXEC(icv icv.cpp "libicv;libbu") + BRLCAD_ADDEXEC(imgdims imgdims.c "libfb;libbu") BRLCAD_ADDEXEC(loop loop.c libbu) BRLCAD_ADDEXEC(lowp lowp.c libbu) Added: brlcad/trunk/src/util/icv.cpp =================================================================== --- brlcad/trunk/src/util/icv.cpp (rev 0) +++ brlcad/trunk/src/util/icv.cpp 2015-11-25 22:50:20 UTC (rev 66708) @@ -0,0 +1,431 @@ +/* I C V . C P P + * BRL-CAD + * + * Copyright (c) 2015 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file icv.cpp + * + * Image converter. + * + */ + +#include "common.h" +#include <stdlib.h> +#include <string.h> + +#include "bu.h" +#include "icv.h" + +HIDDEN int +extract_path(struct bu_vls *path, const char *input) +{ + int ret = 0; + struct bu_vls wpath = BU_VLS_INIT_ZERO; + char *colon_pos = NULL; + char *inputcpy = NULL; + if (UNLIKELY(!input)) return 0; + inputcpy = bu_strdup(input); + colon_pos = strchr(inputcpy, ':'); + if (colon_pos) { + bu_vls_sprintf(&wpath, "%s", input); + bu_vls_nibble(&wpath, strlen(input) - strlen(colon_pos) + 1); + if (path && bu_vls_strlen(&wpath) > 0) { + ret = 1; + bu_vls_sprintf(path, "%s", bu_vls_addr(&wpath)); + } + bu_vls_free(&wpath); + } else { + if (path) bu_vls_sprintf(path, "%s", input); + ret = 1; + } + if (inputcpy) bu_free(inputcpy, "input copy"); + if (path && !(bu_vls_strlen(path) > 0)) return 0; + return ret; +} + +HIDDEN int +extract_format_prefix(struct bu_vls *format, const char *input) +{ + struct bu_vls wformat = BU_VLS_INIT_ZERO; + char *colon_pos = NULL; + char *inputcpy = NULL; + if (UNLIKELY(!input)) return 0; + inputcpy = bu_strdup(input); + colon_pos = strchr(inputcpy, ':'); + if (colon_pos) { + int ret = 0; + bu_vls_sprintf(&wformat, "%s", input); + bu_vls_trunc(&wformat, -1 * strlen(colon_pos)); + if (bu_vls_strlen(&wformat) > 0) { + ret = 1; + if (format) bu_vls_sprintf(format, "%s", bu_vls_addr(&wformat)); + } + bu_vls_free(&wformat); + if (inputcpy) bu_free(inputcpy, "input copy"); + return ret; + } else { + if (inputcpy) bu_free(inputcpy, "input copy"); + return 0; + } + /* Shouldn't get here */ + return 0; +} + +int +parse_image_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, const char *input) +{ + int type_int = 0; + mime_image_t type = MIME_IMAGE_UNKNOWN; + + struct bu_vls format_cpy = BU_VLS_INIT_ZERO; + struct bu_vls path = BU_VLS_INIT_ZERO; + + if (UNLIKELY(!input) || UNLIKELY(strlen(input) == 0)) return MIME_IMAGE_UNKNOWN; + + /* If an external routine has specified a format string, that string will + * override the file extension (but not an explicit option or format prefix). + * Stash any local format string here for later processing. The idea is + * to allow some other routine (say, an introspection of a file looking for + * some signature string) to override a file extension based type identification. + * Such introspection is beyond the scope of this function, but should override + * the file extension mechanism. */ + if (format) bu_vls_sprintf(&format_cpy, "%s", bu_vls_addr(format)); + + /* If we have an explicit option, that overrides any other format specifiers */ + if (opt) { + type_int = bu_file_mime(opt, MIME_IMAGE); + type = (type_int < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)type_int; + if (type == MIME_IMAGE_UNKNOWN) { + /* Have prefix, but doesn't result in a known format - that's an error */ + if (slog) bu_vls_printf(slog, "Error: unknown image format \"%s\" specified as an option.\n", opt); + bu_vls_free(&format_cpy); + return -1; + } + } + + /* Try for a format prefix */ + if (extract_format_prefix(format, input)) { + /* If we don't already have a valid type and we had a format prefix, + * find out if it maps to a valid type */ + if (type == MIME_IMAGE_UNKNOWN && format) { + /* Yes - see if the prefix specifies a image format */ + type_int = bu_file_mime(bu_vls_addr(format), MIME_IMAGE); + type = (type_int < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)type_int; + if (type == MIME_IMAGE_UNKNOWN) { + /* Have prefix, but doesn't result in a known format - that's an error */ + if (slog) bu_vls_printf(slog, "Error: unknown image format \"%s\" specified as a format prefix.\n", bu_vls_addr(format)); + bu_vls_free(&format_cpy); + return -1; + } + } + } + + /* If we don't already have a type and we were passed a format string, give it a try */ + if (type == MIME_IMAGE_UNKNOWN && format && bu_vls_strlen(&format_cpy) > 0) { + bu_vls_sprintf(format, "%s", bu_vls_addr(&format_cpy)); + type_int = bu_file_mime(bu_vls_addr(&format_cpy), MIME_IMAGE); + type = (type_int < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)type_int; + if (type == MIME_IMAGE_UNKNOWN) { + /* Have prefix, but doesn't result in a known format - that's an error */ + if (slog) bu_vls_printf(slog, "Error: unknown image format \"%s\" passed to parse_image_string.\n", bu_vls_addr(format)); + bu_vls_free(&format_cpy); + return -1; + } + } + + /* If we have no prefix or the prefix didn't map to a image type, try file extension */ + if (type == MIME_IMAGE_UNKNOWN && extract_path(&path, input)) { + /* TODO - this piece (and maybe most of this function's logic - is + * conceptually a duplicate of the icv_guess_file_format logic, + * although this may actually be a better implementation... It's + * also quite similar to the gcv file format discovery code. There may + * be a libbu-level mime functionality to be written here to + * generically do this - support ImageMagic style FMT:filename and + * file.ext resolutions for *all* mime types */ + if (bu_path_component(format, bu_vls_addr(&path), PATH_EXTENSION)) { + type_int = bu_file_mime(bu_vls_addr(format), MIME_IMAGE); + type = (type_int < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)type_int; + if (type == MIME_IMAGE_UNKNOWN) { + /* Have file extension, but doesn't result in a known format - that's an error */ + if (slog) bu_vls_printf(slog, "Error: file extension \"%s\" does not map to a known image format.\n", bu_vls_addr(format)); + bu_vls_free(&format_cpy); + bu_vls_free(&path); + return -1; + } + } + } + bu_vls_free(&path); + bu_vls_free(&format_cpy); + return (int)type; +} + +int +file_stat(struct bu_vls *msg, int argc, const char **argv, void *set_var) +{ + char **file_set = (char **)set_var; + + BU_OPT_CHECK_ARGV0(msg, argc, argv, "input file"); + + if (!bu_file_exists(argv[0], NULL)){ + if (msg) bu_vls_sprintf(msg, "Error - file %s does not exist!\n", argv[0]); + return -1; + } + + if (file_set) (*file_set) = bu_strdup(argv[0]); + + return 1; +} + +int +file_null(struct bu_vls *msg, int argc, const char **argv, void *set_var) +{ + char **file_set = (char **)set_var; + + BU_OPT_CHECK_ARGV0(msg, argc, argv, "output file"); + + if (bu_file_exists(argv[0], NULL)){ + if (msg) bu_vls_sprintf(msg, "Error - file %s already exists!\n", argv[0]); + return -1; + } + + if (file_set) (*file_set) = bu_strdup(argv[0]); + + return 1; +} + +int +image_mime(struct bu_vls *msg, int argc, const char **argv, void *set_mime) +{ + int type_int; + mime_image_t type = MIME_IMAGE_UNKNOWN; + mime_image_t *set_type = (mime_image_t *)set_mime; + + BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format"); + + type_int = bu_file_mime(argv[0], MIME_IMAGE); + type = (type_int < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)type_int; + if (type == MIME_IMAGE_UNKNOWN) { + if (msg) bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]); + return -1; + } + if (set_type) (*set_type) = type; + return 1; +} + + +int +main(int ac, const char **av) +{ + int uac = 0; + int fmt = 0; + int ret = 0; + const char *in_fmt = NULL; + const char *out_fmt = NULL; + static mime_image_t in_type = MIME_IMAGE_UNKNOWN; + static mime_image_t out_type = MIME_IMAGE_UNKNOWN; + static char *in_path_str = NULL; + static char *out_path_str = NULL; + int need_help = 0; + int skip_in = 0; + int skip_out = 0; + + struct bu_vls parse_msgs = BU_VLS_INIT_ZERO; + struct bu_vls in_format = BU_VLS_INIT_ZERO; + struct bu_vls in_path_raw = BU_VLS_INIT_ZERO; + struct bu_vls in_path = BU_VLS_INIT_ZERO; + struct bu_vls out_format = BU_VLS_INIT_ZERO; + struct bu_vls out_path_raw = BU_VLS_INIT_ZERO; + struct bu_vls out_path = BU_VLS_INIT_ZERO; + struct bu_vls slog = BU_VLS_INIT_ZERO; + + struct bu_opt_desc icv_opt_desc[] = { + {"h", "help", "", NULL, &need_help, "Print help and exit." }, + {"?", "", "", NULL, &need_help, "", }, + {"i", "input", "file", &file_stat, (void *)&in_path_str, "Input file.", }, + {"o", "output", "file", &file_null, (void *)&out_path_str, "Output file.", }, + {"", "input-format", "format", &image_mime, (void *)&in_type, "File format of input file.", }, + {"", "output-format", "format", &image_mime, (void *)&out_type, "File format of output file." }, + BU_OPT_DESC_NULL + }; + + ac-=(ac>0); av+=(ac>0); /* skip program name argv[0] if present */ + + if (ac == 0) { + const char *help = bu_opt_describe(icv_opt_desc, NULL); + bu_log("%s\n", help); + if (help) bu_free((char *)help, "help str"); + /* TODO - print some help */ + goto cleanup; + } + + uac = bu_opt_parse(&parse_msgs, ac, av, icv_opt_desc); + + if (uac == -1) { + bu_log("Parsing error: %s\n", bu_vls_addr(&parse_msgs)); + goto cleanup; + } + + /* First, see if help was requested or needed */ + if (need_help) { + /* Test static help print */ + const char *help = bu_opt_describe(icv_opt_desc, NULL); + bu_log("Options:\n"); + bu_log("%s\n", help); + if (help) bu_free((char *)help, "help str"); +#if 0 + + /* TODO - figure out how to get this info from each plugin to construct this table */ + /* on the fly... */ + bu_log("\nSupported formats:\n"); + bu_log(" ------------------------------------------------------------\n"); + bu_log(" | Extension | File Format | Input | Output |\n"); + bu_log(" |----------------------------------------------------------|\n"); + bu_log(" | pix | PIX file | Yes | Yes |\n"); + bu_log(" |------------|---------------------------|--------|--------|\n"); + bu_log(" | png | Portable Network Graphics | Yes | Yes |\n"); + bu_log(" |------------|---------------------------|--------|--------|\n"); + bu_log(" | bw | Black and White data | Yes | Yes |\n"); + bu_log(" |----------------------------------------------------------|\n"); +#endif + goto cleanup; + } + + /* TODO - Do a general check on option validity here - if anything fails, halt and + * report it */ + + + /* Did we get explicit options for an input and/or output file? */ + if (in_path_str) { + bu_vls_sprintf(&in_path_raw, "%s", in_path_str); + skip_in++; + } + if (out_path_str) { + bu_vls_sprintf(&out_path_raw, "%s", out_path_str); + skip_out++; + } + + /* If not specified explicitly with -i or -o, the input and output paths must always + * be the last two arguments supplied */ + if (!(skip_in && skip_out)) { + if (skip_in && !skip_out) { + bu_vls_sprintf(&out_path_raw, "%s", av[uac - 1]); + } + if (!skip_in && skip_out) { + bu_vls_sprintf(&in_path_raw, "%s", av[uac - 1]); + } + if (!skip_in && !skip_out) { + if (ac > 1) { + bu_vls_sprintf(&in_path_raw, "%s", av[uac - 2]); + bu_vls_sprintf(&out_path_raw, "%s", av[uac - 1]); + } else { + bu_vls_sprintf(&in_path_raw, "%s", av[uac - 1]); + } + } + } + + /* See if we have input and output files specified */ + if (!extract_path(&in_path, bu_vls_addr(&in_path_raw))) { + if (bu_vls_strlen(&in_path_raw) > 0) { + bu_vls_printf(&slog, "Error: no input path identified: %s\n", bu_vls_addr(&in_path_raw)); + } else { + bu_vls_printf(&slog, "Error: no input path.\n"); + } + ret = 1; + } + if (!extract_path(&out_path, bu_vls_addr(&out_path_raw))) { + if (bu_vls_strlen(&out_path_raw) > 0) { + bu_vls_printf(&slog, "Error: no output path identified: %s\n", bu_vls_addr(&out_path_raw)); + } else { + bu_vls_printf(&slog, "Error: no output path.\n"); + } + ret = 1; + } + + /* Make sure we have distinct input and output paths */ + if (bu_vls_strlen(&in_path) > 0 && BU_STR_EQUAL(bu_vls_addr(&in_path), bu_vls_addr(&out_path))) { + bu_vls_printf(&slog, "Error: identical path specified for both input and output: %s\n", bu_vls_addr(&out_path)); + ret = 1; + } + + /* Find out what input file type we are dealing with */ + if (in_type == MIME_IMAGE_UNKNOWN) { + fmt = parse_image_string(&in_format, &slog, in_fmt, bu_vls_addr(&in_path_raw)); + in_type = (fmt < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)fmt; + in_fmt = NULL; + } + /* Identify output file type */ + if (out_type == MIME_IMAGE_UNKNOWN) { + fmt = parse_image_string(&out_format, &slog, out_fmt, bu_vls_addr(&out_path_raw)); + out_type = (fmt < 0) ? MIME_IMAGE_UNKNOWN : (mime_image_t)fmt; + out_fmt = NULL; + } + + /* If we get to this point without knowing both input and output types, we've got a problem */ + if (in_type == MIME_IMAGE_UNKNOWN) { + if (bu_vls_strlen(&in_path) > 0) { + bu_vls_printf(&slog, "Error: no format type identified for input path: %s\n", bu_vls_addr(&in_path)); + } else { + bu_vls_printf(&slog, "Error: no input format type identified.\n"); + } + ret = 1; + } + if (out_type == MIME_IMAGE_UNKNOWN) { + if (bu_vls_strlen(&out_path) > 0) { + bu_vls_printf(&slog, "Error: no format type identified for output path: %s\n", bu_vls_addr(&out_path)); + } else { + bu_vls_printf(&slog, "Error: no output format type identified.\n"); + } + ret = 1; + } + + /* If everything isn't OK, we're done - report and clean up memory */ + if (ret == 1) goto cleanup; + + /* If we've gotten this far, we know enough to try to convert. Until we + * hook in conversion calls to libicv, print a summary of the option + * parsing results for debugging. */ + in_fmt = bu_file_mime_str((int)in_type, MIME_IMAGE); + out_fmt = bu_file_mime_str((int)out_type, MIME_IMAGE); + bu_log("Input file format: %s\n", in_fmt); + bu_log("Output file format: %s\n", out_fmt); + bu_log("Input file path: %s\n", bu_vls_addr(&in_path)); + bu_log("Output file path: %s\n", bu_vls_addr(&out_path)); + + + /* Clean up */ +cleanup: + if (bu_vls_strlen(&slog) > 0) bu_log("%s", bu_vls_addr(&slog)); + if (in_fmt) bu_free((char *)in_fmt, "input format string"); + if (out_fmt) bu_free((char *)out_fmt, "output format string"); + bu_vls_free(&in_format); + bu_vls_free(&in_path); + bu_vls_free(&out_format); + bu_vls_free(&out_path); + bu_vls_free(&slog); + return ret; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/util/icv.cpp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2016-04-26 22:35:46
|
Revision: 67783 http://sourceforge.net/p/brlcad/code/67783 Author: brlcad Date: 2016-04-26 22:35:43 +0000 (Tue, 26 Apr 2016) Log Message: ----------- don't see a practical reason for combining two dsp data files into one outside of debugging purposes or adding noise/features that are probably better dealt with in image compositing software (as a 16-bits per channel image). if we do need this functionality again in the future, it probably belongs with the dsp command and needs to be documented. Modified Paths: -------------- brlcad/trunk/src/util/CMakeLists.txt Removed Paths: ------------- brlcad/trunk/src/util/dsp_add.c Modified: brlcad/trunk/src/util/CMakeLists.txt =================================================================== --- brlcad/trunk/src/util/CMakeLists.txt 2016-04-26 22:24:19 UTC (rev 67782) +++ brlcad/trunk/src/util/CMakeLists.txt 2016-04-26 22:35:43 UTC (rev 67783) @@ -73,7 +73,6 @@ BRLCAD_ADDEXEC(decimate decimate.c libbu) BRLCAD_ADDEXEC(double-asc double-asc.c "libfb;libbu") BRLCAD_ADDEXEC(dpix-pix dpix-pix.c libbu) -BRLCAD_ADDEXEC(dsp_add dsp_add.c libbu) # a new admin file (used also for option handling testing) BRLCAD_ADDEXEC(admin-db "admin-db.cpp" "libbu;librt" NO_INSTALL) Deleted: brlcad/trunk/src/util/dsp_add.c =================================================================== --- brlcad/trunk/src/util/dsp_add.c 2016-04-26 22:24:19 UTC (rev 67782) +++ brlcad/trunk/src/util/dsp_add.c 2016-04-26 22:35:43 UTC (rev 67783) @@ -1,297 +0,0 @@ -/* D S P _ A D D . C - * BRL-CAD - * - * Copyright (c) 2004-2016 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ -/** @file util/dsp_add.c - * - * add 2 files of network unsigned shorts - * - * Options - * h help - */ - -#include "common.h" - -#include <stdlib.h> -#include <sys/stat.h> -#include "bio.h" - -#include "vmath.h" -#include "bu/getopt.h" -#include "bu/malloc.h" -#include "bu/log.h" -#include "bu/cv.h" -#include "bn.h" - - -/* declarations to support use of bu_getopt() system call */ -static const char optstring[] = "h?"; -static const char progname[] = "dsp_add"; -static const char usage[] = "Usage: %s dsp_1 dsp_2 > dsp_3\n"; - -/* purpose: combine two dsp files - * - * description: Combines two dsp files (which are binary files - * comprised of network unsigned shorts). The two files must be of - * identical size. The result, written to stdout, is a file where - * each cell's height is the total of the heights of the same cell - * in the input files. - * - * See the BRL-CAD wiki for a tutorial on using dsp's. - * - * see_also: dsp(5) asc2dsp(1) cv(1) - * - * opt: -h brief help - * - * opt: -? brief help - * - */ - -#define ADD_STYLE_INT 0 -#define ADD_STYLE_FLOAT 1 - -static int style = ADD_STYLE_INT; - -/* - * tell user how to invoke this program, then exit - */ -static void -print_usage(const char *s) -{ - if (s) (void)fputs(s, stderr); - - bu_log(usage, progname); - bu_exit (1, NULL); -} - - -/* - * Parse command line flags - */ -static int -parse_args(int ac, char *av[]) -{ - int c; - - /* get all the option flags from the command line */ - while ((c = bu_getopt(ac, av, optstring)) != -1) - switch (c) { - default: - print_usage(""); - } - - return bu_optind; -} - - -static void -swap_bytes(unsigned short *buf, unsigned long count) -{ - unsigned short *p; - - for (p = &buf[count-1]; p >= buf; p--) - *p = ((*p << 8) & 0x0ff00) | (*p >> 8); -} - - -/* - * Perform floating point addition and re-normalization of the data. - */ -static void -add_float(unsigned short *buf1, unsigned short *buf2, unsigned long count) -{ - unsigned short *p, *q, *e; - double *dbuf, *d; - double min, max, k; - - dbuf = (double *)bu_malloc(sizeof(double) * count, "buffer of double"); - - min = MAX_FASTF; - max = -MAX_FASTF; - e = &buf1[count]; - - /* add everything, keeping track of the min/max values found */ - for (d = dbuf, p = buf1, q = buf2; p < e; p++, q++, d++) { - *d = *p + *q; - if (*d > max) max = *d; - if (*d < min) min = *d; - } - - /* now we convert back to unsigned shorts in the range 1 .. 65535 */ - - k = 65534.0 / (max - min); - - bu_log("min: %g scale: %g\n", min - k, k); - - for (d = dbuf, p = buf1, q = buf2; p < e; p++, q++, d++) - *p = (unsigned short) ((*d - min) * k) + 1; - - bu_free(dbuf, "buffer of double"); -} - - -/* - * Perform simple integer addition to the input streams. - * Issue warning on overflow. - * - * Result: buf1 contents modified - */ -static void -add_int(unsigned short *buf1, unsigned short *buf2, unsigned long count) -{ - int int_value; - unsigned long i; - unsigned short s; - - for (i = 0; i < count; i++) { - int_value = buf1[i] + buf2[i]; - s = (unsigned short)int_value; - - if (s != int_value) { - bu_log("overflow (%d+%d) == %d at %lu\n", - buf1[i], buf2[i], int_value, i); - } - buf1[i] = s; - } - -} - - -/* - * Call parse_args to handle command line arguments first, then - * process input. - */ -int -main(int ac, char *av[]) -{ - int next_arg; - FILE *in1, *in2; - unsigned short *buf1, *buf2; - size_t count; - int in_cookie, out_cookie; - int conv; - struct stat sb; - size_t ret; - - if (ac < 2) - print_usage(""); - - if (isatty(fileno(stdout))) - print_usage("Must redirect standard output\n"); - - next_arg = parse_args(ac, av); - - if (next_arg >= ac) - print_usage("No files specified\n"); - - /* Open the files */ - - in1 = fopen(av[next_arg], "r"); - if (!in1) { - perror(av[next_arg]); - return -1; - } - - if (fstat(fileno(in1), &sb)) { - perror(av[next_arg]); - fclose(in1); - return -1; - } - - count = sb.st_size; - buf1 = (unsigned short *)bu_malloc((size_t)sb.st_size, "buf1"); - - next_arg++; - - in2 = fopen(av[next_arg], "r"); - if (!in2) { - perror(av[next_arg]); - fclose(in1); - return -1; - } - - if (fstat(fileno(in2), &sb)) { - perror(av[next_arg]); - fclose(in1); - fclose(in2); - return -1; - } - - if ((size_t)sb.st_size != count) { - fclose(in1); - fclose(in2); - bu_exit(EXIT_FAILURE, "**** ERROR **** file size mis-match\n"); - } - - buf2 = (unsigned short *)bu_malloc((size_t)sb.st_size, "buf2"); - - count = count >> 1; /* convert count of char to count of short */ - - /* Read the terrain data */ - ret = fread(buf1, sizeof(short), count, in1); - if (ret < count) - perror("fread"); - fclose(in1); - - ret = fread(buf2, sizeof(short), count, in2); - if (ret < count) - perror("fread"); - fclose(in2); - - /* Convert from network to host format */ - in_cookie = bu_cv_cookie("nus"); - out_cookie = bu_cv_cookie("hus"); - conv = (bu_cv_optimize(in_cookie) != bu_cv_optimize(out_cookie)); - - if (conv) { - swap_bytes(buf1, count); - swap_bytes(buf2, count); - } - - /* add the two datasets together */ - switch (style) { - case ADD_STYLE_FLOAT : add_float(buf1, buf2, count); break; - case ADD_STYLE_INT : add_int(buf1, buf2, count); break; - default : bu_log("Error: Unknown add style\n"); - break; - } - - /* convert back to network format & write out */ - if (conv) { - swap_bytes(buf1, count); - swap_bytes(buf2, count); - } - - if (fwrite(buf1, sizeof(short), count, stdout) != count) { - bu_log("Error writing data\n"); - return -1; - } - - return 0; -} - - -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2016-07-26 05:26:10
|
Revision: 68490 http://sourceforge.net/p/brlcad/code/68490 Author: brlcad Date: 2016-07-26 05:26:08 +0000 (Tue, 26 Jul 2016) Log Message: ----------- misleading and inconsistent, set input filename to "-" as if the users specified that (even if these tools probably don't yet consistently support that syntax Modified Paths: -------------- brlcad/trunk/src/util/bw-imp.c brlcad/trunk/src/util/bwscale.c brlcad/trunk/src/util/rle_args.c Modified: brlcad/trunk/src/util/bw-imp.c =================================================================== --- brlcad/trunk/src/util/bw-imp.c 2016-07-26 04:58:02 UTC (rev 68489) +++ brlcad/trunk/src/util/bw-imp.c 2016-07-26 05:26:08 UTC (rev 68490) @@ -68,7 +68,7 @@ static int (*pattern)[8] = dither; /* -> dither or halftone */ static FILE *infp; /* input file handle */ -static const char hyphen[] = "hyphen"; +static const char hyphen[] = "-"; static const char *file_name = hyphen; /* name of input file, for banner */ static size_t height; /* input height */ Modified: brlcad/trunk/src/util/bwscale.c =================================================================== --- brlcad/trunk/src/util/bwscale.c 2016-07-26 04:58:02 UTC (rev 68489) +++ brlcad/trunk/src/util/bwscale.c 2016-07-26 05:26:08 UTC (rev 68490) @@ -54,7 +54,7 @@ ssize_t bufy; /* y coordinate in buffer */ FILE *buffp; static char *file_name; -static char hyphen[] = "hyphen"; +static char hyphen[] = "-"; int rflag = 0; int inx = 512; Modified: brlcad/trunk/src/util/rle_args.c =================================================================== --- brlcad/trunk/src/util/rle_args.c 2016-07-26 04:58:02 UTC (rev 68489) +++ brlcad/trunk/src/util/rle_args.c 2016-07-26 05:26:08 UTC (rev 68490) @@ -25,7 +25,7 @@ #include "bu/file.h" #include "bu/log.h" -char hyphen[] = "hyphen"; +char hyphen[] = "-"; int get_args(int argc, char **argv, rle_hdr *outrle, FILE** infp, char** infile, int **background, size_t* file_width, size_t* file_height) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2016-09-01 04:48:23
|
Revision: 68776 http://sourceforge.net/p/brlcad/code/68776 Author: brlcad Date: 2016-09-01 04:48:20 +0000 (Thu, 01 Sep 2016) Log Message: ----------- copypasta. zlib.h is not used in these files. Modified Paths: -------------- brlcad/trunk/src/util/png-bw.c brlcad/trunk/src/util/png-pix.c brlcad/trunk/src/util/png_info.c Modified: brlcad/trunk/src/util/png-bw.c =================================================================== --- brlcad/trunk/src/util/png-bw.c 2016-09-01 04:47:25 UTC (rev 68775) +++ brlcad/trunk/src/util/png-bw.c 2016-09-01 04:48:20 UTC (rev 68776) @@ -28,7 +28,6 @@ #include <stdlib.h> #include <math.h> #include <string.h> -#include <zlib.h> #include <png.h> #include "bio.h" Modified: brlcad/trunk/src/util/png-pix.c =================================================================== --- brlcad/trunk/src/util/png-pix.c 2016-09-01 04:47:25 UTC (rev 68775) +++ brlcad/trunk/src/util/png-pix.c 2016-09-01 04:48:20 UTC (rev 68776) @@ -27,7 +27,6 @@ #include <stdlib.h> #include <math.h> -#include <zlib.h> #include <png.h> #include "bio.h" Modified: brlcad/trunk/src/util/png_info.c =================================================================== --- brlcad/trunk/src/util/png_info.c 2016-09-01 04:47:25 UTC (rev 68775) +++ brlcad/trunk/src/util/png_info.c 2016-09-01 04:48:20 UTC (rev 68776) @@ -27,7 +27,6 @@ #include <stdlib.h> #include <math.h> -#include <zlib.h> #include <png.h> #include "bio.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2018-03-06 06:11:58
|
Revision: 70798 http://sourceforge.net/p/brlcad/code/70798 Author: brlcad Date: 2018-03-06 06:11:56 +0000 (Tue, 06 Mar 2018) Log Message: ----------- make sure ctype functions aren't defined as macros (thus probably not having or needing a decl) Modified Paths: -------------- brlcad/trunk/src/util/hex.c brlcad/trunk/src/util/plot3rot.c Modified: brlcad/trunk/src/util/hex.c =================================================================== --- brlcad/trunk/src/util/hex.c 2018-03-06 06:08:30 UTC (rev 70797) +++ brlcad/trunk/src/util/hex.c 2018-03-06 06:11:56 UTC (rev 70798) @@ -38,7 +38,7 @@ #include "bu/str.h" #include "bu/exit.h" -#if defined(HAVE_ISASCII) && !defined(HAVE_DECL_ISASCII) +#if defined(HAVE_ISASCII) && !defined(HAVE_DECL_ISASCII) && !defined(isascii) extern int isascii(int c); #endif Modified: brlcad/trunk/src/util/plot3rot.c =================================================================== --- brlcad/trunk/src/util/plot3rot.c 2018-03-06 06:08:30 UTC (rev 70797) +++ brlcad/trunk/src/util/plot3rot.c 2018-03-06 06:11:56 UTC (rev 70798) @@ -40,10 +40,11 @@ #include "bn/plot3.h" #include "bn.h" -#if defined(HAVE_ISASCII) && !defined(HAVE_DECL_ISASCII) +#if defined(HAVE_ISASCII) && !defined(HAVE_DECL_ISASCII) && !defined(isascii) extern int isascii(int c); #endif + #define UPPER_CASE(c) ((c)-32) #define COPY(n) {size_t ret; ret = fread(cbuf, 1, n, fp); if (ret < n) perror("fread"); ret = fwrite(cbuf, 1, n, stdout); if (ret < n) perror("fwrite");} #define SKIP(n) {size_t ret; ret = fread(cbuf, 1, n, fp); if (ret < n) perror("fread");} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2020-07-25 16:25:48
|
Revision: 76496 http://sourceforge.net/p/brlcad/code/76496 Author: starseeker Date: 2020-07-25 16:25:45 +0000 (Sat, 25 Jul 2020) Log Message: ----------- Add binary 'b' flag to some fopen calls Modified Paths: -------------- brlcad/trunk/src/util/bw-a.c brlcad/trunk/src/util/bw-png.c brlcad/trunk/src/util/bw-ps.c brlcad/trunk/src/util/bwscale.c brlcad/trunk/src/util/mac-pix.c brlcad/trunk/src/util/pix-ppm.c brlcad/trunk/src/util/pix-ps.c brlcad/trunk/src/util/pix3filter.c brlcad/trunk/src/util/pixbgstrip.c brlcad/trunk/src/util/pixborder.c brlcad/trunk/src/util/pixembed.c brlcad/trunk/src/util/pixfilter.c brlcad/trunk/src/util/pixhalve.c brlcad/trunk/src/util/pixrot.c brlcad/trunk/src/util/pixscale.c brlcad/trunk/src/util/plot3-ps.c brlcad/trunk/src/util/sun-pix.c Modified: brlcad/trunk/src/util/bw-a.c =================================================================== --- brlcad/trunk/src/util/bw-a.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/bw-a.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -93,7 +93,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { (void) fprintf(stderr, "bw-a: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/bw-png.c =================================================================== --- brlcad/trunk/src/util/bw-png.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/bw-png.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -90,7 +90,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { perror(file_name); fprintf(stderr, "bw-png: cannot open \"%s\" for reading\n", Modified: brlcad/trunk/src/util/bw-ps.c =================================================================== --- brlcad/trunk/src/util/bw-ps.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/bw-ps.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -163,7 +163,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "bw-ps: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/bwscale.c =================================================================== --- brlcad/trunk/src/util/bwscale.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/bwscale.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -356,7 +356,7 @@ /* XXX - backward compatibility hack */ if (bu_optind+5 == argc) { file_name = argv[bu_optind++]; - if ((buffp = fopen(file_name, "r")) == NULL) { + if ((buffp = fopen(file_name, "rb")) == NULL) { bu_log("bwscale: cannot open \"%s\" for reading\n",file_name); return 0; } @@ -377,7 +377,7 @@ buffp = stdin; } else { file_name = argv[bu_optind]; - if ((buffp = fopen(file_name, "r")) == NULL) { + if ((buffp = fopen(file_name, "rb")) == NULL) { bu_log("bwscale: cannot open \"%s\" for reading\n", file_name); return 0; } Modified: brlcad/trunk/src/util/mac-pix.c =================================================================== --- brlcad/trunk/src/util/mac-pix.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/mac-pix.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -173,7 +173,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "mac-pix: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/pix-ppm.c =================================================================== --- brlcad/trunk/src/util/pix-ppm.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pix-ppm.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -95,7 +95,7 @@ file_name = "-"; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { perror(file_name); bu_exit(1, "%s: cannot open \"%s\" for reading\n", bu_getprogname(), file_name); } Modified: brlcad/trunk/src/util/pix-ps.c =================================================================== --- brlcad/trunk/src/util/pix-ps.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pix-ps.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -185,7 +185,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "pix-ps: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/pix3filter.c =================================================================== --- brlcad/trunk/src/util/pix3filter.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pix3filter.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -161,7 +161,7 @@ file_name = argv[bu_optind]; working_name = (char *)bu_malloc(strlen(file_name)+5, "working_name"); - if ((curfp = fopen(file_name, "r")) == NULL) { + if ((curfp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading\n", file_name); @@ -191,7 +191,7 @@ bu_free(working_name, "free working_name"); return 0; } - if ((oldfp = fopen(file_name, "r")) == NULL) { + if ((oldfp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading.\n", file_name); Modified: brlcad/trunk/src/util/pixbgstrip.c =================================================================== --- brlcad/trunk/src/util/pixbgstrip.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixbgstrip.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -98,7 +98,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { perror(file_name); fprintf(stderr, "pixbgstrip: cannot open \"%s\" for reading\n", Modified: brlcad/trunk/src/util/pixborder.c =================================================================== --- brlcad/trunk/src/util/pixborder.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixborder.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -445,7 +445,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - infp = fopen(file_name, "r"); + infp = fopen(file_name, "rb"); if (infp == NULL) { perror(file_name); (void) fprintf(stderr, "Cannot open file '%s'\n", file_name); Modified: brlcad/trunk/src/util/pixembed.c =================================================================== --- brlcad/trunk/src/util/pixembed.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixembed.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -103,7 +103,7 @@ buffp = stdin; } else { file_name = argv[bu_optind]; - if ((buffp = fopen(file_name, "r")) == NULL) { + if ((buffp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "pixembed: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/pixfilter.c =================================================================== --- brlcad/trunk/src/util/pixfilter.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixfilter.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -122,7 +122,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "pixfilter: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/pixhalve.c =================================================================== --- brlcad/trunk/src/util/pixhalve.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixhalve.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -94,7 +94,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { perror(file_name); fprintf(stderr, "pixhalve: cannot open \"%s\" for reading\n", Modified: brlcad/trunk/src/util/pixrot.c =================================================================== --- brlcad/trunk/src/util/pixrot.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixrot.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -126,7 +126,7 @@ ifp = stdin; } else { file_name = argv[bu_optind]; - if ((ifp = fopen(file_name, "r")) == NULL) { + if ((ifp = fopen(file_name, "rb")) == NULL) { bu_log("pixrot: cannot open \"%s\" for reading\n", file_name); return 0; } Modified: brlcad/trunk/src/util/pixscale.c =================================================================== --- brlcad/trunk/src/util/pixscale.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/pixscale.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -383,7 +383,7 @@ /* XXX - backward compatibility hack */ if (bu_optind+5 == argc) { file_name = argv[bu_optind++]; - if ((buffp = fopen(file_name, "r")) == NULL) { + if ((buffp = fopen(file_name, "rb")) == NULL) { bu_log("pixscale: cannot open \"%s\" for reading\n", file_name); return 0; } @@ -400,7 +400,7 @@ buffp = stdin; } else { file_name = argv[bu_optind]; - if ((buffp = fopen(file_name, "r")) == NULL) { + if ((buffp = fopen(file_name, "rb")) == NULL) { bu_log("pixscale: cannot open \"%s\" for reading\n", file_name); return 0; } Modified: brlcad/trunk/src/util/plot3-ps.c =================================================================== --- brlcad/trunk/src/util/plot3-ps.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/plot3-ps.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -400,7 +400,7 @@ infp = stdin; } else { file_name = argv[bu_optind]; - if ((infp = fopen(file_name, "r")) == NULL) { + if ((infp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "plot3-ps: cannot open \"%s\" for reading\n", file_name); Modified: brlcad/trunk/src/util/sun-pix.c =================================================================== --- brlcad/trunk/src/util/sun-pix.c 2020-07-25 16:08:46 UTC (rev 76495) +++ brlcad/trunk/src/util/sun-pix.c 2020-07-25 16:25:45 UTC (rev 76496) @@ -167,7 +167,7 @@ fp = stdin; } else { file_name = argv[bu_optind]; - if ((fp = fopen(file_name, "r")) == NULL) { + if ((fp = fopen(file_name, "rb")) == NULL) { fprintf(stderr, "sun-pix: cannot open \"%s\" for reading\n", file_name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2020-07-25 16:27:26
|
Revision: 76497 http://sourceforge.net/p/brlcad/code/76497 Author: starseeker Date: 2020-07-25 16:27:23 +0000 (Sat, 25 Jul 2020) Log Message: ----------- Add binary 'b' flag to more fopen calls Modified Paths: -------------- brlcad/trunk/src/util/ap-pix.c brlcad/trunk/src/util/bwcrop.c brlcad/trunk/src/util/bwhist.c brlcad/trunk/src/util/bwhisteq.c brlcad/trunk/src/util/bwstat.c brlcad/trunk/src/util/pixcrop.c brlcad/trunk/src/util/pixdiff.c brlcad/trunk/src/util/pixhist.c brlcad/trunk/src/util/pixhist3d-plot3.c brlcad/trunk/src/util/pixhist3d.c brlcad/trunk/src/util/pixstat.c brlcad/trunk/src/util/plot3-asc.c brlcad/trunk/src/util/plot3stat.c Modified: brlcad/trunk/src/util/ap-pix.c =================================================================== --- brlcad/trunk/src/util/ap-pix.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/ap-pix.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -78,13 +78,13 @@ if (argc != 2) usage(argv0); - magfp = fopen(argv[1], "r"); + magfp = fopen(argv[1], "rb"); if (magfp == NULL) { bu_exit(2, "%s: can't open \"%s\"\n", argv0, argv[1]); } - yelfp = fopen(argv[1], "r"); + yelfp = fopen(argv[1], "rb"); bu_fseek(yelfp, 50*sizeof(yelline), 0); - cyafp = fopen(argv[1], "r"); + cyafp = fopen(argv[1], "rb"); bu_fseek(cyafp, 100*sizeof(cyaline), 0); line = 0; Modified: brlcad/trunk/src/util/bwcrop.c =================================================================== --- brlcad/trunk/src/util/bwcrop.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/bwcrop.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -128,7 +128,7 @@ if (argc < 3) { bu_exit(1, "%s", usage); } - if ((ifp = fopen(argv[1], "r")) == NULL) { + if ((ifp = fopen(argv[1], "rb")) == NULL) { bu_exit(2, "bwcrop: can't open %s for reading\n", argv[1]); } if ((ofp = fopen(argv[2], "w")) == NULL) { Modified: brlcad/trunk/src/util/bwhist.c =================================================================== --- brlcad/trunk/src/util/bwhist.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/bwhist.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -71,7 +71,7 @@ /* look for optional input file */ if (argc > 1) { - if ((fp = fopen(argv[1], "r")) == 0) { + if ((fp = fopen(argv[1], "rb")) == 0) { bu_exit(1, "bwhist: can't open '%s'\n", argv[1]); } argv++; Modified: brlcad/trunk/src/util/bwhisteq.c =================================================================== --- brlcad/trunk/src/util/bwhisteq.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/bwhisteq.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -76,7 +76,7 @@ bu_exit(1, "%s", usage); } - if ((fp = fopen(argv[1], "r")) == NULL) { + if ((fp = fopen(argv[1], "rb")) == NULL) { bu_exit(2, "bwhisteq: Can't open \"%s\"\n", argv[1]); } Modified: brlcad/trunk/src/util/bwstat.c =================================================================== --- brlcad/trunk/src/util/bwstat.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/bwstat.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -95,7 +95,7 @@ /* check for optional input file */ if (argc > 1) { - if ((fp = fopen(argv[1], "r")) == 0) { + if ((fp = fopen(argv[1], "rb")) == 0) { bu_exit(1, "bwstat: can't open \"%s\"\n", argv[1]); } argv++; Modified: brlcad/trunk/src/util/pixcrop.c =================================================================== --- brlcad/trunk/src/util/pixcrop.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixcrop.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -128,7 +128,7 @@ if (argc < 3) { bu_exit(1, "%s", usage); } - if ((ifp = fopen(argv[1], "r")) == NULL) { + if ((ifp = fopen(argv[1], "rb")) == NULL) { bu_exit(2, "bwcrop: can't open %s for reading\n", argv[1]); } if ((ofp = fopen(argv[2], "w")) == NULL) { Modified: brlcad/trunk/src/util/pixdiff.c =================================================================== --- brlcad/trunk/src/util/pixdiff.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixdiff.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -78,7 +78,7 @@ if (BU_STR_EQUAL(argv[1], "-")) f1 = stdin; - else if ((f1 = fopen(argv[1], "r")) == NULL) { + else if ((f1 = fopen(argv[1], "rb")) == NULL) { perror(argv[1]); return 1; } Modified: brlcad/trunk/src/util/pixhist.c =================================================================== --- brlcad/trunk/src/util/pixhist.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixhist.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -70,7 +70,7 @@ /* look for optional input file */ if (argc > 1) { - if ((fp = fopen(argv[1], "r")) == 0) { + if ((fp = fopen(argv[1], "rb")) == 0) { bu_exit(1, "pixhist: can't open \"%s\"\n", argv[1]); } argv++; Modified: brlcad/trunk/src/util/pixhist3d-plot3.c =================================================================== --- brlcad/trunk/src/util/pixhist3d-plot3.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixhist3d-plot3.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -59,7 +59,7 @@ bu_setprogname(argv[0]); if (argc > 1) { - if ((fp = fopen(argv[1], "r")) == NULL) { + if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "%s", Usage); bu_exit(1, "pixhist3d-plot3: can't open \"%s\"\n", argv[1]); } Modified: brlcad/trunk/src/util/pixhist3d.c =================================================================== --- brlcad/trunk/src/util/pixhist3d.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixhist3d.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -73,7 +73,7 @@ if (argc > 1) { if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) bu_exit(2, "%s", Usage); - if ((fp = fopen(argv[1], "r")) == NULL) { + if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "%s", Usage); bu_exit(1, "pixhist3d: can't open \"%s\"\n", argv[1]); } Modified: brlcad/trunk/src/util/pixstat.c =================================================================== --- brlcad/trunk/src/util/pixstat.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/pixstat.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -96,7 +96,7 @@ /* check for optional input file */ if (argc > 1) { - if ((fp = fopen(argv[1], "r")) == 0) { + if ((fp = fopen(argv[1], "rb")) == 0) { bu_exit(1, "pixstat: can't open \"%s\"\n", argv[1]); } argv++; Modified: brlcad/trunk/src/util/plot3-asc.c =================================================================== --- brlcad/trunk/src/util/plot3-asc.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/plot3-asc.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -142,7 +142,7 @@ argv++; } if (argc == 2) { - if ((fp = fopen(argv[1], "r")) == NULL) { + if ((fp = fopen(argv[1], "rb")) == NULL) { perror("plot3-asc"); return 1; } Modified: brlcad/trunk/src/util/plot3stat.c =================================================================== --- brlcad/trunk/src/util/plot3stat.c 2020-07-25 16:25:45 UTC (rev 76496) +++ brlcad/trunk/src/util/plot3stat.c 2020-07-25 16:27:23 UTC (rev 76497) @@ -157,7 +157,7 @@ argv++; } if (argc == 2) { - if ((fp = fopen(argv[1], "r")) == NULL) { + if ((fp = fopen(argv[1], "rb")) == NULL) { perror("plot3stat"); bu_exit (1, NULL); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2020-07-25 16:40:45
|
Revision: 76498 http://sourceforge.net/p/brlcad/code/76498 Author: starseeker Date: 2020-07-25 16:40:42 +0000 (Sat, 25 Jul 2020) Log Message: ----------- Add binary flags for more fopen calls Modified Paths: -------------- brlcad/trunk/src/util/asc-plot3.c brlcad/trunk/src/util/bombardier.c brlcad/trunk/src/util/bw-pix.c brlcad/trunk/src/util/bwcrop.c brlcad/trunk/src/util/bwdiff.c brlcad/trunk/src/util/pix-ppm.c brlcad/trunk/src/util/pix3filter.c brlcad/trunk/src/util/pixblend.c brlcad/trunk/src/util/pixclump.c brlcad/trunk/src/util/pixcolors.c brlcad/trunk/src/util/pixcount.cpp brlcad/trunk/src/util/pixcrop.c brlcad/trunk/src/util/pixdiff.c brlcad/trunk/src/util/pixinterp2x.c brlcad/trunk/src/util/pixmerge.c brlcad/trunk/src/util/pixmorph.c brlcad/trunk/src/util/pixuntile.c brlcad/trunk/src/util/plot3-dm.c brlcad/trunk/src/util/plot3rot.c Modified: brlcad/trunk/src/util/asc-plot3.c =================================================================== --- brlcad/trunk/src/util/asc-plot3.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/asc-plot3.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -65,7 +65,7 @@ char *bp; char buf[BUF_LEN]; char sarg[BUF_LEN]; - static char *fm[] = { "r", "w" }; + static char *fm[] = { "rb", "wb" }; double darg[6] = {0.0}; static FILE *fp[2]; int i; Modified: brlcad/trunk/src/util/bombardier.c =================================================================== --- brlcad/trunk/src/util/bombardier.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/bombardier.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -163,7 +163,7 @@ return; } - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); if (!fp) { perror("unable to open file"); bu_log("ERROR: unable to open log file [%s]\n", filename); Modified: brlcad/trunk/src/util/bw-pix.c =================================================================== --- brlcad/trunk/src/util/bw-pix.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/bw-pix.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -47,8 +47,8 @@ if (BU_STR_EQUAL(name, "-")) { *fp = stdin; } else if (BU_STR_EQUAL(name, ".")) { - *fp = fopen("/dev/null", "r"); - } else if ((*fp = fopen(name, "r")) == NULL) { + *fp = fopen("/dev/null", "rb"); + } else if ((*fp = fopen(name, "rb")) == NULL) { bu_exit(2, "bw3-pix: Can't open \"%s\"\n", name); } } Modified: brlcad/trunk/src/util/bwcrop.c =================================================================== --- brlcad/trunk/src/util/bwcrop.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/bwcrop.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -131,7 +131,7 @@ if ((ifp = fopen(argv[1], "rb")) == NULL) { bu_exit(2, "bwcrop: can't open %s for reading\n", argv[1]); } - if ((ofp = fopen(argv[2], "w")) == NULL) { + if ((ofp = fopen(argv[2], "wb")) == NULL) { bu_exit(3, "bwcrop: can't open %s for writing\n", argv[2]); } Modified: brlcad/trunk/src/util/bwdiff.c =================================================================== --- brlcad/trunk/src/util/bwdiff.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/bwdiff.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -61,8 +61,8 @@ if (BU_STR_EQUAL(name, "-")) *fp = stdin; else if (BU_STR_EQUAL(name, ".")) - *fp = fopen("/dev/null", "r"); - else if ((*fp = fopen(name, "r")) == NULL) + *fp = fopen("/dev/null", "rb"); + else if ((*fp = fopen(name, "rb")) == NULL) bu_exit(2, "bwdiff: Can't open \"%s\"\n", name); } Modified: brlcad/trunk/src/util/pix-ppm.c =================================================================== --- brlcad/trunk/src/util/pix-ppm.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pix-ppm.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -77,7 +77,7 @@ autosize = 0; break; case 'o': { - outfp = fopen(bu_optarg, "w+"); + outfp = fopen(bu_optarg, "wb+"); if (outfp == (FILE *)NULL) { bu_exit(1, "%s: cannot open \"%s\" for writing\n", bu_getprogname(), bu_optarg); } Modified: brlcad/trunk/src/util/pix3filter.c =================================================================== --- brlcad/trunk/src/util/pix3filter.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pix3filter.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -133,7 +133,7 @@ } if (bu_optind + 3 <= argc) { - if ((oldfp = fopen(argv[bu_optind], "r")) == NULL) { + if ((oldfp = fopen(argv[bu_optind], "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading\n", argv[bu_optind]); @@ -140,7 +140,7 @@ return 0; } - if ((curfp = fopen(argv[++bu_optind], "r")) == NULL) { + if ((curfp = fopen(argv[++bu_optind], "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading\n", argv[bu_optind]); @@ -147,7 +147,7 @@ return 0; } - if ((newfp = fopen(argv[++bu_optind], "r")) == NULL) { + if ((newfp = fopen(argv[++bu_optind], "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading\n", argv[bu_optind]); @@ -183,7 +183,7 @@ } snprintf(working_name, strlen(file_name)+5, "%s.%d", file_name, frameNumber-1); - if ((oldfp = fopen(working_name, "r")) == NULL) { + if ((oldfp = fopen(working_name, "rb")) == NULL) { if (frameNumber-1 != 0) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading.\n", @@ -201,7 +201,7 @@ } snprintf(working_name, strlen(file_name)+5, "%s.%d", file_name, frameNumber+1); - if ((newfp = fopen(working_name, "r")) == NULL) { + if ((newfp = fopen(working_name, "rb")) == NULL) { fprintf(stderr, "pix3filter: cannot open \"%s\" for reading.\n", working_name); Modified: brlcad/trunk/src/util/pixblend.c =================================================================== --- brlcad/trunk/src/util/pixblend.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixblend.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -124,7 +124,7 @@ f1_name = argv[bu_optind++]; if (BU_STR_EQUAL(f1_name, "-")) f1 = stdin; - else if ((f1 = fopen(f1_name, "r")) == NULL) { + else if ((f1 = fopen(f1_name, "rb")) == NULL) { perror(f1_name); fprintf(stderr, "pixblend: cannot open \"%s\" for reading\n", @@ -135,7 +135,7 @@ f2_name = argv[bu_optind++]; if (BU_STR_EQUAL(f2_name, "-")) f2 = stdin; - else if ((f2 = fopen(f2_name, "r")) == NULL) { + else if ((f2 = fopen(f2_name, "rb")) == NULL) { perror(f2_name); fprintf(stderr, "pixblend: cannot open \"%s\" for reading\n", Modified: brlcad/trunk/src/util/pixclump.c =================================================================== --- brlcad/trunk/src/util/pixclump.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixclump.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -112,7 +112,7 @@ unsigned char rgb[3]; struct bu_vls v = BU_VLS_INIT_ZERO; - if ((fp = fopen(f_name, "r")) == NULL) + if ((fp = fopen(f_name, "rb")) == NULL) bu_exit(1, "Cannot open color file '%s'\n", bu_optarg); for (line_nm = 1; bu_vls_gets(&v, fp) != -1; @@ -230,11 +230,11 @@ */ if (infp == NULL) { inf_name = argv[bu_optind]; - if ((infp = fopen(inf_name, "r")) == NULL) + if ((infp = fopen(inf_name, "rb")) == NULL) bu_exit(1, "Cannot open input file '%s'\n", inf_name); if (outfp == NULL) { outf_name = argv[++bu_optind]; - if ((outfp = fopen(outf_name, "w")) == NULL) + if ((outfp = fopen(outf_name, "wb")) == NULL) bu_exit(1, "Cannot open output file '%s'\n", outf_name); } } Modified: brlcad/trunk/src/util/pixcolors.c =================================================================== --- brlcad/trunk/src/util/pixcolors.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixcolors.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -147,7 +147,7 @@ usage(); if (bu_optind == ac-1) { FILE *fd; - if ((fd=fopen(av[bu_optind], "r")) == (FILE *)NULL) { + if ((fd=fopen(av[bu_optind], "rb")) == (FILE *)NULL) { perror(av[bu_optind]); bu_exit (1, NULL); } Modified: brlcad/trunk/src/util/pixcount.cpp =================================================================== --- brlcad/trunk/src/util/pixcount.cpp 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixcount.cpp 2020-07-25 16:40:42 UTC (rev 76498) @@ -208,11 +208,11 @@ */ if (infp == NULL) { inf_name = argv[bu_optind]; - if ((infp = fopen(inf_name, "r")) == NULL) + if ((infp = fopen(inf_name, "rb")) == NULL) bu_exit(1, "Cannot open input file '%s'\n", inf_name); if (outfp == NULL) { outf_name = argv[++bu_optind]; - if ((outfp = fopen(outf_name, "w")) == NULL) + if ((outfp = fopen(outf_name, "wb")) == NULL) bu_exit(1, "Cannot open output file '%s'\n", outf_name); } } Modified: brlcad/trunk/src/util/pixcrop.c =================================================================== --- brlcad/trunk/src/util/pixcrop.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixcrop.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -131,7 +131,7 @@ if ((ifp = fopen(argv[1], "rb")) == NULL) { bu_exit(2, "bwcrop: can't open %s for reading\n", argv[1]); } - if ((ofp = fopen(argv[2], "w")) == NULL) { + if ((ofp = fopen(argv[2], "wb")) == NULL) { bu_exit(3, "bwcrop: can't open %s for writing\n", argv[2]); } Modified: brlcad/trunk/src/util/pixdiff.c =================================================================== --- brlcad/trunk/src/util/pixdiff.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixdiff.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -84,7 +84,7 @@ } if (BU_STR_EQUAL(argv[2], "-")) f2 = stdin; - else if ((f2 = fopen(argv[2], "r")) == NULL) { + else if ((f2 = fopen(argv[2], "rb")) == NULL) { perror(argv[2]); return 1; } Modified: brlcad/trunk/src/util/pixinterp2x.c =================================================================== --- brlcad/trunk/src/util/pixinterp2x.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixinterp2x.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -73,7 +73,7 @@ } } if (argv[bu_optind] != NULL) { - if ((infp = fopen(argv[bu_optind], "r")) == NULL) { + if ((infp = fopen(argv[bu_optind], "rb")) == NULL) { perror(argv[bu_optind]); return 0; } Modified: brlcad/trunk/src/util/pixmerge.c =================================================================== --- brlcad/trunk/src/util/pixmerge.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixmerge.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -140,7 +140,7 @@ f1_name = argv[bu_optind++]; if (BU_STR_EQUAL(f1_name, "-")) f1 = stdin; - else if ((f1 = fopen(f1_name, "r")) == NULL) { + else if ((f1 = fopen(f1_name, "rb")) == NULL) { perror(f1_name); fprintf(stderr, "pixmerge: cannot open \"%s\" for reading\n", @@ -152,7 +152,7 @@ f2_name = argv[bu_optind++]; if (BU_STR_EQUAL(f2_name, "-")) f2 = stdin; - else if ((f2 = fopen(f2_name, "r")) == NULL) { + else if ((f2 = fopen(f2_name, "rb")) == NULL) { perror(f2_name); fprintf(stderr, "pixmerge: cannot open \"%s\" for reading\n", Modified: brlcad/trunk/src/util/pixmorph.c =================================================================== --- brlcad/trunk/src/util/pixmorph.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixmorph.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -427,17 +427,17 @@ return 1; } - picA = fopen(picAname, "r"); + picA = fopen(picAname, "rb"); if (picA == NULL) { fprintf(stderr, "pixmorph: cannot open %s\n", picAname); return 1; } - picB = fopen(picBname, "r"); + picB = fopen(picBname, "rb"); if (picB == NULL) { fprintf(stderr, "pixmorph: cannot open %s\n", picBname); return 1; } - linesfile = fopen(linesfilename, "r"); + linesfile = fopen(linesfilename, "rb"); if (linesfile == NULL) { fprintf(stderr, "pixmorph: cannot open %s\n", linesfilename); return 1; Modified: brlcad/trunk/src/util/pixuntile.c =================================================================== --- brlcad/trunk/src/util/pixuntile.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/pixuntile.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -148,7 +148,7 @@ } else { snprintf(name, sizeof(name), "%s.%d", base_name, framenumber); } - if ((f[i] = fopen(name, "w")) == NULL) { + if ((f[i] = fopen(name, "wb")) == NULL) { perror(name); goto done; } Modified: brlcad/trunk/src/util/plot3-dm.c =================================================================== --- brlcad/trunk/src/util/plot3-dm.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/plot3-dm.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -589,7 +589,7 @@ char *bnp; file = argv[i]; - if ((fp = fopen(file, "r")) == NULL) { + if ((fp = fopen(file, "rb")) == NULL) { bu_log("%s: can't open \"%s\"\n", argv[0], file); continue; } Modified: brlcad/trunk/src/util/plot3rot.c =================================================================== --- brlcad/trunk/src/util/plot3rot.c 2020-07-25 16:27:23 UTC (rev 76497) +++ brlcad/trunk/src/util/plot3rot.c 2020-07-25 16:40:42 UTC (rev 76498) @@ -342,7 +342,7 @@ fclose(fp); if (BU_STR_EQUAL(argv[bu_optind], "-")) fp = stdin; - else if ((fp = fopen(argv[bu_optind], "r")) == NULL) { + else if ((fp = fopen(argv[bu_optind], "rb")) == NULL) { bu_log("plot3rot: can't open \"%s\"\n", argv[bu_optind]); continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2020-07-25 17:40:06
|
Revision: 76499 http://sourceforge.net/p/brlcad/code/76499 Author: starseeker Date: 2020-07-25 17:40:03 +0000 (Sat, 25 Jul 2020) Log Message: ----------- Put stdin and stdout in binary mode up front for utilities. This won't matter on most platforms, but should help on Windows unless we've got an implicit assumption of O_TEXT mode sneaking in there somewhere. Modified Paths: -------------- brlcad/trunk/src/util/alias-pix.c brlcad/trunk/src/util/asc-plot3.c brlcad/trunk/src/util/bw-a.c brlcad/trunk/src/util/bw-ps.c brlcad/trunk/src/util/bwdiff.c brlcad/trunk/src/util/bwhist.c brlcad/trunk/src/util/bwrot.c brlcad/trunk/src/util/bwscale.c brlcad/trunk/src/util/bwshrink.c brlcad/trunk/src/util/bwstat.c brlcad/trunk/src/util/decimate.c brlcad/trunk/src/util/double-asc.c brlcad/trunk/src/util/gencolor.c brlcad/trunk/src/util/halftone.c brlcad/trunk/src/util/mac-pix.c brlcad/trunk/src/util/pix-alias.c brlcad/trunk/src/util/pix-ppm.c brlcad/trunk/src/util/pix-ps.c brlcad/trunk/src/util/pix-sun.c brlcad/trunk/src/util/pixbgstrip.c brlcad/trunk/src/util/pixblend.c brlcad/trunk/src/util/pixborder.c brlcad/trunk/src/util/pixclump.c brlcad/trunk/src/util/pixcolors.c brlcad/trunk/src/util/pixcount.cpp brlcad/trunk/src/util/pixdiff.c brlcad/trunk/src/util/pixelswap.c brlcad/trunk/src/util/pixembed.c brlcad/trunk/src/util/pixfilter.c brlcad/trunk/src/util/pixhalve.c brlcad/trunk/src/util/pixhist.c brlcad/trunk/src/util/pixhist3d-plot3.c brlcad/trunk/src/util/pixhist3d.c brlcad/trunk/src/util/pixinterp2x.c brlcad/trunk/src/util/pixmerge.c brlcad/trunk/src/util/pixrot.c brlcad/trunk/src/util/pixsaturate.c brlcad/trunk/src/util/pixscale.c brlcad/trunk/src/util/pixshrink.c brlcad/trunk/src/util/pixstat.c brlcad/trunk/src/util/pixtile.c brlcad/trunk/src/util/pixuntile.c brlcad/trunk/src/util/plot3-asc.c brlcad/trunk/src/util/plot3-plot3.c brlcad/trunk/src/util/plot3-ps.c brlcad/trunk/src/util/plot3color.c brlcad/trunk/src/util/plot3getframe.c brlcad/trunk/src/util/plot3line2.c brlcad/trunk/src/util/plot3rot.c brlcad/trunk/src/util/plot3stat.c brlcad/trunk/src/util/png-bw.c brlcad/trunk/src/util/sun-pix.c brlcad/trunk/src/util/wavelet.c Modified: brlcad/trunk/src/util/alias-pix.c =================================================================== --- brlcad/trunk/src/util/alias-pix.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/alias-pix.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -69,6 +69,9 @@ if (ac > 2 || isatty(fileno(stdin))) usage(); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (ac > 1) { p = av[1]; if (*p == '-' && *(p+1) == 'v') verbose = 1; Modified: brlcad/trunk/src/util/asc-plot3.c =================================================================== --- brlcad/trunk/src/util/asc-plot3.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/asc-plot3.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -83,6 +83,10 @@ if (argc > 3) { printusage(); } + + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + fp[0] = stdin; fp[1] = stdout; for (i = 0; (i < 2) && (--argc > 0); ++i) { Modified: brlcad/trunk/src/util/bw-a.c =================================================================== --- brlcad/trunk/src/util/bw-a.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bw-a.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -118,6 +118,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void) fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/bw-ps.c =================================================================== --- brlcad/trunk/src/util/bw-ps.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bw-ps.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -182,18 +182,23 @@ int main(int argc, char **argv) { - FILE *ofp = stdout; size_t num = 0; size_t scans_per_patch, bytes_per_patch; size_t y; + FILE *ofp = NULL; bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); } + ofp = stdout; + if (encapsulated) { xpoints = width; ypoints = height; Modified: brlcad/trunk/src/util/bwdiff.c =================================================================== --- brlcad/trunk/src/util/bwdiff.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwdiff.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -58,12 +58,13 @@ open_file(FILE **fp, char *name) { /* check for special names */ - if (BU_STR_EQUAL(name, "-")) + if (BU_STR_EQUAL(name, "-")) { *fp = stdin; - else if (BU_STR_EQUAL(name, ".")) + } else if (BU_STR_EQUAL(name, ".")) { *fp = fopen("/dev/null", "rb"); - else if ((*fp = fopen(name, "rb")) == NULL) + } else if ((*fp = fopen(name, "rb")) == NULL) { bu_exit(2, "bwdiff: Can't open \"%s\"\n", name); + } } @@ -75,6 +76,8 @@ size_t ret; bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); while (argc > 3) { if (BU_STR_EQUAL(argv[1], "-m")) { Modified: brlcad/trunk/src/util/bwhist.c =================================================================== --- brlcad/trunk/src/util/bwhist.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwhist.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -58,6 +58,8 @@ FILE *fp; bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) bu_exit(1, "%s", Usage); @@ -76,9 +78,9 @@ } argv++; argc--; - } else + } else { fp = stdin; - + } /* check usage */ if (argc > 1 || isatty(fileno(fp))) bu_exit(1, "%s", Usage); Modified: brlcad/trunk/src/util/bwrot.c =================================================================== --- brlcad/trunk/src/util/bwrot.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwrot.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -304,9 +304,12 @@ double angle = 0.0; ssize_t io; + bu_setprogname(argv[0]); + + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); ifp = stdin; ofp = stdout; - bu_setprogname(argv[0]); if (!get_args(argc, argv, &ifp, &ofp, &angle)) { bu_exit(1, "%s", usage); Modified: brlcad/trunk/src/util/bwscale.c =================================================================== --- brlcad/trunk/src/util/bwscale.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwscale.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -396,6 +396,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv) || isatty(fileno(stdout))) bu_exit(1, "%s", usage); Modified: brlcad/trunk/src/util/bwshrink.c =================================================================== --- brlcad/trunk/src/util/bwshrink.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwshrink.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -186,6 +186,8 @@ usage(); /* process stdin */ + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); /* get buffer for image */ size = width * height; Modified: brlcad/trunk/src/util/bwstat.c =================================================================== --- brlcad/trunk/src/util/bwstat.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/bwstat.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -83,6 +83,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) bu_exit(1, "%s", Usage); Modified: brlcad/trunk/src/util/decimate.c =================================================================== --- brlcad/trunk/src/util/decimate.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/decimate.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -71,6 +71,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc < 4) { bu_exit (1, "%s", usage); } Modified: brlcad/trunk/src/util/double-asc.c =================================================================== --- brlcad/trunk/src/util/double-asc.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/double-asc.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -163,6 +163,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + bu_log("DEPRECATION WARNING: This command is scheduled for removal. Please contact the developers if you use this command.\n\n"); bu_snooze(BU_SEC2USEC(1)); Modified: brlcad/trunk/src/util/gencolor.c =================================================================== --- brlcad/trunk/src/util/gencolor.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/gencolor.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -122,6 +122,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + get_args(argc, argv); argc = argc - bu_optind + 1; argv = argv + bu_optind - 1; Modified: brlcad/trunk/src/util/halftone.c =================================================================== --- brlcad/trunk/src/util/halftone.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/halftone.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -922,22 +922,26 @@ size_t ret; bu_setprogname(argv[0]); -/* - * parameter processing. - */ + + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + + /* + * parameter processing. + */ setup(argc, argv); -/* - * Get a tone map. Map is the result. 1.0 is slope, 0.0 is - * the Y intercept (y=mx+b). 0 is the address of a function to - * do a x to y mapping, 0 means use the default function. - */ + /* + * Get a tone map. Map is the result. 1.0 is slope, 0.0 is + * the Y intercept (y=mx+b). 0 is the address of a function to + * do a x to y mapping, 0 means use the default function. + */ (void) tonescale(Map, 1.0, 0.0, 0); -/* - * Currently the halftone file is scaled from 0 to 255 on output to - * ease display via bw-fb. In the future there might be flag to - * set Scale to 1 to get a unscaled output. - */ + /* + * Currently the halftone file is scaled from 0 to 255 on output to + * ease display via bw-fb. In the future there might be flag to + * set Scale to 1 to get a unscaled output. + */ Scale = 255/Levels; if (Debug) { @@ -951,33 +955,33 @@ Line = (unsigned char *) bu_malloc(width, "Line"); Out = (unsigned char *) bu_malloc(width, "Out"); -/* - * should be a test here to make sure we got the memory requested. - */ + /* + * should be a test here to make sure we got the memory requested. + */ -/* - * Currently only the Floyd-Steinberg method uses the surpent flag - * so we make things easy with in the 'y' loop by resetting surpent - * for all other methods to "No Surpent". - */ + /* + * Currently only the Floyd-Steinberg method uses the surpent flag + * so we make things easy with in the 'y' loop by resetting surpent + * for all other methods to "No Surpent". + */ if (Method != M_FLOYD) Surpent = 0; for (y=0; y<height; y++) { int NextX; -/* - * A few of the methods benefit by knowing when a new line is - * started. - */ + /* + * A few of the methods benefit by knowing when a new line is + * started. + */ NewFlag = 1; (void) sharpen(Line, 1, width, stdin, Map); -/* - * Only M_FLOYD will have Surpent != 0. - */ + /* + * Only M_FLOYD will have Surpent != 0. + */ if (Surpent && y % 2) { for (x=width-1; x>=0; x--) { pixel = Line[x]; Out[x] = Scale*tone_floyd(pixel, x, y, x-1, - y+1, NewFlag); + y+1, NewFlag); NewFlag = 0; } } else { @@ -987,19 +991,19 @@ switch (Method) { case M_FOLLY: Out[x] = Scale*tone_folly(pixel, x, y, - NextX, y+1, NewFlag); + NextX, y+1, NewFlag); break; case M_FLOYD: Out[x] = Scale*tone_floyd(pixel, x, y, - NextX, y+1, NewFlag); + NextX, y+1, NewFlag); break; case M_THRESH: Out[x]=Scale*tone_simple(pixel, x, y, - NextX, y+1, NewFlag); + NextX, y+1, NewFlag); break; case M_CLASSIC: Out[x]=Scale*tone_classic(pixel, x, y, - NextX, y+1, NewFlag); + NextX, y+1, NewFlag); break; } NewFlag=0; Modified: brlcad/trunk/src/util/mac-pix.c =================================================================== --- brlcad/trunk/src/util/mac-pix.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/mac-pix.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -229,6 +229,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv) || isatty(fileno(stdout))) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pix-alias.c =================================================================== --- brlcad/trunk/src/util/pix-alias.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pix-alias.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -148,6 +148,9 @@ progname = *av; if (isatty(fileno(stdin))) usage(); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* Get # of options & turn all the option flags off */ optlen = strlen(options); Modified: brlcad/trunk/src/util/pix-ppm.c =================================================================== --- brlcad/trunk/src/util/pix-ppm.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pix-ppm.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -168,6 +168,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* important to store these before calling get_args(). they're * also not necessarily constants so have to set here instead of * with the declaration. Modified: brlcad/trunk/src/util/pix-ps.c =================================================================== --- brlcad/trunk/src/util/pix-ps.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pix-ps.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -217,6 +217,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc == 1 && isatty(fileno(stdin)) && isatty(fileno(stdout)) ) printusage(); if (!get_args(argc, argv)) Modified: brlcad/trunk/src/util/pix-sun.c =================================================================== --- brlcad/trunk/src/util/pix-sun.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pix-sun.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -323,6 +323,9 @@ progname = *av; if (isatty(fileno(stdin))) usage(); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* Get # of options & turn all the option flags off */ optlen = strlen(options); Modified: brlcad/trunk/src/util/pixbgstrip.c =================================================================== --- brlcad/trunk/src/util/pixbgstrip.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixbgstrip.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -134,6 +134,9 @@ bu_exit (1, NULL); } + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* autosize input? */ if (fileinput && autosize) { size_t w, h; Modified: brlcad/trunk/src/util/pixblend.c =================================================================== --- brlcad/trunk/src/util/pixblend.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixblend.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -170,6 +170,9 @@ bu_exit (1, NULL); } + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!iflg && !rflg) { /* Default action: interpolate by 50% */ iflg = 1; Modified: brlcad/trunk/src/util/pixborder.c =================================================================== --- brlcad/trunk/src/util/pixborder.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixborder.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -483,6 +483,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + VSETALL(border_rgb, 1); rgb_to_hsv(border_rgb, border_hsv); VSETALL(exterior_rgb, 1); Modified: brlcad/trunk/src/util/pixclump.c =================================================================== --- brlcad/trunk/src/util/pixclump.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixclump.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -177,6 +177,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* * Initialize the color table */ Modified: brlcad/trunk/src/util/pixcolors.c =================================================================== --- brlcad/trunk/src/util/pixcolors.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixcolors.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -128,6 +128,9 @@ progname = *av; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* Get # of options & turn all the option flags off */ Modified: brlcad/trunk/src/util/pixcount.cpp =================================================================== --- brlcad/trunk/src/util/pixcount.cpp 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixcount.cpp 2020-07-25 17:40:03 UTC (rev 76499) @@ -176,6 +176,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* * Process the command line */ Modified: brlcad/trunk/src/util/pixdiff.c =================================================================== --- brlcad/trunk/src/util/pixdiff.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixdiff.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -72,6 +72,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc != 3 || isatty(fileno(stdout))) { bu_exit(1, "Usage: pixdiff f1.pix f2.pix >file.pix\n"); } Modified: brlcad/trunk/src/util/pixelswap.c =================================================================== --- brlcad/trunk/src/util/pixelswap.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixelswap.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -99,7 +99,10 @@ bu_setprogname(av[0]); - i=parse_args(ac, av); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + + i=parse_args(ac, av); /* if ac == 1, there is only 1 argument; i.e., run-with-no-arguments */ if (ac == 1) usage(""); Modified: brlcad/trunk/src/util/pixembed.c =================================================================== --- brlcad/trunk/src/util/pixembed.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixembed.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -127,6 +127,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv) || isatty(fileno(stdout))) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pixfilter.c =================================================================== --- brlcad/trunk/src/util/pixfilter.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixfilter.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -150,6 +150,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* Select Default Filter (low pass) */ select_filter("low"); Modified: brlcad/trunk/src/util/pixhalve.c =================================================================== --- brlcad/trunk/src/util/pixhalve.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixhalve.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -321,6 +321,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pixhist.c =================================================================== --- brlcad/trunk/src/util/pixhist.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixhist.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -61,6 +61,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* check for verbose flag */ if (argc > 1 && BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/pixhist3d-plot3.c =================================================================== --- brlcad/trunk/src/util/pixhist3d-plot3.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixhist3d-plot3.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -58,6 +58,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc > 1) { if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "%s", Usage); Modified: brlcad/trunk/src/util/pixhist3d.c =================================================================== --- brlcad/trunk/src/util/pixhist3d.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixhist3d.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -70,6 +70,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc > 1) { if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) bu_exit(2, "%s", Usage); Modified: brlcad/trunk/src/util/pixinterp2x.c =================================================================== --- brlcad/trunk/src/util/pixinterp2x.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixinterp2x.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -97,6 +97,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + infp = stdin; if (!get_args(argc, argv)) { (void)fputs(usage, stderr); Modified: brlcad/trunk/src/util/pixmerge.c =================================================================== --- brlcad/trunk/src/util/pixmerge.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixmerge.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -175,6 +175,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv) || isatty(fileno(stdout))) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pixrot.c =================================================================== --- brlcad/trunk/src/util/pixrot.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixrot.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -148,6 +148,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv) || isatty(fileno(stdout))) { bu_exit(1, "%s", usage); } Modified: brlcad/trunk/src/util/pixsaturate.c =================================================================== --- brlcad/trunk/src/util/pixsaturate.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixsaturate.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -67,6 +67,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc != 2) printusage (); if ( BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?") ) Modified: brlcad/trunk/src/util/pixscale.c =================================================================== --- brlcad/trunk/src/util/pixscale.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixscale.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -420,6 +420,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc == 1 && isatty(fileno(stdin)) && isatty(fileno(stdout))) bu_exit(1, "%s", usage); if (!get_args(argc, argv) || isatty(fileno(stdout))) Modified: brlcad/trunk/src/util/pixshrink.c =================================================================== --- brlcad/trunk/src/util/pixshrink.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixshrink.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -245,6 +245,9 @@ bu_setprogname(av[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + (void)parse_args(ac, av); if (isatty(fileno(stdin))) usage(); Modified: brlcad/trunk/src/util/pixstat.c =================================================================== --- brlcad/trunk/src/util/pixstat.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixstat.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -87,6 +87,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + /* check for verbose flag */ if (argc > 1 && BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/pixtile.c =================================================================== --- brlcad/trunk/src/util/pixtile.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixtile.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -119,6 +119,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/pixuntile.c =================================================================== --- brlcad/trunk/src/util/pixuntile.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/pixuntile.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -112,6 +112,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/plot3-asc.c =================================================================== --- brlcad/trunk/src/util/plot3-asc.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3-asc.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -132,6 +132,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + while (argc > 1) { if (BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/plot3-plot3.c =================================================================== --- brlcad/trunk/src/util/plot3-plot3.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3-plot3.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -147,6 +147,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + while (argc > 1) { if (BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/plot3-ps.c =================================================================== --- brlcad/trunk/src/util/plot3-ps.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3-ps.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -424,6 +424,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit (1, NULL); Modified: brlcad/trunk/src/util/plot3color.c =================================================================== --- brlcad/trunk/src/util/plot3color.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3color.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -44,6 +44,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc != 4 || isatty(fileno(stdout))) { bu_exit(1, "%s", usage); } Modified: brlcad/trunk/src/util/plot3getframe.c =================================================================== --- brlcad/trunk/src/util/plot3getframe.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3getframe.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -124,6 +124,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + while (argc > 1) { if (BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/plot3line2.c =================================================================== --- brlcad/trunk/src/util/plot3line2.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3line2.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -49,6 +49,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (argc < 5 || isatty(fileno(stdout))) { bu_exit(1, "%s", usage); } Modified: brlcad/trunk/src/util/plot3rot.c =================================================================== --- brlcad/trunk/src/util/plot3rot.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3rot.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -325,6 +325,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + if (!get_args(argc, argv)) { fputs("Usage: plot3rot [options] [file1 ... fileN] > file.plot3\n", stderr); Modified: brlcad/trunk/src/util/plot3stat.c =================================================================== --- brlcad/trunk/src/util/plot3stat.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/plot3stat.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -147,6 +147,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + while (argc > 1) { if (BU_STR_EQUAL(argv[1], "-v")) { verbose++; Modified: brlcad/trunk/src/util/png-bw.c =================================================================== --- brlcad/trunk/src/util/png-bw.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/png-bw.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -76,6 +76,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + while (argc > 1 && argv[1][0] == '-') { if (BU_STR_EQUAL(argv[1], "-v")) verbose = 1; Modified: brlcad/trunk/src/util/sun-pix.c =================================================================== --- brlcad/trunk/src/util/sun-pix.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/sun-pix.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -268,6 +268,9 @@ bu_setprogname(argv[0]); + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + fp = stdin; if (!get_args(argc, argv) || (isatty(fileno(stdout)) && (hflag == 0))) { (void)fputs(usage, stderr); Modified: brlcad/trunk/src/util/wavelet.c =================================================================== --- brlcad/trunk/src/util/wavelet.c 2020-07-25 16:40:42 UTC (rev 76498) +++ brlcad/trunk/src/util/wavelet.c 2020-07-25 17:40:03 UTC (rev 76499) @@ -173,6 +173,9 @@ size_t sample_size; /* size of data type x #values/sample */ size_t scanline_size; /* # bytes in a scanline */ + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); + sample_size = value_size * channels; scanline_size = sample_size * width; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2020-07-28 04:55:30
|
Revision: 76542 http://sourceforge.net/p/brlcad/code/76542 Author: brlcad Date: 2020-07-28 04:55:28 +0000 (Tue, 28 Jul 2020) Log Message: ----------- if we reopen the input, make sure it stays binary Modified Paths: -------------- brlcad/trunk/src/util/bwshrink.c brlcad/trunk/src/util/halftone.c brlcad/trunk/src/util/pixshrink.c Modified: brlcad/trunk/src/util/bwshrink.c =================================================================== --- brlcad/trunk/src/util/bwshrink.c 2020-07-28 04:03:18 UTC (rev 76541) +++ brlcad/trunk/src/util/bwshrink.c 2020-07-28 04:55:28 UTC (rev 76542) @@ -155,7 +155,7 @@ } if (bu_optind < ac) { char *ifname = bu_file_realpath(av[bu_optind], NULL); - if (freopen(ifname, "r", stdin) == (FILE *)NULL) { + if (freopen(ifname, "rb", stdin) == (FILE *)NULL) { perror(ifname); bu_exit (-1, NULL); } else Modified: brlcad/trunk/src/util/halftone.c =================================================================== --- brlcad/trunk/src/util/halftone.c 2020-07-28 04:03:18 UTC (rev 76541) +++ brlcad/trunk/src/util/halftone.c 2020-07-28 04:55:28 UTC (rev 76542) @@ -894,7 +894,7 @@ } } else { char *ifname = bu_file_realpath(argv[bu_optind], NULL); - if (freopen(ifname, "r", stdin) == NULL ) { + if (freopen(ifname, "rb", stdin) == NULL ) { bu_free(ifname,"ifname alloc from bu_file_realpath"); bu_exit(1, "halftone: cannot open \"%s\" for reading.\n", argv[bu_optind]); } Modified: brlcad/trunk/src/util/pixshrink.c =================================================================== --- brlcad/trunk/src/util/pixshrink.c 2020-07-28 04:03:18 UTC (rev 76541) +++ brlcad/trunk/src/util/pixshrink.c 2020-07-28 04:55:28 UTC (rev 76542) @@ -221,7 +221,7 @@ } if (bu_optind < ac) { char *ifname = bu_file_realpath(av[bu_optind], NULL); - if (freopen(ifname, "r", stdin) == (FILE *)NULL) { + if (freopen(ifname, "rb", stdin) == (FILE *)NULL) { perror(ifname); bu_free(ifname, "ifname alloc from bu_file_realpath"); bu_exit (-1, NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |