-
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.
Merge pull request #63 from VincentAuriau/dev/illus
ADD: possibility to change colors
- Loading branch information
Showing
26 changed files
with
658 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ venv/ | |
.idea/ | ||
.DS_Store | ||
__pycache__/ | ||
.pstats | ||
*.egg-info/ | ||
dist/ | ||
settings.py |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,205 @@ | ||
import numpy as np | ||
from PIL import Image | ||
|
||
from settings import settings | ||
|
||
|
||
class ColorEditor(object): | ||
def __init__( | ||
self, | ||
white_cell, | ||
down_white_cell, | ||
black_cell, | ||
down_black_cell, | ||
white_piece_fill, | ||
white_piece_border, | ||
black_piece_fill, | ||
black_piece_border, | ||
): | ||
self.white_cell = white_cell | ||
self.down_white_cell = down_white_cell | ||
self.black_cell = black_cell | ||
self.down_black_cell = down_black_cell | ||
self.white_piece_fill = white_piece_fill | ||
self.white_piece_border = white_piece_border | ||
self.black_piece_fill = black_piece_fill | ||
self.black_piece_border = black_piece_border | ||
|
||
def get_edited_black_cell(self): | ||
return np.array([[self.black_cell] * 64] * 64), np.array( | ||
[[self.down_black_cell] * 64] * 64 | ||
) | ||
|
||
def get_edited_white_cell(self): | ||
return np.array([[self.white_cell] * 64] * 64), np.array( | ||
[[self.down_white_cell] * 64] * 64 | ||
) | ||
|
||
def get_edited_black_material(self, material_type, cell_color): | ||
if cell_color == "black": | ||
cell_color = self.black_cell | ||
else: | ||
cell_color = self.white_cell | ||
|
||
image = Image.open(settings["grayscale_images"][material_type]) | ||
r_map = { | ||
0: cell_color[0], | ||
128: self.black_piece_fill[0], | ||
255: self.black_piece_border[0], | ||
} | ||
g_map = { | ||
0: cell_color[1], | ||
128: self.black_piece_fill[1], | ||
255: self.black_piece_border[1], | ||
} | ||
b_map = { | ||
0: cell_color[2], | ||
128: self.black_piece_fill[2], | ||
255: self.black_piece_border[2], | ||
} | ||
|
||
edited_img = np.array(image) | ||
edited_img = np.dstack( | ||
[ | ||
np.vectorize(r_map.get)(edited_img), | ||
np.vectorize(g_map.get)(edited_img), | ||
np.vectorize(b_map.get)(edited_img), | ||
] | ||
) | ||
|
||
if cell_color == "black": | ||
cell_color = self.down_black_cell | ||
else: | ||
cell_color = self.down_white_cell | ||
|
||
r_map = { | ||
0: cell_color[0], | ||
128: self.black_piece_fill[0], | ||
255: self.black_piece_border[0], | ||
} | ||
g_map = { | ||
0: cell_color[1], | ||
128: self.black_piece_fill[1], | ||
255: self.black_piece_border[1], | ||
} | ||
b_map = { | ||
0: cell_color[2], | ||
128: self.black_piece_fill[2], | ||
255: self.black_piece_border[2], | ||
} | ||
|
||
down_edited_img = np.array(image) | ||
down_edited_img = np.dstack( | ||
[ | ||
np.vectorize(r_map.get)(edited_img), | ||
np.vectorize(g_map.get)(edited_img), | ||
np.vectorize(b_map.get)(edited_img), | ||
] | ||
) | ||
|
||
return edited_img, down_edited_img | ||
|
||
def get_edited_white_material(self, material_type, cell_color): | ||
if cell_color == "black": | ||
cell_color = self.black_cell | ||
else: | ||
cell_color = self.white_cell | ||
|
||
image = Image.open(settings["grayscale_images"][material_type]) | ||
r_map = { | ||
0: cell_color[0], | ||
128: self.white_piece_fill[0], | ||
255: self.white_piece_border[0], | ||
} | ||
g_map = { | ||
0: cell_color[1], | ||
128: self.white_piece_fill[1], | ||
255: self.white_piece_border[1], | ||
} | ||
b_map = { | ||
0: cell_color[2], | ||
128: self.white_piece_fill[2], | ||
255: self.white_piece_border[2], | ||
} | ||
|
||
edited_img = np.array(image) | ||
edited_img = np.dstack( | ||
[ | ||
np.vectorize(r_map.get)(edited_img), | ||
np.vectorize(g_map.get)(edited_img), | ||
np.vectorize(b_map.get)(edited_img), | ||
] | ||
) | ||
|
||
if cell_color == "black": | ||
cell_color = self.down_black_cell | ||
else: | ||
cell_color = self.down_white_cell | ||
|
||
r_map = { | ||
0: cell_color[0], | ||
128: self.white_piece_fill[0], | ||
255: self.white_piece_border[0], | ||
} | ||
g_map = { | ||
0: cell_color[1], | ||
128: self.white_piece_fill[1], | ||
255: self.white_piece_border[1], | ||
} | ||
b_map = { | ||
0: cell_color[2], | ||
128: self.white_piece_fill[2], | ||
255: self.white_piece_border[2], | ||
} | ||
|
||
down_edited_img = np.array(image) | ||
down_edited_img = np.dstack( | ||
[ | ||
np.vectorize(r_map.get)(edited_img), | ||
np.vectorize(g_map.get)(edited_img), | ||
np.vectorize(b_map.get)(edited_img), | ||
] | ||
) | ||
|
||
return edited_img | ||
|
||
def generate_all_images(self, path="temp_illustrations"): | ||
b, down_b = self.get_edited_black_cell() | ||
Image.from_array(b).save(os.path.join(path, "b.png")) | ||
Image.from_array(down_b).save(os.path.join(path, "down_b.png")) | ||
w, down_w = self.get_edited_black_cell() | ||
Image.from_array(w).save(os.path.join(path, "w.png")) | ||
Image.from_array(down_w).save(os.path.join(path, "down_w.png")) | ||
for piece in ["pawn", "bishop", "knight", "rook", "king", "queen"]: | ||
wb_p, down_wb_p = self.get_edited_black_material( | ||
material_type=piece, cell_color="white" | ||
) | ||
bb_p, down_bb_p = self.get_edited_black_material( | ||
material_type=piece, cell_color="black" | ||
) | ||
ww_p, down_ww_p = self.get_edited_white_material( | ||
material_type=piece, cell_color="white" | ||
) | ||
bw_p, down_bw_p = self.get_edited_white_material( | ||
material_type=piece, cell_color="black" | ||
) | ||
prefix = "N" if piece == "knight" else piece[0].upper() | ||
Image.from_array(wb_p).save(os.path.join(path, f"wb_{prefix}.png")) | ||
Image.from_array(down_wb_p).save( | ||
os.path.join(path, f"down_wb_{prefix}.png") | ||
) | ||
|
||
Image.from_array(bb_p).save(os.path.join(path, f"bb_{prefix}.png")) | ||
Image.from_array(down_bb_p).save( | ||
os.path.join(path, f"down_bb_{prefix}.png") | ||
) | ||
|
||
Image.from_array(ww_p).save(os.path.join(path, f"ww_{prefix}.png")) | ||
Image.from_array(down_ww_p).save( | ||
os.path.join(path, f"down_ww_{prefix}.png") | ||
) | ||
|
||
Image.from_array(bw_p).save(os.path.join(path, f"bw_{prefix}.png")) | ||
Image.from_array(down_bw_p).save( | ||
os.path.join(path, f"down_bw_{prefix}.png") | ||
) |
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,147 @@ | ||
import argparse | ||
import os | ||
|
||
from PIL import Image | ||
import numpy as np | ||
|
||
|
||
def color_one_img(pil_img, background_color, border_color, inner_color): | ||
img = np.array(pil_img) | ||
x_min = np.min(np.where(img == 255)[0]) | ||
x_max = np.max(np.where(img == 255)[0]) | ||
img = img[x_min:x_max] | ||
|
||
r_dict = {0: background_color[0], 128: inner_color[0], 255: border_color[0]} | ||
g_dict = {0: background_color[1], 128: inner_color[1], 255: border_color[1]} | ||
b_dict = {0: background_color[2], 128: inner_color[2], 255: border_color[2]} | ||
|
||
img = [ | ||
np.vectorize(r_dict.get)(img), | ||
np.vectorize(g_dict.get)(img), | ||
np.vectorize(b_dict.get)(img), | ||
] | ||
img = np.dstack(img) | ||
|
||
img = Image.fromarray(img.astype("uint8")) | ||
|
||
img = img.resize((int(img.size[0] / img.size[1] * 450), 450)) | ||
|
||
x_coordinate = int((500 - img.size[0]) / 2) | ||
y_coordinate = 25 | ||
|
||
background = np.dstack( | ||
[np.ones((500, 500)) * background_color[i] for i in range(3)] | ||
).astype("uint8") | ||
background = Image.fromarray(background) | ||
background.paste(img, (x_coordinate, y_coordinate)) | ||
return background | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-ccb", "--color_cell_black", nargs="+") | ||
parser.add_argument("-ccw", "--color_cell_white", nargs="+") | ||
|
||
parser.add_argument("-ibp", "--inner_black_piece", nargs="+") | ||
parser.add_argument("-obp", "--outer_black_piece", nargs="+") | ||
|
||
parser.add_argument("-iwp", "--inner_white_piece", nargs="+") | ||
parser.add_argument("-owp", "--outer_white_piece", nargs="+") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.color_cell_black is None: | ||
color_cell_b = [0, 191, 255] | ||
else: | ||
color_cell_b = [int(i) for i in args.color_cell_black] | ||
|
||
if args.color_cell_white is None: | ||
color_cell_w = [207, 185, 151] | ||
else: | ||
color_cell_w = [int(i) for i in args.color_cell_white] | ||
|
||
if args.inner_black_piece is None: | ||
inner_color_b = [109, 7, 26] | ||
else: | ||
inner_color_b = [int(i) for i in args.inner_black_piece] | ||
if args.outer_black_piece is None: | ||
border_color_b = [0, 0, 0] | ||
else: | ||
border_color_b = [int(i) for i in args.outer_black_piece] | ||
|
||
if args.inner_white_piece is None: | ||
inner_color_w = [200, 200, 200] | ||
else: | ||
inner_color_w = [int(i) for i in args.inner_white_piece] | ||
if args.outer_white_piece is None: | ||
border_color_w = [255, 255, 255] | ||
else: | ||
border_color_w = [int(i) for i in args.outer_white_piece] | ||
|
||
down_color_cell_b = np.clip(np.array(color_cell_b) - 70, 0, 255) | ||
down_color_cell_w = np.clip(np.array(color_cell_w) - 70, 0, 255) | ||
|
||
for img_name in os.listdir("../gs_illustrations"): | ||
img = Image.open(os.path.join("../gs_illustrations", img_name)) | ||
img_bb = color_one_img(img, color_cell_b, border_color_b, inner_color_b) | ||
img_ww = color_one_img(img, color_cell_w, border_color_w, inner_color_w) | ||
img_wb = color_one_img(img, color_cell_w, border_color_b, inner_color_b) | ||
img_bw = color_one_img(img, color_cell_b, border_color_w, inner_color_w) | ||
|
||
down_img_bb = color_one_img( | ||
img, down_color_cell_b, border_color_b, inner_color_b | ||
) | ||
down_img_ww = color_one_img( | ||
img, down_color_cell_w, border_color_w, inner_color_w | ||
) | ||
down_img_wb = color_one_img( | ||
img, down_color_cell_w, border_color_b, inner_color_b | ||
) | ||
down_img_bw = color_one_img( | ||
img, down_color_cell_b, border_color_w, inner_color_w | ||
) | ||
|
||
name = img_name.split("_")[0] | ||
name = { | ||
"pawn": "P", | ||
"bishop": "B", | ||
"knight": "N", | ||
"rook": "R", | ||
"queen": "Q", | ||
"king": "K", | ||
}[name] | ||
img_bb.save(os.path.join("../temp_images", f"bb_{name}.png")) | ||
img_bw.save(os.path.join("../temp_images", f"bw_{name}.png")) | ||
img_wb.save(os.path.join("../temp_images", f"wb_{name}.png")) | ||
img_ww.save(os.path.join("../temp_images", f"ww_{name}.png")) | ||
|
||
down_img_bb.save(os.path.join("../temp_images", f"down_bb_{name}.png")) | ||
down_img_bw.save(os.path.join("../temp_images", f"down_bw_{name}.png")) | ||
down_img_wb.save(os.path.join("../temp_images", f"down_wb_{name}.png")) | ||
down_img_ww.save(os.path.join("../temp_images", f"down_ww_{name}.png")) | ||
|
||
bg_w = Image.fromarray( | ||
np.dstack([np.ones((500, 500)) * color_cell_w[i] for i in range(3)]).astype( | ||
"uint8" | ||
) | ||
) | ||
bg_w.save(os.path.join("../temp_images", "w.png")) | ||
bg_b = Image.fromarray( | ||
np.dstack([np.ones((500, 500)) * color_cell_b[i] for i in range(3)]).astype( | ||
"uint8" | ||
) | ||
) | ||
bg_b.save(os.path.join("../temp_images", "b.png")) | ||
|
||
down_bg_w = Image.fromarray( | ||
np.dstack( | ||
[np.ones((500, 500)) * down_color_cell_w[i] for i in range(3)] | ||
).astype("uint8") | ||
) | ||
down_bg_w.save(os.path.join("../temp_images", "down_w.png")) | ||
down_bg_b = Image.fromarray( | ||
np.dstack( | ||
[np.ones((500, 500)) * down_color_cell_b[i] for i in range(3)] | ||
).astype("uint8") | ||
) | ||
down_bg_b.save(os.path.join("../temp_images", "down_b.png")) |
Oops, something went wrong.