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"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2006-12-28 20:56:04 +08:00
|
|
|
#define EPSILON 0.0001
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-24 21:59:12 +08:00
|
|
|
#define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
|
|
|
|
#define INT_BLEND(a,b,alpha,tmp) (INT_MULT((a) - (b), alpha, tmp) + (b))
|
|
|
|
|
2006-06-27 14:41:38 +08:00
|
|
|
|
2008-02-05 00:59:45 +08:00
|
|
|
static void convert_from_rgb (guchar *pixels,
|
|
|
|
gint width);
|
|
|
|
static void convert_from_rgba (guchar *pixels,
|
|
|
|
gint width);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
|
|
|
|
2006-06-30 01:58:54 +08:00
|
|
|
gboolean
|
2006-06-27 06:48:05 +08:00
|
|
|
draw_page_cairo (GtkPrintContext *context,
|
|
|
|
PrintData *data)
|
|
|
|
{
|
2007-07-25 22:59:15 +08:00
|
|
|
GimpDrawable *drawable = gimp_drawable_get (data->drawable_id);
|
|
|
|
GimpPixelRgn region;
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
guchar *pixels;
|
|
|
|
gdouble cr_width;
|
|
|
|
gdouble cr_height;
|
|
|
|
gdouble cr_dpi_x;
|
|
|
|
gdouble cr_dpi_y;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint stride;
|
|
|
|
gint y;
|
|
|
|
gdouble scale_x;
|
|
|
|
gdouble scale_y;
|
|
|
|
|
|
|
|
width = drawable->width;
|
|
|
|
height = drawable->height;
|
|
|
|
|
|
|
|
gimp_tile_cache_ntiles (width / gimp_tile_width () + 1);
|
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
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
cr_width = gtk_print_context_get_width (context);
|
|
|
|
cr_height = gtk_print_context_get_height (context);
|
|
|
|
cr_dpi_x = gtk_print_context_get_dpi_x (context);
|
|
|
|
cr_dpi_y = gtk_print_context_get_dpi_y (context);
|
|
|
|
|
2006-12-27 07:29:33 +08:00
|
|
|
scale_x = cr_dpi_x / data->xres;
|
|
|
|
scale_y = cr_dpi_y / data->yres;
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-24 04:47:25 +08:00
|
|
|
cairo_translate (cr,
|
|
|
|
data->offset_x / cr_dpi_x * 72.0,
|
|
|
|
data->offset_y / cr_dpi_y * 72.0);
|
2006-06-27 06:48:05 +08:00
|
|
|
cairo_scale (cr, scale_x, scale_y);
|
|
|
|
|
2006-12-27 09:28:43 +08:00
|
|
|
gimp_pixel_rgn_init (®ion, drawable, 0, 0, width, height, FALSE, FALSE);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 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
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
for (y = 0; y < height; y++, pixels += stride)
|
2006-12-27 09:28:43 +08:00
|
|
|
{
|
2007-07-25 22:59:15 +08:00
|
|
|
gimp_pixel_rgn_get_row (®ion, pixels, 0, y, width);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-24 04:47:25 +08:00
|
|
|
switch (drawable->bpp)
|
|
|
|
{
|
|
|
|
case 3:
|
2007-07-25 22:59:15 +08:00
|
|
|
convert_from_rgb (pixels, width);
|
2007-07-24 04:47:25 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2007-07-25 22:59:15 +08:00
|
|
|
convert_from_rgba (pixels, width);
|
2007-07-24 04:47:25 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
if (y % 16 == 0)
|
|
|
|
gimp_progress_update ((gdouble) y / (gdouble) height);
|
2006-12-27 22:46:18 +08:00
|
|
|
}
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
cairo_set_source_surface (cr, surface, 0, 0);
|
2007-07-25 21:35:13 +08:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
|
|
|
cairo_fill (cr);
|
2007-07-25 22:59:15 +08:00
|
|
|
cairo_surface_destroy (surface);
|
2007-07-25 21:35:13 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
gimp_progress_update (1.0);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
2006-12-27 09:28:43 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
static void
|
|
|
|
convert_from_rgb (guchar *pixels,
|
|
|
|
gint width)
|
2006-12-27 09:28:43 +08:00
|
|
|
{
|
2007-07-25 22:59:15 +08:00
|
|
|
guint32 *cairo_data = (guint32 *) pixels;
|
|
|
|
guchar *p;
|
|
|
|
gint i;
|
2007-07-24 04:47:25 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
for (i = width - 1, p = pixels + 3 * width - 1; i >= 0; i--)
|
2007-07-24 04:47:25 +08:00
|
|
|
{
|
|
|
|
guint32 b = *p--;
|
|
|
|
guint32 g = *p--;
|
|
|
|
guint32 r = *p--;
|
|
|
|
|
|
|
|
cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
static void
|
|
|
|
convert_from_rgba (guchar *pixels,
|
|
|
|
gint width)
|
2007-07-24 04:47:25 +08:00
|
|
|
{
|
2007-07-25 22:59:15 +08:00
|
|
|
guint32 *cairo_data = (guint32 *) pixels;
|
|
|
|
guchar *p;
|
|
|
|
gint i;
|
2006-12-27 09:28:43 +08:00
|
|
|
|
2007-07-25 22:59:15 +08:00
|
|
|
for (i = 0, p = pixels; i < width; i++)
|
2006-06-27 06:48:05 +08:00
|
|
|
{
|
|
|
|
guint32 r = *p++;
|
|
|
|
guint32 g = *p++;
|
|
|
|
guint32 b = *p++;
|
|
|
|
guint32 a = *p++;
|
|
|
|
|
|
|
|
if (a != 255)
|
|
|
|
{
|
2007-07-24 21:59:12 +08:00
|
|
|
guint32 tmp;
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-07-24 04:47:25 +08:00
|
|
|
/* composite on a white background */
|
|
|
|
|
2007-07-24 21:59:12 +08:00
|
|
|
r = INT_BLEND (r, 255, a, tmp);
|
|
|
|
g = INT_BLEND (g, 255, a, tmp);
|
|
|
|
b = INT_BLEND (b, 255, a, tmp);
|
2006-06-27 06:48:05 +08:00
|
|
|
}
|
|
|
|
|
2007-07-24 04:47:25 +08:00
|
|
|
cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
|
2006-06-27 06:48:05 +08:00
|
|
|
}
|
|
|
|
}
|