モノトーンの伝説日記

OBS Studio と Blackmagic Design が大好き。

<mini> PorterDuff についてのまとめ

 どこまで使えるか否か。

 Android との互換性を考えると,基本的な PorterDuffMode しか使えないなーという感じですね。

 WinObjC という Windows Runtime 上で動く iOS 互換環境の CoreGraphics でもおなじみのように,ほぼ全てのモードが Windows 上で使えます。唯一,「kCGBlendModePlusDarker」のみシミュレーションできませんね。

※ 表は横スクロールできます

Mode
Expression
Android
PorterDuff.Mode
Apple
CGBlendMode
Direct2D
D2D1_COMPOSITE_MODE
Direct2D
D2D1_BLEND_MODE
Clear
O = 0

(Software only: CLEAR)
kCGBlendModeClear × ×
SourceCopy
O = S
SRC kCGBlendModeCopy D2D1_COMPOSITE_MODE_SOURCE_COPY ×
DestinationCopy
O = D
DST × × ×
SourceOver
O = S + (1 - Sa) * D
SRC_OVER kCGBlendModeNormal D2D1_COMPOSITE_MODE_SOURCE_OVER ×
DestinationOver
O = (1 - Da) * S + D
DST_OVER kCGBlendModeDestinationOver D2D1_COMPOSITE_MODE_DESTINATION_OVER ×
SourceIn
O = Da * S
SRC_IN kCGBlendModeSourceIn D2D1_COMPOSITE_MODE_SOURCE_IN ×
DestinationIn
O = Sa * D
DST_IN kCGBlendModeDestinationIn D2D1_COMPOSITE_MODE_DESTINATION_IN ×
SourceOut
O = (1 - Da) * S
SRC_OUT kCGBlendModeSourceOut D2D1_COMPOSITE_MODE_SOURCE_OUT ×
DestinationOut
O = (1 - Sa) * D
DST_OUT kCGBlendModeDestinationOut D2D1_COMPOSITE_MODE_DESTINATION_OUT ×
SourceAtop
O = Da * S + (1 - Sa) * D
SRC_ATOP kCGBlendModeSourceAtop D2D1_COMPOSITE_MODE_SOURCE_ATOP ×
DestinationAtop
O = (1 - Da) * S + Sa * D
DST_ATOP kCGBlendModeDestinationAtop D2D1_COMPOSITE_MODE_DESTINATION_ATOP ×
Xor
O = (1 - Da) * S + (1 - Sa) * D
XOR
(kCGBlendModeXOR)
D2D1_COMPOSITE_MODE_XOR ×
Add
O = min(1, S + D)
ADD kCGBlendModePlusLighter D2D1_COMPOSITE_MODE_PLUS ×
PlusDarker
O = max(0, 1 - (1 - S) - (1 - D))
× kCGBlendModePlusDarker × ×
BoundedSourceCopy
O = S (範囲内のみ)
× × D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY ×
MaskInvert
O = (1 - D) * S + (1 - Sa) * D
× × D2D1_COMPOSITE_MODE_MASK_INVERT ×
? × × D2D1_COMPOSITE_MODE_FORCE_DWORD D2D1_BLEND_MODE_FORCE_DWORD
Darken
O = (1 - Da) * S + (1 - Sa) * D + min(S, D)

(Software only: DARKEN)
kCGBlendModeDarken × D2D1_BLEND_MODE_DARKEN
Lighten
O = (1 - Da) * S + (1 - Sa) * D + max(S, D)

(Software only: LIGHTEN)
kCGBlendModeLighten × D2D1_BLEND_MODE_LIGHTEN
Multiply
O = S * D
MULTIPLY kCGBlendModeMultiply × D2D1_BLEND_MODE_MULTIPLY
Screen
O = S + D - (S * D)
SCREEN kCGBlendModeScreen × D2D1_BLEND_MODE_SCREEN
Overlay
O = 2 * Sa * Da * S * D - 2 * (Da - S) * (Sa - D)

(Software only: OVERLAY)
kCGBlendModeOverlay × D2D1_BLEND_MODE_OVERLAY
ColorDodge × kCGBlendModeColorDodge × D2D1_BLEND_MODE_COLOR_DODGE
LinearDodge × × × D2D1_BLEND_MODE_LINEAR_DODGE
ColorBurn × kCGBlendModeColorBurn × D2D1_BLEND_MODE_COLOR_BURN
LinearBurn × × × D2D1_BLEND_MODE_LINEAR_BURN
DarkerColor × × × D2D1_BLEND_MODE_DARKER_COLOR
LighterColor × × × D2D1_BLEND_MODE_LIGHTER_COLOR
SoftLight × kCGBlendModeSoftLight × D2D1_BLEND_MODE_SOFT_LIGHT
HardLight × kCGBlendModeHardLight × D2D1_BLEND_MODE_HARD_LIGHT
Vivid × × × D2D1_BLEND_MODE_VIVID_LIGHT
LinearLight × × × D2D1_BLEND_MODE_LINEAR_LIGHT
PinLight × × × D2D1_BLEND_MODE_PIN_LIGHT
HardMix × × × D2D1_BLEND_MODE_HARD_MIX
Difference × kCGBlendModeDifference × D2D1_BLEND_MODE_DIFFERENCE
Exculusion × kCGBlendModeExclusion × D2D1_BLEND_MODE_EXCLUSION
Hue × kCGBlendModeHue × D2D1_BLEND_MODE_HUE
Saturation × kCGBlendModeSaturation × D2D1_BLEND_MODE_SATURATION
Color × kCGBlendModeColor × D2D1_BLEND_MODE_COLOR
Luminosity × kCGBlendModeLuminosity × D2D1_BLEND_MODE_LUMINOSITY
Subtract × kCGBlendModeLuminosity × D2D1_BLEND_MODE_SUBTRACT
Dissolve × × × D2D1_BLEND_MODE_DISSOLVE

参考用

SetROP2 関数

docs.microsoft.com

docs.microsoft.com

PorterDuff.Mode  |  Android Developers

tech.recruit-mp.co.jp

CGBlendMode - Core Graphics | Apple Developer Documentation

https://skia.org/user/api/skpaint_overview

CoreGraphics の Windows 実装向けの CGContext.h

WinObjC/CGContext.h at master · Microsoft/WinObjC · GitHub