View | Details | Raw Unified | Return to bug 324503
Collapse All | Expand All

(-)src/bitmap.c (-28 / +59 lines)
Lines 2145-2186 Link Here
2145
cairo_surface_t *
2145
cairo_surface_t *
2146
gdip_bitmap_ensure_surface (GpBitmap *bitmap)
2146
gdip_bitmap_ensure_surface (GpBitmap *bitmap)
2147
{
2147
{
2148
	BitmapData	*data;
2148
	cairo_format_t format;
2149
	BitmapData *data = bitmap->active_bitmap;
2149
2150
2150
	data= bitmap->active_bitmap;
2151
	if (bitmap->surface || !data || !data->scan0)
2152
		return bitmap->surface;
2151
2153
2152
	if ((bitmap->surface == NULL) && (data != NULL) && (data->scan0 != NULL)) {
2154
	switch (data->pixel_format) {
2153
		switch (data->pixel_format) {
2155
	case PixelFormat24bppRGB:
2154
			case PixelFormat24bppRGB: {
2156
		format = CAIRO_FORMAT_RGB24;
2155
				bitmap->surface = cairo_image_surface_create_for_data(
2157
		break;
2156
							(BYTE*)data->scan0,
2157
							CAIRO_FORMAT_RGB24, 
2158
							data->width, 
2159
							data->height, 
2160
							data->stride);
2161
				break;
2162
			}
2163
2158
2164
			case PixelFormat32bppARGB:
2159
	case PixelFormat32bppARGB:	/* premultiplication is required */
2165
			case PixelFormat32bppRGB:
2160
	case PixelFormat32bppRGB:	/* no alpha */
2166
			case PixelFormat32bppPARGB: {
2161
	case PixelFormat32bppPARGB:	/* alpha already premultiplied */
2167
				bitmap->surface = cairo_image_surface_create_for_data(
2162
		format = CAIRO_FORMAT_ARGB32;
2168
							(BYTE*)data->scan0,
2163
		break;
2169
							CAIRO_FORMAT_ARGB32,
2170
							data->width, 
2171
							data->height, 
2172
							data->stride);
2173
				break;
2174
			}
2175
2164
2176
			default: {
2165
	default:
2177
				g_warning ("gdip_bitmap_ensure_surface: Unable to create a surface for raw bitmap data of format 0x%08x", data->pixel_format);
2166
		g_warning ("gdip_bitmap_ensure_surface: Unable to create a surface for raw bitmap data of format 0x%08x", data->pixel_format);
2178
				break;
2167
		return NULL;
2168
	}
2169
2170
	bitmap->surface = cairo_image_surface_create_for_data ((BYTE*)data->scan0, format, 
2171
		data->width, data->height, data->stride);
2172
	return bitmap->surface;
2173
}
2174
2175
BOOL
2176
gdip_bitmap_format_needs_premultiplication (GpBitmap *bitmap)
2177
{
2178
	return (bitmap->active_bitmap->pixel_format == PixelFormat32bppARGB);
2179
}
2180
2181
BYTE*
2182
gdip_bitmap_get_premultiplied_scan0 (GpBitmap *bitmap)
2183
{
2184
	BitmapData *data = bitmap->active_bitmap;
2185
	BYTE* premul = (BYTE*) GdipAlloc (data->height * data->stride);
2186
	if (!premul)
2187
		return NULL;
2188
2189
	BYTE *source = (BYTE*)data->scan0;
2190
	BYTE *target = premul;
2191
	int y, x;
2192
	for (y = 0; y < data->height; y++) {
2193
		ARGB *sp = (ARGB*) source;
2194
		ARGB *tp = (ARGB*) target;
2195
		for (x = 0; x < data->width; x++) {
2196
			BYTE a = source [3]; /* format is BGRA */
2197
			if (a < 0xff) {
2198
				BYTE *s = (BYTE*)sp;
2199
				BYTE *t = (BYTE*)tp;
2200
				t[0] = pre_multiplied_table [s[0]][a];
2201
				t[1] = pre_multiplied_table [s[1]][a];
2202
				t[2] = pre_multiplied_table [s[2]][a];
2203
				t[3] = a;
2204
			} else {
2205
				*tp = *sp;
2179
			}
2206
			}
2207
			sp++;
2208
			tp++;
2180
		}
2209
		}
2210
		source += data->stride;
2211
		target += data->stride;
2181
	}
2212
	}
2182
2213
2183
	return bitmap->surface;
2214
	return premul;
2184
}
2215
}
2185
2216
2186
GpBitmap *
2217
GpBitmap *
(-)src/texturebrush.c (-16 / +22 lines)
Lines 87-106 Link Here
87
static GpStatus
87
static GpStatus
88
draw_tile_texture (cairo_t *ct, GpBitmap *bitmap, GpTexture *brush)
88
draw_tile_texture (cairo_t *ct, GpBitmap *bitmap, GpTexture *brush)
89
{
89
{
90
	cairo_surface_t *original;
90
	cairo_surface_t *original = NULL;
91
	cairo_surface_t *texture;
91
	cairo_surface_t *texture;
92
	cairo_pattern_t *pat;
92
	cairo_pattern_t *pat;
93
	GpStatus	status;
93
	GpStatus	status;
94
	GpRect		*rect = &brush->rectangle;
94
	GpRect		*rect = &brush->rectangle;
95
	cairo_t		*ct2;
95
	cairo_t		*ct2;
96
	BYTE *premul = NULL;
96
97
97
	if (rect == NULL)  {
98
	if (!rect)
98
		return InvalidParameter;
99
		return InvalidParameter;
99
	}
100
100
101
	gdip_bitmap_ensure_surface (bitmap);
101
	gdip_bitmap_ensure_surface (bitmap);
102
	original = bitmap->surface;
103
102
103
	if (gdip_bitmap_format_needs_premultiplication (bitmap)) {
104
		premul = gdip_bitmap_get_premultiplied_scan0 (bitmap);
105
		if (premul) {
106
			BitmapData *data = bitmap->active_bitmap;
107
			original = cairo_image_surface_create_for_data (premul, CAIRO_FORMAT_ARGB32, 
108
				data->width, data->height, data->stride);
109
		}
110
	}
111
112
	/* if premul isn't required (or couldn't be computed, e.g. out of memory) */
113
	if (!original)
114
		original = bitmap->surface;
115
104
	/* Use the original as a pattern */
116
	/* Use the original as a pattern */
105
	pat = cairo_pattern_create_for_surface (original);
117
	pat = cairo_pattern_create_for_surface (original);
106
	status = gdip_get_pattern_status(pat);
118
	status = gdip_get_pattern_status(pat);
Lines 137-142 Link Here
137
	cairo_pattern_destroy (pat);
149
	cairo_pattern_destroy (pat);
138
	cairo_surface_destroy (texture);
150
	cairo_surface_destroy (texture);
139
151
152
	if (premul) {
153
		cairo_surface_destroy (original);
154
		GdipFree (premul);
155
	}
140
	return gdip_get_status (cairo_status (ct));
156
	return gdip_get_status (cairo_status (ct));
141
}
157
}
142
158
Lines 437-459 Link Here
437
	cairo_pattern_t	*pattern;
453
	cairo_pattern_t	*pattern;
438
	GpTexture	*texture;
454
	GpTexture	*texture;
439
	GpImage		*img;
455
	GpImage		*img;
440
	GpImage		*gr_img;
441
	GpBitmap	*gr_bmp;
442
	cairo_format_t	format;
443
	unsigned int	width;
444
	unsigned int	height;
445
	GpStatus	status = Ok;
456
	GpStatus	status = Ok;
446
	BOOL		dispose_bitmap;
457
	BOOL		dispose_bitmap;
447
458
448
	if ((graphics == NULL) || (brush == NULL) || (graphics->ct == NULL)) {
459
	if (!graphics || !brush || !graphics->ct)
449
		return InvalidParameter;
460
		return InvalidParameter;
450
	}
451
461
452
	texture = (GpTexture *) brush;
462
	texture = (GpTexture *) brush;
453
	img = texture->image;
463
	img = texture->image;
454
	if (img == NULL) {
464
	if (!img)
455
		return InvalidParameter;
465
		return InvalidParameter;
456
	}
457
466
458
	if (img->type != ImageTypeBitmap)
467
	if (img->type != ImageTypeBitmap)
459
		return NotImplemented;
468
		return NotImplemented;
Lines 470-478 Link Here
470
	} else {
479
	} else {
471
		dispose_bitmap = FALSE;
480
		dispose_bitmap = FALSE;
472
	}
481
	}
473
	width = img->active_bitmap->width;
474
	height = img->active_bitmap->height;
475
	format = img->active_bitmap->pixel_format;
476
482
477
	ct = graphics->ct;
483
	ct = graphics->ct;
478
484
(-)src/bitmap-private.h (+3 lines)
Lines 149-154 Link Here
149
cairo_surface_t* gdip_bitmap_ensure_surface (GpBitmap *bitmap) GDIP_INTERNAL;
149
cairo_surface_t* gdip_bitmap_ensure_surface (GpBitmap *bitmap) GDIP_INTERNAL;
150
GpBitmap* gdip_convert_indexed_to_rgb (GpBitmap *bitmap) GDIP_INTERNAL;
150
GpBitmap* gdip_convert_indexed_to_rgb (GpBitmap *bitmap) GDIP_INTERNAL;
151
151
152
BOOL gdip_bitmap_format_needs_premultiplication (GpBitmap *bitmap) GDIP_INTERNAL;
153
BYTE* gdip_bitmap_get_premultiplied_scan0 (GpBitmap *bitmap) GDIP_INTERNAL;
154
152
void gdip_process_bitmap_attributes (GpBitmap *bitmap, void **dest, GpImageAttributes* attr, BOOL *allocated) GDIP_INTERNAL;
155
void gdip_process_bitmap_attributes (GpBitmap *bitmap, void **dest, GpImageAttributes* attr, BOOL *allocated) GDIP_INTERNAL;
153
156
154
ColorPalette* gdip_create_greyscale_palette (int num_colors) GDIP_INTERNAL;
157
ColorPalette* gdip_create_greyscale_palette (int num_colors) GDIP_INTERNAL;

Return to bug 324503