Mail Archives: djgpp/2000/01/03/13:58:58
On 2 Jan 00, at 16:57, Matej wrote:
> Let's say I draw a red circle with black background in a program like
> Paint and I save it to be a .bmp file (or .pcx, but not gif!). Then, I
> write a program with a colorful background and want my program to
> display only that red circle without the black background. So, how to
> write that routine to show only the red circle?
Greetings Matej,
Indexed 256 colour images have a 256 colour palette. In which you
specify a rgb triplet colour for each index. So if you want to set
index number 2 to red you would make index 2 equal to
(red=255,green=0,blue=0) etc.
So since you are using indexed 256 colour images (pcx etc)you
select one entry out of the 256 which you think should be
transparent. I use Palette entry 0, which i've set to ( R 0, G 0,B 0)
ie-:black.
So in the bitmap for your circle you would draw the black
background using the palette entry 0 (which in this case is helpfully
set to black) and the red circle using any other palette entry (or
entries) so long as they aren't entry 0 (because when we draw the
bitmap we will not be drawing pixels which start with entry 0. That's
how we get the transparency).
So first you would draw your colorful background to the screen and
then you draw your circle bitmap on it as follows.
And your blitting routine would skip drawing pixels which have the
palette entry of 0. So in your circle bitmap the black background
will be skipped because it is drawn with palette index 0, but the
circle will be drawn because it is drawn with entries other than 0.
So your code will be,
Check the palette index of the pixel,
If it is equal to zero (0) dont draw it (its a transparent pixel) instead
skip to the next pixel,
Or else If it is not equal to zero draw it (it's not a transparent pixel)
and go to the next pixel.
loop until done.
Drawing transparent pixels means that your routine will have to
check every pixel so it might be a little slow.
I hope this sound clear if you still have probelms please mail me as
I can send you some sample code from a great book which i learnt
the principles from it should help you.
Kalum
- Raw text -