BUG: CAIRO_FORMAT_ARGB32, image_surface transparency = CAIRO_IMAGE_IS_OPAQUE after write_png()

Submitted by Adrian Johnson on June 7, 2016, 11:46 a.m.

Details

Message ID e0b7a3f8-238b-07c0-4c98-50a93bfe0adf@redneon.com
State New
Series "BUG: CAIRO_FORMAT_ARGB32, image_surface transparency = CAIRO_IMAGE_IS_OPAQUE after write_png()"
Headers show

Commit Message

Adrian Johnson June 7, 2016, 11:46 a.m.
On 07/06/16 15:28, lamer314@mail.ru wrote:
> Ok, but writing PNG shall not affect consequent writings. If we paint
> later with transparent source it is not opaque anymore and then 
> _cairo_image_analyze_transparency() shall run again.

I missed that part of the bug report. I thought the bug was about
writing ARGB32 images as opaque PNG when all alpha is 255. Failing to
analyze the transparency after updating the image is a bug. The attached
patch should fix it.

> I think it would be good idea to add some function like
> cairo_surface_write_to_png_flat() which will dump image data
> to PNG in the same format as surface. It also can be usefull for
> debugging then user can open file in image viwer and see what data
> in what format hi is actually working on.

The PNG surface is a convenience for testing, debugging, and creating
examples. Providing comprehensive support for image reading and writing
with various options is outside the scope of cairo. There are other
libraries that can perform this task.

Patch hide | download patch | download mbox

From 4899600853cebaca1aafcb59815748e7a0e99fa2 Mon Sep 17 00:00:00 2001
From: Adrian Johnson <ajohnson@redneon.com>
Date: Tue, 7 Jun 2016 20:42:53 +0930
Subject: [PATCH] image: only cache transparency and color analysis for
 snapshot surfaces

---
 src/cairo-image-surface.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 13d6272..0e4aa99 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -52,6 +52,7 @@ 
 #include "cairo-recording-surface-private.h"
 #include "cairo-region-private.h"
 #include "cairo-scaled-font-private.h"
+#include "cairo-surface-snapshot-inline.h"
 #include "cairo-surface-snapshot-private.h"
 #include "cairo-surface-subsurface-private.h"
 
@@ -1158,7 +1159,7 @@  _cairo_image_analyze_transparency (cairo_image_surface_t *image)
 {
     int x, y;
 
-    if (image->transparency != CAIRO_IMAGE_UNKNOWN)
+    if (_cairo_surface_is_snapshot (&image->base) && image->transparency != CAIRO_IMAGE_UNKNOWN)
 	return image->transparency;
 
     if ((image->base.content & CAIRO_CONTENT_ALPHA) == 0)
@@ -1215,7 +1216,7 @@  _cairo_image_analyze_color (cairo_image_surface_t      *image)
 {
     int x, y;
 
-    if (image->color != CAIRO_IMAGE_UNKNOWN_COLOR)
+    if (_cairo_surface_is_snapshot (&image->base) && image->color != CAIRO_IMAGE_UNKNOWN_COLOR)
 	return image->color;
 
     if (image->format == CAIRO_FORMAT_A1)
-- 
2.1.4


Comments

lamer314@mail.ru June 7, 2016, 5:05 p.m.
Tuesday, June 7, 2016, 2:46:04 PM, you wrote:

AJ> On 07/06/16 15:28, lamer314@mail.ru wrote:
>> Ok, but writing PNG shall not affect consequent writings. If we paint
>> later with transparent source it is not opaque anymore and then 
>> _cairo_image_analyze_transparency() shall run again.

AJ> I missed that part of the bug report. I thought the bug was about
AJ> writing ARGB32 images as opaque PNG when all alpha is 255. Failing to
AJ> analyze the transparency after updating the image is a bug. The attached
AJ> patch should fix it.

Hi Adrian, the patch works great. Thanks a lot for fast response.

Tuesday, June 7, 2016, 8:01:19 PM LOCAL
--