/*************************************************************************** * Copyright (C) 2004 by Johan Maes * * on4qz@telenet.be * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "effects.h" static inline int blendComponent( int v, int av, int s, int as ) { return as*s + av*v -(av*as*s)/255; } static inline QRgb blend( QRgb v, QRgb s ) { //shadow image is already reduced and blurred int as = qAlpha(s); int av = qAlpha(v); if ( as == 0 || av == 255 ) return v; int a = as + av -(as*av)/255; int r = blendComponent( qRed(v),av, qRed(s), as)/a; int g = blendComponent( qGreen(v),av, qGreen(s), as)/a; int b = blendComponent( qBlue(v),av, qBlue(s), as)/a; return qRgba(r,g,b,a); } void blendImage(QImage &dst,QPoint start,QImage &src) { // pre-multiply source int i,j; int w=src.width(); int dx=dst.width(); int dy=dst.height(); int h=src.height(); int posx=start.x(); int posy=start.y(); for(j=0;j=dx)||((j+posy)>=dy) || ((i+posx)<0)||((j+posy)<0)) continue; dst.setPixel(i+posx,j+posy,blend(src.pixel(i,j),dst.pixel(i+posx,j+posy))); } } } #define byteCheck(x) if(x<0) x=0;if(x>255) x=255; void horizontalGradient(QImage &im,QColor start,QColor end) { int i,j; int a,r,g,b; double stepA,stepR,stepG,stepB; stepA=((double)(qAlpha(end.rgb())-qAlpha(start.rgb())))/im.height(); stepR=((double)(qRed(end.rgb())-qRed(start.rgb())))/im.height(); stepG=((double)(qGreen(end.rgb())-qGreen(start.rgb())))/im.height(); stepB=((double)(qBlue(end.rgb())-qBlue(start.rgb())))/im.height(); a=qAlpha(start.rgb()); r=qRed(start.rgb()); g=qGreen(start.rgb()); b=qBlue(start.rgb()); for(j=0;j