BRL-CAD
icv_fade.c
Go to the documentation of this file.
1 /* I C V _ F A D E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2013-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file icv_fade.c
21  *
22  * this is tester function for icv_fade api.
23  *
24  */
25 
26 
27 #include "common.h"
28 
29 #include <stdlib.h>
30 
31 #include "bio.h"
32 #include "bu/log.h"
33 #include "bu/getopt.h"
34 #include "icv.h"
35 
36 void usage()
37 {
38  bu_log("\n\
39  [-b -p -d -m]\n\
40  [-%% percentage] [-f fraction]\n\
41  [-o out_file] [file] > [out_file]\n");
42 
43  bu_log("#Image Options\n\
44  \t -b for bw image\n\
45  \t -d for dpix image\n\
46  \t -m for b image\n\
47  \t -p for pix image\n");
48 }
49 
50 int main(int argc, char* argv[])
51 {
52  char *out_file = NULL;
53  char *in_file = NULL;
54  int c;
55  int inx=0, iny=0;
56  icv_image_t *bif;
58  double multiplier=0.2;
59  if (argc<2) {
60  usage();
61  return 1;
62  }
63 
64  while ((c = bu_getopt(argc, argv, "s:w:n:o:%:f:bpdmh?")) != -1) {
65  switch (c) {
66  case 's':
67  inx = iny = atoi(bu_optarg);
68  break;
69  case 'w':
70  inx = atoi(bu_optarg);
71  break;
72  case 'n':
73  iny = atoi(bu_optarg);
74  break;
75  case 'o':
76  out_file = bu_optarg;
77  break;
78  case '%':
79  multiplier = atof(bu_optarg) / 100.0;
80  if (multiplier < 0.0)
81  bu_exit (1, "tester_icv_fade : percent is negative");
82  break;
83  case 'f':
84  multiplier = atof(bu_optarg);
85  if (multiplier < 0.0)
86  bu_exit(1,"tester_icv_fade : fraction is negative");
87  break;
88  case 'b' :
89  format = ICV_IMAGE_BW;
90  break;
91  case 'p' :
92  format = ICV_IMAGE_PIX;
93  break;
94  case 'd' :
95  format = ICV_IMAGE_DPIX;
96  break;
97  case 'm' :
98  format = ICV_IMAGE_PPM;
99  break;
100  default:
101  usage();
102  return 1;
103 
104  }
105  }
106  if (bu_optind >= argc) {
107  if (isatty(fileno(stdin))) {
108  usage();
109  return 1;
110  }
111  }
112  else {
113  in_file = argv[bu_optind];
114  bu_optind++;
115  }
116 
117  bif = icv_read(in_file, format, inx, iny);
118  icv_fade(bif, multiplier);
119  icv_write(bif,out_file, format);
120  icv_destroy(bif);
121 
122  return 0;
123 }
124 
125 /*
126  * Local Variables:
127  * tab-width: 8
128  * mode: C
129  * indent-tabs-mode: t
130  * c-file-style: "stroustrup"
131  * End:
132  * ex: shiftwidth=4 tabstop=8
133  */
icv_image_t * icv_read(const char *filename, int format, int width, int height)
Definition: fileformat.c:162
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int icv_fade(icv_image_t *img, double fraction)
Definition: filter.c:326
int icv_destroy(icv_image_t *bif)
Definition: fileformat.c:321
char * bu_optarg
Definition: globals.c:91
Header file for the BRL-CAD common definitions.
int bu_optind
Definition: globals.c:89
Definition: icv.h:86
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
int icv_write(icv_image_t *bif, const char *filename, ICV_IMAGE_FORMAT format)
Definition: fileformat.c:186
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
int main(int argc, char *argv[])
Definition: icv_fade.c:50
ICV_IMAGE_FORMAT
Definition: icv.h:50
void usage()
Definition: icv_fade.c:36