-
Notifications
You must be signed in to change notification settings - Fork 7
/
ascii.c
61 lines (45 loc) · 1.02 KB
/
ascii.c
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "webcam.hpp"
#include "ascii.h"
#include "image.h"
#include "options.h"
void ascii_read_init(unsigned short int webcam_index) {
webcam_init(webcam_index);
}
void ascii_write_init() {
console_clear();
cursor_reset();
cursor_hide();
}
char *ascii_read() {
FILE *jpeg = webcam_read();
image_t *original = image_read(jpeg),
*resized = image_new(opt_width, opt_height);
fclose(jpeg);
image_clear(resized);
image_resize(original, resized);
char *ascii = image_print(resized);
image_destroy(original);
image_destroy(resized);
return ascii;
}
void ascii_write(char *f) {
for (int i = 0; f[i] != '\0'; ++i)
if (f[i] == '\t')
cursor_reset();
else
putchar(f[i]);
ascii_zzz();
}
void ascii_write_destroy() {
console_clear();
cursor_reset();
cursor_show();
}
void ascii_read_destroy() {
console_clear();
cursor_reset();
}