BRL-CAD
icv_crop.c
Go to the documentation of this file.
1 #include "common.h"
2 
3 #include <stdlib.h>
4 
5 #include "bio.h"
6 #include "bu/log.h"
7 #include "bu/getopt.h"
8 #include "icv.h"
9 
10 void usage()
11 {
12  bu_log("[-s squaresize] [-w width] [-n height] [-W out_width ] [-N out_height] \n\
13  [-b -p -d -m] \n\
14  [-S out_squaresize] [-o out_file] [file] \n");
15 
16  bu_log("#Image Options\n\
17  \t -b for bw image\n\
18  \t -d for dpix image\n\
19  \t -m for b image\n\
20  \t -p for pix image\n");
21 }
22 
23 int main(int argc, char* argv[])
24 {
25  char *out_file = NULL;
26  char *in_file = NULL;
27  int c;
28  int inx=0, iny=0;
29  int outx=0, outy=0;
30  icv_image_t *bif;
32  int urx, ury, ulx, uly, llx, lly, lrx, lry;
33  int ret;
34 
35  if (argc<2) {
36  usage();
37  return 1;
38  }
39 
40  while ((c = bu_getopt(argc, argv, "s:W:w:N:n:s:S:o:bpdmh?")) != -1) {
41  switch (c) {
42  case 's':
43  inx = iny = atoi(bu_optarg);
44  break;
45  case 'W':
46  outx = atoi(bu_optarg);
47  break;
48  case 'w':
49  inx = atoi(bu_optarg);
50  break;
51  case 'N':
52  outy = atoi(bu_optarg);
53  break;
54  case 'n':
55  iny = atoi(bu_optarg);
56  break;
57  case 'S':
58  outy = outx = atoi(bu_optarg);
59  break;
60  case 'o':
61  out_file = bu_optarg;
62  break;
63  case 'b' :
64  format = ICV_IMAGE_BW;
65  break;
66  case 'p' :
67  format = ICV_IMAGE_PIX;
68  break;
69  case 'd' :
70  format = ICV_IMAGE_DPIX;
71  break;
72  case 'm' :
73  format = ICV_IMAGE_PPM;
74  break;
75  default: /* 'h' '?' */
76  usage();
77  return 1;
78 
79  }
80  }
81 
82  if (bu_optind >= argc) {
83  usage();
84  return 1;
85  }
86  in_file = argv[bu_optind];
87 
88  bu_log("\t (ulx,uly) (urx,ury)\n\
89  \t __________________\n\
90  \t / |\n\
91  \t / |\n\
92  \t / |\n\
93  \t / |\n\
94  \t / |\n\
95  \t /______________________|\n\
96  \t (llx,lly) (lrx,lry)\n");
97 
98 
99  bu_log("Prompting Input Parameters\n");
100 
101  bu_log("\tUpper left corner in input file (ulx, uly)?: ");
102  ret = scanf("%d%d", &ulx, &uly);
103  if (ret != 2)
104  perror("scanf");
105 
106  bu_log("\tUpper right corner (urx, ury)?: ");
107  ret = scanf("%d%d", &urx, &ury);
108  if (ret != 2)
109  perror("scanf");
110 
111  bu_log("\tLower right (lrx, lry)?: ");
112  ret = scanf("%d%d", &lrx, &lry);
113  if (ret != 2)
114  perror("scanf");
115 
116  bu_log("\tLower left (llx, lly)?: ");
117  ret = scanf("%d%d", &llx, &lly);
118  if (ret != 2)
119  perror("scanf");
120 
121 
122  bif = icv_read(in_file, format, inx, iny);
123  icv_crop(bif, ulx, uly, urx, ury, lrx, lry, llx, lly, outy, outx);
124  icv_write(bif,out_file, format);
125  icv_destroy(bif);
126  return 0;
127 }
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_crop.c:23
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 icv_crop(icv_image_t *img, int ulx, int uly, int urx, int ury, int lrx, int lry, int llx, int lly, unsigned int ynum, unsigned int xnum)
Definition: crop.c:81
Definition: icv.h:86
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
void usage()
Definition: icv_crop.c:10
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