Partially support _NET_WM_STRUT_PARTIAL.
[wmaker-crm.git] / wrlib / alpha_combine.c
blobe670d626cd7ff2046eb434b313fb84ccca71811c
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "wraster.h"
22 void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
23 int width, int height, int dwi, int swi, int opacity) {
24 int x, y;
25 int t, sa;
26 int alpha;
27 float ratio, cratio;
29 for (y=0; y<height; y++) {
30 for (x=0; x<width; x++) {
31 sa=s_has_alpha?*(s+3):255;
33 if (opacity!=255) {
34 t = sa * opacity + 0x80;
35 sa = ((t>>8)+t)>>8;
38 t = *(d+3) * (255-sa) + 0x80;
39 alpha = sa + (((t>>8)+t)>>8);
41 if (sa==0 || alpha==0) {
42 ratio = 0;
43 cratio = 1.0;
44 } else if(sa == alpha) {
45 ratio = 1.0;
46 cratio = 0;
47 } else {
48 ratio = (float)sa / alpha;
49 cratio = 1.0 - ratio;
52 *d = (int)*d * cratio + (int)*s * ratio;
53 s++; d++;
54 *d = (int)*d * cratio + (int)*s * ratio;
55 s++; d++;
56 *d = (int)*d * cratio + (int)*s * ratio;
57 s++; d++;
58 *d = alpha;
59 d++;
61 if (s_has_alpha) s++;
63 d+=dwi;
64 s+=swi;