BRL-CAD
icv_rect.c
Go to the documentation of this file.
1 /* I C V _ R E C T . 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_rect.c
21  *
22  * tester function for icv_rect api.
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("[-s squaresize] [-w width] [-n height] [-W out_width ] [-N out_height] \n\
38  [-b -p -d -m] \n\
39  [-x xorig] [-y yorig] [-S out_squaresize] [-o out_file] [file] > [out_file]\n");
40 
41  bu_log("#Image Options\n\
42  \t -b for bw image\n\
43  \t -d for dpix image\n\
44  \t -m for b image\n\
45  \t -p for pix image\n");
46 }
47 
48 int main(int argc, char* argv[])
49 {
50  char *out_file = NULL;
51  char *in_file = NULL;
52  int c;
53  int inx=0, iny=0;
54  int xorig=0, yorig=0;
55  int outx=0, outy=0;
56  icv_image_t *bif;
58 
59  if (argc<2) {
60  usage();
61  return 1;
62  }
63 
64  while ((c = bu_getopt(argc, argv, "s:W:w:N:n:S:x:y:o:bpdmh?")) != -1) {
65  switch (c) {
66  case 's':
67  inx = iny = atoi(bu_optarg);
68  break;
69  case 'W':
70  outx = atoi(bu_optarg);
71  break;
72  case 'w':
73  inx = atoi(bu_optarg);
74  break;
75  case 'N':
76  outy = atoi(bu_optarg);
77  break;
78  case 'n':
79  iny = atoi(bu_optarg);
80  break;
81  case 'S':
82  outy = outx = atoi(bu_optarg);
83  break;
84  case 'x':
85  xorig = atoi(bu_optarg);
86  break;
87  case 'y':
88  yorig = atoi(bu_optarg);
89  break;
90  case 'o':
91  out_file = bu_optarg;
92  break;
93  case 'b' :
94  format = ICV_IMAGE_BW;
95  break;
96  case 'p' :
97  format = ICV_IMAGE_PIX;
98  break;
99  case 'd' :
100  format = ICV_IMAGE_DPIX;
101  break;
102  case 'm' :
103  format = ICV_IMAGE_PPM;
104  break;
105  default:
106  usage();
107  return 1;
108 
109  }
110  }
111  if (bu_optind >= argc) {
112  if (isatty(fileno(stdin))) {
113  usage();
114  return 1;
115  }
116  }
117  else {
118  in_file = argv[bu_optind];
119  bu_optind++;
120  }
121 
122  bif = icv_read(in_file, format, inx, iny);
123  icv_rect(bif, xorig, yorig, outx, outy);
124  icv_write(bif,out_file, format);
125  icv_destroy(bif);
126 
127  return 0;
128 }
129 
130 /*
131  * Local Variables:
132  * tab-width: 8
133  * mode: C
134  * indent-tabs-mode: t
135  * c-file-style: "stroustrup"
136  * End:
137  * ex: shiftwidth=4 tabstop=8
138  */
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 main(int argc, char *argv[])
Definition: icv_rect.c:48
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
void usage()
Definition: icv_rect.c:35
int icv_rect(icv_image_t *img, int xorig, int yorig, int xnum, int ynum)
Definition: crop.c:32
int icv_write(icv_image_t *bif, const char *filename, ICV_IMAGE_FORMAT format)
Definition: fileformat.c:186
ICV_IMAGE_FORMAT
Definition: icv.h:50