Skip to content

Commit 29e2140

Browse files
committed
⚗️ --colorful
1 parent 3ad828c commit 29e2140

2 files changed

Lines changed: 10 additions & 35 deletions

File tree

src/badapple/__main__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
type=float
7070
)
7171

72+
parser.add_argument(
73+
'--colorful',
74+
help='RGB with ANSI (Experimental)',
75+
action='store_true'
76+
)
7277
parser.add_argument(
7378
'--not_clear',
7479
help='not clear screen (with ANSI) before each frame',
@@ -116,7 +121,7 @@
116121
p_list=p_list,
117122
video=video, output=a.output,
118123
font=a.font, audio=audio, player=player,
119-
x=x, y=y, fps=a.rate,
124+
x=x, y=y, fps=a.rate, colorful=a.colorful,
120125
need_clear=need_clear, contrast=a.contrast, preload=a.preload,
121126
debug=a.debug
122127
)

src/badapple/play.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,17 @@
11
import os
22
import cv2
3-
import numpy as np
43

54
from .util import get_func, Timer, Font
65
from .audio import get_player
76
from .replay import replay
8-
9-
10-
def get_buffer(
11-
fnt: Font, img: np.ndarray,
12-
x: int, y: int,
13-
contrast: bool = False,
14-
):
15-
img = cv2.resize(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), (x, y))
16-
# ndarray(shape=(y, x), dtype=np.uint8)
17-
18-
if contrast:
19-
max_pixel = np.max(img)
20-
min_pixel = np.min(img)
21-
if max_pixel == min_pixel:
22-
if max_pixel >= 128:
23-
img = np.full((y, x), 0xff, dtype=np.uint8)
24-
else:
25-
img = np.zeros((y, x), dtype=np.uint8)
26-
else:
27-
max_min = max_pixel - min_pixel
28-
img = (((img.astype(dtype=np.uint16) - min_pixel) * 0xff +
29-
max_min // 2) // max_min).astype(dtype=np.uint8)
30-
31-
buffer = ''
32-
for j in range(y//2):
33-
for k in range(x):
34-
buffer += fnt.get(img[j*2, k], img[j*2+1, k])
35-
buffer += '\n'
36-
37-
return buffer
7+
from .frame2str import get_buffer
388

399

4010
def play(
4111
p_list: list,
4212
video: str, output: str,
4313
font: str, audio: str, player: str,
44-
x: int, y: int, fps: int,
14+
x: int, y: int, fps: int, colorful: bool = False,
4515
need_clear: bool = True, contrast: bool = False, preload: bool = False,
4616
debug: bool = False
4717
) -> None:
@@ -126,7 +96,7 @@ def play(
12696
raise Exception(i)
12797
if i % mo:
12898
continue
129-
buffer = get_buffer(fnt, img, x, y, contrast)
99+
buffer = get_buffer(fnt, img, x, y, colorful, contrast)
130100

131101
fp.write(buffer + '\n')
132102
fp.flush()
@@ -154,7 +124,7 @@ def play(
154124
raise Exception(i)
155125
if i % mo:
156126
continue
157-
buffer = get_buffer(fnt, img, x, y, contrast)
127+
buffer = get_buffer(fnt, img, x, y, colorful, contrast)
158128

159129
rewind()
160130
print(buffer, end='', flush=True)

0 commit comments

Comments
 (0)