BRL-CAD
icv_size_up.c
Go to the documentation of this file.
1 /* I C V _ S I Z E _ U P . 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_size_up.c
21  *
22  * tester api for icv_resize api. This utility tests for the methods
23  * dealing in to increase the size of the image.
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 "bu/str.h"
35 #include "icv.h"
36 
37 void usage()
38 {
39  bu_log("\
40  [-s squaresize] [-w width] [-n height] \n\
41  [-f binterp|ninterp]\n\
42  [-b -p -d -m] \n\
43  [-o out_file] [file] > [out_file]\n");
44 
45  bu_log("#Image Options\n\
46  \t -b for bw image\n\
47  \t -d for dpix image\n\
48  \t -m for b image\n\
49  \t -p for pix image\n");
50 
51 }
52 
53 int main(int argc, char* argv[])
54 {
55  char *out_file = NULL;
56  char *in_file = NULL;
57  int c;
58  int inx=0, iny=0;
59  int outx=0, outy=0;
60  icv_image_t *bif;
63 
64  if (argc<2) {
65  usage();
66  return 1;
67  }
68 
69  while ((c = bu_getopt(argc, argv, "s:w:n:S:W:N:M:o:bpdmh?")) != -1) {
70  switch (c) {
71  case 's':
72  inx = iny = atoi(bu_optarg);
73  break;
74  case 'w':
75  inx = atoi(bu_optarg);
76  break;
77  case 'n':
78  iny = atoi(bu_optarg);
79  break;
80  case 'S':
81  outx = outy = atoi(bu_optarg);
82  break;
83  case 'W':
84  outx = atoi(bu_optarg);
85  break;
86  case 'N':
87  outy = atoi(bu_optarg);
88  break;
89  case 'o':
90  out_file = bu_optarg;
91  break;
92  case 'M':
93  if (BU_STR_EQUAL(bu_optarg, "binterp"))
94  method = ICV_RESIZE_BINTERP;
95  else if (BU_STR_EQUAL(bu_optarg, "ninterp"))
96  method = ICV_RESIZE_NINTERP;
97  else {
98  usage();
99  bu_exit(1, "Wrong Input Argument\n");
100  }
101  break;
102  case 'b':
103  format = ICV_IMAGE_BW;
104  break;
105  case 'p':
106  format = ICV_IMAGE_PIX;
107  break;
108  case 'd':
109  format = ICV_IMAGE_DPIX;
110  break;
111  case 'm':
112  format = ICV_IMAGE_PPM;
113  break;
114  default:
115  usage();
116  return 1;
117 
118  }
119  }
120  if (bu_optind >= argc) {
121  if (isatty(fileno(stdin))) {
122  usage();
123  return 1;
124  }
125  }
126  else {
127  in_file = argv[bu_optind];
128  bu_optind++;
129  }
130 
131  if (outx == 0 || outy == 0) {
132  bu_exit(1, "Bad outputsize\n");
133  }
134 
135  bif = icv_read(in_file, format, inx, iny);
136  icv_resize(bif, method, outx, outy, 0);
137  icv_write(bif,out_file, format);
138  icv_destroy(bif);
139 
140  return 0;
141 }
142 
143 /*
144  * Local Variables:
145  * tab-width: 8
146  * mode: C
147  * indent-tabs-mode: t
148  * c-file-style: "stroustrup"
149  * End:
150  * ex: shiftwidth=4 tabstop=8
151  */
int main(int argc, char *argv[])
Definition: icv_size_up.c:53
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
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
void usage()
Definition: icv_size_up.c:37
ICV_IMAGE_FORMAT
Definition: icv.h:50
int icv_resize(icv_image_t *bif, ICV_RESIZE_METHOD method, unsigned int out_width, unsigned int out_height, unsigned int factor)
Definition: size.c:213
ICV_RESIZE_METHOD
Definition: icv.h:675
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126