Stephan Assmus | 8 Sep 19:00 2004

Re: [AGG] agg_span_image_filter_rgba32

I think the "secondary" alpha expressing coverage value is a must have. 
That much up front.

When you filter an image in premultiplied space, there is no problem, 
because there is no "undefined" colors. In non-premultiplied space, 
there is a problem, because there can be undefined colors, most notably 
colors at pixels with alpha = 0.

This simple function...

pixel combine(pixel a, pixel b)
	pixel result;
	result.color = (a.color + b.color) / 2;
	result.alpha = (a.alpha + b.alpha) / 2;
	return result;
} becoming more complex in the non-premultiplied case:

pixel combine(pixel a, pixel b)
	pixel result;
	result.color = (a.color * a.alpha + b.color * b.alpha)
							/ (a.alpha + b.alpha);
	result.alpha = (a.alpha + b.alpha) / 2;
	return result;

(well, you'll have to watch out for division by zero...)

I think this is the problem I'm seeing with the filter. The filter 
actually ignores the alpha value of a pixel completely (other than 
filtering it). I have attached a screen shot of what I mean. In the 
"scaled" clip, I have scaled a bit in x direction. I think the 
interpolator is interpolating the "visible" pixels with the "invisible" 
ones at edges going from semi opaque to fully transparent. The actual 
image borders are at the black and white line, so it is not the 
"background" color that I'm seeing. The filter, when mixing an opaque 
green pixel with a completely transparent pixel, will not produce a 
semi-transparent green pixel, but a semi-transparent green/black pixel, 
if black happend to be in the color channels of the completely 
transparent pixel. But it should have *ignored* the color channel of 
that pixel. See what I mean?

I know, I could be using premultiplied colors everywhere in my 
application, but I think this will really complicate things in terms of 
gamma correction and color management that I might decide to add later. 
On the other hand, the premultiplied color space does have a speed 
advantage. But as you saw yourself in the case of the coverage alpha 
values, mixing them in is an additional step. Therefor I think that 
premultiplied colors are good for games and such, where there is *only* 
alpha-blending, but no actual image editing or other types of 
blending. Maybe I'm wrong though. At least in my application, I have 
tons of cases where I need the "real" color of a pixel. For example 
when layers are blended in other blending modes, like "multiply" or 
"luminance" and such.

Best regards,

Attachment (BeOS Attributes): application/x-be_attribute, 105 bytes
Attachment (BeOS Attributes): application/x-be_attribute, 105 bytes