Update Serbian translation from master branch
[wmaker-crm.git] / wrlib / alpha_combine.c
blob915f65b91ae525bafaf530804e45ee424959ab03
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,
18 * MA 02110-1301, USA.
21 #include "config.h"
23 #include "wraster.h"
24 #include "wr_i18n.h"
27 void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
28 int width, int height, int dwi, int swi, int opacity) {
29 int x, y;
30 int t, sa;
31 int alpha;
32 float ratio, cratio;
34 for (y=0; y<height; y++) {
35 for (x=0; x<width; x++) {
36 sa=s_has_alpha?*(s+3):255;
38 if (opacity!=255) {
39 t = sa * opacity + 0x80;
40 sa = ((t>>8)+t)>>8;
43 t = *(d+3) * (255-sa) + 0x80;
44 alpha = sa + (((t>>8)+t)>>8);
46 if (sa==0 || alpha==0) {
47 ratio = 0;
48 cratio = 1.0;
49 } else if(sa == alpha) {
50 ratio = 1.0;
51 cratio = 0;
52 } else {
53 ratio = (float)sa / alpha;
54 cratio = 1.0F - ratio;
57 *d = (int)*d * cratio + (int)*s * ratio;
58 s++; d++;
59 *d = (int)*d * cratio + (int)*s * ratio;
60 s++; d++;
61 *d = (int)*d * cratio + (int)*s * ratio;
62 s++; d++;
63 *d = alpha;
64 d++;
66 if (s_has_alpha) s++;
68 d+=dwi;
69 s+=swi;