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

« back to all changes in this revision

Viewing changes to plug-ins/xjt/xjpeg.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
31
31
 
32
32
#include "config.h"
33
33
 
34
 
#include <setjmp.h>
35
 
#include <stdio.h>
36
34
#include <stdlib.h>
37
35
#include <string.h>
 
36
#include <setjmp.h>
 
37
 
 
38
#include <glib/gstdio.h>
38
39
 
39
40
/* Include for External Libraries */
40
41
#include <jpeglib.h>
83
84
 */
84
85
 
85
86
gint32
86
 
xjpg_load_layer (char   *filename,
87
 
            gint32  image_id,
88
 
            int     image_type,
89
 
            char          *layer_name,
90
 
            gdouble        layer_opacity,
91
 
            GimpLayerModeEffects     layer_mode
 
87
xjpg_load_layer (const char    *filename,
 
88
                 gint32         image_id,
 
89
                 int            image_type,
 
90
                 char          *layer_name,
 
91
                 gdouble        layer_opacity,
 
92
                 GimpLayerModeEffects     layer_mode
92
93
            )
93
94
{
94
95
  GimpPixelRgn l_pixel_rgn;
110
111
 
111
112
  l_layer_type = GIMP_GRAY_IMAGE;
112
113
 
113
 
  if ((infile = fopen (filename, "rb")) == NULL)
 
114
  if ((infile = g_fopen (filename, "rb")) == NULL)
114
115
  {
115
116
      g_warning ("can't open \"%s\"\n", filename);
116
117
      return -1;
127
128
      if (infile)
128
129
        fclose (infile);
129
130
 
130
 
      fprintf(stderr, "XJT: JPEG load error\n");
 
131
      g_printerr ("XJT: JPEG load error\n");
131
132
      return -1;
132
133
  }
133
134
 
183
184
      l_layer_type = GIMP_RGB_IMAGE;
184
185
      break;
185
186
    default:
186
 
      fprintf(stderr, "XJT: cant load layer %s (type is not GRAY and not RGB)\n", filename);
 
187
      g_printerr ("XJT: cant load layer %s (type is not GRAY and not RGB)\n", filename);
187
188
      fclose (infile);
188
189
      return -1;
189
190
    }
197
198
                             layer_mode);
198
199
  if(l_layer_id < 0)
199
200
  {
200
 
      fprintf(stderr, "XJT: cant create new layer\n");
 
201
      g_printerr ("XJT: cant create new layer\n");
201
202
      fclose (infile);
202
203
      return -1;
203
204
  }
267
268
 */
268
269
 
269
270
gint
270
 
xjpg_load_layer_alpha (char   *filename,
271
 
            gint32  image_id,
272
 
            gint32  layer_id
273
 
            )
 
271
xjpg_load_layer_alpha (const char *filename,
 
272
                       gint32      image_id,
 
273
                       gint32      layer_id)
274
274
{
275
275
  GimpPixelRgn l_pixel_rgn;
276
276
  GimpDrawable *l_drawable;
297
297
  /* add alpha channel */
298
298
  gimp_layer_add_alpha (layer_id);
299
299
 
300
 
  if ((infile = fopen (filename, "rb")) == NULL)
 
300
  if ((infile = g_fopen (filename, "rb")) == NULL)
301
301
  {
302
302
      /* No alpha found, thats OK, use full opaque alpha channel
303
303
       * (there is no need not store alpha channels on full opaque channels)
317
317
      if (infile)
318
318
        fclose (infile);
319
319
 
320
 
      fprintf(stderr, "XJT: JPEG alpha load error\n");
 
320
      g_printerr ("XJT: JPEG alpha load error\n");
321
321
      return -1;
322
322
  }
323
323
 
366
366
  l_drawable = gimp_drawable_get (layer_id);
367
367
  if(l_drawable == NULL)
368
368
  {
369
 
    fprintf(stderr, "XJT: gimp_drawable_get failed on layer id %d\n", (int)layer_id);
 
369
    g_printerr ("XJT: gimp_drawable_get failed on layer id %d\n", (int)layer_id);
370
370
    fclose(infile);
371
371
    return -1;
372
372
  }
373
373
 
374
374
  /* Check if jpeg file can be used as alpha channel
375
375
   */
376
 
  if((cinfo.output_components != 1) || 
 
376
  if((cinfo.output_components != 1) ||
377
377
     (cinfo.output_width  != l_drawable->width) ||
378
378
     (cinfo.output_height != l_drawable->height))
379
379
  {
380
 
     fprintf(stderr, "XJT: cant load %s as alpha channel\n", filename);
 
380
     g_printerr ("XJT: cant load %s as alpha channel\n", filename);
381
381
     fclose (infile);
382
382
     return -1;
383
383
  }
384
 
  
 
384
 
385
385
  /* buffer to read in the layer and merge with the alpha from jpeg file */
386
386
  l_dstbuf = g_new (guchar, l_tile_height * l_drawable->width * l_drawable->bpp);
387
387
 
466
466
 */
467
467
 
468
468
gint32
469
 
xjpg_load_channel (char   *filename,
470
 
            gint32  image_id,
471
 
            gint32  drawable_id,
472
 
            char          *channel_name,
473
 
            gdouble        channel_opacity,
474
 
            guchar red, guchar  green, guchar blue
475
 
            )
 
469
xjpg_load_channel (const char   *filename,
 
470
                   gint32        image_id,
 
471
                   gint32        drawable_id,
 
472
                   char         *channel_name,
 
473
                   gdouble       channel_opacity,
 
474
                   guchar red, guchar  green, guchar blue)
476
475
{
477
476
  GimpPixelRgn l_pixel_rgn;
478
477
  GimpDrawable *l_drawable;
493
492
  cinfo.err = jpeg_std_error (&jerr.pub);
494
493
  jerr.pub.error_exit = my_error_exit;
495
494
 
496
 
  if ((infile = fopen (filename, "rb")) == NULL)
 
495
  if ((infile = g_fopen (filename, "rb")) == NULL)
497
496
  {
498
497
      g_warning ("can't open \"%s\"\n", filename);
499
498
      return -1;
510
509
      if (infile)
511
510
        fclose (infile);
512
511
 
513
 
      fprintf(stderr, "XJT: JPEG load error\n");
 
512
      g_printerr ("XJT: JPEG load error\n");
514
513
      return -1;
515
514
  }
516
515
 
560
559
   */
561
560
  if(cinfo.output_components != 1)
562
561
  {
563
 
      fprintf(stderr, "XJT: cant load RGB layer %s into GRAY Image\n", filename);
 
562
      g_printerr ("XJT: cant load RGB layer %s into GRAY Image\n", filename);
564
563
      fclose (infile);
565
564
      return -1;
566
565
  }
575
574
                                       &l_color);
576
575
     if(l_drawable_id < 0)
577
576
     {
578
 
         fprintf(stderr, "XJT: cant create new channel\n");
 
577
         g_printerr ("XJT: cant create new channel\n");
579
578
         fclose (infile);
580
579
         return -1;
581
580
     }
586
585
  }
587
586
 
588
587
  l_drawable = gimp_drawable_get (l_drawable_id);
589
 
  
 
588
 
590
589
  if((l_drawable->width != cinfo.output_width)
591
590
  || (l_drawable->height != cinfo.output_height)
592
591
  || (l_drawable->bpp != cinfo.output_components) )
593
592
  {
594
 
         fprintf(stderr, "XJT: cant load-overwrite drawable (size missmatch)\n");
 
593
         g_printerr ("XJT: cant load-overwrite drawable (size missmatch)\n");
595
594
         fclose (infile);
596
595
         return -1;
597
596
  }
664
663
 *   - save the drawable without alpha channel.
665
664
 *     (optional clear full transparent pixels to 0,
666
665
 *      resulting in better compression)
667
 
 *   - save the alpha channel 
 
666
 *   - save the alpha channel
668
667
 * ============================================================================
669
668
 */
670
669
 
671
670
 
672
671
gint
673
 
xjpg_save_drawable (char   *filename,
674
 
            gint32  image_ID,
675
 
            gint32  drawable_ID,
676
 
            gint save_mode,
677
 
            t_JpegSaveVals *jsvals)
 
672
xjpg_save_drawable (const char     *filename,
 
673
                    gint32          image_ID,
 
674
                    gint32          drawable_ID,
 
675
                    gint            save_mode,
 
676
                    t_JpegSaveVals *jsvals)
678
677
{
679
678
  GimpPixelRgn pixel_rgn;
680
679
  GimpDrawable *drawable;
698
697
  temp = NULL;
699
698
  data = NULL;
700
699
  l_alpha_sum = 0xff;
701
 
  
 
700
 
702
701
  drawable = gimp_drawable_get (drawable_ID);
703
702
  drawable_type = gimp_drawable_type (drawable_ID);
704
703
  switch (drawable_type)
711
710
    case GIMP_RGBA_IMAGE:
712
711
    case GIMP_GRAYA_IMAGE:
713
712
      break;
714
 
      
 
713
 
715
714
    case GIMP_INDEXED_IMAGE:
716
715
      /*g_message ("jpeg: cannot operate on indexed color images");*/
717
716
      return FALSE;
764
763
   * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
765
764
   * requires it in order to write binary files.
766
765
   */
767
 
  if ((outfile = fopen (filename, "wb")) == NULL)
 
766
  if ((outfile = g_fopen (filename, "wb")) == NULL)
768
767
    {
769
768
      g_message ("can't open %s\n", filename);
770
769
      return FALSE;
846
845
  temp = (guchar *) g_malloc (cinfo.image_width * cinfo.input_components);
847
846
  data = (guchar *) g_malloc (rowstride * gimp_tile_height ());
848
847
  src = data;
849
 
  
 
848
 
850
849
  while (cinfo.next_scanline < cinfo.image_height)
851
850
  {
852
851
      if ((cinfo.next_scanline % gimp_tile_height ()) == 0)
927
926
     * == full opaque image. We can remove the file
928
927
     * to save diskspace
929
928
     */
930
 
    remove(filename);
 
929
    g_remove(filename);
931
930
  }
932
931
 
933
932
  /* Step 7: release JPEG compression object */