BRL-CAD
icv_read_write.c
Go to the documentation of this file.
1 /* I C V _ R E A D _ W R I 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_read_write.c
21  *
22  * This testing function is to test the time required in loading and
23  * image to icv container and saving it again.
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("tester_icv_read_write [-s squaresize] [-w width] [-n height]]\n\
38  [-b -p -d -m]\n\
39  [-o out_file] [in_file] > [out_file]\n");
40 
41  bu_log("#Options\n\
42  \t -b for bw images\n\
43  \t -d for dpix images\n\
44  \t -m for b images\n\
45  \t -p for pix images\n");
46 }
47 
48 int main(int argc, char* argv[])
49 {
50  char *out_file = NULL;
51  char *in_file = NULL;
52  int inx=0, iny=0;
53  icv_image_t *bif;
55  int c;
56 
57  if (argc<2) {
58  usage();
59  return 1;
60  }
61 
62  while ((c = bu_getopt(argc, argv, "s:o:w:nbpdmh?")) != -1) {
63  switch (c) {
64  case 'o' :
65  bu_log("out_file = %s\n", bu_optarg);
66  out_file = bu_optarg;
67  break;
68  case 's' :
69  inx = iny = atoi(bu_optarg);
70  break;
71  case 'w' :
72  inx = atoi(bu_optarg);
73  break;
74  case 'n' :
75  iny = atoi(bu_optarg);
76  break;
77  case 'b' :
78  bu_log("There was in bw\n");
79  format = ICV_IMAGE_BW;
80  break;
81  case 'p' :
82  format = ICV_IMAGE_PIX;
83  break;
84  case 'd' :
85  format = ICV_IMAGE_DPIX;
86  break;
87  case 'm' :
88  format = ICV_IMAGE_PPM;
89  break;
90  default:
91  usage();
92  return 1;
93 
94  }
95 
96  bu_log("C= %c, optind = %d\n", c, bu_optind);
97  }
98  if (bu_optind >= argc) {
99  if (isatty(fileno(stdin))) {
100  usage();
101  return 1;
102  }
103  }
104  else {
105  in_file = argv[bu_optind];
106  bu_optind++;
107  }
108 
109  bu_log("in_file = %s, out_file = %s\n", in_file, out_file);
110 
111  bif = icv_read(in_file, format, inx, iny);
112  icv_write(bif,out_file, format);
113  icv_destroy(bif);
114 
115  return 0;
116 }
117 
118 /*
119  * Local Variables:
120  * tab-width: 8
121  * mode: C
122  * indent-tabs-mode: t
123  * c-file-style: "stroustrup"
124  * End:
125  * ex: shiftwidth=4 tabstop=8
126  */
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
void usage()
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 main(int argc, char *argv[])
ICV_IMAGE_FORMAT
Definition: icv.h:50