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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseMono_raw_input.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseMono_raw_input.c,v $
 37  * Date    :  $Date: 2009/04/20 12:05:23 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: tlbaseMono_raw_input.c,v 1.4 2009/04/20 12:05:23 neil Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseMono_raw_input.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <sys/param.h>
 56 #include <string.h>
 57 
 58 #include <tina/sys/sysDef.h>
 59 #include <tina/sys/sysPro.h>
 60 #include <tina/file/fileDef.h>
 61 #include <tina/file/filePro.h>
 62 #include <tina/image/imgDef.h>
 63 #include <tina/image/imgPro.h>
 64 #include <tina/math/mathDef.h>
 65 #include <tina/math/mathPro.h>
 66 #include <tinatool/wdgts/wdgtsDef.h>
 67 #include <tinatool/wdgts/wdgtsPro.h>
 68 #include <tinatool/tlbase/tlbase_InfrDef.h>
 69 #include <tinatool/tlbase/tlbase_InfrPro.h>
 70 #include <tinatool/tlbase/tlbase_ImcDef.h>
 71 #include <tinatool/tlbase/tlbase_ImcPro.h>
 72 
 73 
 74 static char directory_name[MAXPATHLEN];
 75 static char file_name[MAXPATHLEN];
 76 static char pathname[MAXPATHLEN];
 77 static void *pdir=0, *pfile=0;
 78 static void *ppadding;
 79 static int raw_width=0;
 80 static int raw_height = 0;
 81 static int padding = 0;
 82 static int endian = 0;
 83 static Vartype v_type = char_v;
 84 static int signed_val=0;
 85 
 86 static Imrect *raw_input_proc(void)
 87 {
 88   Imrect *im = NULL;
 89 
 90   (void) strip_spaces(file_name);
 91   (void) strip_spaces(directory_name);
 92   (void) string_append(pathname, directory_name, "/", file_name, NULL);
 93 
 94   im = raw_read_image(pathname, raw_width, raw_height,
 95                                 v_type, (unsigned int) padding );
 96   if (im!=NULL&&endian) im_endian_inplace(im);
 97   return(im); 
 98 }
 99 
100 static Imrect *ascii_input_proc(void)
101 {
102   Matrix *mp = NULL; /* pointer to the matrix that is loaded */
103   Imrect *im = NULL; /* pointer to the image that is put onto the stack */
104   int row, col;      /* loop control variables */
105 
106   (void) strip_spaces(file_name);
107   (void) strip_spaces(directory_name);
108   (void) string_append(pathname, directory_name, "/", file_name, NULL);
109 
110   /* import the matrix from its stored file */
111 
112   mp = matrix_read_file(pathname);
113 
114   if (mp==NULL)
115     {
116       error("\ninput_proc: unable to load matrix file", warning);
117       return(NULL);
118     }
119 
120   /* create a new image of same size and roi as matrix */
121 
122   im = im_alloc(mp->m, mp->n, NULL, mp->vtype);
123 
124   /* copy matrix elements into new image */
125 
126   switch (mp->vtype)
127     {
128     case int_v:
129       FOR_IM(im->region, row, col) IM_INT(im, row, col) = mp->el.int_v[row][col];
130       break;
131     case float_v:
132       FOR_IM(im->region, row, col) IM_FLOAT(im, row, col) = mp->el.float_v[row][col];
133       break;
134     case double_v:
135       FOR_IM(im->region, row, col) IM_DOUBLE(im, row, col) = mp->el.double_v[row][col];
136       break;
137     }
138 
139   matrix_free(mp);
140   return(im);
141 }
142 
143 /* store an image to a file in the ascii matrix structure */
144 
145 static void input_proc(void)
146 {
147     Imrect *im=NULL;
148 
149     if (endian ==2) im = ascii_input_proc();
150     else im = raw_input_proc(); 
151 
152     stack_push((void *) im, IMRECT, im_free);
153     imcalc_draw(imcalc_tv_get());
154 }
155 
156 static void output_proc(void)
157 {
158   Matrix *mp = NULL; /* pointer to the matrix to be saved */
159   Imrect *im = NULL; /* pointer to the image that is retrieved from the stack */
160   int row, col;      /* loop control variables */
161   int type;          /* used when popping image off stack */
162 
163   (void) strip_spaces(file_name);
164   (void) strip_spaces(directory_name);
165   (void) string_append(pathname, directory_name, "/", file_name, NULL);
166 
167   if (stack_check_types(IMRECT, NULL) == false)
168     {
169       error("\noutput_proc: non-imrect type on stack", warning);
170       return;
171     }
172 
173   im = (Imrect *)stack_pop(&type);
174 
175   /* check image type */
176 
177   if ((im->vtype!=int_v)&&(im->vtype!=float_v)&&(im->vtype!=double_v))
178     {
179       error("\noutput_proc: wrong type imrect on stack", warning);
180       stack_push((void *) im, IMRECT, im_free);
181       return;
182     }
183 
184   mp = matrix_alloc(im->region->uy-im->region->ly,
185                     im->region->ux-im->region->lx,
186                     matrix_full, im->vtype);
187 
188   /* copy image elements into new matrix */
189 
190   switch (im->vtype)
191     {
192     case int_v:
193       FOR_IM(im->region, row, col)
194         mp->el.int_v[row-im->region->ly][col-im->region->lx] = IM_INT(im, row, col);
195       break;
196     case float_v:
197       FOR_IM(im->region, row, col)
198         mp->el.float_v[row-im->region->ly][col-im->region->lx] = IM_FLOAT(im, row, col);
199       break;
200     case double_v:
201       FOR_IM(im->region, row, col)
202         mp->el.double_v[row-im->region->ly][col-im->region->lx] = IM_DOUBLE(im, row, col);
203       break;
204     }
205 
206   /* export the matrix to file */
207 
208   mp = matrix_write_file(mp, pathname);
209 
210   matrix_free(mp);
211   stack_push((void *) im, IMRECT, im_free);
212   imcalc_draw(imcalc_tv_get());
213 }
214 
215 static void type_choice_proc(int val)
216 {
217     switch (val)
218     {
219         case 0:
220           if (signed_val) v_type = char_v; 
221           else v_type = uchar_v;
222         break;
223         case 1:
224           if (signed_val) v_type = short_v;
225           else v_type = ushort_v;
226         break;
227         case 2:
228           if (signed_val) v_type = int_v;
229           else v_type = uint_v;
230         break;
231         case 3:
232           v_type = float_v;
233         break;
234         case 4:
235           v_type = double_v;
236         break;
237         
238     }
239 }
240 
241 static void sign_check_proc(int val)
242 {
243    signed_val = val;
244    printf("sign %d\n", signed_val);
245    if (signed_val)
246    {
247       if (v_type == uchar_v) 
248           v_type = char_v;
249       if (v_type == ushort_v) 
250           v_type = short_v;
251       if (v_type == uint_v) 
252           v_type = int_v;
253    }
254    else
255    {
256       if (v_type == char_v) 
257           v_type = uchar_v;
258       if (v_type == short_v)
259           v_type = ushort_v;
260       if (v_type == int_v) 
261           v_type = uint_v;
262    }
263 }
264 
265 static void endian_choice_proc(int val)
266 {
267     switch (val)
268     {
269         case 0:
270           endian = 0;
271         break;
272         case 1:
273           endian = 1;
274         break;
275         case 2:
276           endian = 2;
277         break;
278     }
279 }
280 
281 static void scan_proc(void)
282 {
283     scan_files(directory_name,file_name);
284     tw_sglobal_reset(pdir);
285     tw_sglobal_reset(pfile);
286 }
287 
288 static void inc_block_proc()
289 {
290    int data_size = var_size(v_type);
291 
292    padding += data_size*raw_height*raw_width;
293    tw_iglobal_reset(ppadding);
294 }
295 
296 static void dec_block_proc()
297 {
298    int data_size = var_size(v_type);
299    padding -= data_size*raw_height*raw_width;
300    tw_iglobal_reset(ppadding);
301 }
302 
303 void raw_input_tool(int x, int y)
304 {
305   static void *tv_screen = NULL;
306 
307   if (tv_screen)
308     {
309       tw_show_tool(tv_screen);
310       return;
311     }
312   tv_screen = tw_tool("Raw Input Tool", x, y);
313 
314   tw_button("input", input_proc, NULL);
315   tw_button("output", output_proc, NULL);
316   tw_button("scan",scan_proc, NULL);
317   tw_label("                 ");
318   tw_help_button("raw_input_tool");
319 
320   tw_newrow();
321   pdir = (void *) tw_sglobal("Directory:", directory_name, 32);
322   tw_newrow();
323   pfile = (void*) tw_sglobal("File:", file_name, 32);
324   tw_newrow();
325   tw_choice(" endian:", endian_choice_proc, 0,
326             "big", "little", "ascii",
327              NULL);
328   tw_check(" signed:", sign_check_proc, 0,
329             "yes", NULL);
330   tw_newrow();
331   tw_choice(" type:", type_choice_proc, 0,
332             "char", "short", "int", "float", "double",
333              NULL);
334   tw_button("<",dec_block_proc, NULL);
335   tw_button(">",inc_block_proc, NULL);
336   tw_newrow();
337   ppadding = tw_iglobal(" skip :", &padding, 8);
338   tw_iglobal(" width :", &raw_width, 5);
339   tw_iglobal(" height :", &raw_height, 5);
340 
341   tw_end_tool();
342 
343 }
344 

~ [ 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.