色彩管理模組
允許透過色彩管理來操控顏色和資源。
此模組揭示 Color 一個類別,允許透過適當的色彩管理來表達顏色。 此 Color 物件被層堆疊 API 的不同介面使用,如 Fills 與 Uniform sources。
範例
import substance_painter as sp
# Open a project using legacy color management
# Get the currently displayed stack
stack = sp.textureset.get_active_stack()
# Define a color (web standard dark orange #ff8c00)
dark_orange_sRGB = sp.colormanagement.Color(
# r, g, b components in floating point format
1.0, 0.54902, 0.0,
# Specify r,g,b values are encoded in sRGB
sp.colormanagement.GenericColorSpace.sRGB)
dark_orange_linear = sp.colormanagement.Color(
# r, g, b components in floating point format
1.0, 0.26225, 0.0,
# Specify r,g,b values are encoded in working space (Linear sRGB in legacy mode)
sp.colormanagement.GenericColorSpace.Working)
# Here print the internal data of the colors. They should match what have been set above.
print('Internal color data:')
print(f' dark_orange_sRGB: {dark_orange_sRGB.value_raw}, {dark_orange_sRGB.color_space}')
print(f' dark_orange_linear: {dark_orange_linear.value_raw}, {dark_orange_linear.color_space}')
def _pretty_str(value):
return f'({value[0]:.5f}, {value[1]:.5f}, {value[2]:.5f})'
# Here use the Color object interface to access data encoded in working space.
# values should be equivalent to dark_orange_linear.value_raw
print('Linear color data:')
print(f' dark_orange_sRGB.working: {_pretty_str(dark_orange_sRGB.working)}')
print(f' dark_orange_sRGB.convert(working): {_pretty_str(dark_orange_sRGB.convert(sp.colormanagement.GenericColorSpace.Working))}')
print(f' dark_orange_linear.working: {_pretty_str(dark_orange_linear.working)}')
print(f' dark_orange_linear.value_raw: {_pretty_str(dark_orange_linear.value_raw)}')
# Here use the Color object interface to access data encoded in sRGB space.
# values should be equivalent to dark_orange_sRGB.value_raw
print('sRGB color data:')
print(f' dark_orange_sRGB.sRGB: {_pretty_str(dark_orange_sRGB.sRGB)}')
print(f' dark_orange_linear.sRGB: {_pretty_str(dark_orange_linear.sRGB)}')
print(f' dark_orange_linear.convert(sRGB): {_pretty_str(dark_orange_linear.convert(sp.colormanagement.GenericColorSpace.sRGB))}')
print(f' dark_orange_sRGB.value_raw: {_pretty_str(dark_orange_sRGB.value_raw)}')
def _insert_fill_with_uniform_basecolor(color):
position = sp.layerstack.InsertPosition.from_textureset_stack(stack)
fill = sp.layerstack.insert_fill(position)
fill.set_source(sp.textureset.ChannelType.BaseColor, color)
return fill
# Insert two fill layers with both colors above
fill_sRGB = _insert_fill_with_uniform_basecolor(dark_orange_sRGB)
fill_linear = _insert_fill_with_uniform_basecolor(dark_orange_linear)
# At this point you should have 2 fill layers inside your stack that look exactly the
# same with the same color visually.
# Additionaly, if you are not confortable with color spaces, you can create a Color object
# without specifying any color space. In this case the color space will be
# deduced depending on the context where this color is used (sRGB on color managed
# channels such as BaseColor, raw otherwise).
# sRGB is the most common color space used for computer screens, this is why many color pickers
# will give you sRGB data. sRGB is also the standard color space for the web, so a lot of color
# data you can get from the web will be sRGB encoded.
# This is why we assume sRGB for color managed channels.
# Since we need the context to deduce the color space, you can't use any methods that
# would do explicit color space conversion. Instead we exposed another flexible property.
# See the example below:
# Define a color (web standard dark orange #ff8c00)
dark_orange_no_colorspace = sp.colormanagement.Color(
# r, g, b components in floating point format
1.0, 0.54902, 0.0)
# Print assumed sRGB data and compare with the colors defined above with proper color space
print('sRGB color data for color with undefined color space:')
print(f' dark_orange_no_colorspace: {dark_orange_no_colorspace.value_raw}, {dark_orange_no_colorspace.color_space}')
print(f' dark_orange_no_colorspace.value: {_pretty_str(dark_orange_no_colorspace.value)}')
print(f' dark_orange_sRGB.sRGB: {_pretty_str(dark_orange_sRGB.sRGB)}')
print(f' dark_orange_linear.sRGB: {_pretty_str(dark_orange_linear.sRGB)}')
# The calls below would raise due to the lack of color space.
# print(f' dark_orange_no_colorspace.sRGB: {_pretty_str(dark_orange_no_colorspace.sRGB)}')
# print(f' dark_orange_no_colorspace.working: {_pretty_str(dark_orange_no_colorspace.working)}')
# print(f' dark_orange_no_colorspace.convert(working): {_pretty_str(dark_orange_no_colorspace.convert(sp.colormanagement.GenericColorSpace.Working)}')
# Insert a fill layer with the color with undefined color space
fill_no_colorspace = _insert_fill_with_uniform_basecolor(dark_orange_no_colorspace)
# At this point you should have 3 fill layers inside your stack that look exactly the
# same with the same color visually.
# Select the Fill layer
sp.layerstack.set_selected_nodes([fill_sRGB, fill_linear, fill_no_colorspace])
類別 substance_painter.colormanagement.Color(r: float, g: float, b: float, color_space: GenericColorSpace | str |None = None) substance_painter.colormanagement.Color
描述一種顏色(帶有色彩空間)。
如果你不熟悉色彩空間,可以在不指定資料色彩空間的情況下建立顏色。 在這種情況下,色彩空間會根據使用GenericColorSpace.sRGB 該顏色的情境推導出(在色彩管理通道中使用時,否則 GenericColorSpace.Raw )。
在色彩管理通道中,我們假設 sRGB 是因為它是電腦螢幕最常用的色彩空間,這也是為什麼許多色彩選擇器會提供 sRGB 資料。 sRGB 也是網頁的標準色彩空間,所以你從網路上取得的很多色彩資料都會被 sRGB 編碼。
由不同 API 存取者回傳的顏色物件,永遠會有定義的色彩空間。
變數:
- value_raw (元組 [ float**, float*,* float*])– 以彩色編碼的原始 r,g,b 資料,_space。
- color_space(GenericColorSpace*|* str)– 編碼值_raw的色彩空間。若無,則會根據使用該顏色
GenericColorSpace.sRGB的情境推導出(在色彩管理頻道中使用時,GenericColorSpace.Raw否則)。
參數:
- r (浮點)– 紅色分量
- g (浮點)– 綠色分量
- b (浮點)– 藍色分量
- color_space(GenericColorSpace*|* str)– 資料編碼的色彩空間。若未指定,則會根據顏色使用的
GenericColorSpace.sRGB情境推導(若用於色彩管理頻道GenericColorSpace.Raw,否則)(預設:無)。
convert(color_space: GenericColorSpace | str) -> 元組[浮點、浮點點數、浮點點數] substance_painter.colormanagement.Color.convert
取得編碼在給定色彩空間中的 r、g、b 值
參數:color_space (GenericColorSpace | str)– 你需要將資料編碼到的色彩空間。
回傳: 在給定色彩空間中編碼的 r、g、b 資料
回傳類型: 元組[浮點數(float float 浮點點數]
Raises:RuntimeError – 如果 Color.color_space 為 None
屬性值:元組[浮點數(float float 浮點數] substance_painter.colormanagement.Color.value
色彩值
Getter:
若 Color.color_space 定義為 ,則回傳 sRGB 編碼的顏色,若 未 GenericColorSpace.Raw定義,則返回 Color.value_raw。
類型: 元組[浮點,浮點,浮點]
屬性 sRGB:元組[浮點、浮點、浮點] substance_painter.colormanagement.Color.sRGB
sRGB 空間中的顏色值
Getter: 回傳以 sRGB 編碼的色彩值
設定器: 將色彩值設定為 sRGB 編碼值
類型: 元組[浮點,浮點,浮點]
Raises: RuntimeError: 如果 Color.color_space 是 None
屬性運作方式:元組[浮點,浮點點,浮點點] substance_painter.colormanagement.Color.working
工作空間中的色彩值
Getter: 回傳工作空間編碼的色彩值
設定器: 將色彩值設定為工作空間編碼值
類型: 元組[浮點,浮點,浮點]
Raises: RuntimeError: 如果 Color.color_space 是 None
ColorSpace 枚舉
以下枚舉說明 Substance Painter 所支援的不同預設色彩空間。
另外要注意,除了這些列舉外,如果你在專案中使用 OCIO 或 ACE 色彩管理引擎,也可以指定包含你設定中可用色彩空間名稱的純字串。
GenericColorSpace 而純字串則可以用來描述 are、g、b 資料是如何編碼 Color 的,或在呼叫 convert() 函式指定你想將資料轉換成哪個色彩空間時。
所有這些枚舉和純字串都可以用來存取或覆蓋 SourceBitmap 色彩空間。
class substance_painter.colormanagement.GenericColorSpace(value) substance_painter.colormanagement.GenericColorSpace
通用色彩空間適用於任何使用的任何色彩空間引擎。
可以用來取得 Color.color_space 資源。
成員:
sRGBWorkingRaw類別 substance_painter.colormanagement.LegacyColorSpace(value) substance_painter.colormanagement.LegacyColorSpace
舊有色彩空間。
不要用它們來覆蓋資源的色彩空間,要用GenericColorSpace.Working GenericColorSpace.sRGB或取代。
只能用來取得資源。 無法用於 Color.color_space。
成員:
LinearsRGBclass substance_painter.colormanagement.DataColorSpace(value) substance_painter.colormanagement.DataColorSpace
資料色彩空間。
用於非色彩管理通道(如金屬色或高度)的色彩空間。
只能用來取得資源。 無法用於 Color.color_space。
成員:
DataDataSignedclass substance_painter.colormanagement.NormalColorSpace(value) substance_painter.colormanagement.NormalColorSpace
正常的色彩空間。
用於正常通道的色彩空間,用以指定如何解讀正常資料。
只能用來取得資源。 無法用於 Color.color_space。
成員:
NormalXYZRightNormalXYZLeft