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 
23 #include "sys_x11.h"
24 #include <unistd.h>
25 
26 
27 
28 int ptools_isOK;
29 
30 //---------------- Callback functions
31 
32 
pt_widget_destroy(GtkWidget * widget)33 void pt_widget_destroy( GtkWidget *widget )
34 {
35 	ptools_isOK = FALSE;
36 	gtk_widget_destroy( widget );
37 }
38 
pt_main_destroy(GtkWidget * widget)39 void pt_main_destroy	(GtkWidget *widget)
40 {
41 	ptools_isOK = FALSE;
42 	gtk_main_quit();
43 }
44 
45 
46 
pt_set_size_source(GtkWidget * widget,gpointer data)47 void  pt_set_size_source(GtkWidget *widget, gpointer data)
48 {
49 	GtkWidget **dp;
50     char text[32];
51 
52 	dp = (GtkWidget**) data;
53 
54    sprintf( text, "%ld", gTrPtr->src->width );
55    gtk_entry_set_text( GTK_ENTRY(dp[kSetPerspectivePrefs_Width]), text );
56    sprintf( text, "%ld", gTrPtr->src->height );
57    gtk_entry_set_text( GTK_ENTRY(dp[kSetPerspectivePrefs_Height]), text );
58 }
59 
60 
61 
62 
63 
64 
65 
filter_main(TrformStr * TrPtr,struct size_Prefs * spref)66 void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
67 {
68 	dispatch	( TrPtr, spref);
69 
70 }
71 
72 
73 
74 // Error reporting
75 
PrintErrorIntern(char * fmt,va_list ap)76 void  PrintErrorIntern( char* fmt, va_list ap)
77 {
78 	char message[255];
79 
80 	vsprintf(message, fmt, ap);
81 
82 	gimp_message (message);
83 }
84 
85 // Progress report; return false if canceled
86 
ProgressIntern(int command,char * argument)87 int ProgressIntern( int command, char* argument )
88 {
89 	double percentage;
90 
91 	switch( command )
92 	{
93 		case _initProgress:
94 			gimp_progress_init( argument );
95 			return TRUE;
96 			break;
97 		case _setProgress:
98 			sscanf(argument,"%lf", &percentage);
99 			gimp_progress_update ((gdouble) percentage/100.0);
100 			return TRUE;
101 			break;
102 		case _disposeProgress:
103 			percentage = 1.0;
104 			gimp_progress_update ((gdouble) percentage);
105 			return TRUE;
106 			break;
107 		case _idleProgress:
108 			return TRUE;
109 	}
110 	return TRUE;
111 }
112 
infoDlgIntern(int command,char * argument)113 int infoDlgIntern ( int command, char* argument )	// Display info: same argumenmts as progress
114 {
115 	if( command != _setProgress)
116 		return Progress( command, argument );
117 	else
118 		return Progress( command, "0.5" );
119 }
120 
121 
122 
readPrefs(char * pref,int selector)123 int readPrefs( char* pref, int selector )
124 {
125 
126 	struct {
127 		char						v[sizeof(PREF_VERSION)];
128 		struct correct_Prefs		c;
129 		struct remap_Prefs			r;
130 		struct perspective_Prefs	p;
131 		struct adjust_Prefs			a;
132 		struct interp_Prefs			i;
133 		struct size_Prefs			s;
134 		panControls					pc;
135 	} prf;
136 	char *home_dir;
137 	char prefname[512];
138 	long size;
139 
140 	FILE 	*prfile;
141 	int result = 0;
142 
143 	home_dir = getenv ("HOME");
144 	if (!home_dir)
145 		return -1;
146 	sprintf (prefname, "%s/.gimp/pano13.prf", home_dir);
147 
148 
149 	if( (prfile = fopen( prefname, "rb" )) != NULL )
150 	{
151 		size = fread( &prf, 1, sizeof(prf),  prfile);
152 		fclose( prfile );
153 
154 		if( size != sizeof(prf) )
155 		{
156 			result = -1;
157 		}
158 		else
159 		{
160 			switch( selector)
161 			{
162 				case _version:
163 					memcpy( pref, &prf.v, sizeof( PREF_VERSION ) );
164 					break;
165 				case _correct:
166 					if( prf.c.magic != 20 )
167 						result = -1;
168 					else
169 						memcpy( pref, &prf.c, sizeof(struct correct_Prefs));
170 					break;
171 				case _remap:
172 					if( prf.r.magic != 30 )
173 						result = -1;
174 					else
175 						memcpy( pref, &prf.r , sizeof(struct remap_Prefs));
176 					break;
177 				case _perspective:
178 					if( prf.p.magic != 40 )
179 						result = -1;
180 					else
181 						memcpy( pref, &prf.p , sizeof(struct perspective_Prefs));
182 					break;
183 				case _adjust:
184 					if( prf.a.magic != 50 )
185 						result = -1;
186 					else
187 						memcpy( pref, &prf.a , sizeof(struct adjust_Prefs));
188 					break;
189 				case _interpolate:
190 					if( prf.i.magic != 60 )
191 						result = -1;
192 					else
193 						memcpy( pref, &prf.i , sizeof(struct interp_Prefs));
194 					break;
195 				case _sizep:
196 					if( prf.s.magic != 70 )
197 						result = -1;
198 					else
199 						memcpy( pref, &prf.s , sizeof(struct size_Prefs));
200 					break;
201 				case _panright:
202 				case _panleft:
203 				case _panup:
204 				case _pandown:
205 				case _zoomin:
206 				case _zoomout:
207 				case _apply:
208 				case _getPano:
209 				case _increment:
210 					memcpy( pref, &prf.pc , sizeof(panControls));
211 					break;
212 			}// switch
213 		} // sizes match
214 	}
215 	else
216 		result = -1;
217 
218 	return result;
219 }
220 
221 
222 
223 
224 
writePrefs(char * prefs,int selector)225 void writePrefs( char* prefs, int selector )
226 {
227 
228 	struct {
229 		char						v[sizeof(PREF_VERSION)];
230 		struct correct_Prefs		c;
231 		struct remap_Prefs			r;
232 		struct perspective_Prefs	p;
233 		struct adjust_Prefs			a;
234 		struct interp_Prefs			i;
235 		struct size_Prefs			s;
236 		panControls					pc;
237 	} prf;
238 
239 	FILE 	*prfile;
240 	char *home_dir;
241 	char prefname[512];
242 
243 
244 	home_dir = getenv ("HOME");
245 	if (!home_dir)
246 		return ;
247 	sprintf (prefname, "%s/.gimp/pano13.prf", home_dir);
248 
249 	if( (prfile = fopen( prefname, "rb" )) != NULL )
250 	{
251 		fread( &prf, 1, sizeof(prf),  prfile);
252 		fclose( prfile );
253 	}
254 
255 	switch( selector)
256 	{
257 		case _version:
258 			memcpy( &prf.v,  prefs, sizeof( PREF_VERSION ) );
259 			break;
260 		case _correct:
261 			memcpy( &prf.c , prefs, sizeof(struct correct_Prefs));
262 			break;
263 		case _remap:
264 			memcpy( &prf.r , prefs, sizeof(struct remap_Prefs));
265 			break;
266 		case _perspective:
267 			memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs));
268 			break;
269 		case _adjust:
270 			memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs));
271 			break;
272 		case _interpolate:
273 			memcpy( &prf.i , prefs, sizeof(struct interp_Prefs));
274 			break;
275 		case _sizep:
276 			memcpy( &prf.s , prefs, sizeof(struct size_Prefs));
277 			break;
278 		case _panright:
279 		case _panleft:
280 		case _panup:
281 		case _pandown:
282 		case _zoomin:
283 		case _zoomout:
284 		case _apply:
285 		case _getPano:
286 		case _increment:
287 			memcpy( &prf.pc , prefs, sizeof(panControls));
288 			break;
289 	}
290 
291 	if( (prfile = fopen( prefname, "wb" )) != NULL )
292 	{
293 		fwrite( &prf, 1, sizeof(prf), prfile);
294 		fclose(prfile);
295 	}
296 }
297 
298 
mymalloc(long numBytes)299 void**  mymalloc( long numBytes )					// Memory allocation, use Handles
300 {
301 	char **mem;
302 
303 	mem = (char**)malloc( sizeof(char*) );			// Allocate memory for pointer
304 	if(mem == NULL)
305 		return (void**)NULL;
306 	else
307 	{
308 		(*mem) = (char*) malloc( numBytes );		// Allocate numBytes
309 		if( *mem == NULL )
310 		{
311 			free( mem );
312 			return (void**)NULL;
313 		}
314 		else
315 			return (void**)mem;
316 	}
317 }
318 
myfree(void ** Hdl)319 void 	myfree( void** Hdl )						// free Memory, use Handles
320 {
321 	free( (char*) *Hdl );
322 	free( (char**) Hdl );
323 }
324 
325 
showScript(fullPath * scriptFile)326 void 	showScript			( fullPath* scriptFile )
327 {
328 	char cmd[sizeof(fullPath) + 16];
329 
330 	sprintf( cmd, "xedit \"%s\"", scriptFile->name );
331 	system( cmd );
332 }
333 
334 
335 
makePathForResult(fullPath * path)336 void 	makePathForResult	( fullPath *path )
337 {
338 	char *home_dir;
339 
340 	home_dir = getenv ("HOME");
341 	if (!home_dir || strlen( home_dir ) > sizeof( fullPath ) - 15 )
342 		home_dir = ".";
343 	sprintf (path->name, "%s/ptool_result", home_dir);
344 }
345 
makePathToHost(fullPath * path)346 void 	makePathToHost 		( fullPath *path )
347 {
348 	sprintf ( path->name, "gimp");
349 }
350 
351 
352 
353 // Fname is appended to host-directory path
354 
MakeTempName(fullPath * destPath,char * fname)355 void MakeTempName( fullPath *destPath, char *fname )
356 {
357 	char *home_dir;
358 
359 	home_dir = getenv ("HOME");
360 	if (!home_dir || strlen( home_dir ) > sizeof( fullPath ) - 64 )
361 		home_dir = ".";
362 	sprintf (destPath->name, "%s/.gimp/%s", home_dir,fname);
363 }
364 
365 
366 
367 
ptool_save_callback(GtkWidget * widget,gpointer data)368 void ptool_save_callback		(GtkWidget *widget, gpointer data)
369 {
370     GtkWidget *filew;
371     static wdata wd;
372 
373     filew = gtk_file_selection_new ("Save corrections as...");
374   	gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
375 
376 	wd.data = data;
377 	wd.widg = filew;
378 
379      gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
380 			"clicked", (GtkSignalFunc) pt_save_corr, (gpointer) &wd );
381 
382     gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
383 			       "clicked", (GtkSignalFunc) gtk_widget_destroy,
384 			       GTK_OBJECT (GTK_WINDOW (filew)));
385 
386     gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "Corrections");
387 
388   	gtk_widget_show (filew);
389 }
390 
pt_save_corr(GtkWidget * widget,gpointer data)391 void pt_save_corr				(GtkWidget *widget, gpointer data)
392 {
393 	FILE *cf;
394     cPrefs *c;
395     char *filename;
396 
397     c = (cPrefs*) ((wdata*)data)->data;
398  	filename = gtk_file_selection_get_filename ((GtkFileSelection *)  ((wdata*)data)->widg );
399   	if (! filename)
400     	return;
401 
402 	if( (cf = fopen( filename, "wb" )) != NULL )
403 	{
404 		fwrite( c, sizeof(cPrefs), 1 , cf);
405 		fclose( cf );
406 	}
407 	gtk_widget_destroy( ((wdata*)data)->widg ) ;
408 }
409 
410 
411 
ptool_load_callback(GtkWidget * widget,gpointer data)412 void ptool_load_callback		(GtkWidget *widget, gpointer data)
413 {
414     GtkWidget *filew;
415    	static wdata wd;
416 
417     filew = gtk_file_selection_new ("Please find corrections file...");
418   	gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
419 
420 	wd.data = data;
421 	wd.widg = filew;
422 
423     /* Connect the ok_button to file_ok_sel function */
424     gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
425 			"clicked", (GtkSignalFunc) pt_load_corr, (gpointer) &wd );
426 
427 
428     /* Connect the cancel_button to destroy the widget */
429     gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
430 			       "clicked", (GtkSignalFunc) gtk_widget_destroy,
431 			       GTK_OBJECT (GTK_WINDOW (filew)));
432 
433     gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "");
434 
435   	gtk_widget_show (filew);
436 }
437 
438 
pt_load_corr(GtkWidget * widget,gpointer data)439 void pt_load_corr				(GtkWidget *widget, gpointer data)
440 {
441 	FILE *cf;
442     cPrefs *c, cP;
443     char *filename;
444 	long size;
445 
446     c = (cPrefs*) ((wdata*)data)->data;
447 	filename = gtk_file_selection_get_filename ((GtkFileSelection *)  ((wdata*)data)->widg );
448    	if (! filename)
449     	return;
450 
451 	if( (cf = fopen( filename, "rb" )) != NULL )
452 	{
453 		size = fread( &cP, 1, sizeof(cPrefs),  cf);
454 		fclose( cf );
455 		if( size == sizeof(cPrefs) )
456 		{
457 			memcpy((char*) c, (char*)&cP, sizeof(struct correct_Prefs));
458 		}
459 	}
460 	gtk_widget_destroy( ((wdata*)data)->widg );
461 }
462 
463 
464 // Set file as specified by dialog
465 // data is *fullPath
pt_find_file(GtkWidget * widget,gpointer data)466 void pt_find_file( GtkWidget *widget, gpointer data )
467 {
468     GtkWidget *filew;
469 	static wdata wd;
470 
471     filew = gtk_file_selection_new ("Find/Set file...");
472   	gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
473 
474 	wd.data = data;
475 	wd.widg = filew;
476 
477     /* Connect the ok_button to file_ok_sel function */
478     gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
479 			"clicked", (GtkSignalFunc) pt_set_file, (gpointer)&wd );
480 
481 
482     /* Connect the cancel_button to destroy the widget */
483     gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
484 			       "clicked", (GtkSignalFunc) gtk_widget_destroy,
485 			       GTK_OBJECT (GTK_WINDOW (filew)));
486 
487     gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "");
488 
489   	gtk_widget_show (filew);
490 }
491 
pt_set_file(GtkWidget * widget,gpointer data)492 void pt_set_file				(GtkWidget *widget, gpointer data)
493 {
494     fullPath *a;
495 	char* filename;
496 
497     a = (fullPath*) ((wdata*)data)->data;
498 	filename = gtk_file_selection_get_filename ((GtkFileSelection *)  ((wdata*)data)->widg );
499    	if (! filename )
500     	return;
501 	if( strlen(filename) > sizeof( fullPath )-1)
502 	{
503 		PrintError("Path too long");
504 		gtk_widget_destroy( ((wdata*)data)->widg );
505 		return;
506 	}
507 
508 	strcpy( a->name, filename );
509 
510 	gtk_widget_destroy( ((wdata*)data)->widg );
511 }
512 
513 
514 
ConvFileName(fullPath * fspec,char * string)515 void ConvFileName( fullPath *fspec,char *string)
516 {
517 	strcpy( string, fspec->name );
518 }
519 
520 //--------------- Unused Functions -------------------------------
521 
FindFile(fullPath * fspec)522 int FindFile( fullPath *fspec )	{ return 0;};
SaveFileAs(fullPath * path,char * prompt,char * name)523 int SaveFileAs( fullPath *path, char *prompt, char *name )	{ return 0;};
524 
525