ColorBlend公式

ColorBlend公式Theblendoper defineChanne Normal A B uint8 A defineChanne Lighten A B uint8 B amp g

The blend operation that occurs for each blend mode in Photoshop can be summed up in the following macros:

#defineChannelBlend_Normal(A,B)((uint8)(A))#defineChannelBlend_Lighten(A,B)((uint8)((B > A)? B:A))#defineChannelBlend_Darken(A,B)((uint8)((B > A)? A:B))#defineChannelBlend_Multiply(A,B)((uint8)((A * B)/255))#defineChannelBlend_Average(A,B)((uint8)((A + B)/2))#defineChannelBlend_Add(A,B)((uint8)(min(255,(A + B))))#defineChannelBlend_Subtract(A,B)((uint8)((A + B <255)?0:(A + B -255)))#defineChannelBlend_Difference(A,B)((uint8)(abs(A - B)))#defineChannelBlend_Negation(A,B)((uint8)(255- abs(255- A - B)))#defineChannelBlend_Screen(A,B)((uint8)(255-(((255- A)*(255- B))>>8)))#defineChannelBlend_Exclusion(A,B)((uint8)(A + B -2* A * B /255))#defineChannelBlend_Overlay(A,B)((uint8)((B <128)?(2* A * B /255):(255-2*(255- A)*(255- B)/255)))#defineChannelBlend_SoftLight(A,B)((uint8)((B <128)?(2*((A>>1)+64))*((float)B/255):(255-(2*(255-((A>>1)+64))*(float)(255-B)/255))))#defineChannelBlend_HardLight(A,B)(ChannelBlend_Overlay(B,A))#defineChannelBlend_ColorDodge(A,B)((uint8)((B ==255)? B:min(255,((A <<8)/(255- B)))))#defineChannelBlend_ColorBurn(A,B)((uint8)((B ==0)? B:max(0,(255-((255- A)<<8)/ B))))#defineChannelBlend_LinearDodge(A,B)(ChannelBlend_Add(A,B))#defineChannelBlend_LinearBurn(A,B)(ChannelBlend_Subtract(A,B))#defineChannelBlend_LinearLight(A,B)((uint8)(B <128)?ChannelBlend_LinearBurn(A,(2* B)):ChannelBlend_LinearDodge(A,(2*(B -128))))#defineChannelBlend_VividLight(A,B)((uint8)(B <128)?ChannelBlend_ColorBurn(A,(2* B)):ChannelBlend_ColorDodge(A,(2*(B -128))))#defineChannelBlend_PinLight(A,B)((uint8)(B <128)?ChannelBlend_Darken(A,(2* B)):ChannelBlend_Lighten(A,(2*(B -128))))#defineChannelBlend_HardMix(A,B)((uint8)((ChannelBlend_VividLight(A,B)<128)?0:255))#defineChannelBlend_Reflect(A,B)((uint8)((B ==255)? B:min(255,(A * A /(255- B)))))#defineChannelBlend_Glow(A,B)(ChannelBlend_Reflect(B,A))#defineChannelBlend_Phoenix(A,B)((uint8)(min(A,B)- max(A,B)+255))#defineChannelBlend_Alpha(A,B,O)((uint8)(O * A +(1- O)* B))#defineChannelBlend_AlphaF(A,B,F,O)(ChannelBlend_Alpha(F(A,B),A,O))

To blend a single RGB pixel you would do the following:
ImageTColorR=ChannelBlend_Glow(ImageAColorR,ImageBColorR);ImageTColorB=ChannelBlend_Glow(ImageAColorB,ImageBColorB);ImageTColorG=ChannelBlend_Glow(ImageAColorG,ImageBColorG);ImageTColor= RGB(ImageTColorR,ImageTColorB,ImageTColorG);

If we wanted to perform a blend operation with a particular opacity, say 50%:
ImageTColorR=ChannelBlend_AlphaF(ImageAColorR,ImageBColorR,Blend_Subtract,0.5F);

If you have pointers to the image data for images A, B, and T (our target), we can simplify the blending of all three channels using this macro:
#defineColorBlend_Buffer(T,A,B,M)(T)[0]=ChannelBlend_M((A)[0], (B)[0]),(T)[1]=ChannelBlend_M((A)[1], (B)[1]),(T)[2]=ChannelBlend_M((A)[2], (B)[2])

And can derive the following RGB color blend macros:
#defineColorBlend_Normal(T,A,B)(ColorBlend_Buffer(T,A,B,Normal))#defineColorBlend_Lighten(T,A,B)(ColorBlend_Buffer(T,A,B,Lighten))#defineColorBlend_Darken(T,A,B)(ColorBlend_Buffer(T,A,B,Darken))#defineColorBlend_Multiply(T,A,B)(ColorBlend_Buffer(T,A,B,Multiply))#defineColorBlend_Average(T,A,B)(ColorBlend_Buffer(T,A,B,Average))#defineColorBlend_Add(T,A,B)(ColorBlend_Buffer(T,A,B,Add))#defineColorBlend_Subtract(T,A,B)(ColorBlend_Buffer(T,A,B,Subtract))#defineColorBlend_Difference(T,A,B)(ColorBlend_Buffer(T,A,B,Difference))#defineColorBlend_Negation(T,A,B)(ColorBlend_Buffer(T,A,B,Negation))#defineColorBlend_Screen(T,A,B)(ColorBlend_Buffer(T,A,B,Screen))#defineColorBlend_Exclusion(T,A,B)(ColorBlend_Buffer(T,A,B,Exclusion))#defineColorBlend_Overlay(T,A,B)(ColorBlend_Buffer(T,A,B,Overlay))#defineColorBlend_SoftLight(T,A,B)(ColorBlend_Buffer(T,A,B,SoftLight))#defineColorBlend_HardLight(T,A,B)(ColorBlend_Buffer(T,A,B,HardLight))#defineColorBlend_ColorDodge(T,A,B)(ColorBlend_Buffer(T,A,B,ColorDodge))#defineColorBlend_ColorBurn(T,A,B)(ColorBlend_Buffer(T,A,B,ColorBurn))#defineColorBlend_LinearDodge(T,A,B)(ColorBlend_Buffer(T,A,B,LinearDodge))#defineColorBlend_LinearBurn(T,A,B)(ColorBlend_Buffer(T,A,B,LinearBurn))#defineColorBlend_LinearLight(T,A,B)(ColorBlend_Buffer(T,A,B,LinearLight))#defineColorBlend_VividLight(T,A,B)(ColorBlend_Buffer(T,A,B,VividLight))#defineColorBlend_PinLight(T,A,B)(ColorBlend_Buffer(T,A,B,PinLight))#defineColorBlend_HardMix(T,A,B)(ColorBlend_Buffer(T,A,B,HardMix))#defineColorBlend_Reflect(T,A,B)(ColorBlend_Buffer(T,A,B,Reflect))#defineColorBlend_Glow(T,A,B)(ColorBlend_Buffer(T,A,B,Glow))#defineColorBlend_Phoenix(T,A,B)(ColorBlend_Buffer(T,A,B,Phoenix))

And example would be:
ColorBlend_Glow(TargetPtr,ImageAPtr,ImageBPtr);

The remainder of the photoshop blend modes involve converting RGB to HLS and back again.
#defineColorBlend_Hue(T,A,B)ColorBlend_Hls(T,A,B,HueB,LuminationA,SaturationA)#defineColorBlend_Saturation(T,A,B)ColorBlend_Hls(T,A,B,HueA,LuminationA,SaturationB)#defineColorBlend_Color(T,A,B)ColorBlend_Hls(T,A,B,HueB,LuminationA,SaturationB)#defineColorBlend_Luminosity(T,A,B)ColorBlend_Hls(T,A,B,HueA,LuminationB,SaturationA)#defineColorBlend_Hls(T,A,B,O1,O2,O3){ 
     float64HueA,LuminationA,SaturationA;float64HueB,LuminationB,SaturationL;Color_RgbToHls((A)[2],(A)[1],(A)[0],&HueA,&LuminationA,&SaturationA);Color_RgbToHls((B)[2],(B)[1],(B)[0],&HueB,&LuminationB,&SaturationB);Color_HlsToRgb(O1,O2,O3,&(T)[2],&(T)[1],&(T)[0]);}

These functions will be helpful in converting RGB to HLS.
int32Color_HueToRgb(float64 M1,float64 M2,float64Hue,float64*Channel){ 
     if(Hue<0.0)Hue+=1.0;elseif(Hue>1.0)Hue-=1.0;if((6.0*Hue)<1.0)*Channel=(M1 +(M2 - M1)*Hue*6.0);elseif((2.0*Hue)<1.0)*Channel=(M2);elseif((3.0*Hue)<2.0)*Channel=(M1 +(M2 - M1)*((2.0F/3.0F)-Hue)*6.0);else*Channel=(M1);return TRUE;}int32Color_RgbToHls(uint8Red,uint8Green,uint8Blue,float64*Hue,float64*Lumination,float64*Saturation){ 
     float64Delta;float64Max,Min;float64Redf,Greenf,Bluef;Redf=((float64)Red/255.0F);Greenf=((float64)Green/255.0F);Bluef=((float64)Blue/255.0F);Max= max(max(Redf,Greenf),Bluef);Min= min(min(Redf,Greenf),Bluef);*Hue=0;*Lumination=(Max+Min)/2.0F;*Saturation=0;if(Max==Min)return TRUE;Delta=(Max-Min);if(*Lumination<0.5)*Saturation=Delta/(Max+Min);else*Saturation=Delta/(2.0-Max-Min);if(Redf==Max)*Hue=(Greenf-Bluef)/Delta;elseif(Greenf==Max)*Hue=2.0+(Bluef-Redf)/Delta;else*Hue=4.0+(Redf-Greenf)/Delta;*Hue/=6.0;if(*Hue<0.0)*Hue+=1.0;return TRUE;}int32Color_HlsToRgb(float64Hue,float64Lumination,float64Saturation,uint8*Red,uint8*Green,uint8*Blue){ 
     float64 M1, M2;float64Redf,Greenf,Bluef;if(Saturation==0){ 
     Redf=Lumination;Greenf=Lumination;Bluef=Lumination;}else{ 
     if(Lumination<=0.5) M2 =Lumination*(1.0+Saturation);else M2 =Lumination+Saturation-Lumination*Saturation; M1 =(2.0*Lumination- M2);Color_HueToRgb(M1, M2,Hue+(1.0F/3.0F),&Redf);Color_HueToRgb(M1, M2,Hue,&Greenf);Color_HueToRgb(M1, M2,Hue-(1.0F/3.0F),&Bluef);}*Red=(uint8)(Redf*255);*Blue=(uint8)(Bluef*255);*Green=(uint8)(Greenf*255);return TRUE;}

 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226007.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午8:03
下一篇 2026年3月17日 上午8:03


相关推荐

  • 我学MSMQ(二)

    我学MSMQ(二)

    2021年8月28日
    62
  • sunlime 激活码(最新序列号破解)

    sunlime 激活码(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    56
  • ubuntu 20.04 安装 微信最新方式

    ubuntu 20.04 安装 微信最新方式ubuntu20 安装微信最新方式思路 1 下载安装 deepin wine 用于启动微信 2 下载安装微信 deb 可能会遇到的问题 1 盲目查看博客滴安装 如下面这段 这段安装是没有错的 错就错在安装的 deepin wine 版本为 2 18 12 这个版本不支持微信最新版本 deepin com wechat 2 6 8 65deepin0 i386 deb 安装必要的工具及 deepin wine 依赖 sudoaptinsta git 如已安装可自

    2026年3月20日
    2
  • 使用vue-quill-editor实现富文本编辑器

    使用vue-quill-editor实现富文本编辑器一 什么是富文本编辑器 简单介绍一下 看过上面的图 您大致对富文本编辑器有个了解了 传统的 textArea 输入框输入的内容没法做格式上的更改 它的功能跟我们的 word 一样 可以对其中内容的格式做一些调整 还可以添加图片等等 它在开发中有个专有名词 叫富文本编辑器 1 ueditor 国内人用 ueditor 的比较多 真的很中国化 经常在贴吧或论坛里看到这种风格的富文本编辑器 2 bootst

    2026年3月17日
    3
  • turtle画曲线_心形曲线图

    turtle画曲线_心形曲线图这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式欢迎使用Markdown编辑器你好!这是你第一次使用Markdown编辑器所展示的欢迎页。如果你想学习如何使用Markdown编辑器,可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

    2022年10月9日
    4
  • Win10+Ubuntu18.04双系统安装教程「建议收藏」

    Win10+Ubuntu18.04双系统安装教程「建议收藏」一.说在前头不同的配置安装方法不同,我也是小白第一次安,也是看了无数个教程不断重安了无数次才成功的,所以我的教程不一定适合你的配置,但你可以耐心的按照我的思路尝试,如果你有更好的想法,欢迎指出。我的配置如下:神舟笔记本,双硬盘(128固态+1t机械),bios模式为uefi(按Win+R打开运行,输入msinfo32,回车查看系统信息。在BIOS模式中如果显示“传统”,表示系统启动方式为…

    2022年7月24日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号