~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/jpeg/jpeg.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
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 of the License, or
 
7
 * (at your option) 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 program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <stdio.h>
 
22
#include <setjmp.h>
 
23
#include <string.h>
 
24
 
 
25
#include <jpeglib.h>
 
26
#include <jerror.h>
 
27
 
 
28
#ifdef HAVE_EXIF
 
29
#include <libexif/exif-data.h>
 
30
#endif /* HAVE_EXIF */
 
31
 
 
32
#include <libgimp/gimp.h>
 
33
#include <libgimp/gimpui.h>
 
34
 
 
35
#include "libgimp/stdplugins-intl.h"
 
36
 
 
37
#include "jpeg.h"
 
38
#include "jpeg-load.h"
 
39
#include "jpeg-save.h"
 
40
#include "gimpexif.h"
 
41
 
 
42
 
 
43
/* Declare local functions.
 
44
 */
 
45
 
 
46
static void  query (void);
 
47
static void  run   (const gchar      *name,
 
48
                    gint              nparams,
 
49
                    const GimpParam  *param,
 
50
                    gint             *nreturn_vals,
 
51
                    GimpParam       **return_vals);
 
52
 
 
53
gboolean      undo_touched;
 
54
gboolean      load_interactive;
 
55
gchar        *image_comment;
 
56
gint32        display_ID;
 
57
JpegSaveVals  jsvals;
 
58
gint32        orig_image_ID_global;
 
59
gint32        drawable_ID_global;
 
60
 
 
61
const GimpPlugInInfo PLUG_IN_INFO =
 
62
{
 
63
  NULL,  /* init_proc  */
 
64
  NULL,  /* quit_proc  */
 
65
  query, /* query_proc */
 
66
  run,   /* run_proc   */
 
67
};
 
68
 
 
69
 
 
70
MAIN ()
 
71
 
 
72
 
 
73
static void
 
74
query (void)
 
75
{
 
76
  static const GimpParamDef load_args[] =
 
77
  {
 
78
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
 
79
    { GIMP_PDB_STRING,   "filename",     "The name of the file to load" },
 
80
    { GIMP_PDB_STRING,   "raw-filename", "The name of the file to load" }
 
81
  };
 
82
  static const GimpParamDef load_return_vals[] =
 
83
  {
 
84
    { GIMP_PDB_IMAGE,   "image",         "Output image" }
 
85
  };
 
86
 
 
87
#ifdef HAVE_EXIF
 
88
 
 
89
  static const GimpParamDef thumb_args[] =
 
90
  {
 
91
    { GIMP_PDB_STRING, "filename",     "The name of the file to load"  },
 
92
    { GIMP_PDB_INT32,  "thumb-size",   "Preferred thumbnail size"      }
 
93
  };
 
94
  static const GimpParamDef thumb_return_vals[] =
 
95
  {
 
96
    { GIMP_PDB_IMAGE,  "image",        "Thumbnail image"               },
 
97
    { GIMP_PDB_INT32,  "image-width",  "Width of full-sized image"     },
 
98
    { GIMP_PDB_INT32,  "image-height", "Height of full-sized image"    }
 
99
  };
 
100
 
 
101
#endif /* HAVE_EXIF */
 
102
 
 
103
  static const GimpParamDef save_args[] =
 
104
  {
 
105
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
 
106
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
 
107
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
 
108
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
 
109
    { GIMP_PDB_STRING,   "raw-filename", "The name of the file to save the image in" },
 
110
    { GIMP_PDB_FLOAT,    "quality",      "Quality of saved image (0 <= quality <= 1)" },
 
111
    { GIMP_PDB_FLOAT,    "smoothing",    "Smoothing factor for saved image (0 <= smoothing <= 1)" },
 
112
    { GIMP_PDB_INT32,    "optimize",     "Optimization of entropy encoding parameters (0/1)" },
 
113
    { GIMP_PDB_INT32,    "progressive",  "Enable progressive jpeg image loading (0/1)" },
 
114
    { GIMP_PDB_STRING,   "comment",      "Image comment" },
 
115
    { GIMP_PDB_INT32,    "subsmp",       "The subsampling option number" },
 
116
    { GIMP_PDB_INT32,    "baseline",     "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" },
 
117
    { GIMP_PDB_INT32,    "restart",      "Frequency of restart markers (in rows, 0 = no restart markers)" },
 
118
    { GIMP_PDB_INT32,    "dct",          "DCT algorithm to use (speed/quality tradeoff)" }
 
119
  };
 
120
 
 
121
  gimp_install_procedure (LOAD_PROC,
 
122
                          "loads files in the JPEG file format",
 
123
                          "loads files in the JPEG file format",
 
124
                          "Spencer Kimball, Peter Mattis & others",
 
125
                          "Spencer Kimball & Peter Mattis",
 
126
                          "1995-1999",
 
127
                          N_("JPEG image"),
 
128
                          NULL,
 
129
                          GIMP_PLUGIN,
 
130
                          G_N_ELEMENTS (load_args),
 
131
                          G_N_ELEMENTS (load_return_vals),
 
132
                          load_args, load_return_vals);
 
133
 
 
134
  gimp_register_file_handler_mime (LOAD_PROC, "image/jpeg");
 
135
  gimp_register_magic_load_handler (LOAD_PROC,
 
136
                                    "jpg,jpeg,jpe",
 
137
                                    "",
 
138
                                    "6,string,JFIF,6,string,Exif");
 
139
 
 
140
#ifdef HAVE_EXIF
 
141
 
 
142
  gimp_install_procedure (LOAD_THUMB_PROC,
 
143
                          "Loads a thumbnail from a JPEG image",
 
144
                          "Loads a thumbnail from a JPEG image (only if it exists)",
 
145
                          "S. Mukund <muks@mukund.org>, Sven Neumann <sven@gimp.org>",
 
146
                          "S. Mukund <muks@mukund.org>, Sven Neumann <sven@gimp.org>",
 
147
                          "November 15, 2004",
 
148
                          NULL,
 
149
                          NULL,
 
150
                          GIMP_PLUGIN,
 
151
                          G_N_ELEMENTS (thumb_args),
 
152
                          G_N_ELEMENTS (thumb_return_vals),
 
153
                          thumb_args, thumb_return_vals);
 
154
 
 
155
  gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
 
156
 
 
157
#endif /* HAVE_EXIF */
 
158
 
 
159
  gimp_install_procedure (SAVE_PROC,
 
160
                          "saves files in the JPEG file format",
 
161
                          "saves files in the lossy, widely supported JPEG format",
 
162
                          "Spencer Kimball, Peter Mattis & others",
 
163
                          "Spencer Kimball & Peter Mattis",
 
164
                          "1995-1999",
 
165
                          N_("JPEG image"),
 
166
                          "RGB*, GRAY*",
 
167
                          GIMP_PLUGIN,
 
168
                          G_N_ELEMENTS (save_args), 0,
 
169
                          save_args, NULL);
 
170
 
 
171
  gimp_register_file_handler_mime (SAVE_PROC, "image/jpeg");
 
172
  gimp_register_save_handler (SAVE_PROC, "jpg,jpeg,jpe", "");
 
173
}
 
174
 
 
175
static void
 
176
run (const gchar      *name,
 
177
     gint              nparams,
 
178
     const GimpParam  *param,
 
179
     gint             *nreturn_vals,
 
180
     GimpParam       **return_vals)
 
181
{
 
182
  static GimpParam   values[4];
 
183
  GimpRunMode        run_mode;
 
184
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
 
185
  gint32             image_ID;
 
186
  gint32             drawable_ID;
 
187
  gint32             orig_image_ID;
 
188
  GimpParasite      *parasite;
 
189
  gboolean           err;
 
190
  GimpExportReturn   export = GIMP_EXPORT_CANCEL;
 
191
 
 
192
  run_mode = param[0].data.d_int32;
 
193
 
 
194
  INIT_I18N ();
 
195
 
 
196
  *nreturn_vals = 1;
 
197
  *return_vals  = values;
 
198
  values[0].type          = GIMP_PDB_STATUS;
 
199
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
 
200
 
 
201
  image_ID_global = -1;
 
202
  layer_ID_global = -1;
 
203
 
 
204
  if (strcmp (name, LOAD_PROC) == 0)
 
205
    {
 
206
      switch (run_mode)
 
207
        {
 
208
        case GIMP_RUN_INTERACTIVE:
 
209
        case GIMP_RUN_WITH_LAST_VALS:
 
210
          gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
211
          load_interactive = TRUE;
 
212
          break;
 
213
        default:
 
214
          load_interactive = FALSE;
 
215
          break;
 
216
        }
 
217
 
 
218
      image_ID = load_image (param[1].data.d_string, run_mode, FALSE);
 
219
 
 
220
      if (image_ID != -1)
 
221
        {
 
222
          *nreturn_vals = 2;
 
223
          values[1].type         = GIMP_PDB_IMAGE;
 
224
          values[1].data.d_image = image_ID;
 
225
        }
 
226
      else
 
227
        {
 
228
          status = GIMP_PDB_EXECUTION_ERROR;
 
229
        }
 
230
 
 
231
    }
 
232
 
 
233
#ifdef HAVE_EXIF
 
234
 
 
235
  else if (strcmp (name, LOAD_THUMB_PROC) == 0)
 
236
    {
 
237
      if (nparams < 2)
 
238
        {
 
239
          status = GIMP_PDB_CALLING_ERROR;
 
240
        }
 
241
      else
 
242
        {
 
243
          const gchar *filename = param[0].data.d_string;
 
244
          gint         width    = 0;
 
245
          gint         height   = 0;
 
246
          gint32       image_ID;
 
247
 
 
248
          image_ID = load_thumbnail_image (filename, &width, &height);
 
249
 
 
250
          if (image_ID != -1)
 
251
            {
 
252
              *nreturn_vals = 4;
 
253
              values[1].type         = GIMP_PDB_IMAGE;
 
254
              values[1].data.d_image = image_ID;
 
255
              values[2].type         = GIMP_PDB_INT32;
 
256
              values[2].data.d_int32 = width;
 
257
              values[3].type         = GIMP_PDB_INT32;
 
258
              values[3].data.d_int32 = height;
 
259
            }
 
260
          else
 
261
            {
 
262
              status = GIMP_PDB_EXECUTION_ERROR;
 
263
            }
 
264
        }
 
265
    }
 
266
 
 
267
#endif /* HAVE_EXIF */
 
268
 
 
269
  else if (strcmp (name, SAVE_PROC) == 0)
 
270
    {
 
271
      image_ID = orig_image_ID = param[1].data.d_int32;
 
272
      drawable_ID = param[2].data.d_int32;
 
273
 
 
274
       /*  eventually export the image */
 
275
      switch (run_mode)
 
276
        {
 
277
        case GIMP_RUN_INTERACTIVE:
 
278
        case GIMP_RUN_WITH_LAST_VALS:
 
279
          gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
280
          export = gimp_export_image (&image_ID, &drawable_ID, "JPEG",
 
281
                                      (GIMP_EXPORT_CAN_HANDLE_RGB |
 
282
                                       GIMP_EXPORT_CAN_HANDLE_GRAY));
 
283
          switch (export)
 
284
            {
 
285
            case GIMP_EXPORT_EXPORT:
 
286
              {
 
287
                gchar *tmp = g_filename_from_utf8 (_("Export Preview"), -1,
 
288
                                                   NULL, NULL, NULL);
 
289
                if (tmp)
 
290
                  {
 
291
                    gimp_image_set_filename (image_ID, tmp);
 
292
                    g_free (tmp);
 
293
                  }
 
294
 
 
295
                display_ID = -1;
 
296
              }
 
297
              break;
 
298
            case GIMP_EXPORT_IGNORE:
 
299
              break;
 
300
            case GIMP_EXPORT_CANCEL:
 
301
              values[0].data.d_status = GIMP_PDB_CANCEL;
 
302
              return;
 
303
              break;
 
304
            }
 
305
          break;
 
306
        default:
 
307
          break;
 
308
        }
 
309
 
 
310
      g_free (image_comment);
 
311
      image_comment = NULL;
 
312
 
 
313
      parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
 
314
      if (parasite)
 
315
        {
 
316
          image_comment = g_strndup (gimp_parasite_data (parasite),
 
317
                                     gimp_parasite_data_size (parasite));
 
318
          gimp_parasite_free (parasite);
 
319
        }
 
320
 
 
321
#ifdef HAVE_EXIF
 
322
 
 
323
      exif_data = gimp_metadata_generate_exif (orig_image_ID);
 
324
      if (exif_data)
 
325
        jpeg_setup_exif_for_save (exif_data, orig_image_ID);
 
326
 
 
327
#endif /* HAVE_EXIF */
 
328
 
 
329
      jsvals.quality        = DEFAULT_QUALITY;
 
330
      jsvals.smoothing      = DEFAULT_SMOOTHING;
 
331
      jsvals.optimize       = DEFAULT_OPTIMIZE;
 
332
      jsvals.progressive    = DEFAULT_PROGRESSIVE;
 
333
      jsvals.baseline       = DEFAULT_BASELINE;
 
334
      jsvals.subsmp         = DEFAULT_SUBSMP;
 
335
      jsvals.restart        = DEFAULT_RESTART;
 
336
      jsvals.dct            = DEFAULT_DCT;
 
337
      jsvals.preview        = DEFAULT_PREVIEW;
 
338
      jsvals.save_exif      = DEFAULT_EXIF;
 
339
      jsvals.save_thumbnail = DEFAULT_THUMBNAIL;
 
340
      jsvals.save_xmp       = DEFAULT_XMP;
 
341
 
 
342
#ifdef HAVE_EXIF
 
343
 
 
344
      if (exif_data && (exif_data->data))
 
345
        jsvals.save_thumbnail = TRUE;
 
346
 
 
347
#endif /* HAVE_EXIF */
 
348
 
 
349
      switch (run_mode)
 
350
        {
 
351
        case GIMP_RUN_INTERACTIVE:
 
352
          /*  Possibly retrieve data  */
 
353
          gimp_get_data (SAVE_PROC, &jsvals);
 
354
 
 
355
          /* load up the previously used values */
 
356
          parasite = gimp_image_parasite_find (orig_image_ID,
 
357
                                               "jpeg-save-options");
 
358
          if (parasite)
 
359
            {
 
360
              const JpegSaveVals *save_vals = gimp_parasite_data (parasite);
 
361
 
 
362
              jsvals.quality        = save_vals->quality;
 
363
              jsvals.smoothing      = save_vals->smoothing;
 
364
              jsvals.optimize       = save_vals->optimize;
 
365
              jsvals.progressive    = save_vals->progressive;
 
366
              jsvals.baseline       = save_vals->baseline;
 
367
              jsvals.subsmp         = save_vals->subsmp;
 
368
              jsvals.restart        = save_vals->restart;
 
369
              jsvals.dct            = save_vals->dct;
 
370
              jsvals.preview        = save_vals->preview;
 
371
              jsvals.save_exif      = save_vals->save_exif;
 
372
              jsvals.save_thumbnail = save_vals->save_thumbnail;
 
373
              jsvals.save_xmp       = save_vals->save_xmp;
 
374
 
 
375
              gimp_parasite_free (parasite);
 
376
            }
 
377
 
 
378
          if (jsvals.preview)
 
379
            {
 
380
              /* we freeze undo saving so that we can avoid sucking up
 
381
               * tile cache with our unneeded preview steps. */
 
382
              gimp_image_undo_freeze (image_ID);
 
383
 
 
384
              undo_touched = TRUE;
 
385
            }
 
386
 
 
387
          /* prepare for the preview */
 
388
          image_ID_global = image_ID;
 
389
          orig_image_ID_global = orig_image_ID;
 
390
          drawable_ID_global = drawable_ID;
 
391
 
 
392
          /*  First acquire information with a dialog  */
 
393
          err = save_dialog ();
 
394
 
 
395
          if (undo_touched)
 
396
            {
 
397
              /* thaw undo saving and flush the displays to have them
 
398
               * reflect the current shortcuts */
 
399
              gimp_image_undo_thaw (image_ID);
 
400
              gimp_displays_flush ();
 
401
            }
 
402
 
 
403
          if (!err)
 
404
            status = GIMP_PDB_CANCEL;
 
405
          break;
 
406
 
 
407
        case GIMP_RUN_NONINTERACTIVE:
 
408
          /*  Make sure all the arguments are there!  */
 
409
          /*  pw - added two more progressive and comment */
 
410
          /*  sg - added subsampling, preview, baseline, restarts and DCT */
 
411
          if (nparams != 14)
 
412
            {
 
413
              status = GIMP_PDB_CALLING_ERROR;
 
414
            }
 
415
          else
 
416
            {
 
417
              /* Once the PDB gets default parameters, remove this hack */
 
418
              if (param[5].data.d_float > 0.05)
 
419
                {
 
420
                  jsvals.quality     = 100.0 * param[5].data.d_float;
 
421
                  jsvals.smoothing   = param[6].data.d_float;
 
422
                  jsvals.optimize    = param[7].data.d_int32;
 
423
                  jsvals.progressive = param[8].data.d_int32;
 
424
                  jsvals.baseline    = param[11].data.d_int32;
 
425
                  jsvals.subsmp      = param[10].data.d_int32;
 
426
                  jsvals.restart     = param[12].data.d_int32;
 
427
                  jsvals.dct         = param[13].data.d_int32;
 
428
 
 
429
                  /* free up the default -- wasted some effort earlier */
 
430
                  g_free (image_comment);
 
431
                  image_comment = g_strdup (param[9].data.d_string);
 
432
                }
 
433
 
 
434
              jsvals.preview = FALSE;
 
435
 
 
436
              if (jsvals.quality < 0.0 || jsvals.quality > 100.0)
 
437
                status = GIMP_PDB_CALLING_ERROR;
 
438
              else if (jsvals.smoothing < 0.0 || jsvals.smoothing > 1.0)
 
439
                status = GIMP_PDB_CALLING_ERROR;
 
440
              else if (jsvals.subsmp < 0 || jsvals.subsmp > 2)
 
441
                status = GIMP_PDB_CALLING_ERROR;
 
442
              else if (jsvals.dct < 0 || jsvals.dct > 2)
 
443
                status = GIMP_PDB_CALLING_ERROR;
 
444
            }
 
445
          break;
 
446
 
 
447
        case GIMP_RUN_WITH_LAST_VALS:
 
448
          /*  Possibly retrieve data  */
 
449
          gimp_get_data (SAVE_PROC, &jsvals);
 
450
 
 
451
          parasite = gimp_image_parasite_find (orig_image_ID,
 
452
                                               "jpeg-save-options");
 
453
          if (parasite)
 
454
            {
 
455
              const JpegSaveVals *save_vals = gimp_parasite_data (parasite);
 
456
 
 
457
              jsvals.quality     = save_vals->quality;
 
458
              jsvals.smoothing   = save_vals->smoothing;
 
459
              jsvals.optimize    = save_vals->optimize;
 
460
              jsvals.progressive = save_vals->progressive;
 
461
              jsvals.baseline    = save_vals->baseline;
 
462
              jsvals.subsmp      = save_vals->subsmp;
 
463
              jsvals.restart     = save_vals->restart;
 
464
              jsvals.dct         = save_vals->dct;
 
465
              jsvals.preview     = FALSE;
 
466
 
 
467
              gimp_parasite_free (parasite);
 
468
            }
 
469
          break;
 
470
 
 
471
        default:
 
472
          break;
 
473
        }
 
474
 
 
475
      if (status == GIMP_PDB_SUCCESS)
 
476
        {
 
477
          if (save_image (param[3].data.d_string,
 
478
                          image_ID,
 
479
                          drawable_ID,
 
480
                          orig_image_ID,
 
481
                          FALSE))
 
482
            {
 
483
              /*  Store mvals data  */
 
484
              gimp_set_data (SAVE_PROC, &jsvals, sizeof (JpegSaveVals));
 
485
            }
 
486
          else
 
487
            {
 
488
              status = GIMP_PDB_EXECUTION_ERROR;
 
489
            }
 
490
        }
 
491
 
 
492
      if (export == GIMP_EXPORT_EXPORT)
 
493
        {
 
494
          /* If the image was exported, delete the new display. */
 
495
          /* This also deletes the image.                       */
 
496
 
 
497
          if (display_ID != -1)
 
498
            gimp_display_delete (display_ID);
 
499
          else
 
500
            gimp_image_delete (image_ID);
 
501
        }
 
502
 
 
503
      /* pw - now we need to change the defaults to be whatever
 
504
       * was used to save this image.  Dump the old parasites
 
505
       * and add new ones. */
 
506
 
 
507
      gimp_image_parasite_detach (orig_image_ID, "gimp-comment");
 
508
      if (image_comment && strlen (image_comment))
 
509
        {
 
510
          parasite = gimp_parasite_new ("gimp-comment",
 
511
                                        GIMP_PARASITE_PERSISTENT,
 
512
                                        strlen (image_comment) + 1,
 
513
                                        image_comment);
 
514
          gimp_image_parasite_attach (orig_image_ID, parasite);
 
515
          gimp_parasite_free (parasite);
 
516
        }
 
517
      gimp_image_parasite_detach (orig_image_ID, "jpeg-save-options");
 
518
 
 
519
      parasite = gimp_parasite_new ("jpeg-save-options",
 
520
                                    0, sizeof (jsvals), &jsvals);
 
521
      gimp_image_parasite_attach (orig_image_ID, parasite);
 
522
      gimp_parasite_free (parasite);
 
523
    }
 
524
  else
 
525
    {
 
526
      status = GIMP_PDB_CALLING_ERROR;
 
527
    }
 
528
 
 
529
  values[0].data.d_status = status;
 
530
}
 
531
 
 
532
/*
 
533
 * Here's the routine that will replace the standard error_exit method:
 
534
 */
 
535
 
 
536
void
 
537
my_error_exit (j_common_ptr cinfo)
 
538
{
 
539
  /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
 
540
  my_error_ptr myerr = (my_error_ptr) cinfo->err;
 
541
 
 
542
  /* Always display the message. */
 
543
  /* We could postpone this until after returning, if we chose. */
 
544
  (*cinfo->err->output_message) (cinfo);
 
545
 
 
546
  /* Return control to the setjmp point */
 
547
  longjmp (myerr->setjmp_buffer, 1);
 
548
}
 
549
 
 
550
void
 
551
my_emit_message (j_common_ptr cinfo,
 
552
                 int          msg_level)
 
553
{
 
554
  if (msg_level == -1)
 
555
    {
 
556
      /*  disable loading of EXIF data  */
 
557
      cinfo->client_data = GINT_TO_POINTER (TRUE);
 
558
 
 
559
      (*cinfo->err->output_message) (cinfo);
 
560
    }
 
561
}
 
562
 
 
563
void
 
564
my_output_message (j_common_ptr cinfo)
 
565
{
 
566
  gchar  buffer[JMSG_LENGTH_MAX + 1];
 
567
 
 
568
  (*cinfo->err->format_message)(cinfo, buffer);
 
569
 
 
570
  if (GPOINTER_TO_INT (cinfo->client_data))
 
571
    {
 
572
      gchar *msg = g_strconcat (buffer,
 
573
                                "\n\n",
 
574
                                _("EXIF data will be ignored."),
 
575
                                NULL);
 
576
      g_message (msg);
 
577
      g_free (msg);
 
578
    }
 
579
  else
 
580
    {
 
581
      g_message (buffer);
 
582
    }
 
583
}