RGB顏色混合(Blend)

最近這段時(shí)間在搞openGL ES處理視頻和圖像,要進(jìn)行紋理混合,重新溫習(xí)了一下大學(xué)時(shí)候的課本,找了一些資料,把一些常用的顏色混合算法都列出來,對比PS和GPUImage中的算法,供大家參考。

預(yù)習(xí):

色彩模型有很多種,包含RGB、YUV、HSL、HSV、HSB、Ycc、XYZ、LAB、CMYK等等,這些模型感興趣你可以都了解一下,但你要知道這些模型建立的核心,那就是“以人為本”, 全部參照人類視網(wǎng)膜感光能力而設(shè)計(jì),有的模型是國際照明委員會(CIE)進(jìn)行過大量的人類視覺測量和統(tǒng)計(jì)得出的,畢竟可能存在我們混合出來的某些色彩,在一些動物眼里根本無法區(qū)分(據(jù)說蛇的眼里沒有色彩),那這種混合就沒有任何意義,色彩模型的創(chuàng)建也就形同虛設(shè)了,好在人類可以區(qū)分很多種色相,實(shí)踐也有了意義。

? ? ? ? 這里重點(diǎn)講一下三原色,至于三原色是哪些就不再講了,回去翻中學(xué)課本,想通過三原色來講解一些光的本質(zhì)。?

? ? ? ? 我們都知道光線中存在一個色譜,這個色譜分為可見光波段不可見光波段,我們的討論范圍只在可見光范圍內(nèi),如果你對外端不可見光譜感興趣,就移步到百科里去看看視網(wǎng)膜不可感知的電磁波,例如無線電波、微波、紅外、紫外、射線、遠(yuǎn)紅外等等,這些已經(jīng)超出了人類視網(wǎng)膜接收的電磁波的波長,我們的視網(wǎng)膜只能接收波長為400~700納米的電磁波,但科學(xué)界已經(jīng)找到很多人,能夠接收380~780之間的電磁波,這類人就比較牛逼了,再進(jìn)化幾代可能會出現(xiàn)寫輪眼白眼輪回眼什么的,一眼看穿別人身體內(nèi)血液流動產(chǎn)生的電信號。

? ? ? ? 可見光譜中包含7種波長不同的光,就是毛爺爺說的“赤橙黃綠青藍(lán)紫,誰持彩練當(dāng)空舞”,波長從長到短,紅色最長,紫色最短,你能看到這個世界上的很多東西,全都要感謝“反射”的存在,光線照射在物體上,反射后進(jìn)入你的眼睛,所以你就看到了這個物體,如果這個世界沒有了反射,基本來講你除了能看到光源(太陽,燈)之外,就是個瞎子了,就像你在太空了,除了能看到一些發(fā)光的恒星,啥也看不到,一片漆黑,而光線照射在不同的物體上時(shí),這個物體會把赤橙黃綠青藍(lán)紫中的某些波段的光吸收了,例如一片樹葉,把赤橙黃青藍(lán)紫6種顏色吸收了,剩下“綠”光就反射出來進(jìn)入你的視網(wǎng)膜,所以你覺得樹葉是綠的。

? ? ? ? 了解上面的反射原理后 ,我們進(jìn)入正題,顏色混合。

? ? ? ? 顏色混合分為色光混合還有顏料混合。

色光混合就是可見光的混合,例如圖1:(圖直接從網(wǎng)上扣的,感謝原作者,但不知道原作者是誰)


圖1 色光混合

色光混合過程中,光線疊加后越來越亮,最后變成白色

顏料混合就是水彩之類的物理物質(zhì)混合,例如圖2:(這個圖直接從網(wǎng)上扣的,感謝原作者,但不知道原作者是誰)


圖2 顏料混合

顏料混合過程中,光線疊加后越來越暗,最后變成黑色

為什么會這樣呢?我們把耀眼的白色當(dāng)成是耀眼的太陽光,非常熱,能量非常高,暗淡的黑色當(dāng)做是漆黑的深夜,非常寒冷,能量非常低 (實(shí)時(shí)確實(shí)如此), ?所以,色光的混合是一種能量聚集的形式,混合的光越多,能量越高,顏色越趨近于白色,所以色光混合又叫“能量疊加”,而顏料混合得數(shù)量越多,越趨近于黑色,又叫“能量衰減”,知道了這些概念了,你知道從中的原因嗎? 色光混合又叫能量疊加,這個很好理解,但顏料為什么越混合越暗呢?這就跟物理性質(zhì)有關(guān)了,顏料的混合形式恰恰跟色光混合原理相反,色光是單純的疊加混合,而顏料,是一種補(bǔ)色混合,這就跟反射有關(guān)了,顏料吸收掉其他顏色,只剩下不能吸收的顏色反射出去,這就是顏料的原理,比如紅色的顏料,是因?yàn)樗樟似渌伾褵o法吸收的紅色反射出去,看上去就紅了,被吸收的那些顏色就是補(bǔ)色,所以,顏料混合的顏色越多,就相當(dāng)于每種顏色的補(bǔ)色都被逐漸集齊,然后幾乎吸收了光譜中所有的顏色,不黑才怪。


真的要進(jìn)入正題了


既然本文叫RGB顏色混合,那就跟顏料混合沒啥關(guān)系了,只是用顏料混合作對比,讓你明白色光混合的本質(zhì)。 在計(jì)算機(jī)中,用來描述顏色的模型有很多,本文我們探討RGBA的混合模式,這里你必須知道一套混合模型" Porter-Duff ", Porter-Duff模型已經(jīng)有三十多年的歷史了,在1984年由Thomas Porter 和 Tom Duff 發(fā)表,(論文傳送門)已經(jīng)被計(jì)算機(jī)界廣泛應(yīng)用,如果你有多平臺開發(fā)經(jīng)驗(yàn),你會發(fā)現(xiàn)很多領(lǐng)域都在使用這套模型,DirectX、OpenGL、Metal、Vulkan、Mantle中隨處可見Porter-Duff的身影,這套模型中羅列出了12種混合模式,在計(jì)算機(jī)中極大推動了圖形學(xué)和圖像學(xué)的發(fā)展,貢獻(xiàn)之大。

論文中提到的12個模型


下面,我們來一個更直觀的示意圖,看看每種情況對應(yīng)哪些形式:官方示意:傳送門

圖形化描述模型

下面會講解這些混合模式的算法,在講解之前,你有必要了解一些計(jì)算過程中的特殊因式,否則很多步驟將晦澀難懂。

(1-a) ?。 ?接下來的很多公式里,你會看到大量的(1-a),為什么要用1減去透明度?得到的是什么呢?實(shí)際上在做這些算法的時(shí)候,研究人員盡量模擬光線的特性來設(shè)計(jì),例如,光線穿透一些具有透明度的物體,一部分光會投射過去,剩下一部分反射回來,被我們看到。 ?

? ? ? ? 假設(shè)有兩塊有顏色的玻璃,一塊紅色,一塊綠色,紅色的玻璃透明度alpha = 0.2 ,則這塊玻璃的透光率為80%,因?yàn)橛?0%的光透過去了,只有20%能被我們的眼睛接收,所以透明度為0.2,若alpha = 0,則透光率為100%,所有光線都透過去了,我們就看不到了,另一塊綠色玻璃的透明度是0.6,則透光率是40%?,F(xiàn)在,將兩塊玻璃疊放到一起,用一束太陽光照射后,光線先穿過紅色玻璃,有80%的光透過去了,再經(jīng)過綠色玻璃,有 80 * 40% = 32%的光透過去了,也就是兩塊玻璃疊加后,總的透光率為32%,所以透明度為0.68.

所以,總透明度 ? = 1 - (a1透光率)*(a2透光率)?

????????????????????????????= ?1 - ( 1-a1 )* (1 - a2)?

? ? ? ? ? ? ? ? ? ? ? ? ? ? = ?a1 + a2 - a1 * a2?


了解透光率的特性后,接下來很多混合模式,相信你都可以看懂了。

討論P(yáng)orter-Duff模型之前,我們按照論文中,先定義幾個符號,以便你理解公式

C -表示像素的顏色,即(RGBA)的RGB部分,C是color的縮寫 (特別注意,Porter-Duff模型中所有RGB均為左乘后的結(jié)果,具體原因請翻閱論文,所以此處的R是Xr * Xa 的結(jié)果,即原始色彩 * 透明度 ?, 關(guān)于pre-multiplied和post-multiplied的知識點(diǎn)請移步到百科)

A -表示像素的透明度,A即alpha

s ?-表示兩個混合像素的源像素,s即source

d -表示兩個混合像素的目標(biāo)像素,d即destination

r -表示兩個像素混合后的結(jié)果,r即result

F -表示作用于C或A上的因子,F(xiàn)即factor


于是,Porter-Duff中定義了核心公式:

Cr = Cs*Fs + Cd*Fd ? ? ; ? ?Ar = As*Fs + Ad*Fd ? 。

即 :

結(jié)果色 = 源色 * 原因子 + ?目標(biāo)色 * 目標(biāo)因子。 ? ? ?結(jié)果alpha = 源透明度 * 源因子 + 目標(biāo)透明度 * 目標(biāo)因子。

對于論文中提到的12種不同的混合方式,僅僅是Fs與Fd的取值不同,

例如SRC_OVER ?, Fs = 1 , Fd = ( 1-As )

1. CLEAR????????????????????????????????Fs = Fd = 0

2. SRC????????????????????????????????????Fs = 1?Fd = 0

3. DST????????????????????????????????????Fs = 0?Fd = 1

4. SRC OVER ? ? ? ? ? ? ? ? ? ? ? ??Fs = 1 Fd = (1-As)

5. DST OVER ? ? ? ? ? ? ? ? ? ? ? ??Fs = (1-Ad) Fd = 1

6. SRC IN????????????????????????????????Fs = Ad Fd = 0

7. DST IN????????????????????????????????Fs = 0 Fd = As

8. SRC OUT????????????????????????????Fs = (1-Ad) Fd = 0

9. DST OUT????????????????????????????Fs = 0 Fd = (1-As)

10.SRC ATOP????????????????????????Fs = Ad Fd = (1-As)

11.DST ATOP????????????????????????Fs = (1-Ad) Fd = As

12.XOR???????????????????????????????????Fs = (1-Ad) Fd = (1-As)



為什么系數(shù)會是這樣呢?

這里準(zhǔn)備了兩幅圖,我們來根據(jù)混合兩幅圖像,更具體的分析混合樣式,請注意,Src的圖和Dst的圖,都有一半不透明,另一邊半透明,這樣在融合時(shí)能看清具體的模式。本文中示例的Demo已上傳GitHub,有興趣的同學(xué)可以下載看看。Demo傳送門


源素材和目標(biāo)素材,注意各有一半半透明

1.SrcOver


SrcOver

圖中,SrcOver是由Src疊加在了Dst上,是一種最普通的光學(xué)疊加,設(shè)光線全量為1,則照射在Src上的量度為1,穿透Src照射在Dst上的光量為 1 - As ,此刻,兩個圖層均享受到了光量,達(dá)到了混合效果,因此,光量比重系數(shù) ?Fs = 1 , Fd = ( 1-As ) 。

計(jì)算公式: Cr = Cs + Cd * ( 1 - As ) ; ? ? ? ? ? ?Ar = As + Ad * ( 1 - ?As )

還原左乘:Cr =?Cos * As + Cod * Ad * ( 1 - As ) ; ? (其中Cs = Cos * As, ?Cd = Cod * Ad)

得出的Cr都是在左乘的基礎(chǔ)上算出的,還原真實(shí)色彩需要 / Ar 。


SrcOver效果圖

2.DstOver


DstOver

同樣,DstOver,是由Dst疊加在了Src上,也是一種最普通的光學(xué)疊加,設(shè)光線全量為1,則照射在Dst上的量度為1,穿透Dst照射在Src上的光量為 1 - Ad ,因此,光量比重系數(shù)Fs = ( 1-Ad )?, Fd = 1 ,計(jì)算方式與SrcOver相同

計(jì)算公式: Cr = Cs * ( 1 - Ad ) + Cd ?; ? ? ? ? ? ?Ar = As ?* ( 1 - ?Ad )?+ Ad

還原左乘:Cr =?Cos * As?* ( 1 - Ad ) + Cod * Ad ?; ? (其中Cs = Cos * As, ?Cd = Cod * Ad)


DstOver效果圖

3.SrcOut


SrcOut

SrcOut可以看成是Dst覆蓋在Src上后進(jìn)行了剪裁,即DstOver,Dst涵蓋的部分完全消失,假設(shè)光線全量為1,透過Dst后到達(dá)Src的光量為1-Ad,此時(shí)讓Dst消失,相當(dāng)于講Dst的全部光量抹除為0,故 Fs = 1-Ad,F(xiàn)d = 0;

計(jì)算公式: Cr = Cs * ( 1 - Ad ) ? ; ? ? ? ? ? ?Ar = As ?* ( 1 - ?Ad )

還原左乘:Cr =?Cos * As?* ( 1 - Ad ) ; ? (其中Cs = Cos * As, ?Cd = Cod * Ad)


SrcOut效果圖

4.DstOut


DstOut

DstOut可以看成是Src覆蓋在Dst上后進(jìn)行了剪裁,即SrcOver,Src涵蓋的部分完全消失,假設(shè)光線全量為1,透過Src后到達(dá)Dst的光量為1-As,此時(shí)讓Src消失,相當(dāng)于講Src的全部光量抹除為0,故 Fs = 0,F(xiàn)d = 1 - As;

計(jì)算公式: Cr = Cd * ( 1 - As ) ; ? ? ? ? ? ?Ar = Ad * ( 1 - ?As )

還原左乘:Cr = ?Cod * Ad * ( 1 - As ) ; ? (其中Cs = Cos * As, ?Cd = Cod * Ad)


DstOut效果圖

5.SrcIn

SrcIn 不能通過簡單的光學(xué)疊加而形成,要實(shí)現(xiàn)這種效果,可以通過其他渠道來生成,方法很多,其中有一種簡單的方法,如下圖所示

SrcIn


SrcIn = SrcOver - DstOut - SrcOut;

所以 SrcIn ? = (Cs + Cd * ( 1 - As )) - (Cd * ( 1 - As )) - (Cs * ( 1 - Ad )) ;

= Cs + Cd - Cd*As - Cd + Cd*As - Cs +Cs*Ad ;

= Cs*Ad ;

= Cs * Ad + Cd * 0 ; (化標(biāo)準(zhǔn)式)

所以 ?Fs = Ad ; ? Fd = 0;


SrcIn效果圖

6.DstIn

DstIn 也不能通過簡單的光學(xué)疊加而形成,跟SrcIn一樣,要實(shí)現(xiàn)這種效果,可以通過其他渠道來生成,方法很多,其中有一種簡單的方法,如下圖所示

DstIn


DstIn = DstOver - DstOut - SrcOut;

所以 DstIn ?= (Cs * ( 1 - Ad ) + Cd) - (Cd * ( 1 - As )) - (Cs * ( 1 - Ad )) ;

= Cs - Cs*Ad + Cd - Cd + Cd*As - Cs +Cs*Ad ;

= Cd*As ;

= Cs *0+ Cd *As; (化標(biāo)準(zhǔn)式)

所以 ?Fs = 0 ; ? Fd = As;


DstIn效果圖

7.SrcATop


SrcATop

SrcAtop = SrcOver - SrcOut;

=?(Cs + Cd * ( 1 - As )) - (Cs * ( 1 - Ad )) ;

=?Cs + Cd - Cd*As - Cs +Cs*Ad ;

= Cs*Ad + Cd - Cd *As

= Cs*Ad + Cd * (1 - As)

所以 ?Fs = Ad ; ? Fd = 1 - As;


SrcATop效果圖

8.DstATop


DstATop

DstATop = DstOver - DstOut;

= (Cs * ( 1 - Ad ) + Cd) - (Cd * ( 1 - As )) ;

= Cs - Cs*Ad + Cd - Cd + Cd*As ;

= Cs - Cs*Ad + Cd*As

= Cs * ( 1 - Ad ) + Cd * As

所以 Fs = (1-Ad) ?Fd = As


DstATop效果圖

9.Xor

Xor的組成形式就有很多方式了,如下面三幅圖,我們分別來推出標(biāo)準(zhǔn)公式中的混合因子:

Xor-1


Xor-2


Xor-3



Xor1 = DstOver - DstIn

= (Cs * ( 1 - Ad ) + Cd) - (Cd*As)

= Cs - Cs*Ad + Cd - Cd*As

= Cs * (1-Ad) + Cd * (1-As)

所以Fs =(1-Ad) ? ? ? Fd =?(1-As)


Xor2 = SrcOver - SrcIn

= (Cs + Cd * ( 1 - As )) - (Cs*Ad)

= Cs + Cd - Cd * As - Cs*Ad

= Cs *(1-Ad)+ Cd *(1-As)

所以Fs =(1-Ad)Fd =?(1-As)


Xor3 = DstOut + SrcOut

=?Cd * ( 1 - As ) + ?Cs * ( 1 - Ad )

= Cs *(1-Ad)+ Cd *(1-As)

所以Fs =(1-Ad)Fd =?(1-As)


以上三種形式均可得出 ?Fs =(1-Ad)Fd =?(1-As) 。


Xor效果圖

以下混合模式大部分來自于流行圖像處理軟件中的模式,有關(guān)PhotoShop中模式的解讀,請移步 PS混合模式傳送門

10.Darken ?(變暗)

這個模式比較前景層和背景層的象素(或比較前景層或背景層的色彩通道),并將較暗的象素點(diǎn)( 即前景層和背景層相同位置處灰度值較小的 )放入輸出結(jié)果( 指兩個圖層混合后得到的結(jié)果 )中。Photoshop、Paint Shop Pro、PhotoLine 和 GIMP分別比較不同顏色通道中的象素,每個象素點(diǎn)相鄰的象素點(diǎn)不參與比較(即前景層的紅色通道和背景層的紅色通道進(jìn)行比較,其中灰度值較小的象素點(diǎn)將被保留到輸出結(jié)果的紅色通道中)。各個通道中,通過比較,灰度值較小的象素點(diǎn)將被保留下來,放入到輸出結(jié)果中。因此,象素混合在一起是很普遍的(輸出結(jié)果中,一個象素點(diǎn)的色階值可以看成是由RGB三個通道中對應(yīng)位置處象素點(diǎn)的灰度值確定的,而這RGB通道中的象素點(diǎn)有的來自前景層,有的來自背景層 ),例如,輸出結(jié)果中,紅色通道中的象素點(diǎn)來自于前景層,而其在綠色和藍(lán)色通道中的象素點(diǎn)則來自背景層。相反,Photo-Paint 同時(shí)比較三個通道中象素的灰度值,將三個通道中至少一個通道的灰度值最小的象素點(diǎn)保留到結(jié)果中,最終,所有的通道被轉(zhuǎn)換到輸出結(jié)果中(同時(shí)分別比較背景層和前景層的RGB通道,如果前景層R通道中某個象素點(diǎn)的灰度值,是六個通道中相應(yīng)位置處象素點(diǎn)灰度值最小的,則將前景層該位置處象素點(diǎn)的三個通道中對應(yīng)的象素點(diǎn)放入輸出結(jié)果的對應(yīng)通道中,即由一個通道中最暗的那個象素點(diǎn)來決定將那個層對應(yīng)位置處的象素點(diǎn)被保留到輸出結(jié)果中 )。當(dāng)兩個圖層的最小值相等的時(shí)候,使用前景圖層的數(shù)值。 還有第三種計(jì)算方式:Picture Publisher 和PhotoImpact 不是分開比較RGB值,而是比較它們的綜合灰度值(例如常用的[305911]計(jì)算方式), 和在Photo-Paint里一樣,最后的結(jié)果取前景圖層值或者背景圖層中象素的灰度值。

灰度值計(jì)算方法

任何顏色都有紅、綠、藍(lán)三原色組成,假如原來某點(diǎn)的顏色為RGB(R,G,B),那么,我們可以通過下面幾種方法,將其轉(zhuǎn)換為灰度:

1.浮點(diǎn)算法:Gray=R*0.3+G*0.59+B*0.11

2.整數(shù)方法:Gray=(R*30+G*59+B*11)/100

3.移位方法:Gray =(R*28+G*151+B*77)>>8;

4.平均值法:Gray=(R+G+B)/3;

5.僅取綠色:Gray=G;

Darken常用的幾種處理算法有

1)Cr = min(Cs,Cd); ? ?????????Ar = 1 ?

2) ?Cr = [ min(Cs-r,Cd-r), min(Cs-g,Cd-g),min(Cs-b,Cd-b)] ?????????Ar = 1 ??

3) ?Cr = Cs + Cd * ( 1 - As ) ,即SrcOver或DstOver ,其中,灰度值最小的像素作為Src在最上層,進(jìn)行混合處理(注意:不是整個圖層至于上方或下方,而是單個像素)。?

11.Lighten ?(變亮)

有關(guān)Lighten的算法,跟Darken是相反的,Lighten是獲取灰度比較亮的那個像素,所以根據(jù)上述Darken算法可以直接得出Lighten的算法

1)Cr = max(Cs,Cd);

2) ?Cr = [ max(Cs-r,Cd-r), max(Cs-g,Cd-g),max(Cs-b,Cd-b)]

3) ?Cr = Cs + Cd * ( 1 - As ) ,即SrcOver或DstOver ,其中,灰度值最大的像素作為Src在最上層,進(jìn)行混合處理(注意:不是整個圖層至于上方或下方,而是單個像素)。

12.Multiply (正片疊底)

將上下兩層圖層像素顏色進(jìn)行乘法計(jì)算,獲得灰度級更低的顏色而成為合成后的顏色,圖層合成后的效果簡單地說是低灰階的像素顯現(xiàn)而高灰階不顯現(xiàn)(即深色出現(xiàn),淺色不出現(xiàn),黑色灰度級為0,白色灰度級為255),該公式在pre-multiplied上討論。

Cr = Cs * Cd ; ? ? ? ?Ar = Ca * Da; ?

13.Screen ?(濾色)

首先把兩層圖像的像素值取互補(bǔ)數(shù),然后將它們相乘,最后再取互補(bǔ)數(shù)。這和正片疊底得到的結(jié)果是相反的。它會得到一個更亮的圖像,該公式在pre-multiplied上討論。

Cr = 1 - (1-Cs)(1-Cd) ? ? ? ? ? ? ? ? Ar = ?1 - (1-Ca)(1-Da)



14.(陸續(xù)補(bǔ)充,持續(xù)更新)


本文中示例的Demo已上傳GitHub,有興趣的同學(xué)可以下載看看。 Demo傳送門


(最近繁忙,暫時(shí)整理這么多,等閑了繼續(xù),本文持續(xù)更新,逐步添加其他效果的顏色合成原理及說明)

以下是PhotoShop中的一些官方定義的效果:(PS官方效果傳送門

Normal(正常)

Edits or paints each pixel to make it the result color. This is the default mode. (Normal mode is calledThresholdwhen you’re working with a bitmapped or indexed-color image.)

Dissolve(溶解)

Edits or paints each pixel to make it the result color. However, the result color is a random replacement of the pixels with the base color or the blend color, depending on the opacity at any pixel location.

Behind(背后)

Edits or paints only on the transparent part of a layer. This mode works only in layers with Lock Transparency deselected and is analogous to painting on the back of transparent areas on a sheet of acetate.

Clear(消除)

Edits or paints each pixel and makes it transparent. This mode is available for the Shape tools (when fill region?is selected), Paint Bucket tool, Brush tool, Pencil tool, Fill command, and Stroke command. You must be in a layer with Lock Transparency deselected to use this mode.

Darken(變暗)

(B > A) ? A : B

Looks at the color information in each channel and selects the base or blend color—whichever is darker—as the result color. Pixels lighter than the blend color are replaced, and pixels darker than the blend color do not change.

Multiply(正片疊底)

(A * B) / 255

Looks at the color information in each channel and multiplies the base color by the blend color. The result color is always a darker color. Multiplying any color with black produces black. Multiplying any color with white leaves the color unchanged. When you’re painting with a color other than black or white, successive strokes with a painting tool produce progressively darker colors. The effect is similar to drawing on the image with multiple marking pens.

Color Burn(顏色加深)

B == 0 ? B : max(0, (255 - ((255 - A) << 8 ) / B))

Looks at the color information in each channel and darkens the base color to reflect the blend color by increasing the contrast between the two. Blending with white produces no change.

Linear Burn(線性加深)

(A + B < 255) ? 0 : (A + B - 255)

Looks at the color information in each channel and darkens the base color to reflect the blend color by decreasing the brightness. Blending with white produces no change.

Lighten(變亮)

(B > A) ? B : A

Looks at the color information in each channel and selects the base or blend color—whichever is lighter—as the result color. Pixels darker than the blend color are replaced, and pixels lighter than the blend color do not change.

Screen(濾色)

255 - (((255 - A) * (255 - B)) >> 8))

Looks at each channel’s color information and multiplies the inverse of the blend and base colors. The result color is always a lighter color. Screening with black leaves the color unchanged. Screening with white produces white. The effect is similar to projecting multiple photographic slides on top of each other.

Color Dodge(顏色減淡)

(B == 255) ? B : min(255, ((A << 8 ) / (255 - B)))

Looks at the color information in each channel and brightens the base color to reflect the blend color by decreasing contrast between the two. Blending with black produces no change.

Linear Dodge (Add) (線性減淡)

min(255, (A + B))

Looks at the color information in each channel and brightens the base color to reflect the blend color by increasing the brightness. Blending with black produces no change.

Overlay(疊加)

(B < 128) ? (2 * A * B / 255):(255 - 2 * (255 - A) * (255 - B) / 255)

Multiplies or screens the colors, depending on the base color. Patterns or colors overlay the existing pixels while preserving the highlights and shadows of the base color. The base color is not replaced, but mixed with the blend color to reflect the lightness or darkness of the original color.

Soft Light(柔光)

B < 128 ? (2 * (( A >> 1) + 64)) * (B / 255) : (255 - ( 2 * (255 - ( (A >> 1) + 64 ) ) * ( 255 - B ) / 255 ));

Darkens or lightens the colors, depending on the blend color. The effect is similar to shining a diffused spotlight on the image. If the blend color (light source) is lighter than 50% gray, the image is lightened as if it were dodged. If the blend color is darker than 50% gray, the image is darkened as if it were burned in. Painting with pure black or white produces a distinctly darker or lighter area, but does not result in pure black or white.

Hard Light(強(qiáng)光)

Overlay(B,A) (A < 128) ? (2 * A * B / 255) : (255 - 2 * (255 - A) * (255 - B) / 255)

Multiplies or screens the colors, depending on the blend color. The effect is similar to shining a harsh spotlight on the image. If the blend color (light source) is lighter than 50% gray, the image is lightened, as if it were screened. This is useful for adding highlights to an image. If the blend color is darker than 50% gray, the image is darkened, as if it were multiplied. This is useful for adding shadows to an image. Painting with pure black or white results in pure black or white.

Vivid Light(亮光)

B < 128 ? ColorBurn(A,(2 * B)) : ColorDodge(A,(2 * (B - 128)))

Burns or dodges the colors by increasing or decreasing the contrast, depending on the blend color. If the blend color (light source) is lighter than 50% gray, the image is lightened by decreasing the contrast. If the blend color is darker than 50% gray, the image is darkened by increasing the contrast.

Linear Light(線性光)

min(255, max(0, ($B + 2 * $A) - 1))

Burns or dodges the colors by decreasing or increasing the brightness, depending on the blend color. If the blend color (light source) is lighter than 50% gray, the image is lightened by increasing the brightness. If the blend color is darker than 50% gray, the image is darkened by decreasing the brightness.

Pin Light(點(diǎn)光)

max(0, max(2 * B - 255, min(B, 2*A)))

Replaces the colors, depending on the blend color. If the blend color (light source) is lighter than 50% gray, pixels darker than the blend color are replaced, and pixels lighter than the blend color do not change. If the blend color is darker than 50% gray, pixels lighter than the blend color are replaced, and pixels darker than the blend color do not change. This is useful for adding special effects to an image.

Hard Mix(實(shí)色混合)

(VividLight(A,B) < 128) ? 0 : 255

Adds the red, green and blue channel values of the blend color to the RGB values of the base color. If the resulting sum for a channel is 255 or greater, it receives a value of 255; if less than 255, a value of 0. Therefore, all blended pixels have red, green, and blue channel values of either 0 or 255. This changes all pixels to primary additive colors (red, green, or blue), white, or black.

Difference(色差)

abs(A - B)

Looks at the color information in each channel and subtracts either the blend color from the base color or the base color from the blend color, depending on which has the greater brightness value. Blending with white inverts the base color values; blending with black produces no change.

Exclusion(排除)

A + B - 2 * A * B / 255

Creates an effect similar to but lower in contrast than the Difference mode. Blending with white inverts the base color values. Blending with black produces no change.

Subtract(減去)

(A + B < 255) ? 0 : (A + B - 255)

Looks at the color information in each channel and subtracts the blend color from the base color. In 8- and 16-bit images, any resulting negative values are clipped to zero.

Divide(劃分)

Looks at the color information in each channel and divides the blend color from the base color.

Hue(色相)

Creates a result color with the luminance and saturation of the base color and the hue of the blend color.

Saturation(飽和度)

Creates a result color with the luminance and hue of the base color and the saturation of the blend color. Painting with this mode in an area with no (0) saturation (gray) causes no change.

Color(顏色)

Creates a result color with the luminance of the base color and the hue and saturation of the blend color. This preserves the gray levels in the image and is useful for coloring monochrome images and for tinting color images.

Luminosity(明度)

Creates a result color with the hue and saturation of the base color and the luminance of the blend color. This mode creates the inverse effect of Color mode.

Lighter Color(亮色)

Compares the total of all channel values for the blend and base color and displays the higher value color. Lighter Color does not produce a third color, which can result from the Lighten blend, because it chooses the highest channel values from both the base and blend color to create the result color.

Darker Color(暗色)

Compares the total of all channel values for the blend and base color and displays the lower value color. Darker Color does not produce a third color, which can result from the Darken blend, because it chooses the lowest channel values from both the base and the blend color to create the result color.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容