# \[despammed\] Bliting, alpha channel, anti-alliasing

**URL:** <https://discourse.libsdl.org/t/despammed-bliting-alpha-channel-anti-alliasing/7979>\
**Category:** SDL Development\
**Created:** [December 21, 2002, 4:53am UTC](https://discourse.libsdl.org/t/despammed-bliting-alpha-channel-anti-alliasing/7979 "2002-12-21T04:53:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tatsujin](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@Tatsujin](https://discourse.libsdl.org/u/Tatsujin)\
**Post date:** [December 21, 2002, 4:53am UTC](https://discourse.libsdl.org/t/despammed-bliting-alpha-channel-anti-alliasing/7979/1 "2002-12-21T04:53:01Z")

</div>

Adilson Oliveira wrote:

> Hi.
> 
> I’m developping an apication and the sprites I have to use has an  
> anti-aliasing effect. When I blit them on the background surface, I got  
> an ugly border because of the transparecy.  
> Any ideias how to have transparency on anti-aliased images? Is an alpha  
> channel the solution? If so, how?

Just a guess, but is the anti-alias by any chance against black background?  
That won’t work because the transparency blends against the non-black background thus  
you get the black border in the anti-aliased edge pixels.

The solution is actually to not have any anti-alias at the edges, but only use  
edge-transparency =\> alpha channel!  
Then it will anti-alias nicely against any background, and also any overall  
transparency you might use will work as well.

I hope I managed to explain that in somewhat understandable terms…

/Andr?

---

<div class="post-metadata">

**Author:** ![Adilson\_Oliveira](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/adilson_oliveira/32/226_2.png) [@Adilson\_Oliveira](https://discourse.libsdl.org/u/Adilson_Oliveira)\
**Post date:** [December 23, 2002, 2:51am UTC](https://discourse.libsdl.org/t/despammed-bliting-alpha-channel-anti-alliasing/7979/2 "2002-12-23T02:51:00Z")

</div>

Tatsujin wrote:

> Adilson Oliveira wrote:
> 
> > Hi.
> > 
> > I’m developping an apication and the sprites I have to use has an  
> > anti-aliasing effect. When I blit them on the background surface, I  
> > got an ugly border because of the transparecy.  
> > Any ideias how to have transparency on anti-aliased images? Is an  
> > alpha channel the solution? If so, how?
> 
> Just a guess, but is the anti-alias by any chance against black background?

You’re right. It’s black

> That won’t work because the transparency blends against the non-black  
> background thus you get the black border in the anti-aliased edge pixels.
> 
> The solution is actually to not have any anti-alias at the edges, but  
> only use edge-transparency =\> alpha channel!  
> Then it will anti-alias nicely against any background, and also any  
> overall transparency you might use will work as well.
> 
> I hope I managed to explain that in somewhat understandable terms…

Hmmm… unfortunatly not 😉  
Sorry but I’m starting on this subject. Can you explain further,  
specialy this part:

> The solution is actually to not have any anti-alias at the edges, but  
> only use edge-transparency =\> alpha channel!  
> How do I do that? I understand the images must not have an anti-alias  
> but I completly missed the 2nd part.

TIA

Adilson.

---

<div class="post-metadata">

**Author:** ![Loren\_Osborn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/7c8e57/32.png) [@Loren\_Osborn](https://discourse.libsdl.org/u/Loren_Osborn)\
**Post date:** [December 23, 2002, 11:46pm UTC](https://discourse.libsdl.org/t/despammed-bliting-alpha-channel-anti-alliasing/7979/3 "2002-12-23T23:46:01Z")

</div>

> Tatsujin wrote:
> 
> > Adilson Oliveira wrote:
> > 
> > > Hi.
> > > 
> > > I’m developping an apication and the sprites I have to use has an  
> > > anti-aliasing effect. When I blit them on the background surface, I  
> > > got an ugly border because of the transparecy.  
> > > Any ideias how to have transparency on anti-aliased images? Is an  
> > > alpha channel the solution? If so, how?
> > 
> > Just a guess, but is the anti-alias by any chance against black background?
> 
> You’re right. It’s black

The thing to keep in mind is that black is zero…

> > That won’t work because the transparency blends against the non-black  
> > background thus you get the black border in the anti-aliased edge pixels.
> > 
> > The solution is actually to not have any anti-alias at the edges, but  
> > only use edge-transparency =\> alpha channel!  
> > Then it will anti-alias nicely against any background, and also any  
> > overall transparency you might use will work as well.
> > 
> > I hope I managed to explain that in somewhat understandable terms…
> 
> Hmmm… unfortunatly not 😉  
> Sorry but I’m starting on this subject. Can you explain further,  
> specialy this part:
> 
> > The solution is actually to not have any anti-alias at the edges, but  
> > only use edge-transparency =\> alpha channel!  
> > How do I do that? I understand the images must not have an anti-alias  
> > but I completly missed the 2nd part.

What you can do is divide the anti-aliased edge by the alpha channel:

the anti-aliased PIXEL\_VALUE = COLOR \* (alpha/255) +  
BLACK \* ((255-alpha)/255)

since BLACK is 0:

PIXEL\_VALUE = COLOR \* (alpha/255)

so:

COLOR = PIXEL\_VALUE \* (255/alpha)

so… for each pixel, where the alpha isn’t 0 and the PIXEL\_VALUE is  
less than alpha, compute the color as above…

That should fix your problem…

-LorenOn Mon, 2002-12-23 at 02:51, Adilson Oliveira wrote:
