1 /**@(#)
2 **/
3 /* mono_file.c
4 *
5 * Modification: 16-Sep-99 by IH, DICOM added
6 *
7 * file handling for mono_tool.c */
8
9 #include <stdio.h>
10 #include <sys/param.h>
11 #include <string.h>
12 #include <tina/sys.h>
13 #include <tina/sysfuncs.h>
14 #include <tina/math.h>
15 #include <tina/mathfuncs.h>
16 #include <tina/vision.h>
17 #include <tina/visionfuncs.h>
18 #include <tina/file.h>
19 #include <tina/filefuncs.h>
20 #include <tina/file_gen.h>
21 #include <tina/tv.h>
22 #include <tina/tvfuncs.h>
23 #include <tina/toolsfuncs.h>
24 #include <tina/toolsfuncs.h>
25
26
27 #define AIFF_FILE 0
28 #define PGM_FILE 1
29 #define RAD_FILE 2
30 #define EDGE_FILE 3
31 #define POLY_FILE 4
32 #define CAMERA 5
33 #define WISP 6
34 #define RAS 7
35 #define GIF 8
36 #define DICOM_FILE 9
37 extern Imrect *pgm_read_image(char *pathname);
38 extern int pgm_write_image(Imrect *im, char *pathname);
39 extern Imrect *ReadGIF(char *pn, int imageNumber);
40 extern void gif_write_file(Imrect *opm, char *pn);
41 /*
42 extern Imrect *dicom_read_image(char *pathname);
43 */
44
45
46
47 void mono_input(char *directory_name, char *base_name, int file_type)
48 {
49 Imrect *im;
50 char pathname[MAXPATHLEN];
51
52 if (directory_name != NULL)
53 {
54 (void) strip_spaces(base_name);
55 (void) strip_spaces(directory_name);
56 (void) string_append(pathname, directory_name, "/", base_name, NULL);
57 }
58 else
59 {
60 (void) strip_spaces(base_name);
61 (void) string_append(pathname, base_name, NULL);
62 }
63
64 switch (file_type)
65 {
66 case AIFF_FILE:
67 (void) strcat(pathname, ".aiff");
68 if ((im = (Imrect *) aiff_read_image(pathname)))
69 mono_image_set(im);
70 else
71 error("mono_input: null mono aiff image", warning);
72 break;
73
74 case PGM_FILE:
75 (void) strcat(pathname, ".pgm");
76 mono_image_set(pgm_read_image(pathname));
77 break;
78
79 case RAD_FILE:
80 (void) strcat(pathname, ".rad");
81 if ((im = (Imrect *) rad_read_image(pathname)))
82 mono_image_set(im);
83 else
84 error("mono_input: null mono raw image", warning);
85 break;
86
87 case EDGE_FILE:
88 {
89 Imregion *region = NULL;
90 int height = 256, width = 256;
91
92 (void) strcat(pathname, ".edges");
93 if ((im = mono_image()))
94 {
95 height = im->height;
96 width = im->width;
97 region = im->region;
98 }
99 if (im = edges_read_file(pathname, height, width, region))
100 mono_edges_set(im);
101 else
102 error("mono_input: null mono edges", warning);
103 er_find_edge_strings(im);
104 break;
105 }
106
107 case POLY_FILE:
108 (void) strcat(pathname, ".poly");
109 mono_geom_set(geom2_read(pathname));
110 break;
111
112 case CAMERA:
113 mono_camera_set(input_camera_file(pathname, ""));
114 break;
115
116 case RAS:
117 if ((im = (Imrect *) ras_read_image(pathname, uchar_v)))
118 mono_image_set(im);
119 else
120 error("mono_input: null mono ras image", warning);
121 break;
122
123 case GIF:
124 (void) strcat(pathname, ".gif");
125 mono_image_set(ReadGIF(pathname, 1));
126 break;
127
128 case DICOM_FILE:
129 if ((im = (Imrect *) dicom_read_image(pathname)))
130 mono_image_set(im);
131 else
132 error("mono_input: null mono dicom image", warning);
133 break;
134
135 default:
136 error("file type not available", non_fatal);
137 return;
138
139 }
140
141 /* Input camera */
142 switch (file_type)
143 {
144 case AIFF_FILE:
145 if (im)
146 mono_camera_set(input_camera_file(pathname, ""));
147 break;
148 }
149 }
150
151 void mono_output(char *directory_name, char *base_name, int file_type)
152 {
153 char pathname[MAXPATHLEN];
154 Imrect *temp_image;
155
156 (void) strip_spaces(base_name);
157 (void) strip_spaces(directory_name);
158 (void) string_append(pathname, directory_name, "/", base_name, NULL);
159
160 switch (file_type)
161 {
162 case AIFF_FILE:
163 (void) strcat(pathname, ".aiff");
164 aiff_write_image(mono_image(), pathname);
165 break;
166
167 case PGM_FILE:
168 (void) strcat(pathname, ".pgm");
169 pgm_write_image(mono_image(), pathname);
170 break;
171
172 case RAD_FILE:
173 (void) strcat(pathname, ".rad");
174 rad_write_image(mono_image(), pathname);
175 break;
176
177 case EDGE_FILE:
178 (void) strcat(pathname, ".edges");
179 edges_write_file(pathname, mono_edges());
180 break;
181
182 case POLY_FILE: /* to be updated */
183 (void) strcat(pathname, ".poly");
184 geom2_write(pathname, mono_geom_get());
185 break;
186
187 case CAMERA:
188 (void) strcat(pathname, ".cam");
189 cam_write(pathname, mono_camera(), rdist_write_fp);
190 break;
191
192 case WISP:
193 (void) strcat(pathname, ".wisp");
194 wisp_write_edges(pathname, mono_edges(), mono_camera());
195 break;
196
197 /*
198 case GIF:
199 (void) strcat(pathname, ".gif");
200 temp_image = im_copy(mono_image());
201 im_shift(temp_image, -temp_image->region->ly, -temp_image->region->lx);
202 gif_write_file(temp_image, pathname);
203 im_free(temp_image);
204 */
205 break;
206
207 default:
208 error("file type not available for output", non_fatal);
209 return;
210
211 }
212 }
213
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.