BRL-CAD
icv_size_down.c
Go to the documentation of this file.
1 /* I C V _ S I Z E _ D O W N . 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_down.c
21  *
22  * tester api for icv_resize api. This utility tests for the methods
23  * dealing in to decrease 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 under_sample|shrink]\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 factor=2;
60  icv_image_t *bif;
63  size_t index;
64 
65  if (argc<2) {
66  usage();
67  return 1;
68  }
69 
70  while ((c = bu_getopt(argc, argv, "s:w:n:M:f:o:bpdmh?")) != -1) {
71  switch (c) {
72  case 's':
73  inx = iny = atoi(bu_optarg);
74  break;
75  case 'w':
76  inx = atoi(bu_optarg);
77  break;
78  case 'n':
79  iny = atoi(bu_optarg);
80  break;
81  case 'o':
82  out_file = bu_optarg;
83  break;
84  case 'M':
85  if (BU_STR_EQUAL(bu_optarg, "under_sample"))
86  method = ICV_RESIZE_UNDERSAMPLE;
87  else if (BU_STR_EQUAL(bu_optarg, "shrink"))
88  method = ICV_RESIZE_SHRINK;
89  else {
90  usage();
91  bu_exit(1, "Wrong Input Argument\n");
92  }
93  break;
94  case 'f':
95  factor = atoi(bu_optarg);
96  break;
97  case 'b':
98  format = ICV_IMAGE_BW;
99  break;
100  case 'p':
101  format = ICV_IMAGE_PIX;
102  break;
103  case 'd':
104  format = ICV_IMAGE_DPIX;
105  break;
106  case 'm':
107  format = ICV_IMAGE_PPM;
108  break;
109  default:
110  usage();
111  return 1;
112 
113  }
114  }
115  if (bu_optind >= argc) {
116  if (isatty(fileno(stdin))) {
117  usage();
118  return 1;
119  }
120  }
121  else {
122  in_file = argv[bu_optind];
123  bu_optind++;
124  }
125 
126  bif = icv_read(in_file, format, inx, iny);
127  icv_resize(bif, method, 0, 0, (unsigned int) factor);
128  bu_log("File information width %d height%d\n", bif->width, bif->height);
129 
130  for (index = 0; index < 65536; index++)
131  bu_log("index = %ld, data = %f\n", index, bif->data[index]);
132 
133 
134  icv_write(bif,out_file, format);
135  bu_log("File information width %d height%d channels = %d\n", bif->width, bif->height, bif->channels);
136  icv_destroy(bif);
137 
138  return 0;
139 }
140 
141 /*
142  * Local Variables:
143  * tab-width: 8
144  * mode: C
145  * indent-tabs-mode: t
146  * c-file-style: "stroustrup"
147  * End:
148  * ex: shiftwidth=4 tabstop=8
149  */
double * data
Definition: icv.h:89
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 width
Definition: icv.h:91
int main(int argc, char *argv[])
Definition: icv_size_down.c:53
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
int channels
Definition: icv.h:91
Definition: icv.h:86
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
int height
Definition: icv.h:91
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_down.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