-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.6.1 color_temperature step size == 1
lookup tables are boring
- Loading branch information
=
committed
Sep 7, 2023
1 parent
5e39bef
commit 459b874
Showing
8 changed files
with
136 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import math | ||
|
||
|
||
# @see https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html | ||
def apply_color_temperature(color, color_temperature) -> tuple: | ||
if color_temperature == 6600: | ||
return color | ||
|
||
factor_red = 255 if color_temperature <= 6600 \ | ||
else 329.698727446 * ((color_temperature / 100 - 60) ** -0.1332047592) | ||
factor_green = 99.4708025861 * math.log(color_temperature / 100) - 161.1195681661 if color_temperature <= 6600 \ | ||
else 288.1221695283 * ((color_temperature / 100 - 60) ** -0.0755148492) | ||
factor_blue = 255 if color_temperature >= 6600 else 0 if color_temperature <= 1900 \ | ||
else 138.5177312231 * math.log(color_temperature / 100 - 10) - 305.0447927307 | ||
|
||
factor_red = 0 if factor_red < 0 else 255 if factor_red > 255 else factor_red | ||
factor_green = 0 if factor_green < 0 else 255 if factor_green > 255 else factor_green | ||
factor_blue = 0 if factor_blue < 0 else 255 if factor_blue > 255 else factor_blue | ||
|
||
r, g, b = color | ||
return ( | ||
r * (factor_red / 255.0), | ||
g * (factor_green / 255.0), | ||
b * (factor_blue / 255.0) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from PIL import ImageStat | ||
import math | ||
|
||
|
||
def get_brightness(im, br_mode, color): | ||
if br_mode == "dominant": | ||
r, g, b = color | ||
return (r + g + b) / 3 | ||
|
||
if br_mode == "natural": | ||
stat = ImageStat.Stat(im) | ||
r, g, b = stat.mean | ||
return math.sqrt(0.241 * (r ** 2) + 0.691 * (g ** 2) + 0.068 * (b ** 2)) | ||
|
||
if br_mode == "rms": | ||
stat = ImageStat.Stat(im.convert('L')) | ||
return stat.rms[0] | ||
|
||
# mean | ||
stat = ImageStat.Stat(im.convert('L')) | ||
return stat.mean[0] |
Oops, something went wrong.