2 #include "desktop/widget.h"
3 #include "desktop/widget_image.h"
5 #include "io/serial_port.h"
6 #include "io/rgb_image.h"
7 #include "sys/pixfmt.h"
9 void destroy_widget_image(
Widget_t* widget);
11 void widget_image_renderer(
struct Widget*
this,
struct Window* window) {
14 if(this_data->image_data == NULL)
17 size_t real_width = this_data->meta.w;
18 size_t real_height = this_data->meta.h;
20 draw_rgb_image(this_data->image_data, real_width, real_height, 32, this->x, this->y);
24 Widget_t* new_widget_image(
const char *path) {
26 &widget_image_renderer,
27 &destroy_widget_image,
34 bool ok = tga_extract_info(path, &hdr);
40 wgt_data->loaded =
false;
45 wgt_data->path = path;
46 wgt_data->display_mode = NORMAL;
52 void* buffer_image = kcalloc(hdr.w * hdr.h, 4);
53 wgt_data->image_data = buffer_image;
55 tga_extract_pixels(path, buffer_image);
57 pixfmt_conv(buffer_image, 32, hdr.w, hdr.h, SCREEN_BGR, SCREEN_RGB);
61 qemu_ok(
"Loaded successfully!");
66 void destroy_widget_image(
Widget_t* widget) {
69 kfree(wgt_data->image_data);
70 kfree(widget->custom_widget_data);
72 qemu_ok(
"Destroyed image widget");