1 /* alpha_combine.c - Alpha channel combination, based on Gimp 1.1.24
2 * The GIMP -- an image manipulation program
3 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 void RCombineAlpha(unsigned char *d
, unsigned char *s
, int s_has_alpha
,
24 int width
, int height
, int dwi
, int swi
, int opacity
) {
30 for (y
=0; y
<height
; y
++) {
31 for (x
=0; x
<width
; x
++) {
32 sa
=s_has_alpha
?*(s
+3):255;
35 t
= sa
* opacity
+ 0x80;
39 t
= *(d
+3) * (255-sa
) + 0x80;
40 alpha
= sa
+ (((t
>>8)+t
)>>8);
42 if (sa
==0 || alpha
==0) {
45 } else if(sa
== alpha
) {
49 ratio
= (float)sa
/ alpha
;
53 *d
= (int)*d
* cratio
+ (int)*s
* ratio
;
55 *d
= (int)*d
* cratio
+ (int)*s
* ratio
;
57 *d
= (int)*d
* cratio
+ (int)*s
* ratio
;