# Per-pixel alpha-channel, creation of

**URL:** <https://discourse.libsdl.org/t/per-pixel-alpha-channel-creation-of/9512>\
**Category:** SDL Development\
**Created:** [October 13, 2003, 11:48am UTC](https://discourse.libsdl.org/t/per-pixel-alpha-channel-creation-of/9512 "2003-10-13T11:48:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Bishop](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/mark_bishop/32/292_2.png) [@Mark\_Bishop](https://discourse.libsdl.org/u/Mark_Bishop)\
**Post date:** [October 13, 2003, 11:48am UTC](https://discourse.libsdl.org/t/per-pixel-alpha-channel-creation-of/9512/1 "2003-10-13T11:48:00Z")

</div>

Greets, how would you create an image with a per-pixel alpha channel?  
(that is, not a surface alpha-channel with SDL\_SetAlpha.)  
I.e. if I’ve already opened an image plus a grey-scale mask image with  
SDL\_image, then composited them together, how would I alter the format  
to accommodate the alpha-components of the pixels?  
Any links or source would be appreciated, thanks!

```
Mark
```

---

<div class="post-metadata">

**Author:** ![Gabriel\_Gambetta](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gabriel_gambetta/32/4004_2.png) [@Gabriel\_Gambetta](https://discourse.libsdl.org/u/Gabriel_Gambetta)\
**Post date:** [October 13, 2003, 12:19pm UTC](https://discourse.libsdl.org/t/per-pixel-alpha-channel-creation-of/9512/2 "2003-10-13T12:19:01Z")

</div>

> Greets, how would you create an image with a per-pixel alpha channel?

> (that is, not a surface alpha-channel with SDL\_SetAlpha.)  
> I.e. if I’ve already opened an image plus a grey-scale mask image with

> SDL\_image, then composited them together, how would I alter the format

> to accommodate the alpha-components of the pixels?  
> Any links or source would be appreciated, thanks!

Do you want to load a greyscale image as the alpha channel of another  
image? SDL has no such functionality that I’m aware of, I had to write  
my own function for this ☹

Lic. Gabriel Gambetta  
ARTech - GeneXus Development Team  
ggambett at artech.com.uy\> ----- Original Message -----

> From: Mark Bishop [[mailto:sealfin@sealfin.com](mailto:sealfin@sealfin.com)]  
> Sent: Lunes, 13 de Octubre de 2003 03:24 p.m.  
> To: sdl at [libsdl.org](http://libsdl.org)  
> Subject: [SDL] Per-pixel alpha-channel, creation of
> 
> Greets, how would you create an image with a per-pixel alpha channel?  
> (that is, not a surface alpha-channel with SDL\_SetAlpha.)  
> I.e. if I’ve already opened an image plus a grey-scale mask image with  
> SDL\_image, then composited them together, how would I alter the format  
> to accommodate the alpha-components of the pixels?  
> Any links or source would be appreciated, thanks!
> 
> Mark
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Mark\_Bishop](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/mark_bishop/32/292_2.png) [@Mark\_Bishop](https://discourse.libsdl.org/u/Mark_Bishop)\
**Post date:** [October 13, 2003, 1:35pm UTC](https://discourse.libsdl.org/t/per-pixel-alpha-channel-creation-of/9512/3 "2003-10-13T13:35:01Z")

</div>

Greets,

> Do you want to load a greyscale image as the alpha channel of another  
> image? SDL has no such functionality that I’m aware of, I had to write  
> my own function for this ☹  
> Yes; I’ve already gone through any SDL/alpha-channel-related info, and  
> realised I’ll need to roll a function for this.

> Uint32 SDL\_MapRGBA(SDL\_PixelFormat \*fmt, Uint8 r, Uint8 g, Uint8 b,  
> Uint8 a);  
> Simply map the color you want and use a putpixel function to place it  
> onto your surface.  
> Yes, this is pretty much the course I’m going to take - I’d just like to  
> know whether I need to perform any conversions on SDL\_Surface-\>format  
> before the start of the SDL\_MapRGBA routine, or whether SDL will realise  
> correctly that the surface now has a per-pixel alpha-channel?

Thanks for the help,

```
Mark

```
