引用:
原帖由 sfsuvival 于 2010-03-23 12:35 发表
M$这个不是和维基alpha compositing的公式一样吗?
当SourceConstantAlpha=0xFF (合成时不需要改整张图的opacity)
Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red
Dst.Green = Src.Green + (1 - Src.Alpha) ...
好麻烦。还是用这个好了
刚才看了IM的实现,我的妈呀,大概是SVG标准那个实现
00088 static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
00089 const MagickRealType alpha,const MagickPixelPacket *q,
00090 const MagickRealType beta,MagickPixelPacket *composite)
00091 {
00092 MagickRealType
00093 gamma;
00094
00095 if (alpha == TransparentOpacity)
00096 {
00097 *composite=(*q);
00098 return;
00099 }
00100 gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
00101 composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
00102 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
00103 composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
00104 composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
00105 composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
00106 if ((p->colorspace == CMYKColorspace) && (q->colorspace == CMYKColorspace))
00107 composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
00108 }
00038 static inline MagickRealType MagickOver_(const MagickRealType p,
00039 const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
00040 {
00041 MagickRealType
00042 pixel;
00043
00044 pixel=(1.0-QuantumScale*alpha)*p+(1.0-QuantumScale*beta)*q*QuantumScale*alpha;
00045 return(pixel);
00046 }
[
本帖最后由 haibara 于 2010-03-23 23:29 编辑 ]