SayoriOS  0.3.3
rgb_image.c
1 //
2 // Created by ndraey on 25.10.23.
3 //
4 
5 #include <io/screen.h>
6 #include "io/rgb_image.h"
7 #include "io/ports.h"
8 
18 void draw_rgb_image(const char *data, size_t width, size_t height, size_t bpp, int sx, int sy) {
19  int x, y = 0;
20 
21  size_t bytes_pp = bpp >> 3;
22 
23  while(y < height) {
24  x = 0;
25  while(x < width) {
26  int px = PIXIDX(width * bytes_pp, x * bytes_pp, y);
27 
28  char r = data[px];
29  char g = data[px + 1];
30  char b = data[px + 2];
31  char a = data[px + 3];
32  size_t color = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
33 
34 // if((bytes_pp == 4 && a != 0) || bytes_pp == 3) {
35  set_pixel(sx + x, sy + y, color);
36 // } else {
37 // qemu_log("FUCK! %x", a);
38 // }
39 
40  x++;
41  }
42  y++;
43  }
44 }
45 
56 void scale_rgb_image(const char* pixels, unsigned int w1, unsigned int h1, uint32_t w2, uint32_t h2, char alpha, char* out) {
57  uint32_t scr_w = (w1<<16)/w2;
58  uint32_t scr_h = (h1<<16)/h2;
59 
60  int x;
61  int y = 0;
62 
63  uint32_t x2;
64  uint32_t y2;
65 
66  char mod = alpha?4:3;
67  while(y<h2) {
68  x = 0;
69  while(x<w2) {
70  x2 = (x*scr_w)>>16;
71  y2 = (y*scr_h)>>16;
72 
73  out[PIXIDX(w2*mod, x*mod, y)] = pixels[PIXIDX(w1*mod, x2*mod, y2)];
74  out[PIXIDX(w2*mod, x*mod, y)+1] = pixels[PIXIDX(w1*mod, x2*mod, y2)+1];
75  out[PIXIDX(w2*mod, x*mod, y)+2] = pixels[PIXIDX(w1*mod, x2*mod, y2)+2];
76  if(alpha) {
77  out[PIXIDX(w2*mod, x*mod, y)+3] = pixels[PIXIDX(w1*mod, x2*mod, y2)+3];
78  }
79  x++;
80  }
81  y++;
82  }
83 }