Created
April 23, 2022 13:23
-
-
Save HenkPoley/5bb75c7b9802969d3c0b30163a01a6ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/local/bin/python3 | |
import png # pip3 install pypng | |
import colorsys # h_ue,s_aturation,v_alue | |
filename = "rainbow.png" | |
# MacBook1,1 - MacBook7,1: 1280x800 | |
# iMac 27" 5K: 5120x2880 | |
# borderless A4 @ 600ppi: 4960x7016 -> https://www.papersizes.org/a-sizes-in-pixels.htm | |
# AllRGB size: 4096x4096 | |
info = { | |
"width": 4096, | |
"height": 4096, | |
"bitdepth": 8 | |
} | |
channel_max = pow(2, info["bitdepth"]) - 1 | |
rows = list() | |
halfway = int(info["height"] / 2) | |
for y in range(0, halfway): | |
row = [] | |
saturation = 2.0 * float(y) / float(info["height"]) | |
for x in range(0, info["width"]): | |
for channel in colorsys.hsv_to_rgb(float(x)/info["width"], saturation, 1.0): | |
row.append(int(round(channel * channel_max))) | |
rows.append(row) | |
for y in range(halfway, info["height"]): | |
row = [] | |
value = 2.0 * (1.0 - (float(y) / float(info["height"]))) | |
for x in range(0, info["width"]): | |
for channel in colorsys.hsv_to_rgb(float(x)/info["width"], 1.0, value): | |
row.append(int(round(channel * channel_max))) | |
rows.append(row) | |
my_png = png.Image(rows, info) | |
my_png.save(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used to generate these Granger Rainbow's:
Posted publicly because Fulvio Baccaglini asked nicely. His image is here: https://www.flickr.com/photos/185533101@N05/51488653555/
A Granger Rainbow is a test image that shows any smoothness problems in the color handling of your system. If you have a very high end display or printer it should look smooth. Usually you will see bands on clumps when certain colours cannot be represented.
8 bit per color channel means this is only just regular computer RGB. The files don't define a color space. So usually it will attempt to 'hang' the image as some ideal RGB color space, or just stretch it among your system's full range.