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

« back to all changes in this revision

Viewing changes to plug-ins/common/sunras.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
 * SUN raster reading and writing code Copyright (C) 1996 Peter Kirchgessner
4
4
 * (email: peter@kirchgessner.net, WWW: http://www.kirchgessner.net)
36
36
 * V 1.96, PK, 21-Nov-99: Internationalization
37
37
 * V 1.97, PK, 20-Dec-00: Recognize extensions .rs and .ras too
38
38
 */
39
 
static char ident[] = "@(#) GIMP SunRaster file-plugin v1.97  20-Dec-00";
40
39
 
41
40
#include "config.h"
42
41
 
43
42
#include <errno.h>
44
 
#include <stdio.h>
45
 
#include <stdlib.h>
46
43
#include <string.h>
47
 
#ifdef HAVE_UNISTD_H
48
 
#include <unistd.h>
49
 
#endif
50
44
 
51
 
#include <gtk/gtk.h>
 
45
#include <glib/gstdio.h>
52
46
 
53
47
#include <libgimp/gimp.h>
54
48
#include <libgimp/gimpui.h>
56
50
#include "libgimp/stdplugins-intl.h"
57
51
 
58
52
 
 
53
#define LOAD_PROC      "file-sunras-load"
 
54
#define SAVE_PROC      "file-sunras-save"
 
55
#define PLUG_IN_BINARY "sunras"
 
56
 
 
57
 
59
58
typedef int WRITE_FUN(void*,size_t,size_t,FILE*);
60
59
 
61
60
typedef gulong  L_CARD32;
156
155
/* Portability kludge */
157
156
static int my_fwrite (void *ptr, int size, int nmemb, FILE *stream);
158
157
 
159
 
GimpPlugInInfo PLUG_IN_INFO =
 
158
const GimpPlugInInfo PLUG_IN_INFO =
160
159
{
161
160
  NULL,  /* init_proc  */
162
161
  NULL,  /* quit_proc  */
186
185
static void
187
186
query (void)
188
187
{
189
 
  static GimpParamDef load_args[] =
 
188
  static const GimpParamDef load_args[] =
190
189
  {
191
 
    { GIMP_PDB_INT32,  "run_mode",      "Interactive, non-interactive" },
 
190
    { GIMP_PDB_INT32,  "run-mode",      "Interactive, non-interactive" },
192
191
    { GIMP_PDB_STRING, "filename",      "The name of the file to load" },
193
 
    { GIMP_PDB_STRING, "raw_filename",  "The name of the file to load" }
 
192
    { GIMP_PDB_STRING, "raw-filename",  "The name of the file to load" }
194
193
  };
195
194
 
196
 
  static GimpParamDef load_return_vals[] =
 
195
  static const GimpParamDef load_return_vals[] =
197
196
  {
198
197
    { GIMP_PDB_IMAGE,  "image",         "Output image" }
199
198
  };
200
199
 
201
 
  static GimpParamDef save_args[] =
 
200
  static const GimpParamDef save_args[] =
202
201
  {
203
 
    { GIMP_PDB_INT32,    "run_mode",     "Interactive, non-interactive" },
 
202
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
204
203
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
205
204
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
206
205
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
207
 
    { GIMP_PDB_STRING,   "raw_filename", "The name of the file to save the image in" },
 
206
    { GIMP_PDB_STRING,   "raw-filename", "The name of the file to save the image in" },
208
207
    { GIMP_PDB_INT32,    "rle",          "Specify non-zero for rle output, zero for standard output" }
209
208
  };
210
209
 
211
 
  gimp_install_procedure ("file_sunras_load",
 
210
  gimp_install_procedure (LOAD_PROC,
212
211
                          "load file of the SunRaster file format",
213
212
                          "load file of the SunRaster file format",
214
213
                          "Peter Kirchgessner",
221
220
                          G_N_ELEMENTS (load_return_vals),
222
221
                          load_args, load_return_vals);
223
222
 
224
 
  gimp_register_file_handler_mime ("file_sunras_load", "image/x-sun-raster");
225
 
  gimp_register_magic_load_handler ("file_sunras_load",
 
223
  gimp_register_file_handler_mime (LOAD_PROC, "image/x-sun-raster");
 
224
  gimp_register_magic_load_handler (LOAD_PROC,
226
225
                                    "im1,im8,im24,im32,rs,ras",
227
226
                                    "",
228
227
                                    "0,long,0x59a66a95");
229
228
 
230
 
  gimp_install_procedure ("file_sunras_save",
 
229
  gimp_install_procedure (SAVE_PROC,
231
230
                          "save file in the SunRaster file format",
232
231
                          "SUNRAS saving handles all image types except "
233
232
                          "those with alpha channels.",
240
239
                          G_N_ELEMENTS (save_args), 0,
241
240
                          save_args, NULL);
242
241
 
243
 
  gimp_register_file_handler_mime ("file_sunras_save", "image/x-sun-raster");
244
 
  gimp_register_save_handler ("file_sunras_save",
 
242
  gimp_register_file_handler_mime (SAVE_PROC, "image/x-sun-raster");
 
243
  gimp_register_save_handler (SAVE_PROC,
245
244
                              "im1,im8,im24,im32,rs,ras", "");
246
245
}
247
246
 
269
268
  values[0].type          = GIMP_PDB_STATUS;
270
269
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
271
270
 
272
 
  if (strcmp (name, "file_sunras_load") == 0)
 
271
  if (strcmp (name, LOAD_PROC) == 0)
273
272
    {
274
273
      image_ID = load_image (param[1].data.d_string);
275
274
 
284
283
          status = GIMP_PDB_EXECUTION_ERROR;
285
284
        }
286
285
    }
287
 
  else if (strcmp (name, "file_sunras_save") == 0)
 
286
  else if (strcmp (name, SAVE_PROC) == 0)
288
287
    {
289
288
      image_ID = param[1].data.d_int32;
290
289
      drawable_ID = param[2].data.d_int32;
294
293
        {
295
294
        case GIMP_RUN_INTERACTIVE:
296
295
        case GIMP_RUN_WITH_LAST_VALS:
297
 
          gimp_ui_init ("sunras", FALSE);
 
296
          gimp_ui_init (PLUG_IN_BINARY, FALSE);
298
297
          export = gimp_export_image (&image_ID, &drawable_ID, "SUNRAS",
299
298
                                      (GIMP_EXPORT_CAN_HANDLE_RGB |
300
299
                                       GIMP_EXPORT_CAN_HANDLE_GRAY |
313
312
        {
314
313
        case GIMP_RUN_INTERACTIVE:
315
314
          /*  Possibly retrieve data  */
316
 
          gimp_get_data ("file_sunras_save", &psvals);
 
315
          gimp_get_data (SAVE_PROC, &psvals);
317
316
 
318
317
          /*  First acquire information with a dialog  */
319
318
          if (! save_dialog ())
334
333
 
335
334
        case GIMP_RUN_WITH_LAST_VALS:
336
335
          /*  Possibly retrieve data  */
337
 
          gimp_get_data ("file_sunras_save", &psvals);
 
336
          gimp_get_data (SAVE_PROC, &psvals);
338
337
          break;
339
338
 
340
339
        default:
346
345
          if (save_image (param[3].data.d_string, image_ID, drawable_ID))
347
346
            {
348
347
              /*  Store psvals data  */
349
 
              gimp_set_data ("file_sunras_save", &psvals,
350
 
                             sizeof (SUNRASSaveVals));
 
348
              gimp_set_data (SAVE_PROC, &psvals, sizeof (SUNRASSaveVals));
351
349
            }
352
350
          else
353
351
            {
372
370
{
373
371
  gint32 image_ID;
374
372
  FILE *ifp;
375
 
  char *temp = ident; /* Just to satisfy gcc/lint */
376
373
  L_SUNFILEHEADER sunhdr;
377
374
  guchar *suncolmap = NULL;
378
375
 
379
 
  ifp = fopen (filename, "rb");
 
376
  ifp = g_fopen (filename, "rb");
380
377
  if (!ifp)
381
378
    {
382
379
      g_message (_("Could not open '%s' for reading: %s"),
433
430
             *4 + sunhdr.l_ras_maplength, SEEK_SET);
434
431
    }
435
432
 
436
 
  temp = g_strdup_printf (_("Opening '%s'..."),
437
 
                          gimp_filename_to_utf8 (filename));
438
 
  gimp_progress_init (temp);
439
 
  g_free (temp);
 
433
  gimp_progress_init_printf (_("Opening '%s'"),
 
434
                             gimp_filename_to_utf8 (filename));
440
435
 
441
436
  switch (sunhdr.l_ras_depth)
442
437
    {
483
478
  FILE* ofp;
484
479
  GimpImageType drawable_type;
485
480
  gint retval;
486
 
  char *temp;
487
481
 
488
482
  drawable_type = gimp_drawable_type (drawable_ID);
489
483
 
507
501
    }
508
502
 
509
503
  /* Open the output file. */
510
 
  ofp = fopen (filename, "wb");
 
504
  ofp = g_fopen (filename, "wb");
511
505
  if (!ofp)
512
506
    {
513
507
      g_message (_("Could not open '%s' for writing: %s"),
515
509
      return FALSE;
516
510
    }
517
511
 
518
 
  temp = g_strdup_printf (_("Saving '%s'..."),
519
 
                          gimp_filename_to_utf8 (filename));
520
 
  gimp_progress_init (temp);
521
 
  g_free (temp);
 
512
  gimp_progress_init_printf (_("Saving '%s'"),
 
513
                             gimp_filename_to_utf8 (filename));
522
514
 
523
515
  if (drawable_type == GIMP_INDEXED_IMAGE)
524
516
    retval = save_index (ofp,image_ID, drawable_ID, 0, (int)psvals.rle);
1572
1564
static gboolean
1573
1565
save_dialog (void)
1574
1566
{
1575
 
  GtkWidget *dlg;
 
1567
  GtkWidget *dialog;
1576
1568
  GtkWidget *frame;
1577
1569
  gboolean   run;
1578
1570
 
1579
 
  dlg = gimp_dialog_new (_("Save as SUNRAS"), "sunras",
1580
 
                         NULL, 0,
1581
 
                         gimp_standard_help_func, "file-sunras-save",
1582
 
 
1583
 
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1584
 
                         GTK_STOCK_OK,     GTK_RESPONSE_OK,
1585
 
 
1586
 
                         NULL);
 
1571
  dialog = gimp_dialog_new (_("Save as SUNRAS"), PLUG_IN_BINARY,
 
1572
                            NULL, 0,
 
1573
                            gimp_standard_help_func, SAVE_PROC,
 
1574
 
 
1575
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
1576
                            GTK_STOCK_SAVE,   GTK_RESPONSE_OK,
 
1577
 
 
1578
                            NULL);
 
1579
 
 
1580
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
1581
                                           GTK_RESPONSE_OK,
 
1582
                                           GTK_RESPONSE_CANCEL,
 
1583
                                           -1);
 
1584
 
 
1585
  gimp_window_set_transient (GTK_WINDOW (dialog));
1587
1586
 
1588
1587
  /*  file save type  */
1589
1588
  frame = gimp_int_radio_group_new (TRUE, _("Data Formatting"),
1596
1595
                                    NULL);
1597
1596
 
1598
1597
  gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
1599
 
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0);
 
1598
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
 
1599
                      frame, TRUE, TRUE, 0);
1600
1600
  gtk_widget_show (frame);
1601
1601
 
1602
 
  gtk_widget_show (dlg);
1603
 
 
1604
 
  run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
1605
 
 
1606
 
  gtk_widget_destroy (dlg);
 
1602
  gtk_widget_show (dialog);
 
1603
 
 
1604
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
 
1605
 
 
1606
  gtk_widget_destroy (dialog);
1607
1607
 
1608
1608
  return run;
1609
1609
}