mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
wrlib: Improvement in the alpha channel support.
There are some problems in the alpha channel support, as is reported at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=72917 This patch add a new RCombineAlpha function, based on Gimp. This function is called when needed in the raster.c functions. This patch is based on the Brad Jorsch <anomie@users.sourceforge.net> patch for the 0.62.1-0.1 version. [crmafra: v1 was sent by Rodolfo kix Garcia <kix@kix.es>]
This commit is contained in:
committed by
Carlos R. Mafra
parent
e06b3005e8
commit
3ed409cbd0
66
wrlib/alpha_combine.c
Normal file
66
wrlib/alpha_combine.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* alpha_combine.c - Alpha channel combination, based on Gimp 1.1.24
|
||||
* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "wraster.h"
|
||||
|
||||
void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
|
||||
int width, int height, int dwi, int swi, int opacity) {
|
||||
int x, y;
|
||||
int t, sa;
|
||||
int alpha;
|
||||
float ratio, cratio;
|
||||
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
sa=s_has_alpha?*(s+3):255;
|
||||
|
||||
if (opacity!=255) {
|
||||
t = sa * opacity + 0x80;
|
||||
sa = ((t>>8)+t)>>8;
|
||||
}
|
||||
|
||||
t = *(d+3) * (255-sa) + 0x80;
|
||||
alpha = sa + (((t>>8)+t)>>8);
|
||||
|
||||
if (sa==0 || alpha==0) {
|
||||
ratio = 0;
|
||||
cratio = 1.0;
|
||||
} else if(sa == alpha) {
|
||||
ratio = 1.0;
|
||||
cratio = 0;
|
||||
} else {
|
||||
ratio = (float)sa / alpha;
|
||||
cratio = 1.0 - ratio;
|
||||
}
|
||||
|
||||
*d = (int)*d * cratio + (int)*s * ratio;
|
||||
s++; d++;
|
||||
*d = (int)*d * cratio + (int)*s * ratio;
|
||||
s++; d++;
|
||||
*d = (int)*d * cratio + (int)*s * ratio;
|
||||
s++; d++;
|
||||
*d = alpha;
|
||||
d++;
|
||||
|
||||
if (s_has_alpha) s++;
|
||||
}
|
||||
d+=dwi;
|
||||
s+=swi;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user