1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/login/pixel.c

42 lines
1.3 KiB
C
Raw Normal View History

2015-12-24 21:24:51 -05:00
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2014, 2015.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
pixel.c
Pixel utilities.
*******************************************************************************/
#include <stdint.h>
#include "pixel.h"
uint32_t blend_pixel(uint32_t bg_value, uint32_t fg_value)
{
union color_rgba8 fg; fg.value = fg_value;
union color_rgba8 bg; bg.value = bg_value;
if ( fg.a == 255 )
return fg.value;
if ( fg.a == 0 )
return bg.value;
union color_rgba8 ret;
ret.a = 255;
ret.r = ((255-fg.a)*bg.r + fg.a*fg.r) / 256;
ret.g = ((255-fg.a)*bg.g + fg.a*fg.g) / 256;
ret.b = ((255-fg.a)*bg.b + fg.a*fg.b) / 256;
return ret.value;
}