BRL-CAD
icv_saturate.c
Go to the documentation of this file.
1 /* I C V _ S A T U R A T 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_saturate.c
21  *
22  * Brief description
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 
30 #include "bio.h"
31 #include "bu/log.h"
32 #include "bu/getopt.h"
33 #include "icv.h"
34 
35 void usage()
36 {
37  bu_log("\
38  [-f fraction ]\n\
39  [-p -d -m] \n\
40  [-o out_file] [file] > [out_file]\n");
41 
42  bu_log("#Image Options\n\
43  \t -d for dpix image\n\
44  \t -m for ppm image\n\
45  \t -p for pix image\n");
46 
47 }
48 
49 int main(int argc, char* argv[])
50 {
51  char *out_file = NULL;
52  char *in_file = NULL;
53  int c;
54  int inx=0, iny=0;
55  icv_image_t *bif;
56  double fraction = 0;
58 
59  if (argc<2) {
60  usage();
61  return 1;
62  }
63 
64  while ((c = bu_getopt(argc, argv, "f:o:bpdmh?")) != -1) {
65  switch (c) {
66  case 'o':
67  out_file = bu_optarg;
68  break;
69  case 'f' :
70  fraction = atof(bu_optarg);
71  break;
72  case 'b' :
73  format = ICV_IMAGE_BW;
74  break;
75  case 'p' :
76  format = ICV_IMAGE_PIX;
77  break;
78  case 'd' :
79  format = ICV_IMAGE_DPIX;
80  break;
81  case 'm' :
82  format = ICV_IMAGE_PPM;
83  break;
84  default:
85  usage();
86  return 1;
87 
88  }
89  }
90  if (bu_optind >= argc) {
91  if (isatty(fileno(stdin))) {
92  usage();
93  return 1;
94  }
95  }
96  else {
97  in_file = argv[bu_optind];
98  bu_optind++;
99  }
100 
101  bif = icv_read(in_file, format, inx, iny);
102  if (icv_saturate(bif, fraction) < 0)
103  return 1;
104  icv_write(bif,out_file, format);
105  icv_destroy(bif);
106 
107  return 0;
108 
109 }
110 /*
111  * Local Variables:
112  * tab-width: 8
113  * mode: C
114  * indent-tabs-mode: t
115  * c-file-style: "stroustrup"
116  * End:
117  * ex: shiftwidth=4 tabstop=8
118  */
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_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
int icv_saturate(icv_image_t *img, double sat)
Definition: operations.c:263
ICV_IMAGE_FORMAT
Definition: icv.h:50
int main(int argc, char *argv[])
Definition: icv_saturate.c:49
void usage()
Definition: icv_saturate.c:35