2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-06-27 06:48:05 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-09-17 23:03:36 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "print.h"
|
|
|
|
#include "print-draw-page.h"
|
|
|
|
|
2006-06-30 01:58:54 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2006-06-27 14:41:38 +08:00
|
|
|
|
2008-02-22 18:03:01 +08:00
|
|
|
static cairo_surface_t * print_cairo_surface_from_drawable (gint32 drawable_ID);
|
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
static inline void
|
|
|
|
convert_from_rgb (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels)
|
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (dest,
|
|
|
|
src[0], src[1], src[2]);
|
|
|
|
|
|
|
|
src += 3;
|
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
convert_from_rgba (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels)
|
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
|
|
|
GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
|
|
|
|
src[0], src[1], src[2], src[3]);
|
|
|
|
|
|
|
|
src += 4;
|
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-29 17:25:34 +08:00
|
|
|
static inline void
|
|
|
|
convert_from_gray (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels)
|
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (dest,
|
|
|
|
src[0], src[0], src[0]);
|
2008-03-29 17:25:34 +08:00
|
|
|
|
|
|
|
src += 1;
|
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
convert_from_graya (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels)
|
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
|
|
|
|
src[0], src[0], src[0], src[1]);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2008-03-29 17:25:34 +08:00
|
|
|
src += 2;
|
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2008-09-17 22:45:56 +08:00
|
|
|
convert_from_indexed (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels,
|
|
|
|
const guchar *cmap)
|
2008-03-29 17:25:34 +08:00
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
const gint i = 3 * src[0];
|
2008-03-29 17:25:34 +08:00
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (dest,
|
|
|
|
cmap[i], cmap[i + 1], cmap[i + 2]);
|
|
|
|
|
|
|
|
src += 1;
|
2008-03-29 17:25:34 +08:00
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2008-09-17 22:45:56 +08:00
|
|
|
convert_from_indexeda (const guchar *src,
|
|
|
|
guchar *dest,
|
|
|
|
gint pixels,
|
|
|
|
const guchar *cmap)
|
2008-03-29 17:25:34 +08:00
|
|
|
{
|
|
|
|
while (pixels--)
|
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
const gint i = 3 * src[0];
|
2008-03-29 17:25:34 +08:00
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
|
|
|
|
cmap[i], cmap[i + 1], cmap[i + 2], src[1]);
|
|
|
|
|
|
|
|
src += 2;
|
2008-03-29 17:25:34 +08:00
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2006-06-30 01:58:54 +08:00
|
|
|
gboolean
|
2008-02-22 18:03:01 +08:00
|
|
|
print_draw_page (GtkPrintContext *context,
|
2006-06-27 06:48:05 +08:00
|
|
|
PrintData *data)
|
|
|
|
{
|
2007-07-25 22:59:15 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
cairo_surface_t *surface;
|
2006-12-27 09:28:43 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
cr = gtk_print_context_get_cairo_context (context);
|
2006-12-27 21:46:27 +08:00
|
|
|
|
2008-02-22 18:03:01 +08:00
|
|
|
surface = print_cairo_surface_from_drawable (data->drawable_id);
|
|
|
|
|
2008-10-22 23:01:34 +08:00
|
|
|
cairo_translate (cr, data->offset_x, data->offset_y);
|
2008-02-22 18:03:01 +08:00
|
|
|
cairo_scale (cr,
|
2008-10-22 23:01:34 +08:00
|
|
|
gtk_print_context_get_dpi_x (context) / data->xres,
|
|
|
|
gtk_print_context_get_dpi_y (context) / data->yres);
|
2008-02-22 18:03:01 +08:00
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
0, 0,
|
|
|
|
cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface));
|
|
|
|
cairo_set_source_surface (cr, surface, 0, 0);
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2008-02-22 18:03:01 +08:00
|
|
|
static cairo_surface_t *
|
|
|
|
print_cairo_surface_from_drawable (gint32 drawable_ID)
|
|
|
|
{
|
2008-09-17 23:03:36 +08:00
|
|
|
GimpDrawable *drawable = gimp_drawable_get (drawable_ID);
|
2008-02-22 18:03:01 +08:00
|
|
|
GimpPixelRgn region;
|
2008-09-17 23:03:36 +08:00
|
|
|
GimpImageType image_type = gimp_drawable_type (drawable_ID);
|
2008-02-22 18:03:01 +08:00
|
|
|
cairo_surface_t *surface;
|
2008-09-17 23:03:36 +08:00
|
|
|
const gint width = drawable->width;
|
|
|
|
const gint height = drawable->height;
|
|
|
|
guchar cmap[3 * 256] = { 0, };
|
2008-02-22 18:03:01 +08:00
|
|
|
guchar *pixels;
|
|
|
|
gint stride;
|
2008-09-17 23:03:36 +08:00
|
|
|
guint count = 0;
|
|
|
|
guint done = 0;
|
2008-02-22 18:03:01 +08:00
|
|
|
gpointer pr;
|
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable_ID))
|
|
|
|
{
|
2008-09-17 23:03:36 +08:00
|
|
|
guchar *colors;
|
|
|
|
gint num_colors;
|
|
|
|
|
|
|
|
colors = gimp_image_get_colormap (gimp_drawable_get_image (drawable_ID),
|
|
|
|
&num_colors);
|
|
|
|
memcpy (cmap, colors, 3 * num_colors);
|
2008-09-25 23:09:28 +08:00
|
|
|
g_free (colors);
|
2008-09-17 22:45:56 +08:00
|
|
|
}
|
|
|
|
|
2008-02-22 18:03:01 +08:00
|
|
|
surface = cairo_image_surface_create (gimp_drawable_has_alpha (drawable_ID) ?
|
|
|
|
CAIRO_FORMAT_ARGB32 :
|
|
|
|
CAIRO_FORMAT_RGB24,
|
2008-02-22 16:44:53 +08:00
|
|
|
width, height);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
pixels = cairo_image_surface_get_data (surface);
|
|
|
|
stride = cairo_image_surface_get_stride (surface);
|
2007-07-25 21:35:13 +08:00
|
|
|
|
2008-02-22 16:34:42 +08:00
|
|
|
gimp_pixel_rgn_init (®ion, drawable, 0, 0, width, height, FALSE, FALSE);
|
|
|
|
|
|
|
|
for (pr = gimp_pixel_rgns_register (1, ®ion);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
2006-12-27 09:28:43 +08:00
|
|
|
{
|
2008-02-22 16:34:42 +08:00
|
|
|
const guchar *src = region.data;
|
|
|
|
guchar *dest = pixels + region.y * stride + region.x * 4;
|
2008-02-22 18:03:01 +08:00
|
|
|
gint y;
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2008-02-22 16:34:42 +08:00
|
|
|
for (y = 0; y < region.h; y++)
|
2007-07-24 04:47:25 +08:00
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
switch (image_type)
|
2008-02-22 16:34:42 +08:00
|
|
|
{
|
2008-09-17 22:45:56 +08:00
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
convert_from_rgb (src, dest, region.w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
convert_from_rgba (src, dest, region.w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
2008-02-22 18:13:25 +08:00
|
|
|
convert_from_gray (src, dest, region.w);
|
|
|
|
break;
|
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
case GIMP_GRAYA_IMAGE:
|
2008-02-22 18:13:25 +08:00
|
|
|
convert_from_graya (src, dest, region.w);
|
|
|
|
break;
|
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
convert_from_indexed (src, dest, region.w, cmap);
|
2008-02-22 16:34:42 +08:00
|
|
|
break;
|
|
|
|
|
2008-09-17 22:45:56 +08:00
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
convert_from_indexeda (src, dest, region.w, cmap);
|
2008-02-22 16:34:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
src += region.rowstride;
|
|
|
|
dest += stride;
|
2007-07-24 04:47:25 +08:00
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2008-02-22 16:34:42 +08:00
|
|
|
done += region.h * region.w;
|
|
|
|
|
|
|
|
if (count++ % 16 == 0)
|
|
|
|
gimp_progress_update ((gdouble) done / (width * height));
|
2006-12-27 22:46:18 +08:00
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
2006-12-27 09:28:43 +08:00
|
|
|
|
2008-02-22 18:03:01 +08:00
|
|
|
return surface;
|
2006-12-27 09:28:43 +08:00
|
|
|
}
|
|
|
|
|