[cairo] defining CLAMP extend mode

Bill Spitzak spitzak at d2.com
Mon Oct 23 16:15:55 PDT 2006



Owen Taylor wrote:
> On Mon, 2006-10-23 at 15:12 -0700, Bill Spitzak wrote:
>> I'm quite certain the only working implementation is equivalent to doing 
>> EXTEND_PAD, after first clipping to a (antialiased) rectangle that is 
>> the source image boundary transformed to the destination. Don't think of 
>> it as clamping, the actual sampling *is* EXTEND_PAD and is calculated 
>> entirely separately from the clip.
> 
> Having the source pattern affect the destination clip certainly would
> make an already complex rasterization pipeline worse. Even more so if
> (as you imply below) you want to skip it on some platforms.

I may have explained this wrong. It won't effect the clip, what it 
effects is the transparency of the source. The source image is 
transformed and filtered as though EXTEND_PAD was on and then 
mulitiplied by a antialiased transformed rectangle. Outside the 
rectangle this produces zero and that goes through the compositing 
operation in exactly the same way that a zero pixel inside the image would.

>> I agree with Vladimir that this behavior is exactly what everybody wants 
>> and expects, and is what all non-XRender-based graphics api's do.
> 
> That's a strong statement.

Nonetheless, I will stand by it. I have not seen any api that 
antialiases shapes that does not behave this way, except XRender.

> Maybe Vlad's behavior is close enough to NONE to be substituted without
> people knowing ... it certainly is *on average* a more useful behavior;
> but the fact that it isn't easily implemented puts a bit of a squash
> on that idea. Having a functional PAD would be an easier step forward.

I very much believe that the current EXTEND_NONE behavior is useless, 
and not wanted by anybody, and that Vlad's behavior should replace it as 
the default, and in fact EXTEND_NONE removed completely. Any actual use 
can be replicated trivially by adding a row of black pixels around the 
outside, so removing this does not remove any drawing ability.

In fact EXTEND_NONE is so totally useless that replacing it is probably 
not going to break any real program's output. All programs either avoid 
scaling, turn off EXTEND_NONE, or add one or several rows of black 
pixels around the edge of the image to get the correct antialiased image 
(not the 1/2 clipped one the current code produces).

> The behavior you are asking for is not implementable as sampling if you
> are doing antialiasing by any means other than super-sampling.

Not sure I understand this. If my plan cannot be done then multiplying 
two masks cannot be done. The proposal is to do filtering as though 
EXTEND_PAD is on, then multiply the result by a white rectangle drawn 
with antialiasing. Either one, or both, of these steps can be done in a 
super-sampled method, and then the results multiplied. (In reality, you 
really need to filter the image, a per-pixel filtered image results in 
better output than a super-sampled impulse filter, though making each 
super sample a filtered image would be even better).

> What I'm saying is that if the *source sampling* clips to the bounds of
> the source image and uses transparent pixels elsewhere, then you try to
> use a destination shape that has the same (transformed geometric) bounds
> as the source image, then pixels on the margin of the source image will
> have too small alpha values. The source sampled pixel will have a value
> of 50%, then you'll cut out 50% again and get an alpha value of 25%
> for a pixel that should be half covered.

This is actually an argument for doing EXTEND_PAD always. An opaque 
source will not produce any transparent pixels anywhere. However the 
opaque result will be multplied by an antialised rectangle figured out 
in the destination space. This reduces the problem to exactly the same 
problem as trying to hide one rectangle by drawing the same one again in 
a different color, or drawing a rectangle that matches the clip 
boundary, etc, in that the error is no more than 1 destination pixel. 
These problems can then all be addressed together, for instance by doing 
supersampling.


More information about the cairo mailing list