首页 > 后端开发 > C++ > 正文

Photoshop 如何混合图像,有哪些不同的可用混合模式?

Mary-Kate Olsen
发布: 2024-11-20 14:47:11
原创
217 人浏览过

How does Photoshop blend images, and what are the different blend modes available?

Photoshop 如何合并图像

Photoshop 通过对图像 A 的每个像素与其在图像 B 中的相应像素执行混合操作来无缝混合图像每个像素由多个通道组成,每个通道代表一种颜色。对于 RGB 像素,这些通道包括红色、绿色和蓝色。

要合并两个像素,需要使用特定的混合操作组合它们各自的通道。 Photoshop 的混合模式采用以下数学函数:

ChannelBlend_Normal:         ((uint8) A)
ChannelBlend_Lighten:      ((uint8) (B > A) ? B : A)
ChannelBlend_Darken:       ((uint8) (B > A) ? A : B)
ChannelBlend_Multiply:     ((uint8) ((A * B) / 255))
ChannelBlend_Average:      ((uint8) ((A + B) / 2))
ChannelBlend_Add:          ((uint8) min(255, (A + B))))
ChannelBlend_Subtract:     ((uint8) ((A + B < 255) ? 0 : (A + B - 255)))
ChannelBlend_Difference:  ((uint8) abs(A - B))
ChannelBlend_Negation:    ((uint8) (255 - abs(255 - A - B)))
ChannelBlend_Screen:      ((uint8) (255 - (((255 - A) * (255 - B)) >> 8)))
ChannelBlend_Exclusion:   ((uint8) (A + B - 2 * A * B / 255))
ChannelBlend_Overlay:     ((uint8) (B < 128) ? (2 * A * B / 255) : (255 - 2 * (255 - A) * (255 - B) / 255)))
ChannelBlend_SoftLight:   ((uint8) (B < 128) ? (2 * ((A >> 1) + 64)) * ((float) B / 255) : (255 - 2 * (255 - ((A >> 1) + 64)) * (float) (255 - B) / 255))))
ChannelBlend_HardLight:   (ChannelBlend_Overlay(B, A))
ChannelBlend_ColorDodge:  ((uint8) (B == 255) ? B : min(255, ((A << 8 ) / (255 - B)))))
ChannelBlend_ColorBurn:   ((uint8) (B == 0) ? B : max(0, (255 - ((255 - A) << 8 ) / B))))
ChannelBlend_LinearDodge: (ChannelBlend_Add(A, B))
ChannelBlend_LinearBurn:  (ChannelBlend_Subtract(A, B))
ChannelBlend_LinearLight: ((uint8) (B < 128) ? ChannelBlend_LinearBurn(A, (2 * B)) : ChannelBlend_LinearDodge(A, (2 * (B - 128)))))
ChannelBlend_VividLight:  ((uint8) (B < 128) ? ChannelBlend_ColorBurn(A, (2 * B)) : ChannelBlend_ColorDodge(A, (2 * (B - 128)))))
ChannelBlend_PinLight:    ((uint8) (B < 128) ? ChannelBlend_Darken(A, (2 * B)) : ChannelBlend_Lighten(A, (2 * (B - 128)))))
ChannelBlend_HardMix:     ((uint8) ((ChannelBlend_VividLight(A, B) < 128) ? 0 : 255))
ChannelBlend_Reflect:     ((uint8) (B == 255) ? B : min(255, (A * A / (255 - B)))))
ChannelBlend_Glow:        (ChannelBlend_Reflect(B, A))
ChannelBlend_Phoenix:     ((uint8) (min(A, B) - max(A, B) + 255))
ChannelBlend_Alpha:       ((uint8) (O * A + (1 - O) * B))
ChannelBlend_AlphaF:      (ChannelBlend_Alpha(F(A, B), A, O))
登录后复制

混合单个 RGB 像素:

ImageTColorR = ChannelBlend_Glow(ImageAColorR, ImageBColorR);
ImageTColorB = ChannelBlend_Glow(ImageAColorB, ImageBColorB);
ImageTColorG = ChannelBlend_Glow(ImageAColorG, ImageBColorG);

ImageTColor = RGB(ImageTColorR, ImageTColorB, ImageTColorG);
登录后复制

以特定不透明度(例如 50%)进行混合:

ImageTColorR = ChannelBlend_AlphaF(ImageAColorR, ImageBColorR, Blend_Subtract, 0.5F);
登录后复制

要简化所有三个通道的混合,可以使用缓冲区宏:

#define ColorBlend_ ## M(T, A, B) (T)[0] = ChannelBlend_ ## M((A)[0], (B)[0]), (T)[1] = ChannelBlend_ ## M((A)[1], (B)[1]), (T)[2] = ChannelBlend_ ## M((A)[2], (B)[2])
登录后复制

生成以下 RGB 颜色混合宏:

#define ColorBlend_Normal(T, A, B) ColorBlend_Buffer(T, A, B, Normal)
#define ColorBlend_Lighten(T, A, B) ColorBlend_Buffer(T, A, B, Lighten)
#define ColorBlend_Darken(T, A, B) ColorBlend_Buffer(T, A, B, Darken)
#define ColorBlend_Multiply(T, A, B) ColorBlend_Buffer(T, A, B, Multiply)
#define ColorBlend_Average(T, A, B) ColorBlend_Buffer(T, A, B, Average)
#define ColorBlend_Add(T, A, B) ColorBlend_Buffer(T, A, B, Add)
#define ColorBlend_Subtract(T, A, B) ColorBlend_Buffer(T, A, B, Subtract)
#define ColorBlend_Difference(T, A, B) ColorBlend_Buffer(T, A, B, Difference)
#define ColorBlend_Negation(T, A, B) ColorBlend_Buffer(T, A, B, Negation)
#define ColorBlend_Screen(T, A, B) ColorBlend_Buffer(T, A, B, Screen)
#define ColorBlend_Exclusion(T, A, B) ColorBlend_Buffer(T, A, B, Exclusion)
#define ColorBlend_Overlay(T, A, B) ColorBlend_Buffer(T, A, B, Overlay)
#define ColorBlend_SoftLight(T, A, B) ColorBlend_Buffer(T, A, B, SoftLight)
#define ColorBlend_HardLight(T, A, B) ColorBlend_Buffer(T, A, B, HardLight)
#define ColorBlend_ColorDodge(T, A, B) ColorBlend_Buffer(T, A, B, ColorDodge)
#define ColorBlend_ColorBurn(T, A, B) ColorBlend_Buffer(T, A, B, ColorBurn)
#define ColorBlend_LinearDodge(T, A, B) ColorBlend_Buffer(T, A, B, LinearDodge)
#define ColorBlend_LinearBurn(T, A, B) ColorBlend_Buffer(T, A, B, LinearBurn)
#define ColorBlend_LinearLight(T, A, B) ColorBlend_Buffer(T, A, B, LinearLight)
#define ColorBlend_VividLight(T, A, B) ColorBlend_Buffer(T, A, B, VividLight)
#define ColorBlend_PinLight(T, A, B) ColorBlend_Buffer(T, A, B, PinLight)
#define ColorBlend_HardMix(T, A, B) ColorBlend_Buffer(T, A, B, HardMix)
#define ColorBlend_Reflect(T, A, B) ColorBlend_Buffer(T, A, B, Reflect)
#define ColorBlend_Glow(T, A, B) ColorBlend_Buffer(T, A, B, Glow)
#define ColorBlend_Phoenix(T, A, B) ColorBlend_Buffer(T, A, B, Phoenix)
登录后复制

示例:

ColorBlend_Glow(TargetPtr, ImageAPtr, ImageBPtr);
登录后复制

对于涉及 HLS 转换的混合模式:

#define ColorBlend_Hue(T, A, B) ColorBlend_Hls(T, A, B, HueB, LuminationA, SaturationA)
登录后复制

以上是Photoshop 如何混合图像,有哪些不同的可用混合模式?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板