draw in spans of tile height.

2006-12-27  Sven Neumann  <sven@gimp.org>

	* plug-ins/print/print-draw-page.c: draw in spans of tile
height.
This commit is contained in:
Sven Neumann 2006-12-27 01:28:43 +00:00 committed by Sven Neumann
parent f35565c887
commit 8d133fd33f
2 changed files with 77 additions and 71 deletions

View file

@ -1,6 +1,9 @@
2006-12-27 Sven Neumann <sven@gimp.org>
* plug-ins/print/print-draw-page.c
* plug-ins/print/print-draw-page.c: draw in spans of tile height.
2006-12-27 Sven Neumann <sven@gimp.org>
* plug-ins/print/print-page-layout.c
* plug-ins/print/print.[ch]: don't set the resolution and unit on
the image, only initialize the dialog with these values.

View file

@ -34,28 +34,36 @@
#define HEADER_HEIGHT (20 * 72.0 / 25.4)
#define EPSILON 0.0001
static guchar * get_image_pixels (PrintData *data,
gint *width_ptr,
gint *height_ptr,
gint *rowstride_ptr);
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
static cairo_surface_t * create_surface (guchar *pixels,
gint x,
gint y,
gint width,
gint height,
gint rowstride);
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
gboolean
draw_page_cairo (GtkPrintContext *context,
PrintData *data)
{
gint tile_height = gimp_tile_height ();
gint32 image_id = data->image_id;
gint32 drawable_id = data->drawable_id;
GimpDrawable *drawable;
GimpPixelRgn region;
cairo_t *cr;
gdouble cr_width;
gdouble cr_height;
gdouble cr_dpi_x;
gdouble cr_dpi_y;
gint image_width;
gint image_height;
gint image_rowstride;
gint width;
gint height;
gint rowstride;
gint y;
gdouble scale_x;
gdouble scale_y;
gdouble x0 = 0;
@ -63,30 +71,39 @@ draw_page_cairo (GtkPrintContext *context,
guchar *pixels;
cairo_surface_t *surface;
/* export the image */
gimp_export_image (&image_id, &drawable_id, NULL,
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA |
GIMP_EXPORT_NEEDS_ALPHA);
drawable = gimp_drawable_get (drawable_id);
width = drawable->width;
height = drawable->height;
rowstride = drawable->bpp * width;
cr = gtk_print_context_get_cairo_context (context);
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);
pixels = get_image_pixels (data, &image_width, &image_height,
&image_rowstride);
scale_x = cr_dpi_x / data->xres;
scale_y = cr_dpi_y / data->yres;
if (scale_x * image_width > cr_width + EPSILON)
if (scale_x * width > cr_width + EPSILON)
{
g_message (_("Image width (%lg in) is larger than printable width (%lg in)."),
image_width / data->xres, cr_width / cr_dpi_x);
width / data->xres, cr_width / cr_dpi_x);
gtk_print_operation_cancel (data->operation);
return FALSE;
}
if (scale_y * image_height > cr_height + EPSILON)
if (scale_y * height > cr_height + EPSILON)
{
g_message (_("Image height (%lg in) is larger than printable height (%lg in)."),
image_height / data->yres, cr_height / cr_dpi_y);
height / data->yres, cr_height / cr_dpi_y);
gtk_print_operation_cancel (data->operation);
return FALSE;
}
@ -100,73 +117,62 @@ draw_page_cairo (GtkPrintContext *context,
cr_height -= HEADER_HEIGHT;
}
x0 = (cr_width - scale_x * image_width) / 2;
y0 = (cr_height - scale_y * image_height) / 2;
x0 = (cr_width - scale_x * width) / 2;
y0 = (cr_height - scale_y * height) / 2;
surface = cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_ARGB32,
image_width, image_height,
image_rowstride);
cairo_translate (cr, x0, y0);
cairo_scale (cr, scale_x, scale_y);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_mask_surface (cr, surface, 0, 0);
gimp_pixel_rgn_init (&region, drawable, 0, 0, width, height, FALSE, FALSE);
pixels = g_new (guchar, MIN (height, tile_height) * rowstride);
for (y = 0; y < height; y += tile_height)
{
gint h = MIN (tile_height, height - y);
gimp_pixel_rgn_get_rect (&region, pixels, 0, y, width, h);
surface = create_surface (pixels, 0, 0, width, h, rowstride);
cairo_set_source_surface (cr, surface, 0, y);
cairo_mask_surface (cr, surface, 0, y);
cairo_surface_destroy (surface);
}
g_free (pixels);
gimp_drawable_detach (drawable);
if (image_id != data->image_id)
gimp_image_delete (image_id);
return TRUE;
}
static guchar *
get_image_pixels (PrintData *data,
gint *width_ptr,
gint *height_ptr,
gint *rowstride_ptr)
static cairo_surface_t *
create_surface (guchar *pixels,
gint x,
gint y,
gint width,
gint height,
gint rowstride)
{
gint32 image_id = data->image_id;
gint32 drawable_id = data->drawable_id;
GimpDrawable *drawable;
GimpPixelRgn region;
gint width;
gint height;
gint rowstride;
guchar *pixels;
guint32 *cairo_data;
gint len;
guchar *p;
gint i;
/* export the image */
gimp_export_image (&image_id, &drawable_id, NULL,
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA |
GIMP_EXPORT_NEEDS_ALPHA);
drawable = gimp_drawable_get (drawable_id);
width = drawable->width;
height = drawable->height;
rowstride = width * drawable->bpp;
pixels = g_new (guchar, height * rowstride);
gimp_pixel_rgn_init (&region, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_get_rect (&region, pixels, 0, 0, width, height);
gimp_drawable_detach (drawable);
if (image_id != data->image_id)
gimp_image_delete (image_id);
guint32 *cairo_data = (guint32 *) pixels;
guchar *p;
gint len;
gint i;
/* knock pixels into the shape requested by cairo:
*
* CAIRO_FORMAT_ARGB32:
* each pixel is a 32-bit quantity, with alpha in the upper 8 bits,
* then red, then green, then blue. The 32-bit quantities are
* stored native-endian. Pre-multiplied alpha is used.
* stored native-endian. Pre-multiplied alpha is used.
*
*/
cairo_data = (guint32 *) pixels;
len = width * height;
for (i = 0, p = pixels; i < len; i++)
@ -188,11 +194,8 @@ get_image_pixels (PrintData *data,
cairo_data[i] = (a << 24) + (r << 16) + (g << 8) + b;
}
*width_ptr = width;
*height_ptr = height;
*rowstride_ptr = rowstride;
return pixels;
return cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_ARGB32,
width, height, rowstride);
}