Commit a4f32e51 authored by Paolo Bacchilega's avatar Paolo Bacchilega

always flush the cairo surface before getting the data

parent 8a38213a
......@@ -250,11 +250,10 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
}
metadata = _cairo_image_surface_get_metadata (surface);
metadata->has_alpha = FALSE;
cairo_surface_flush (surface);
surface_row = cairo_image_surface_get_data (surface) + line_start;
buffer_stride = srcinfo.output_width * srcinfo.output_components;
buffer = (*srcinfo.mem->alloc_sarray) ((j_common_ptr) &srcinfo, JPOOL_IMAGE, buffer_stride, srcinfo.rec_outbuf_height);
surface_row = _cairo_image_surface_flush_and_get_data (surface) + line_start;
switch (srcinfo.out_color_space) {
case JCS_CMYK:
......
......@@ -232,8 +232,7 @@ _cairo_image_surface_create_from_png (GInputStream *istream,
/* Read the image */
cairo_surface_flush (cairo_png_data->surface);
surface_row = cairo_image_surface_get_data (cairo_png_data->surface);
surface_row = _cairo_image_surface_flush_and_get_data (cairo_png_data->surface);
rowstride = cairo_image_surface_get_stride (cairo_png_data->surface);
row_pointers = g_new (png_bytep, height);
for (row = 0; row < height; row++) {
......
......@@ -534,8 +534,6 @@ _cairo_image_surface_paint_layer (cairo_surface_t *image,
if ((image == NULL) || (layer->pixels == NULL))
return;
cairo_surface_flush (image);
image_width = cairo_image_surface_get_width (image);
image_height = cairo_image_surface_get_height (image);
image_row_stride = cairo_image_surface_get_stride (image);
......@@ -573,7 +571,7 @@ _cairo_image_surface_paint_layer (cairo_surface_t *image,
height = rect.height;
}
image_row = cairo_image_surface_get_data (image) + (y * image_row_stride) + (x * 4);
image_row = _cairo_image_surface_flush_and_get_data (image) + (y * image_row_stride) + (x * 4);
x = (layer->h_offset < 0) ? -layer->h_offset : 0;
y = (layer->v_offset < 0) ? -layer->v_offset : 0;
......
......@@ -340,7 +340,7 @@ _cairo_surface_write_as_jpeg (cairo_surface_t *image,
rowstride = cairo_image_surface_get_stride (image);
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
pixels = cairo_image_surface_get_data (image);
pixels = _cairo_image_surface_flush_and_get_data (image);
g_return_val_if_fail (pixels != NULL, FALSE);
/* allocate a small buffer to convert image data */
......
......@@ -211,7 +211,7 @@ _cairo_surface_write_as_png (cairo_surface_t *image,
width = cairo_image_surface_get_width (image);
height = cairo_image_surface_get_height (image);
alpha = _cairo_image_surface_get_has_alpha (image);
pixels = cairo_image_surface_get_data (image);
pixels = _cairo_image_surface_flush_and_get_data (image);
rowstride = cairo_image_surface_get_stride (image);
cairo_png_data = g_new0 (CairoPngData, 1);
......
......@@ -219,7 +219,7 @@ _cairo_surface_write_as_tga (cairo_surface_t *image,
width = cairo_image_surface_get_width (image);
height = cairo_image_surface_get_height (image);
alpha = _cairo_image_surface_get_has_alpha (image);
pixels = cairo_image_surface_get_data (image);
pixels = _cairo_image_surface_flush_and_get_data (image);
rowstride = cairo_image_surface_get_stride (image);
buffer_data = gth_buffer_data_new ();
......
......@@ -383,7 +383,7 @@ _cairo_surface_write_as_tiff (cairo_surface_t *image,
cols = cairo_image_surface_get_width (image);
rows = cairo_image_surface_get_height (image);
alpha = _cairo_image_surface_get_has_alpha (image);
pixels = cairo_image_surface_get_data (image);
pixels = _cairo_image_surface_flush_and_get_data (image);
rowstride = cairo_image_surface_get_stride (image);
predictor = 2;
......
......@@ -138,7 +138,7 @@ _WebPPictureImportCairoSurface (WebPPicture *const picture,
return 0;
stride = cairo_image_surface_get_stride (image);
src_row = cairo_image_surface_get_data (image);
src_row = _cairo_image_surface_flush_and_get_data (image);
dest_row = picture->argb;
for (y= 0; y < cairo_image_surface_get_height (image); y++) {
......
......@@ -53,8 +53,8 @@ box_blur (cairo_surface_t *source,
/* horizontal blur */
p_src = cairo_image_surface_get_data (source);
p_dest = cairo_image_surface_get_data (destination);
p_src = _cairo_image_surface_flush_and_get_data (source);
p_dest = _cairo_image_surface_flush_and_get_data (destination);
src_rowstride = cairo_image_surface_get_stride (source);
dest_rowstride = cairo_image_surface_get_stride (destination);
width_minus_1 = width - 1;
......@@ -114,8 +114,8 @@ box_blur (cairo_surface_t *source,
/* vertical blur */
p_src = cairo_image_surface_get_data (destination);
p_dest = cairo_image_surface_get_data (source);
p_src = _cairo_image_surface_flush_and_get_data (destination);
p_dest = _cairo_image_surface_flush_and_get_data (source);
src_rowstride = cairo_image_surface_get_stride (destination);
dest_rowstride = cairo_image_surface_get_stride (source);
height_minus_1 = height - 1;
......@@ -235,8 +235,8 @@ _cairo_image_surface_sharpen (cairo_surface_t *source,
source_rowstride = cairo_image_surface_get_stride (source);
blurred_rowstride = cairo_image_surface_get_stride (blurred);
p_src = cairo_image_surface_get_data (source);
p_blurred = cairo_image_surface_get_data (blurred);
p_src = _cairo_image_surface_flush_and_get_data (source);
p_blurred = _cairo_image_surface_flush_and_get_data (blurred);
#define ASSIGN_INTERPOLATED_VALUE(x1, x2) \
if (ABS (x1 - x2) >= threshold) { \
......
......@@ -215,8 +215,8 @@ rotate (cairo_surface_t *image,
/* pre-multiply the background color */
image_with_background = _cairo_image_surface_copy (image);
p_src = cairo_image_surface_get_data (image);
p_new = cairo_image_surface_get_data (image_with_background);
p_src = _cairo_image_surface_flush_and_get_data (image);
p_new = _cairo_image_surface_flush_and_get_data (image_with_background);
src_rowstride = cairo_image_surface_get_stride (image);
new_rowstride = cairo_image_surface_get_stride (image_with_background);
......@@ -247,8 +247,8 @@ rotate (cairo_surface_t *image,
rotated = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, new_width, new_height);
p_src = cairo_image_surface_get_data (image_with_background);
p_new = cairo_image_surface_get_data (rotated);
p_src = _cairo_image_surface_flush_and_get_data (image_with_background);
p_new = _cairo_image_surface_flush_and_get_data (rotated);
src_rowstride = cairo_image_surface_get_stride (image_with_background);
new_rowstride = cairo_image_surface_get_stride (rotated);
......
......@@ -131,10 +131,9 @@ adjust_colors_exec (GthAsyncTask *task,
source_stride = cairo_image_surface_get_stride (adjust_data->source);
destination = cairo_image_surface_create (format, width, height);
cairo_surface_flush (destination);
destination_stride = cairo_image_surface_get_stride (destination);
p_source_line = cairo_image_surface_get_data (adjust_data->source);
p_destination_line = cairo_image_surface_get_data (destination);
p_source_line = _cairo_image_surface_flush_and_get_data (adjust_data->source);
p_destination_line = _cairo_image_surface_flush_and_get_data (destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
......
......@@ -144,10 +144,9 @@ adjust_contrast_exec (GthAsyncTask *task,
source_stride = cairo_image_surface_get_stride (adjust_data->source);
destination = cairo_image_surface_create (format, width, height);
cairo_surface_flush (destination);
destination_stride = cairo_image_surface_get_stride (destination);
p_source_line = cairo_image_surface_get_data (adjust_data->source);
p_destination_line = cairo_image_surface_get_data (destination);
p_source_line = _cairo_image_surface_flush_and_get_data (adjust_data->source);
p_destination_line = _cairo_image_surface_flush_and_get_data (destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
......
......@@ -101,10 +101,9 @@ equalize_exec (GthAsyncTask *task,
source_stride = cairo_image_surface_get_stride (equalize_data->source);
equalize_data->destination = cairo_image_surface_create (format, width, height);
cairo_surface_flush (equalize_data->destination);
destination_stride = cairo_image_surface_get_stride (equalize_data->destination);
p_source_line = cairo_image_surface_get_data (equalize_data->source);
p_destination_line = cairo_image_surface_get_data (equalize_data->destination);
p_source_line = _cairo_image_surface_flush_and_get_data (equalize_data->source);
p_destination_line = _cairo_image_surface_flush_and_get_data (equalize_data->destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
......
......@@ -101,10 +101,9 @@ grayscale_exec (GthAsyncTask *task,
source_stride = cairo_image_surface_get_stride (grayscale_data->source);
destination = cairo_image_surface_create (format, width, height);
cairo_surface_flush (destination);
destination_stride = cairo_image_surface_get_stride (destination);
p_source_line = cairo_image_surface_get_data (grayscale_data->source);
p_destination_line = cairo_image_surface_get_data (destination);
p_source_line = _cairo_image_surface_flush_and_get_data (grayscale_data->source);
p_destination_line = _cairo_image_surface_flush_and_get_data (destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
......
......@@ -95,10 +95,9 @@ negative_exec (GthAsyncTask *task,
source_stride = cairo_image_surface_get_stride (negative_data->source);
negative_data->destination = cairo_image_surface_create (format, width, height);
cairo_surface_flush (negative_data->destination);
destination_stride = cairo_image_surface_get_stride (negative_data->destination);
p_source_line = cairo_image_surface_get_data (negative_data->source);
p_destination_line = cairo_image_surface_get_data (negative_data->destination);
p_source_line = _cairo_image_surface_flush_and_get_data (negative_data->source);
p_destination_line = _cairo_image_surface_flush_and_get_data (negative_data->destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
......
......@@ -128,10 +128,8 @@ _cairo_surface_create_from_ppm (int width,
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
stride = cairo_image_surface_get_stride (surface);
cairo_surface_flush (surface);
buffer_p = buffer;
row = cairo_image_surface_get_data (surface);
row = _cairo_image_surface_flush_and_get_data (surface);
for (r = 0; r < height; r++) {
column = row;
for (c = 0; c < width; c++) {
......
......@@ -63,8 +63,8 @@ _cairo_image_surface_scale_nearest (cairo_surface_t *image,
src_width = cairo_image_surface_get_width (image);
src_height = cairo_image_surface_get_height (image);
p_src = cairo_image_surface_get_data (image);
p_dest = cairo_image_surface_get_data (scaled);
p_src = _cairo_image_surface_flush_and_get_data (image);
p_dest = _cairo_image_surface_flush_and_get_data (scaled);
src_rowstride = cairo_image_surface_get_stride (image);
dest_rowstride = cairo_image_surface_get_stride (scaled);
......@@ -266,8 +266,6 @@ horizontal_scale_transpose (cairo_surface_t *image,
if (resize_filter->cancelled)
return;
cairo_surface_flush (scaled);
scale = MAX (1.0 / scale_factor + EPSILON, 1.0);
support = scale * resize_filter_get_support (resize_filter);
if (support < 0.5) {
......@@ -275,8 +273,8 @@ horizontal_scale_transpose (cairo_surface_t *image,
scale = 1.0;
}
p_src = cairo_image_surface_get_data (image);
p_dest = cairo_image_surface_get_data (scaled);
p_src = _cairo_image_surface_flush_and_get_data (image);
p_dest = _cairo_image_surface_flush_and_get_data (scaled);
src_rowstride = cairo_image_surface_get_stride (image);
dest_rowstride = cairo_image_surface_get_stride (scaled);
weights = g_new (double, 2.0 * support + 3.0);
......@@ -519,8 +517,8 @@ _cairo_image_surface_scale_bilinear_2x2 (cairo_surface_t *image,
src_width = cairo_image_surface_get_width (image);
src_height = cairo_image_surface_get_height (image);
p_src = cairo_image_surface_get_data (image);
p_dest = cairo_image_surface_get_data (scaled);
p_src = _cairo_image_surface_flush_and_get_data (image);
p_dest = _cairo_image_surface_flush_and_get_data (scaled);
src_rowstride = cairo_image_surface_get_stride (image);
dest_rowstride = cairo_image_surface_get_stride (scaled);
......@@ -684,13 +682,11 @@ _cairo_surface_reduce_by_half (cairo_surface_t *src)
src_width / 2,
src_height / 2);
cairo_surface_flush (dest);
dest_rowstride = cairo_image_surface_get_stride (dest);
dest_data = cairo_image_surface_get_data (dest);
dest_data = _cairo_image_surface_flush_and_get_data (dest);
src_rowstride = cairo_image_surface_get_stride (src);
src_data = cairo_image_surface_get_data (src);
src_data = _cairo_image_surface_flush_and_get_data (src);
for (y = 0; y < src_height - (src_height % 2); y += 2) {
row0 = src_data + (MAX (y - 1, 0) * src_rowstride);
......
......@@ -120,6 +120,14 @@ _cairo_clear_surface (cairo_surface_t **surface)
}
unsigned char *
_cairo_image_surface_flush_and_get_data (cairo_surface_t *surface)
{
cairo_surface_flush (surface);
return cairo_image_surface_get_data (surface);
}
cairo_surface_metadata_t *
_cairo_image_surface_get_metadata (cairo_surface_t *surface)
{
......@@ -240,12 +248,10 @@ _cairo_image_surface_copy_subsurface (cairo_surface_t *source,
return NULL;
}
cairo_surface_flush (destination);
source_stride = cairo_image_surface_get_stride (source);
destination_stride = cairo_image_surface_get_stride (destination);
p_source = cairo_image_surface_get_data (source) + (src_y * source_stride) + (src_x * 4);
p_destination = cairo_image_surface_get_data (destination);
p_source = _cairo_image_surface_flush_and_get_data (source) + (src_y * source_stride) + (src_x * 4);
p_destination = _cairo_image_surface_flush_and_get_data (destination);
row_size = width * 4;
while (height-- > 0) {
memcpy (p_destination, p_source, row_size);
......@@ -287,9 +293,8 @@ _cairo_image_surface_create_from_pixbuf (GdkPixbuf *pixbuf)
"pixels", &p_pixels,
NULL );
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cairo_surface_flush (surface);
s_stride = cairo_image_surface_get_stride (surface);
s_pixels = cairo_image_surface_get_data (surface);
s_pixels = _cairo_image_surface_flush_and_get_data (surface);
metadata = _cairo_image_surface_get_metadata (surface);
metadata->has_alpha = (p_n_channels == 4);
......@@ -507,9 +512,8 @@ _cairo_image_surface_transform (cairo_surface_t *source,
&pixel_step);
destination = cairo_image_surface_create (format, destination_width, destination_height);
cairo_surface_flush (destination);
p_source_line = cairo_image_surface_get_data (source);
p_destination_line = cairo_image_surface_get_data (destination) + line_start;
p_source_line = _cairo_image_surface_flush_and_get_data (source);
p_destination_line = _cairo_image_surface_flush_and_get_data (destination) + line_start;
while (height-- > 0) {
p_source = p_source_line;
p_destination = p_destination_line;
......@@ -545,9 +549,9 @@ _cairo_image_surface_color_shift (cairo_surface_t *image,
width = cairo_image_surface_get_width (image);
height = cairo_image_surface_get_height (image);
src_stride = cairo_image_surface_get_stride (image);
src_pixels = cairo_image_surface_get_data (image);
src_pixels = _cairo_image_surface_flush_and_get_data (image);
dest_stride = cairo_image_surface_get_stride (shifted);
dest_pixels = cairo_image_surface_get_data (shifted);
dest_pixels = _cairo_image_surface_flush_and_get_data (shifted);
src_row = src_pixels;
dest_row = dest_pixels;
......@@ -633,8 +637,6 @@ _cairo_paint_full_gradient (cairo_surface_t *surface,
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
return;
cairo_surface_flush (surface);
_gdk_rgba_to_cairo_color_255 (h_color1, &hcolor1);
_gdk_rgba_to_cairo_color_255 (h_color2, &hcolor2);
_gdk_rgba_to_cairo_color_255 (v_color1, &vcolor1);
......@@ -643,7 +645,7 @@ _cairo_paint_full_gradient (cairo_surface_t *surface,
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
s_stride = cairo_image_surface_get_stride (surface);
s_pixels = cairo_image_surface_get_data (surface);
s_pixels = _cairo_image_surface_flush_and_get_data (surface);
for (h = 0; h < height; h++) {
guchar *s_iter = s_pixels;
......
......@@ -156,6 +156,7 @@ void _gdk_rgba_to_cairo_color_255 (GdkRGBA
/* surface */
void _cairo_clear_surface (cairo_surface_t **surface);
unsigned char * _cairo_image_surface_flush_and_get_data (cairo_surface_t *surface);
cairo_surface_metadata_t *
_cairo_image_surface_get_metadata (cairo_surface_t *surface);
gboolean _cairo_image_surface_get_has_alpha (cairo_surface_t *surface);
......
......@@ -151,7 +151,7 @@ gth_histogram_calculate_for_image (GthHistogram *self,
has_alpha = _cairo_image_surface_get_has_alpha (image);
rowstride = cairo_image_surface_get_stride (image);
line = cairo_image_surface_get_data (image);
line = _cairo_image_surface_flush_and_get_data (image);
width = cairo_image_surface_get_width (image);
height = cairo_image_surface_get_height (image);
......
......@@ -58,7 +58,7 @@ _gdk_pixbuf_new_from_cairo_surface (cairo_surface_t *surface)
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
s_stride = cairo_image_surface_get_stride (surface);
s_pixels = cairo_image_surface_get_data (surface);
s_pixels = _cairo_image_surface_flush_and_get_data (surface);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, _cairo_image_surface_get_has_alpha (surface), 8, width, height);
p_stride = gdk_pixbuf_get_rowstride (pixbuf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment