|
1 | 1 | import os |
2 | 2 | import cv2 |
3 | | -import numpy as np |
4 | 3 |
|
5 | 4 | from .util import get_func, Timer, Font |
6 | 5 | from .audio import get_player |
7 | 6 | 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 |
38 | 8 |
|
39 | 9 |
|
40 | 10 | def play( |
41 | 11 | p_list: list, |
42 | 12 | video: str, output: str, |
43 | 13 | font: str, audio: str, player: str, |
44 | | - x: int, y: int, fps: int, |
| 14 | + x: int, y: int, fps: int, colorful: bool = False, |
45 | 15 | need_clear: bool = True, contrast: bool = False, preload: bool = False, |
46 | 16 | debug: bool = False |
47 | 17 | ) -> None: |
@@ -126,7 +96,7 @@ def play( |
126 | 96 | raise Exception(i) |
127 | 97 | if i % mo: |
128 | 98 | continue |
129 | | - buffer = get_buffer(fnt, img, x, y, contrast) |
| 99 | + buffer = get_buffer(fnt, img, x, y, colorful, contrast) |
130 | 100 |
|
131 | 101 | fp.write(buffer + '\n') |
132 | 102 | fp.flush() |
@@ -154,7 +124,7 @@ def play( |
154 | 124 | raise Exception(i) |
155 | 125 | if i % mo: |
156 | 126 | continue |
157 | | - buffer = get_buffer(fnt, img, x, y, contrast) |
| 127 | + buffer = get_buffer(fnt, img, x, y, colorful, contrast) |
158 | 128 |
|
159 | 129 | rewind() |
160 | 130 | print(buffer, end='', flush=True) |
|
0 commit comments