Skip to content

Commit

Permalink
fix(nuke): ColorReplace: should use sRGB color in autolabel
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Oct 24, 2023
1 parent f7e192d commit c9d1ae1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
23 changes: 17 additions & 6 deletions plugins/Color/ColorReplace.gizmo
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ Group {
name ColorReplace1
tile_color 0x7aa9ffff
onCreate {
class __ColorReplace_f6d7a71b4413:
class __ColorReplace_0d3e34f43027:
_COLOR_COUNT = 16

@classmethod
def _linear_to_srgb(cls, v):
if v <= 0.0:
return 0.0
elif v >= 1:
return 1.0
elif v < 0.0031308:
return v * 12.92
else:
return v ** (1 / 2.4) * 1.055 - 0.055

@classmethod
def _hex_color(cls, color):
return "#" + "".join(("%02X" % max(0, min(255, round(i*255))) for i in color))
return "#" + "".join(("%02X" % int(cls._linear_to_srgb(i)*255)) for i in color)

@classmethod
def _color(cls, index):
Expand Down Expand Up @@ -64,11 +75,11 @@ class __ColorReplace_f6d7a71b4413:
continue
k.setVisible(visible)

__ColorReplace_f6d7a71b4413.update_ui()
__ColorReplace_0d3e34f43027.update_ui()
}
autolabel __ColorReplace_f6d7a71b4413.autolabel()
updateUI __ColorReplace_f6d7a71b4413.update_ui()
addUserKnob {20 ColorReplace l "ColorReplace v0.1.2"}
autolabel __ColorReplace_0d3e34f43027.autolabel()
updateUI __ColorReplace_0d3e34f43027.update_ui()
addUserKnob {20 ColorReplace l "ColorReplace v0.1.3"}
addUserKnob {26 color1 l "" +STARTLINE T color1}
addUserKnob {1 label1 l "" -STARTLINE}
addUserKnob {41 src1 l src T Expression1.src}
Expand Down
1 change: 1 addition & 0 deletions wulifang/_util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
from ._clamp import clamp
from ._hex_color import hex_color
from ._iter_chunk import iter_chunk
from ._linear_to_srgb import linear_to_srgb
17 changes: 17 additions & 0 deletions wulifang/_util/_linear_to_srgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals


def linear_to_srgb(__v):
# type: (float) -> float
# https://www.nayuki.io/res/srgb-transform-library/srgbtransform.py
if __v <= 0.0:
return 0.0
elif __v >= 1:
return 1.0
elif __v < 0.0031308:
return __v * 12.92
else:
return __v ** (1 / 2.4) * 1.055 - 0.055

0 comments on commit c9d1ae1

Please sign in to comment.