# Mask surfaces

**URL:** <https://discourse.libsdl.org/t/mask-surfaces/4503>\
**Category:** SDL Development\
**Created:** [May 31, 2001, 4:17am UTC](https://discourse.libsdl.org/t/mask-surfaces/4503 "2001-05-31T04:17:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Markiewicz](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@Ricardo\_Markiewicz](https://discourse.libsdl.org/u/Ricardo_Markiewicz)\
**Post date:** [May 31, 2001, 4:17am UTC](https://discourse.libsdl.org/t/mask-surfaces/4503/1 "2001-05-31T04:17:42Z")

</div>

Hi … i have 2 bmp, 1 is the image and the other is the mask.  
Does SDL havea way to blit the image using the mask bmp, or do i have to do  
this pixel by pixel ??

I need this because BMP doesn’t support alpha and i don’t wanna use PNG or  
another image file format.

## PD :excuse my english!!–

```
    Ricardo Markiewicz - Linux Inside!

```

* * *

## [http://www.globalmente.com/algoritmosii/index.html](http://www.globalmente.com/algoritmosii/index.html)

---

<div class="post-metadata">

**Author:** ![David\_Olofson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_olofson/32/115_2.png) [@David\_Olofson](https://discourse.libsdl.org/u/David_Olofson)\
**Post date:** [May 31, 2001, 6:48am UTC](https://discourse.libsdl.org/t/mask-surfaces/4503/2 "2001-05-31T06:48:17Z")

</div>

Do you want to use the “mask” image as a real alpha channel, or just a mask?

In the latter case, why not just reserving one pixel value for “transparent”,  
and then use SDL’s colorkeying?

If you _do_ need real alpha, you could merge the two images into an RGBA SDL  
surface. (Do this when loading the images or something.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.  
| Multimedia Application Integration Architecture |  
| A Free/Open Source Plugin API for Professional Multimedia |  
`----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter | `--------------------------------------\> david at [linuxdj.com](http://linuxdj.com) -'On Thursday 31 May 2001 06:17, Ricardo Markiewicz wrote:

> Hi … i have 2 bmp, 1 is the image and the other is the mask.  
> Does SDL havea way to blit the image using the mask bmp, or do i have to do  
> this pixel by pixel ??
> 
> I need this because BMP doesn’t support alpha and i don’t wanna use PNG or  
> another image file format.

---

<div class="post-metadata">

**Author:** ![Johannes\_Fortmann](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@Johannes\_Fortmann](https://discourse.libsdl.org/u/Johannes_Fortmann)\
**Post date:** [May 31, 2001, 1:52pm UTC](https://discourse.libsdl.org/t/mask-surfaces/4503/3 "2001-05-31T13:52:55Z")

</div>

> Hi … i have 2 bmp, 1 is the image and the other is the mask.  
> Does SDL havea way to blit the image using the mask bmp, or do i have to  
> do  
> this pixel by pixel ??
> 
> I need this because BMP doesn’t support alpha and i don’t wanna use PNG or  
> another image file format.

You could simply take a colour that is not in your image, colorize the mask  
and paste it on the image (in a paint program).  
Then you set that colour as colourkey, and blit it on the screen. Should  
work perfectly.

HTH

---

<div class="post-metadata">

**Author:** ![Ricardo\_Markiewicz](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@Ricardo\_Markiewicz](https://discourse.libsdl.org/u/Ricardo_Markiewicz)\
**Post date:** [June 1, 2001, 5:02am UTC](https://discourse.libsdl.org/t/mask-surfaces/4503/4 "2001-06-01T05:02:02Z")

</div>

> > Hi … i have 2 bmp, 1 is the image and the other is the mask.  
> > Does SDL havea way to blit the image using the mask bmp, or do i have  
> > to do  
> > this pixel by pixel ??
> > 
> > I need this because BMP doesn’t support alpha and i don’t wanna use PNG  
> > or  
> > another image file format.
> 
> Do you want to use the “mask” image as a real alpha channel, or just a  
> mask?
> 
> In the latter case, why not just reserving one pixel value for  
> “transparent”,  
> and then use SDL’s colorkeying?
> 
> If you _do_ need real alpha, you could merge the two images into an RGBA  
> SDL  
> surface. (Do this when loading the images or something.)

how can i do that ??? :-)On Thu, 31 May 2001 03:48:17 David Olofson wrote:

> On Thursday 31 May 2001 06:17, Ricardo Markiewicz wrote:

## –

```
    Ricardo Markiewicz - Linux Inside!

```

* * *

## [globalmente.com](http://www.globalmente.com/algoritmosii/index.html)

---

<div class="post-metadata">

**Author:** ![David\_Olofson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_olofson/32/115_2.png) [@David\_Olofson](https://discourse.libsdl.org/u/David_Olofson)\
**Post date:** [June 1, 2001, 8:13pm UTC](https://discourse.libsdl.org/t/mask-surfaces/4503/5 "2001-06-01T20:13:42Z")

</div>

There might be some shortcut using SDL calls that I’m not aware of, but if  
not, load the two images and make sure the “real” image is in RGBA 8:8:8:8  
format, and the mask image is in RGB 8:8:8 format. Then (assuming that the  
mask image is a gray scale image; R == G == B), copy one of the channels from  
the mask image into the A channel of the “real” image.

Just keep in mind to use surface-\>w for inner loop counter limit, while using  
surface-\>pitch to calculate the start index of a row within the buffer.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.  
| Multimedia Application Integration Architecture |  
| A Free/Open Source Plugin API for Professional Multimedia |  
`----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter | `--------------------------------------\> david at [linuxdj.com](http://linuxdj.com) -'On Friday 01 June 2001 07:02, Ricardo Markiewicz wrote:

> On Thu, 31 May 2001 03:48:17 David Olofson wrote:
> 
> > On Thursday 31 May 2001 06:17, Ricardo Markiewicz wrote:
> > 
> > > Hi … i have 2 bmp, 1 is the image and the other is the mask.  
> > > Does SDL havea way to blit the image using the mask bmp, or do i have
> > 
> > to do
> > 
> > > this pixel by pixel ??
> > > 
> > > I need this because BMP doesn’t support alpha and i don’t wanna use PNG
> > 
> > or
> > 
> > > another image file format.
> > 
> > Do you want to use the “mask” image as a real alpha channel, or just a  
> > mask?
> > 
> > In the latter case, why not just reserving one pixel value for  
> > “transparent”,  
> > and then use SDL’s colorkeying?
> > 
> > If you _do_ need real alpha, you could merge the two images into an RGBA  
> > SDL  
> > surface. (Do this when loading the images or something.)
> 
> how can i do that ??? 🙂
