[0799e4]: src / Gimpmain.c Maximize Restore History

Download this file

Gimpmain.c    528 lines (477 with data), 13.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/* PanoTools
* Copyright (C) 2004 Douglas Wilkins <dwilkins42@users.sourceforge.net> (the "Author").
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the Author of the
* Software shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization from the Author.
*/
#include "config.h"
#include "dbgutils.h"
#include <string.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "plugin-intl.h"
#include "filter.h"
/* Constants */
#define PROCEDURE_NAME "PanoPlugin"
#define DATA_KEY_VALS "panoplugin"
#define DATA_KEY_UI_VALS "panoplugin_ui"
#define PARASITE_KEY "panoplugin-options"
/* These are defined for translation only */
#define TR_PANTOOLS N_("<Image>/Filters/Panorama Tools")
#define TR_PANCTRLS N_("<Image>/Filters/Pan Controls")
#define AUTHOR "Helmut Dersch <der@fh-furtwangen.de> Douglas Wilkins <dwilkins42@users.sourceforge.net>"
/* Local function prototypes */
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN ()
static void query (void)
{
DENTER;
gchar *help_path;
gchar *help_uri;
static GimpParamDef params[] =
{
{GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"},
{GIMP_PDB_IMAGE, "image", "Input image"},
{GIMP_PDB_DRAWABLE, "drawable_id", "Input Drawable"}
};
static GimpParamDef return_vals[] =
{
{GIMP_PDB_IMAGE, "image", "Returned Image"},
};
gimp_plugin_domain_register (PLUGIN_NAME, LOCALEDIR);
help_path = g_build_filename (DATADIR, "help", NULL);
help_uri = g_filename_to_uri (help_path, NULL, NULL);
g_free (help_path);
gimp_plugin_help_register ("http://panotools.sourceforge.net/panoplugin/help",
help_uri);
gimp_install_procedure ("plug_in_correct",
"Correct Scanned Photographs",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Correct"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_correct", "<Image>/Filters/Panorama Tools");
gimp_install_procedure ("plug_in_perspect",
"Software Shift Lens",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Perspective"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_perspect", "<Image>/Filters/Panorama Tools");
gimp_install_procedure ("plug_in_remap",
"Change Projection",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Remap"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_remap", "<Image>/Filters/Panorama Tools");
gimp_install_procedure ("plug_in_adjust",
"Insert/Extract Image into/from Panorama",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Adjust"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_adjust", "<Image>/Filters/Panorama Tools");
gimp_install_procedure ("plug_in_right",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Move Right"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_right", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_left",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Move Left"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_left", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_up",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Tilt Up"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_up", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_down",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Tilt Down"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_down", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_zoomin",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Zoom In"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_zoomin", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_zoomout",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Zoom Out"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_zoomout", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_apply",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Apply Changes"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_apply", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_getpano",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Get Panorama"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_getpano", "<Image>/Filters/Pan Controls");
gimp_install_procedure ("plug_in_increment",
"Pan",
"",
AUTHOR,
LONGVERSION,
VERSION,
N_("Increment"),
"RGB",
GIMP_PLUGIN,
G_N_ELEMENTS (params),
G_N_ELEMENTS (return_vals),
params,
return_vals);
gimp_plugin_menu_register ("plug_in_increment", "<Image>/Filters/Pan Controls");
DEXIT;
}
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
DENTER;
static GimpParam return_values[1];
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
TrformStr TrStr;
Image src, dest;
sPrefs spref;
guint32 image_id;
GimpDrawable *gimp_drawable;
GimpPixelRgn gimp_src, gimp_dest;
GimpRunMode run_mode;
int need_4bytes = FALSE;
src.data = NULL; // To check later
dest.data = NULL;
/* Initialize i18n support */
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif
textdomain (GETTEXT_PACKAGE);
run_mode = param[0].data.d_int32;
image_id = param[1].data.d_image;
gimp_drawable = gimp_drawable_get (param[2].data.d_drawable);
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
TrStr.mode = _interactive + _show_progress + _hostCanResize;
break;
case GIMP_RUN_NONINTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
TrStr.mode = _useprefs + _show_progress + _hostCanResize;
break;
default:
return;
break;
}
TrStr.tool = _correct;
DTRACE ("Plugin name is: %s", name);
if (strcmp (name, "plug_in_correct") == 0)
{
TrStr.tool = _correct;
need_4bytes = FALSE;
}
else if (strcmp (name, "plug_in_perspect") == 0)
{
TrStr.tool = _perspective;
need_4bytes = FALSE;
}
else if (strcmp (name, "plug_in_remap") == 0)
{
TrStr.tool = _remap;
need_4bytes = FALSE;
}
else if (strcmp (name, "plug_in_adjust") == 0)
{
TrStr.tool = _adjust;
need_4bytes = TRUE;
}
else if (strcmp (name, "plug_in_right") == 0)
{
TrStr.tool = _panright;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_left") == 0)
{
TrStr.tool = _panleft;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_up") == 0)
{
TrStr.tool = _panup;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_down") == 0)
{
TrStr.tool = _pandown;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_zoomin") == 0)
{
TrStr.tool = _zoomin;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_zoomout") == 0)
{
TrStr.tool = _zoomout;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_apply") == 0)
{
TrStr.tool = _apply;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_getpano") == 0)
{
TrStr.tool = _getPano;
need_4bytes = TRUE;;
}
else if (strcmp (name, "plug_in_increment") == 0)
{
TrStr.tool = _increment;
need_4bytes = TRUE;;
}
src.width = gimp_drawable->width;
src.height = gimp_drawable->height;
src.bitsPerPixel = (need_4bytes ? 32 : 24);
src.bytesPerLine = src.width * src.bitsPerPixel / 8;
src.dataformat = _RGB;
src.dataSize = src.height * src.bytesPerLine;
src.data = (unsigned char **) mymalloc (src.dataSize);
src.selection.top = 0;
src.selection.left = 0;
src.selection.right = src.width;
src.selection.bottom = src.height;
DTRACE ("Src: w %ld h %ld bpp %ld bpl %ld ds %ld", src.width,src.height ,src.bitsPerPixel ,src.bytesPerLine,src.dataSize);
if (src.data == NULL)
{
PrintError ("Not enough memory!");
return;
}
gimp_pixel_rgn_init (&gimp_src, gimp_drawable, 0, 0,
gimp_drawable->width,
gimp_drawable->height, FALSE, FALSE);
gimp_pixel_rgn_get_rect (&gimp_src, *src.data, 0, 0, src.width, src.height);
if (need_4bytes)
ThreeToFourBPP (&src);
TrStr.src = &src;
TrStr.dest = &dest;
TrStr.interpolator = _poly3;
TrStr.gamma = 1.0;
filter_main (&TrStr, &spref);
*nreturn_vals = 1;
*return_vals = return_values;
if (TrStr.success)
{
DTRACE ("Transform success");
DTRACE ("Dest: w %ld h %ld bpp %ld bpl %ld ds %ld",
TrStr.dest->width,
TrStr.dest->height ,
TrStr.dest->bitsPerPixel ,
TrStr.dest->bytesPerLine,
TrStr.dest->dataSize);
gimp_image_undo_group_start(image_id);
// if size unchanged: Exchange with src:
if (TrStr.src->width == TrStr.dest->width
&& TrStr.src->height == TrStr.dest->height)
{
// Get changeable dest region
gimp_pixel_rgn_init (&gimp_dest, gimp_drawable, 0, 0,
gimp_drawable->width,
gimp_drawable->height, TRUE, TRUE);
if (need_4bytes)
FourToThreeBPP (&dest);
gimp_pixel_rgn_set_rect (&gimp_dest, *dest.data, 0, 0, dest.width,
dest.height);
}
else // size differs
{
// What should we do now: check preferences
if (spref.displayPart) // Display cropped/framed image
{
// Get changeable dest region
gimp_pixel_rgn_init (&gimp_dest, gimp_drawable, 0, 0,
gimp_drawable->width,
gimp_drawable->height, TRUE, TRUE);
CopyImageData (&src, &dest);
if (need_4bytes)
FourToThreeBPP (&src);
gimp_pixel_rgn_set_rect (&gimp_dest, *src.data, 0, 0, src.width,
src.height);
} // end display cropped part
if (spref.saveFile)
{
// Display full sized image
// Change size of drawable
gimp_image_resize (gimp_drawable_get_image
(gimp_drawable->drawable_id), dest.width,
dest.height, 0, 0);
gimp_layer_resize (gimp_drawable->drawable_id, dest.width,
dest.height, 0, 0);
gimp_drawable_flush (gimp_drawable);
gimp_drawable = gimp_drawable_get (gimp_drawable->drawable_id);
gimp_pixel_rgn_init (&gimp_dest, gimp_drawable, 0, 0,
dest.width, dest.height, TRUE, TRUE);
if (need_4bytes)
FourToThreeBPP (&dest);
gimp_pixel_rgn_set_rect (&gimp_dest, *dest.data, 0, 0,
dest.width, dest.height);
}
} // size differs
gimp_drawable_flush (gimp_drawable);
gimp_drawable_merge_shadow (gimp_drawable->drawable_id, TRUE);
gimp_drawable_update (gimp_drawable->drawable_id, 0, 0,
gimp_drawable->width, gimp_drawable->height);
gimp_drawable_detach (gimp_drawable);
gimp_displays_flush ();
gimp_image_undo_group_end(image_id);
status = GIMP_PDB_SUCCESS;
} // success
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
if (src.data != NULL)
myfree ((void **) src.data);
if (dest.data != NULL)
myfree ((void **) dest.data);
return_values[0].data.d_status = status;
DEXIT;
}