SayoriOS 0.3.3

pavi.c
1 #include "common.h"
2 #include "lib/stdio.h"
3 #include "io/tty.h"
4 #include "io/status_loggers.h"
5 #include "fmt/tga.h"
6 #include "mem/vmm.h"
7 #include "io/rgb_image.h"
8 #include "drv/input/keyboard.h"
9 #include "drv/input/keymap.h"
10 #include "io/ports.h"
11 #include "sys/pixfmt.h"
12
13 tga_header_t pavi_tga_header;
14 void* pavi_image_buffer = 0;
15 void* pavi_view_buffer = 0;
16
17 uint32_t pavi_view(uint32_t argc, char* argv[]) {
18 memset(&pavi_tga_header, 0, sizeof pavi_tga_header);
19
20 if(argc < 1) {
21 tty_error("No arguments!\n");
22 return 1;
23 }
24
25 size_t start_load = timestamp();
26
27 FILE* file = fopen(argv[1], "rb");
28
29 if(!file) {
30 tty_printf("Failed to open file: %s!\n", argv[1]);
31 return 1;
32 }
33
34 fclose(file);
35
36 clean_tty_screen();
37 tty_printf("Pavi - Opening '%s'...", argv[1]);
38
39 tga_extract_info(argv[1], &pavi_tga_header);
40
41 qemu_log("W: %d H: %d", pavi_tga_header.w, pavi_tga_header.h);
42
43 clean_tty_screen();
44 tty_printf("Pavi - Reading contents of '%s'...", argv[1]);
45
46 pavi_image_buffer = kmalloc(pavi_tga_header.w * pavi_tga_header.h * 4);
47 pavi_view_buffer = kmalloc(pavi_tga_header.w * pavi_tga_header.h * 4);
48
49 tga_extract_pixels(argv[1], pavi_image_buffer);
50
51 qemu_warn("Ended reading data");
52
53 size_t nh = getScreenHeight();
54 size_t nw = (size_t)((double)getScreenWidth() * ((double)pavi_tga_header.w / (double)pavi_tga_header.h));
55
56 if(nw > pavi_tga_header.w || nh > pavi_tga_header.h) {
57 nw = pavi_tga_header.w;
58 nh = pavi_tga_header.h;
59 }
60
61 qemu_note("Colormap is: %x", pavi_tga_header.colormap);
62
63 pixfmt_conv(pavi_image_buffer, 32, pavi_tga_header.w, pavi_tga_header.h, SCREEN_BGR, SCREEN_RGB);
64
65 scale_rgb_image(pavi_image_buffer, pavi_tga_header.w, pavi_tga_header.h, nw, nh, 1, pavi_view_buffer);
66
67 qemu_note("Ended scaling");
68
69 size_t end_load = timestamp();
70
71 clean_tty_screen();
72 tty_printf("Pavi - '%s' [%dx%d] => [%dx%d] (Loaded in: %u ms) (Press ESC to exit)", argv[1], pavi_tga_header.w, pavi_tga_header.h, nw, nh, end_load - start_load);
73
74 keyboardctl(KEYBOARD_ECHO, 0);
75
76 draw_rgb_image(pavi_view_buffer, nw, nh, 32, (int)(getScreenWidth() - nw) / 2, 16 + (int)(getScreenHeight() - nh) / 2);
77
78 punch();
79
80 while(1) {
81 int key = getCharRaw();
82
83 if(key == KEY_ESC) {
84 break;
85 }
86 }
87
88 clean_tty_screen();
89
90 keyboardctl(KEYBOARD_ECHO, 1);
91
92 kfree(pavi_image_buffer);
93 kfree(pavi_view_buffer);
94
95 return 0;
96 }
common.h
Основные определения ядра
memset
void * memset(void *ptr, char value, size_t num)
Заполнение массива указанными символами
Definition: string.c:203
fclose
void fclose(FILE *stream)
Закончить работу с файлом
Definition: stdio.c:213
fopen
FILE * fopen(const char *filename, const char *_mode)
Открывает файл
Definition: stdio.c:166
FILE
Структура файла. Требуется для работы с VFS.
Definition: stdio.h:21