2
* "$Id: print-image-gimp.c,v 1.4 2002/05/06 23:27:48 neo Exp $"
4
* Print plug-in for the GIMP.
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>
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)
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
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.
27
#include <gimp-print/gimp-print.h>
29
#include "libgimp/gimp.h"
30
#include "libgimp/gimpui.h"
32
#include "print_gimp.h"
34
#include "libgimp/stdplugins-intl.h"
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.
47
* Stuff which might be useful to do in this layer:
49
* - Scaling, optionally with interpolation/filtering.
51
* - Colour-adjustment.
53
* - Multiple-image composition.
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.
61
/* Concrete type to represent image */
64
GimpDrawable *drawable;
68
* Transformations we can impose on the image. The transformations
69
* are considered to be performed in the order given here.
72
/* 1: Transpose the x and y axes (flip image over its leading diagonal) */
73
int columns; /* Set if returning columns instead of rows. */
75
/* 2: Translate (ox,oy) to the origin */
76
int ox, oy; /* Origin of image */
78
/* 3: Flip vertically about the x axis */
79
int increment; /* +1 or -1 for offset of row n+1 from row n. */
81
/* 4: Crop to width w, height h */
82
int w, h; /* Width and height of output image */
84
/* 5: Flip horizontally about the vertical centre-line of the image */
85
int mirror; /* Set if mirroring rows end-for-end. */
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);
110
static stp_image_t theImage =
128
Image_progress_conclude,
133
Image_GimpDrawable_new(GimpDrawable *drawable)
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);
140
theImage.reset(&theImage);
145
Image_init(stp_image_t *image)
151
Image_reset(stp_image_t *image)
153
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
158
i->w = i->drawable->width;
159
i->h = i->drawable->height;
164
Image_transpose(stp_image_t *image)
166
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
169
if (i->mirror) i->ox += i->w - 1;
171
i->columns = !i->columns;
178
i->mirror = i->increment < 0;
179
i->increment = tmp ? -1 : 1;
185
if (i->mirror) i->ox -= i->w - 1;
189
Image_hflip(stp_image_t *image)
191
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
192
i->mirror = !i->mirror;
196
Image_vflip(stp_image_t *image)
198
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
199
i->oy += (i->h-1) * i->increment;
200
i->increment = -i->increment;
206
* Crop the given number of pixels off the LEFT, TOP, RIGHT and BOTTOM
211
Image_crop(stp_image_t *image, int left, int top, int right, int bottom)
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;
217
int nx = i->ox + i->mirror ? right : left;
218
int ny = i->oy + top * (i->increment);
220
int nw = i->w - left - right;
221
int nh = i->h - top - bottom;
226
else if (nx > xmax) nx = xmax;
229
else if (ny > ymax) ny = ymax;
231
wmax = xmax - nx + 1;
232
hmax = i->increment ? ny + 1 : ymax - ny + 1;
235
else if (nw > wmax) nw = wmax;
238
else if (nh > hmax) nh = hmax;
247
Image_rotate_ccw(stp_image_t *image)
249
Image_transpose(image);
254
Image_rotate_cw(stp_image_t *image)
256
Image_transpose(image);
261
Image_rotate_180(stp_image_t *image)
268
Image_bpp(stp_image_t *image)
270
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
271
return i->drawable->bpp;
275
Image_width(stp_image_t *image)
277
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
282
Image_height(stp_image_t *image)
284
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
288
static stp_image_status_t
289
Image_get_row(stp_image_t *image, unsigned char *data, int row)
291
Gimp_Image_t *i = (Gimp_Image_t *) (image->rep);
293
gimp_pixel_rgn_get_col(&(i->rgn), data,
294
i->oy + row * i->increment, i->ox, i->w);
296
gimp_pixel_rgn_get_row(&(i->rgn), data,
297
i->ox, i->oy + row * i->increment, i->w);
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--)
306
for (c = 0; c < b; c++)
309
data[f*b+c] = data[l*b+c];
318
Image_progress_init(stp_image_t *image)
320
gimp_progress_init(_("Printing..."));
324
Image_note_progress(stp_image_t *image, double current, double total)
326
gimp_progress_update(current / total);
330
Image_progress_conclude(stp_image_t *image)
332
gimp_progress_update(1);
336
Image_get_appname(stp_image_t *image)
338
static char pluginname[] = PLUG_IN_NAME " plug-in V" PLUG_IN_VERSION
344
* End of "$Id: print-image-gimp.c,v 1.4 2002/05/06 23:27:48 neo Exp $".