Apparently TIFF has not one but two types of Alpha channel Associated 
and UnAssociated. The premultiplication of the r,g and b channels by 
255/a on load should only be done with UnAssociated alpha channels 
(which seems to be counter-intuitive to me but what the hell).

The previous patch that Raster did for me didn't take this into account.

Attached is a patch against CVS loader_tiff.c to fix that. 

This possibly means that line 400 (in save) should be changed to
EXTRASAMPLE_UNASSALPHA.

Cheers,

Simon


--- loader_tiff.old     2006-01-05 11:58:04.000000000 +0000
+++ loader_tiff.c       2006-01-05 12:05:56.000000000 +0000
@@ -79,6 +79,7 @@
    uint32             *pixel, pixel_value;
    int                 i, j, dy, rast_offset;
    DATA32             *buffer_pixel, *buffer = img->image->data;
+   int                 alpha_premult = 
(EXTRASAMPLE_UNASSALPHA==img->rgba.alpha);
 
    image_width = img->image->w;
    image_height = img->image->h;
@@ -104,7 +105,7 @@
             g = TIFFGetG(pixel_value);
             b = TIFFGetB(pixel_value);
              pixel_value = (*(pixel++));
-            if ((a > 0) && (a < 255))
+            if ((a > 0) && (a < 255) && (alpha_premult))
               {
                  r = (r * 255) / a;
                  g = (g * 255) / a;

Reply via email to