-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-148330: Add docstrings to module colorsys in all functions #148332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,12 +38,21 @@ | |||||||
| # The ones in this library uses constants from the FCC version of NTSC. | ||||||||
|
|
||||||||
| def rgb_to_yiq(r, g, b): | ||||||||
| """Convert RGB to YIQ. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| r, g, b are in [0, 1]. | ||||||||
| Return (y, i, q) where y is in [0, 1]. | ||||||||
| """ | ||||||||
| y = 0.30*r + 0.59*g + 0.11*b | ||||||||
| i = 0.74*(r-y) - 0.27*(b-y) | ||||||||
| q = 0.48*(r-y) + 0.41*(b-y) | ||||||||
| return (y, i, q) | ||||||||
|
|
||||||||
| def yiq_to_rgb(y, i, q): | ||||||||
| """Convert YIQ to RGB. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| Return (r, g, b) in [0, 1]. | ||||||||
| """ | ||||||||
| # r = y + (0.27*q + 0.41*i) / (0.74*0.41 + 0.27*0.48) | ||||||||
| # b = y + (0.74*q - 0.48*i) / (0.74*0.41 + 0.27*0.48) | ||||||||
| # g = y - (0.30*(r-y) + 0.11*(b-y)) / 0.59 | ||||||||
|
|
@@ -73,6 +82,11 @@ def yiq_to_rgb(y, i, q): | |||||||
| # S: color saturation | ||||||||
|
|
||||||||
| def rgb_to_hls(r, g, b): | ||||||||
| """Convert RGB to HLS (Hue, Lightness, Saturation). | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| r, g, b are in [0, 1]. | ||||||||
| Return (h, l, s) in [0, 1]. | ||||||||
| """ | ||||||||
| maxc = max(r, g, b) | ||||||||
| minc = min(r, g, b) | ||||||||
| sumc = (maxc+minc) | ||||||||
|
|
@@ -97,6 +111,11 @@ def rgb_to_hls(r, g, b): | |||||||
| return h, l, s | ||||||||
|
|
||||||||
| def hls_to_rgb(h, l, s): | ||||||||
| """Convert HLS (Hue, Lightness, Saturation) to RGB. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| h, l, s are in [0, 1]. | ||||||||
| Return (r, g, b) in [0, 1]. | ||||||||
| """ | ||||||||
| if s == 0.0: | ||||||||
| return l, l, l | ||||||||
| if l <= 0.5: | ||||||||
|
|
@@ -123,6 +142,11 @@ def _v(m1, m2, hue): | |||||||
| # V: color brightness | ||||||||
|
|
||||||||
| def rgb_to_hsv(r, g, b): | ||||||||
| """Convert RGB to HSV (Hue, Saturation, Value). | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| r, g, b are in [0, 1]. | ||||||||
| Return (h, s, v) in [0, 1]. | ||||||||
| """ | ||||||||
| maxc = max(r, g, b) | ||||||||
| minc = min(r, g, b) | ||||||||
| rangec = (maxc-minc) | ||||||||
|
|
@@ -143,6 +167,11 @@ def rgb_to_hsv(r, g, b): | |||||||
| return h, s, v | ||||||||
|
|
||||||||
| def hsv_to_rgb(h, s, v): | ||||||||
| """Convert HSV (Hue, Saturation, Value) to RGB. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| h, s, v are in [0, 1]. | ||||||||
| Return (r, g, b) in [0, 1]. | ||||||||
| """ | ||||||||
| if s == 0.0: | ||||||||
| return v, v, v | ||||||||
| i = int(h*6.0) # XXX assume int() truncates! | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but just to clean it up a little more, just put the string next to the start of the doctoring on another line. For example:
Instead of
It becomes
And this change would apply to the other lines that follow this pattern as well.