1 | # Rust wasm image to ascii
|
2 |
|
3 | ```
|
4 | ██████████████████████████████████████████████████
|
5 | ████████████████████ ██████████████████████████
|
6 | ███████████████████ █ █████████████████████████
|
7 | ██████████████████ █████ ███████████████████████
|
8 | █████████████████ █████ █████████████████████
|
9 | ████████████████ █████ █ ███████████████████
|
10 | ██████████████ █████ █ ██ ████████████████
|
11 | ████████████ ███ █ ██████ ███████████████
|
12 | ███████████ █ ██ █ ██████ █ ██████████████
|
13 | ██████████ ██ █ ██ █████ ███ █████████████
|
14 | ██████████ ███ ████ ███████████
|
15 | █████████ █ █████ ███ █ ███████████
|
16 | █████████ █ █ ██ ███ █ ████████████
|
17 | ██████████ ███ █ ███████ █ █████████████
|
18 | ████████ █ █ █ ██ ██████████████
|
19 | ███████ █ █ ███ ████ ███████████████
|
20 | ██████ ██ ███ ███████████ █████████████████
|
21 | ██████ █ █ ████ ████████████████
|
22 | ██████ ██ ███████████████
|
23 | ██████ █████ ██████████████
|
24 | █████ ███████████████
|
25 | ██████ ███ █ 心中有光 ████████████████
|
26 | ███████ █ ██████████████████
|
27 | ███████████ ██████████████████
|
28 | ███████████████ ████████████████████
|
29 | ███████████████ ███████████████████
|
30 | ███████████ ██████████████████
|
31 | █████████ ██ █████████████████
|
32 | ████████ ███████████████
|
33 | ████████ ███████ ██ ██████████████
|
34 | ███████ ██████████ ████████████
|
35 | ██████ █████████████ ████████████
|
36 | ████ ██ ███████████████ ██ █████████
|
37 | ███ ██████████████████████ █ ███████████
|
38 | ██████████████████████████████████████████████████
|
39 | ██████████████████████████████████████████████████
|
40 | ```
|
41 |
|
42 | ### 灰度算法
|
43 |
|
44 | 灰度算法对比:
|
45 |
|
46 | [https://lecepin.github.io/rust-wasm-image-ascii/gray.html](https://lecepin.github.io/rust-wasm-image-ascii/gray.html)
|
47 |
|
48 | ![](./docs/01.webp)
|
49 |
|
50 | 这里直接使用的 `image` crate 的内置算法,上图中的第三种:
|
51 |
|
52 | ```rust
|
53 | // luminance formula credits: https://stackoverflow.com/a/596243
|
54 | // >>> Luminance = 0.2126*R + 0.7152*G + 0.0722*B <<<
|
55 | // calculate RGB values to get luminance of the pixel
|
56 | pub fn get_luminance(r: u8, g: u8, b: u8) -> f32 {
|
57 | let r = 0.2126 * (r as f32);
|
58 | let g = 0.7152 * (g as f32);
|
59 | let b = 0.0722 * (b as f32);
|
60 | r + g + b
|
61 | }
|
62 | ```
|
63 |
|
64 | ### 简单版本
|
65 |
|
66 | 简单版本只做了一种效果,访问地址: [https://lecepin.github.io/rust-wasm-image-ascii/test.html](https://lecepin.github.io/rust-wasm-image-ascii/test.html)
|
67 |
|
68 | ![](./docs/02.webp) |
\ | No newline at end of file |