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

« back to all changes in this revision

Viewing changes to plug-ins/print/print-image-gimp.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
 
/*
2
 
 * "$Id: print-image-gimp.c,v 1.4 2002/05/06 23:27:48 neo Exp $"
3
 
 *
4
 
 *   Print plug-in for the GIMP.
5
 
 *
6
 
 *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
7
 
 *      Robert Krawitz (rlk@alum.mit.edu)
8
 
 *   Copyright 2000 Charles Briscoe-Smith <cpbs@debian.org>
9
 
 *
10
 
 *   This program is free software; you can redistribute it and/or modify it
11
 
 *   under the terms of the GNU General Public License as published by the Free
12
 
 *   Software Foundation; either version 2 of the License, or (at your option)
13
 
 *   any later version.
14
 
 *
15
 
 *   This program is distributed in the hope that it will be useful, but
16
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
 
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18
 
 *   for more details.
19
 
 *
20
 
 *   You should have received a copy of the GNU General Public License
21
 
 *   along with this program; if not, write to the Free Software
22
 
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
 
 */
24
 
 
25
 
#include "config.h"
26
 
 
27
 
#include <gimp-print/gimp-print.h>
28
 
 
29
 
#include "libgimp/gimp.h"
30
 
#include "libgimp/gimpui.h"
31
 
 
32
 
#include "print_gimp.h"
33
 
 
34
 
#include "libgimp/stdplugins-intl.h"
35
 
 
36
 
 
37
 
/*
38
 
 * "Image" ADT
39
 
 *
40
 
 * This file defines an abstract data type called "Image".  An Image wraps
41
 
 * a Gimp drawable (or some other application-level image representation)
42
 
 * for presentation to the low-level printer drivers (which do CMYK
43
 
 * separation, dithering and weaving).  The Image ADT has the ability
44
 
 * to perform any combination of flips and rotations on the image,
45
 
 * and then deliver individual rows to the driver code.
46
 
 *
47
 
 * Stuff which might be useful to do in this layer:
48
 
 *
49
 
 * - Scaling, optionally with interpolation/filtering.
50
 
 *
51
 
 * - Colour-adjustment.
52
 
 *
53
 
 * - Multiple-image composition.
54
 
 *
55
 
 * Also useful might be to break off a thin application-dependent
56
 
 * sublayer leaving this layer (which does the interesting stuff)
57
 
 * application-independent.
58
 
 */
59
 
 
60
 
 
61
 
/* Concrete type to represent image */
62
 
typedef struct
63
 
{
64
 
  GimpDrawable *drawable;
65
 
  GimpPixelRgn  rgn;
66
 
 
67
 
  /*
68
 
   * Transformations we can impose on the image.  The transformations
69
 
   * are considered to be performed in the order given here.
70
 
   */
71
 
 
72
 
  /* 1: Transpose the x and y axes (flip image over its leading diagonal) */
73
 
  int columns;          /* Set if returning columns instead of rows. */
74
 
 
75
 
  /* 2: Translate (ox,oy) to the origin */
76
 
  int ox, oy;           /* Origin of image */
77
 
 
78
 
  /* 3: Flip vertically about the x axis */
79
 
  int increment;        /* +1 or -1 for offset of row n+1 from row n. */
80
 
 
81
 
  /* 4: Crop to width w, height h */
82
 
  int w, h;             /* Width and height of output image */
83
 
 
84
 
  /* 5: Flip horizontally about the vertical centre-line of the image */
85
 
  int mirror;           /* Set if mirroring rows end-for-end. */
86
 
 
87
 
} Gimp_Image_t;
88
 
 
89
 
static const char *Image_get_appname(stp_image_t *image);
90
 
static void Image_progress_conclude(stp_image_t *image);
91
 
static void Image_note_progress(stp_image_t *image,
92
 
                                double current, double total);
93
 
static void Image_progress_init(stp_image_t *image);
94
 
static stp_image_status_t Image_get_row(stp_image_t *image,
95
 
                                        unsigned char *data, int row);
96
 
static int Image_height(stp_image_t *image);
97
 
static int Image_width(stp_image_t *image);
98
 
static int Image_bpp(stp_image_t *image);
99
 
static void Image_rotate_180(stp_image_t *image);
100
 
static void Image_rotate_cw(stp_image_t *image);
101
 
static void Image_rotate_ccw(stp_image_t *image);
102
 
static void Image_crop(stp_image_t *image,
103
 
                       int left, int top, int right, int bottom);
104
 
static void Image_vflip(stp_image_t *image);
105
 
static void Image_hflip(stp_image_t *image);
106
 
static void Image_transpose(stp_image_t *image);
107
 
static void Image_reset(stp_image_t *image);
108
 
static void Image_init(stp_image_t *image);
109
 
 
110
 
static stp_image_t theImage =
111
 
{
112
 
  Image_init,
113
 
  Image_reset,
114
 
  Image_transpose,
115
 
  Image_hflip,
116
 
  Image_vflip,
117
 
  Image_crop,
118
 
  Image_rotate_ccw,
119
 
  Image_rotate_cw,
120
 
  Image_rotate_180,
121
 
  Image_bpp,
122
 
  Image_width,
123
 
  Image_height,
124
 
  Image_get_row,
125
 
  Image_get_appname,
126
 
  Image_progress_init,
127
 
  Image_note_progress,
128
 
  Image_progress_conclude,
129
 
  NULL
130
 
};
131
 
 
132
 
stp_image_t *
133
 
Image_GimpDrawable_new(GimpDrawable *drawable)
134
 
{
135
 
  Gimp_Image_t *i = g_malloc(sizeof(Gimp_Image_t));
136
 
  i->drawable = drawable;
137
 
  gimp_pixel_rgn_init(&(i->rgn), drawable, 0, 0,
138
 
                      drawable->width, drawable->height, FALSE, FALSE);
139
 
  theImage.rep = i;
140
 
  theImage.reset(&theImage);
141
 
  return &theImage;
142
 
}
143
 
 
144
 
static void
145
 
Image_init(stp_image_t *image)
146
 
{
147
 
  /* Nothing to do. */
148
 
}
149
 
 
150
 
static void
151
 
Image_reset(stp_image_t *image)
152
 
{
153
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
154
 
  i->columns = FALSE;
155
 
  i->ox = 0;
156
 
  i->oy = 0;
157
 
  i->increment = 1;
158
 
  i->w = i->drawable->width;
159
 
  i->h = i->drawable->height;
160
 
  i->mirror = FALSE;
161
 
}
162
 
 
163
 
static void
164
 
Image_transpose(stp_image_t *image)
165
 
{
166
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
167
 
  int tmp;
168
 
 
169
 
  if (i->mirror) i->ox += i->w - 1;
170
 
 
171
 
  i->columns = !i->columns;
172
 
 
173
 
  tmp = i->ox;
174
 
  i->ox = i->oy;
175
 
  i->oy = tmp;
176
 
 
177
 
  tmp = i->mirror;
178
 
  i->mirror = i->increment < 0;
179
 
  i->increment = tmp ? -1 : 1;
180
 
 
181
 
  tmp = i->w;
182
 
  i->w = i->h;
183
 
  i->h = tmp;
184
 
 
185
 
  if (i->mirror) i->ox -= i->w - 1;
186
 
}
187
 
 
188
 
static void
189
 
Image_hflip(stp_image_t *image)
190
 
{
191
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
192
 
  i->mirror = !i->mirror;
193
 
}
194
 
 
195
 
static void
196
 
Image_vflip(stp_image_t *image)
197
 
{
198
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
199
 
  i->oy += (i->h-1) * i->increment;
200
 
  i->increment = -i->increment;
201
 
}
202
 
 
203
 
/*
204
 
 * Image_crop:
205
 
 *
206
 
 * Crop the given number of pixels off the LEFT, TOP, RIGHT and BOTTOM
207
 
 * of the image.
208
 
 */
209
 
 
210
 
static void
211
 
Image_crop(stp_image_t *image, int left, int top, int right, int bottom)
212
 
{
213
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
214
 
  int xmax = (i->columns ? i->drawable->height : i->drawable->width) - 1;
215
 
  int ymax = (i->columns ? i->drawable->width : i->drawable->height) - 1;
216
 
 
217
 
  int nx = i->ox + i->mirror ? right : left;
218
 
  int ny = i->oy + top * (i->increment);
219
 
 
220
 
  int nw = i->w - left - right;
221
 
  int nh = i->h - top - bottom;
222
 
 
223
 
  int wmax, hmax;
224
 
 
225
 
  if (nx < 0)         nx = 0;
226
 
  else if (nx > xmax) nx = xmax;
227
 
 
228
 
  if (ny < 0)         ny = 0;
229
 
  else if (ny > ymax) ny = ymax;
230
 
 
231
 
  wmax = xmax - nx + 1;
232
 
  hmax = i->increment ? ny + 1 : ymax - ny + 1;
233
 
 
234
 
  if (nw < 1)         nw = 1;
235
 
  else if (nw > wmax) nw = wmax;
236
 
 
237
 
  if (nh < 1)         nh = 1;
238
 
  else if (nh > hmax) nh = hmax;
239
 
 
240
 
  i->ox = nx;
241
 
  i->oy = ny;
242
 
  i->w = nw;
243
 
  i->h = nh;
244
 
}
245
 
 
246
 
static void
247
 
Image_rotate_ccw(stp_image_t *image)
248
 
{
249
 
  Image_transpose(image);
250
 
  Image_vflip(image);
251
 
}
252
 
 
253
 
static void
254
 
Image_rotate_cw(stp_image_t *image)
255
 
{
256
 
  Image_transpose(image);
257
 
  Image_hflip(image);
258
 
}
259
 
 
260
 
static void
261
 
Image_rotate_180(stp_image_t *image)
262
 
{
263
 
  Image_vflip(image);
264
 
  Image_hflip(image);
265
 
}
266
 
 
267
 
static int
268
 
Image_bpp(stp_image_t *image)
269
 
{
270
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
271
 
  return i->drawable->bpp;
272
 
}
273
 
 
274
 
static int
275
 
Image_width(stp_image_t *image)
276
 
{
277
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
278
 
  return i->w;
279
 
}
280
 
 
281
 
static int
282
 
Image_height(stp_image_t *image)
283
 
{
284
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
285
 
  return i->h;
286
 
}
287
 
 
288
 
static stp_image_status_t
289
 
Image_get_row(stp_image_t *image, unsigned char *data, int row)
290
 
{
291
 
  Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
292
 
  if (i->columns)
293
 
    gimp_pixel_rgn_get_col(&(i->rgn), data,
294
 
                           i->oy + row * i->increment, i->ox, i->w);
295
 
  else
296
 
    gimp_pixel_rgn_get_row(&(i->rgn), data,
297
 
                           i->ox, i->oy + row * i->increment, i->w);
298
 
  if (i->mirror)
299
 
    {
300
 
      /* Flip row -- probably inefficiently */
301
 
      int f, l, b = i->drawable->bpp;
302
 
      for (f = 0, l = i->w - 1; f < l; f++, l--)
303
 
        {
304
 
          int c;
305
 
          unsigned char tmp;
306
 
          for (c = 0; c < b; c++)
307
 
            {
308
 
              tmp = data[f*b+c];
309
 
              data[f*b+c] = data[l*b+c];
310
 
              data[l*b+c] = tmp;
311
 
            }
312
 
        }
313
 
    }
314
 
  return STP_IMAGE_OK;
315
 
}
316
 
 
317
 
static void
318
 
Image_progress_init(stp_image_t *image)
319
 
{
320
 
  gimp_progress_init(_("Printing..."));
321
 
}
322
 
 
323
 
static void
324
 
Image_note_progress(stp_image_t *image, double current, double total)
325
 
{
326
 
  gimp_progress_update(current / total);
327
 
}
328
 
 
329
 
static void
330
 
Image_progress_conclude(stp_image_t *image)
331
 
{
332
 
  gimp_progress_update(1);
333
 
}
334
 
 
335
 
static const char *
336
 
Image_get_appname(stp_image_t *image)
337
 
{
338
 
  static char pluginname[] = PLUG_IN_NAME " plug-in V" PLUG_IN_VERSION
339
 
    " for GIMP";
340
 
  return pluginname;
341
 
}
342
 
 
343
 
/*
344
 
 * End of "$Id: print-image-gimp.c,v 1.4 2002/05/06 23:27:48 neo Exp $".
345
 
 */