1 /* Panorama_Tools - Generate, Edit and Convert Panoramic Images
2 Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this software; see the file COPYING. If not, a copy
16 can be downloaded from http://www.gnu.org/licenses/gpl.html, or
17 obtained by writing to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 /*------------------------------------------------------------*/
21
22 #include "sys_ansi.h"
23 #include "panotypes.h"
24 #include <signal.h>
25
26 //------------------ Public functions required by filter.h -------------------------------
27
28
29 // Required by filter.h but not used in the sys_ansi build of panotools.
30 // just return and do nothing
SetWindowOwner(void * Owner)31 void SetWindowOwner(void * Owner) {return;}
CenterDialog(void * hDlg)32 void CenterDialog(void * hDlg) {return;}
33
34
filter_main(TrformStr * TrPtr,struct size_Prefs * spref)35 void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
36 {
37 dispatch ( TrPtr, spref);
38
39 }
40
41
42
43 // Error reporting
44
PrintErrorIntern(char * fmt,va_list ap)45 void PrintErrorIntern(char* fmt, va_list ap)
46 {
47 char message[512];
48 char *toPrint;
49
50 if (strlen(fmt) < 512) {
51 vsprintf(message, fmt, ap);
52 toPrint = message;
53 } else {
54 // we don't have enough space, so just
55 // print original string
56 toPrint = fmt;
57 }
58
59 #ifdef HasJava
60 if( JavaUI ){
61 JPrintError( toPrint );
62 }else
63 #endif
64 {
65 printf("%s", toPrint);
66
67 // Add an end of line if none is provide
68 if (strlen(toPrint) > 0 &&
69 toPrint[strlen(toPrint)-1] != '\n') {
70 putchar('\n');
71 }
72 fflush(stdout);
73 }
74 }
75
76
77 // Progress report; return false if canceled
78
79
ProgressIntern(int command,char * argument)80 int ProgressIntern( int command, char* argument )
81 {
82 long percent;
83
84 switch( command ){
85 case _initProgress:
86 printf( "\n%s ", argument );
87 return TRUE;
88
89 case _setProgress:
90 sscanf(argument,"%ld", &percent);
91 printf("\b\b\b\b%3ld%%", (long) percent);
92 fflush (stdout);
93 return TRUE;
94
95 case _disposeProgress:
96 printf("\n");
97 return TRUE;
98 case _idleProgress:
99 return TRUE;
100 }
101 return TRUE;
102 }
103
104 volatile sig_atomic_t sigFlag;
105
sigHandler(int sig PT_UNUSED)106 void sigHandler(int sig PT_UNUSED){
107 signal( SIGINT, sigHandler );
108 sigFlag = 1;
109 }
110
infoDlgIntern(int command,char * argument)111 int infoDlgIntern ( int command, char* argument ){
112 static char mainMessage[256];
113 // int reply;
114
115 *mainMessage = 0;
116
117 switch( command ){
118 case _initProgress:
119 signal( SIGINT, sigHandler );
120 sigFlag = 0;
121 printf( "%s\n", argument );
122 return TRUE;
123 case _setProgress:
124 if( *argument != 0 ){
125 if( *argument != '+' ){
126 strcpy( mainMessage, argument );
127 printf( "%s\n", argument );
128 }else{
129 printf( "%s%s", mainMessage, &(argument[1]) );
130 }
131 fflush (stdout);
132 }
133 //printf("\nContinue (c) or stop (s) ?\n");
134 //reply = getchar();
135 //if( reply == 's' )
136 // return FALSE;
137 //return TRUE;
138 if( sigFlag )
139 return FALSE;
140 return TRUE;
141 case _disposeProgress:
142 printf("\n");
143 return TRUE;
144 case _idleProgress:
145 return TRUE;
146 }
147 return TRUE;
148 }
149
150
readPrefs(char * pref,int selector)151 int readPrefs( char* pref, int selector )
152 {
153
154 struct {
155 char v[sizeof(PREF_VERSION)];
156 struct correct_Prefs c;
157 struct remap_Prefs r;
158 struct perspective_Prefs p;
159 struct adjust_Prefs a;
160 struct size_Prefs s;
161 panControls pc;
162 } prf;
163 char* prefname = "pano13.prf";
164 long size;
165
166 FILE *prfile;
167 int result = 0;
168
169
170 if( (prfile = fopen( prefname, "rb" )) != NULL ){
171 size = fread( &prf, 1, sizeof(prf), prfile);
172 fclose( prfile );
173
174 if( size != sizeof(prf) ){
175 result = -1;
176 }else{
177 switch( selector){
178 case _version:
179 memcpy( pref, &prf.v, sizeof( PREF_VERSION ) );
180 break;
181 case _correct:
182 if( prf.c.magic != 20 )
183 result = -1;
184 else
185 memcpy( pref, &prf.c, sizeof(struct correct_Prefs));
186 break;
187 case _remap:
188 if( prf.r.magic != 30 )
189 result = -1;
190 else
191 memcpy( pref, &prf.r , sizeof(struct remap_Prefs));
192 break;
193 case _perspective:
194 if( prf.p.magic != 40 )
195 result = -1;
196 else
197 memcpy( pref, &prf.p , sizeof(struct perspective_Prefs));
198 break;
199 case _adjust:
200 if( prf.a.magic != 50 )
201 result = -1;
202 else
203 memcpy( pref, &prf.a , sizeof(struct adjust_Prefs));
204 break;
205 case _sizep:
206 if( prf.s.magic != 70 )
207 result = -1;
208 else
209 memcpy( pref, &prf.s , sizeof(struct size_Prefs));
210 break;
211 case _panright:
212 case _panleft:
213 case _panup:
214 case _pandown:
215 case _zoomin:
216 case _zoomout:
217 case _apply:
218 case _getPano:
219 case _increment:
220 memcpy( pref, &prf.pc , sizeof(panControls));
221 break;
222 }// switch
223 } // sizes match
224 }
225 else
226 result = -1;
227
228 return result;
229 }
230
231
232
233
234
writePrefs(char * prefs,int selector)235 void writePrefs( char* prefs, int selector ){
236
237 struct {
238 char v[sizeof(PREF_VERSION)];
239 struct correct_Prefs c;
240 struct remap_Prefs r;
241 struct perspective_Prefs p;
242 struct adjust_Prefs a;
243 struct size_Prefs s;
244 panControls pc;
245 } prf;
246
247 FILE *prfile;
248 char* prefname = "pano13.prf";
249
250
251
252 if( (prfile = fopen( prefname, "rb" )) != NULL ){
253 int i;
254 i = fread( &prf, sizeof(prf), 1 , prfile);
255 if (i != sizeof(prf)) {
256 PrintError("Unable to write to preference file [%s]\n", prefname);
257 }
258 fclose( prfile );
259 }
260
261 switch( selector){
262 case _version:
263 memcpy( &prf.v, prefs, sizeof( PREF_VERSION ) );
264 break;
265 case _correct:
266 memcpy( &prf.c , prefs, sizeof(struct correct_Prefs));
267 break;
268 case _remap:
269 memcpy( &prf.r , prefs, sizeof(struct remap_Prefs));
270 break;
271 case _perspective:
272 memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs));
273 break;
274 case _adjust:
275 memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs));
276 break;
277 case _sizep:
278 memcpy( &prf.s , prefs, sizeof(struct size_Prefs));
279 break;
280 case _panright:
281 case _panleft:
282 case _panup:
283 case _pandown:
284 case _zoomin:
285 case _zoomout:
286 case _apply:
287 case _getPano:
288 case _increment:
289 memcpy( &prf.pc , prefs, sizeof(panControls));
290 break;
291 }
292
293 if( (prfile = fopen( prefname, "wb" )) != NULL ){
294 fwrite( &prf, sizeof(prf), 1 , prfile);
295 fclose(prfile);
296 }
297 }
298
299
300 #define signatureSize 4
301
mymalloc(size_t numBytes)302 void** mymalloc( size_t numBytes ) // Memory allocation, use Handles
303 {
304 char **mem;
305
306 mem = (char**)malloc( sizeof(char*) ); // Allocate memory for pointer
307 if(mem == NULL)
308 return (void**)NULL;
309 else
310 {
311 (*mem) = (char*) malloc( numBytes ); // Allocate numBytes
312 if( *mem == NULL )
313 {
314 free( mem );
315 return (void**)NULL;
316 }
317 else
318 return (void**)mem;
319 }
320 }
321
myfree(void ** Hdl)322 void myfree( void** Hdl ) // free Memory, use Handles
323 {
324 free( (char*) *Hdl );
325 free( (char**) Hdl );
326 }
327
328 // Display Scriptfile using plain text editor
329
showScript(fullPath * scriptFile)330 void showScript ( fullPath* scriptFile )
331 {
332 char cmd[sizeof(fullPath) + 16];
333
334 sprintf( cmd, "vi \"%s\"", scriptFile->name );
335 if (system( cmd ) == -1) {
336 PrintError("Unable to execute script editor");
337 }
338 }
339
340
341
342
FindFile(fullPath * fname)343 int FindFile( fullPath *fname ){
344 printf("\n");
345 printf("Load File:\n");
346 if (scanf("%s", fname->name) != 1) {
347 return -1;
348 }
349
350 if(strlen(fname->name) > 0)
351 return 0;
352 else
353 return -1;
354 }
355
SaveFileAs(fullPath * fname,char * prompt PT_UNUSED,char * name PT_UNUSED)356 int SaveFileAs ( fullPath *fname, char *prompt PT_UNUSED, char *name PT_UNUSED){
357 printf("\n");
358 printf("Save File As:\n");
359 if (scanf("%s", fname->name) != 1) {
360 return -1;
361 }
362
363 if(strlen(fname->name) > 0)
364 return 0;
365 else
366 return -1;
367 }
368
369
makePathForResult(fullPath * path)370 void makePathForResult ( fullPath *path ){
371 strcpy( path->name, "//ptool_result" );
372 }
373
makePathToHost(fullPath * path)374 int makePathToHost ( fullPath *path ){
375 strcpy(path->name, "./");
376 return 0;
377 }
378
379
380
381
382 // Fname is appended to host-directory path
383
MakeTempName(fullPath * destPath,char * fname)384 void MakeTempName( fullPath *destPath, char *fname ){
385 sprintf( destPath->name, "pano13.%s", fname );
386 }
387
ConvFileName(fullPath * fspec,char * string)388 void ConvFileName( fullPath *fspec,char *string){
389 strcpy( string, fspec->name );
390 }
391
FullPathtoString(fullPath * path,char * filename)392 int FullPathtoString (fullPath *path, char *filename){
393 if( strlen( path->name ) < 256 )
394 {
395 strcpy( filename, path->name );
396 return 0;
397 }
398 else
399 {
400 return -1;
401 }
402 }
403
IsTextFile(char * fname)404 int IsTextFile( char* fname )
405 {
406
407 if( strrchr( fname, '.' ) != NULL &&
408 (strcmp( strrchr( fname, '.' ), ".txt") == 0 ||
409 strcmp( strrchr( fname, '.' ), ".TXT") == 0) )
410 return TRUE;
411
412
413 return FALSE;
414 }
415
LaunchAndSendScript(char * application,char * script)416 int LaunchAndSendScript(char *application, char *script){
417 char *cmd = (char*)malloc( strlen(application) + strlen(script) + 16);
418 if( cmd == NULL){
419 PrintError("Not enough memory");
420 return -1;
421 }
422 sprintf(cmd, "%s %s", application, script );
423 if (system( cmd ) == -1) {
424 PrintError("Unable to launch script");
425 }
426 free(cmd);
427 return 0;
428 }
429
StringtoFullPath(fullPath * path,char * filename)430 int StringtoFullPath(fullPath *path, char *filename){
431 if(strlen( filename ) < 256 ){
432 strcpy( path->name, filename);
433 return 0;
434 }else{
435 return -1;
436 }
437 }
438