~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/mono/raw_input_tool.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <stdio.h>
  2 #include <sys/param.h>
  3 #include <string.h>
  4 #include <tina/all_tina.h>
  5 #include <tina/tw_Xfuncs.h>
  6 
  7 extern void scan_files(char *dir, char *file);
  8 
  9 static char directory_name[MAXPATHLEN];
 10 static char file_name[MAXPATHLEN];
 11 static char pathname[MAXPATHLEN];
 12 static void *pdir=0, *pfile=0;
 13 static void *ppadding;
 14 static int raw_width=0;
 15 static int raw_height = 0;
 16 static int padding = 0;
 17 static int endian = 0;
 18 static Vartype v_type = char_v;
 19 static int signed_val;
 20 
 21 static Imrect *raw_input_proc(void)
 22 {
 23   Imrect *im = NULL;
 24 
 25   (void) strip_spaces(file_name);
 26   (void) strip_spaces(directory_name);
 27   (void) string_append(pathname, directory_name, "/", file_name, NULL);
 28 
 29   im = raw_read_image(pathname, raw_width, raw_height,
 30                                 v_type, (unsigned int) padding );
 31   if (im!=NULL&&endian) im_endian_inplace(im);
 32   return(im); 
 33 }
 34 
 35 static Imrect *ascii_input_proc(void)
 36 {
 37   Matrix *mp = NULL; /* pointer to the matrix that is loaded */
 38   Imrect *im = NULL; /* pointer to the image that is put onto the stack */
 39   int row, col;      /* loop control variables */
 40 
 41   (void) strip_spaces(file_name);
 42   (void) strip_spaces(directory_name);
 43   (void) string_append(pathname, directory_name, "/", file_name, NULL);
 44 
 45   /* import the matrix from its stored file */
 46 
 47   mp = matrix_read_file(pathname);
 48 
 49   if (mp==NULL)
 50     {
 51       error("\ninput_proc: unable to load matrix file", warning);
 52       return(NULL);
 53     }
 54 
 55   /* create a new image of same size and roi as matrix */
 56 
 57   im = im_alloc(mp->m, mp->n, NULL, mp->vtype);
 58 
 59   /* copy matrix elements into new image */
 60 
 61   switch (mp->vtype)
 62     {
 63     case int_v:
 64       FOR_IM(im->region, row, col) IM_INT(im, row, col) = mp->el.int_v[row][col];
 65       break;
 66     case float_v:
 67       FOR_IM(im->region, row, col) IM_FLOAT(im, row, col) = mp->el.float_v[row][col];
 68       break;
 69     case double_v:
 70       FOR_IM(im->region, row, col) IM_DOUBLE(im, row, col) = mp->el.double_v[row][col];
 71       break;
 72     }
 73 
 74   matrix_free(mp);
 75   return(im);
 76 }
 77 
 78 /* store an image to a file in the ascii matrix structure */
 79 
 80 static void input_proc(void)
 81 {
 82     Imrect *im=NULL;
 83 
 84     if (endian ==2) im = ascii_input_proc();
 85     else im = raw_input_proc(); 
 86 
 87     stack_push((void *) im, IMRECT, im_free);
 88     imcalc_draw(imcalc_tv_get());
 89 }
 90 
 91 static void output_proc(void)
 92 {
 93   Matrix *mp = NULL; /* pointer to the matrix to be saved */
 94   Imrect *im = NULL; /* pointer to the image that is retrieved from the stack */
 95   int row, col;      /* loop control variables */
 96   int type;          /* used when popping image off stack */
 97 
 98   (void) strip_spaces(file_name);
 99   (void) strip_spaces(directory_name);
100   (void) string_append(pathname, directory_name, "/", file_name, NULL);
101 
102   if (stack_check_types(IMRECT, NULL) == false)
103     {
104       error("\noutput_proc: non-imrect type on stack", warning);
105       return;
106     }
107 
108   im = (Imrect *)stack_pop(&type);
109 
110   /* check image type */
111 
112   if ((im->vtype!=int_v)&&(im->vtype!=float_v)&&(im->vtype!=double_v))
113     {
114       error("\noutput_proc: wrong type imrect on stack", warning);
115       stack_push((void *) im, IMRECT, im_free);
116       return;
117     }
118 
119   mp = matrix_alloc(im->region->uy-im->region->ly,
120                     im->region->ux-im->region->lx,
121                     matrix_full, im->vtype);
122 
123   /* copy image elements into new matrix */
124 
125   switch (im->vtype)
126     {
127     case int_v:
128       FOR_IM(im->region, row, col)
129         mp->el.int_v[row-im->region->ly][col-im->region->lx] = IM_INT(im, row, col);
130       break;
131     case float_v:
132       FOR_IM(im->region, row, col)
133         mp->el.float_v[row-im->region->ly][col-im->region->lx] = IM_FLOAT(im, row, col);
134       break;
135     case double_v:
136       FOR_IM(im->region, row, col)
137         mp->el.double_v[row-im->region->ly][col-im->region->lx] = IM_DOUBLE(im, row, col);
138       break;
139     }
140 
141   /* export the matrix to file */
142 
143   mp = matrix_write_file(mp, pathname);
144 
145   matrix_free(mp);
146   stack_push((void *) im, IMRECT, im_free);
147   imcalc_draw(imcalc_tv_get());
148 }
149 
150 static void type_choice_proc(int val)
151 {
152     switch (val)
153     {
154         case 0:
155           if (signed_val) v_type = char_v; 
156           else v_type = uchar_v;
157         break;
158         case 1:
159           if (signed_val) v_type = short_v;
160           else v_type = ushort_v;
161         break;
162         case 2:
163           if (signed_val) v_type = int_v;
164           else v_type = uint_v;
165         break;
166         case 3:
167           v_type = float_v;
168         break;
169         case 4:
170           v_type = double_v;
171         break;
172         
173     }
174 }
175 
176 static void sign_check_proc(int val)
177 {
178    signed_val = val;
179 }
180 
181 static void endian_choice_proc(int val)
182 {
183     switch (val)
184     {
185         case 0:
186           endian = 0;
187         break;
188         case 1:
189           endian = 1;
190         break;
191         case 2:
192           endian = 2;
193         break;
194     }
195 }
196 
197 static void scan_proc(void)
198 {
199     scan_files(directory_name,file_name);
200     tw_sglobal_reset(pdir);
201     tw_sglobal_reset(pfile);
202 }
203 
204 static void inc_block_proc()
205 {
206    int data_size = var_size(v_type);
207 
208    padding += data_size*raw_height*raw_width;
209    tw_iglobal_reset(ppadding);
210 }
211 
212 static void dec_block_proc()
213 {
214    int data_size = var_size(v_type);
215    padding -= data_size*raw_height*raw_width;
216    tw_iglobal_reset(ppadding);
217 }
218 
219 void raw_input_tool(int x, int y)
220 {
221   static void *tv_screen = NULL;
222 
223   if (tv_screen)
224     {
225       tw_show_tool(tv_screen);
226       return;
227     }
228   tv_screen = tw_tool("Raw Input Tool", x, y);
229 
230   tw_button("input", input_proc, NULL);
231   tw_button("output", output_proc, NULL);
232   tw_button("scan",scan_proc, NULL);
233   tw_label("                 ");
234   tw_help_button("raw_input_tool");
235 
236   tw_newrow();
237   pdir = (void *) tw_sglobal("Directory:", directory_name, 32);
238   tw_newrow();
239   pfile = (void*) tw_sglobal("File:", file_name, 32);
240   tw_newrow();
241   tw_choice(" endian:", endian_choice_proc, 0,
242             "big", "little", "ascii",
243              NULL);
244   tw_check(" signed:", sign_check_proc, 0,
245             "yes", NULL);
246   tw_newrow();
247   tw_choice(" type:", type_choice_proc, 0,
248             "char", "short", "int", "float", "double",
249              NULL);
250   tw_button("<",dec_block_proc, NULL);
251   tw_button(">",inc_block_proc, NULL);
252   tw_newrow();
253   ppadding = tw_iglobal(" skip :", &padding, 8);
254   tw_iglobal(" width :", &raw_width, 5);
255   tw_iglobal(" height :", &raw_height, 5);
256 
257   tw_end_tool();
258 
259 }
260 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.