don't add an alpha channel.

2007-07-23  Sven Neumann  <sven@gimp.org>

	* plug-ins/print/print.c: don't add an alpha channel.

	* plug-ins/print/print-draw-page.c: always use 
CAIRO_FORMAT_RGB24.


svn path=/trunk/; revision=22977
This commit is contained in:
Sven Neumann 2007-07-23 20:47:25 +00:00 committed by Sven Neumann
parent 9b96fc8e4c
commit 1665395f50
3 changed files with 72 additions and 54 deletions

View File

@ -1,3 +1,9 @@
2007-07-23 Sven Neumann <sven@gimp.org>
* plug-ins/print/print.c: don't add an alpha channel.
* plug-ins/print/print-draw-page.c: always use CAIRO_FORMAT_RGB24.
2007-07-23 Sven Neumann <sven@gimp.org>
* app/core/gimpprojection-construct.c: minor code cleanup.

View File

@ -30,15 +30,17 @@
#define EPSILON 0.0001
static cairo_surface_t * create_surface (guchar *pixels,
gint width,
gint height,
gint rowstride);
static cairo_surface_t * create_surface_from_rgb (guchar *pixels,
gint width,
gint height);
static cairo_surface_t * create_surface_from_rgba (guchar *pixels,
gint width,
gint height);
#if 0
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
#endif
@ -46,36 +48,26 @@ 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;
const gint tile_height = gimp_tile_height ();
GimpDrawable *drawable;
GimpPixelRgn region;
cairo_t *cr;
cairo_surface_t *surface = NULL;
guchar *pixels;
gdouble cr_width;
gdouble cr_height;
gdouble cr_dpi_x;
gdouble cr_dpi_y;
gint width;
gint height;
gint rowstride;
gint y;
gdouble scale_x;
gdouble scale_y;
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);
drawable = gimp_drawable_get (data->drawable_id);
width = drawable->width;
height = drawable->height;
rowstride = drawable->bpp * width;
cr = gtk_print_context_get_cairo_context (context);
@ -87,9 +79,6 @@ draw_page_cairo (GtkPrintContext *context,
scale_x = cr_dpi_x / data->xres;
scale_y = cr_dpi_y / data->yres;
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
#if 0
/* print header if it is requested */
if (data->show_info_header)
@ -103,12 +92,14 @@ draw_page_cairo (GtkPrintContext *context,
}
#endif
cairo_translate (cr, data->offset_x / cr_dpi_x * 72.0, data->offset_y / cr_dpi_y * 72.0);
cairo_translate (cr,
data->offset_x / cr_dpi_x * 72.0,
data->offset_y / cr_dpi_y * 72.0);
cairo_scale (cr, scale_x, scale_y);
gimp_pixel_rgn_init (&region, drawable, 0, 0, width, height, FALSE, FALSE);
pixels = g_new (guchar, MIN (height, tile_height) * rowstride);
pixels = g_new (guchar, MIN (height, tile_height) * 4 * width);
for (y = 0; y < height; y += tile_height)
{
@ -116,7 +107,15 @@ draw_page_cairo (GtkPrintContext *context,
gimp_pixel_rgn_get_rect (&region, pixels, 0, y, width, h);
surface = create_surface (pixels, width, h, rowstride);
switch (drawable->bpp)
{
case 3:
surface = create_surface_from_rgb (pixels, width, h);
break;
case 4:
surface = create_surface_from_rgba (pixels, width, h);
break;
}
cairo_set_source_surface (cr, surface, 0, y);
@ -132,31 +131,43 @@ draw_page_cairo (GtkPrintContext *context,
gimp_drawable_detach (drawable);
if (image_id != data->image_id)
gimp_image_delete (image_id);
return TRUE;
}
static cairo_surface_t *
create_surface (guchar *pixels,
gint width,
gint height,
gint rowstride)
create_surface_from_rgb (guchar *pixels,
gint width,
gint height)
{
guint32 *cairo_data = (guint32 *) pixels;
guchar *p;
gint len;
gint i;
guint32 *cairo_data = (guint32 *) pixels;
const guchar *p;
gsize 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.
*
*/
len = width * height;
for (i = len - 1, p = pixels + 3 * len - 1; i >= 0; i--)
{
guint32 b = *p--;
guint32 g = *p--;
guint32 r = *p--;
cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
}
return cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_RGB24,
width, height, 4 * width);
}
static cairo_surface_t *
create_surface_from_rgba (guchar *pixels,
gint width,
gint height)
{
guint32 *cairo_data = (guint32 *) pixels;
const guchar *p;
gsize len;
gsize i;
len = width * height;
@ -171,16 +182,18 @@ create_surface (guchar *pixels,
{
gdouble alpha = a / 255.0;
r *= alpha;
g *= alpha;
b *= alpha;
/* composite on a white background */
r = (guint) (alpha * r + 255 - a) & 0xFF;
g = (guint) (alpha * g + 255 - a) & 0xFF;
b = (guint) (alpha * b + 255 - a) & 0xFF;
}
cairo_data[i] = (a << 24) + (r << 16) + (g << 8) + b;
cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
}
return cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_ARGB32,
width, height, rowstride);
return cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_RGB24,
width, height, 4 * width);
}
#if 0

View File

@ -162,8 +162,7 @@ print_image (gint32 image_ID,
/* export the image */
export = gimp_export_image (&image_ID, &drawable_ID, NULL,
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA |
GIMP_EXPORT_NEEDS_ALPHA);
GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
return FALSE;