From 9bfd9fb6a7c568b56a5ef525a2b76351780bae66 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 18 Oct 2018 18:37:31 +0200 Subject: in-kernel bmp loader --- video/compositor.c | 118 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 27 deletions(-) (limited to 'video/compositor.c') diff --git a/video/compositor.c b/video/compositor.c index d7094b1..2b67385 100644 --- a/video/compositor.c +++ b/video/compositor.c @@ -17,22 +17,27 @@ ringbuffer bg_invl; -// TODO: int16 int32 mixed nonsense -// +// TODO: int16 int32 mixed nonsense ! struct window { uint32_t pid; ringbuffer *invl; + struct pdirectory *vmem; // retreive from task manager? int16_t posx; int16_t posy; + uint16_t width; uint16_t height; uint16_t active; + bool draw_border; bool draw_meat; + + bool borderless; // never show borders + bool fixed; // can not be moved }; struct icon @@ -127,7 +132,6 @@ static uint32_t get_pixel(uint8_t *src, int x,int y) static void put_pixel_alpha(uint8_t *dst, int x,int y, uint32_t color) { // TODO: do not use hardcoded alpha! - uint16_t a=0xaa; uint32_t col=get_pixel(dst,x,y); @@ -139,10 +143,11 @@ static void put_pixel_alpha(uint8_t *dst, int x,int y, uint32_t color) uint8_t src_b=color&0xff; uint8_t src_g=(color&0xff00)>>8; uint8_t src_r=(color&0xff0000)>>16; + uint8_t src_a=(color&0xff000000)>>24; - uint8_t out_r=((src_r*(0xff-a))>>8)+((a*dst_r)>>8); - uint8_t out_g=((src_g*(0xff-a))>>8)+((a*dst_g)>>8); - uint8_t out_b=((src_b*(0xff-a))>>8)+((a*dst_b)>>8); + uint8_t out_r=((src_r*(src_a))>>8)+(((0xff-src_a)*dst_r)>>8); + uint8_t out_g=((src_g*(src_a))>>8)+(((0xff-src_a)*dst_g)>>8); + uint8_t out_b=((src_b*(src_a))>>8)+(((0xff-src_a)*dst_b)>>8); put_pixel(dst, x,y,(out_r<<16)+(out_g<<8)+out_b); } @@ -162,7 +167,6 @@ static void cpy_rect(uint8_t *src, uint16_t src_x, uint16_t src_y, if(transp&&transp_key==val)continue; // TODO: quick workaround for arrow black if(alpha) - put_pixel_alpha(dst,dst_x+x,dst_y+y,val); else put_pixel(dst,dst_x+x,dst_y+y,val); @@ -508,12 +512,20 @@ void compositor_kb_handle(char c) void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key) { // klog("%d %d %d",diff_x,diff_y,key); - static uint8_t lastkey; + static uint8_t lastkey=0; + + if(!(key&2)&&(lastkey&2)) // right mouse click + { + lastkey=key; + klog("tell init to spawn new foolshell"); + fd_write(get_tty(1),'0'); // tell init to spawn new xterm + } mouse_x+=diff_x; mouse_y+=diff_y; mouse_k=key; + if(mouse_x<0)mouse_x=0; if(mouse_y<0)mouse_y=0; @@ -642,13 +654,62 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key) lastkey=key; } + +/** THIS CAN LOAD WINDOWS ARGB BITMAPS WITH BITMAPINFOHEADER */ +void load_bmp(uint8_t *dst,char *filename) +{ + + klog("loading bitmap %s",filename); + fd dat=mount_file_open(filename); + char B=fd_read(&dat); // 0x0 + char M=fd_read(&dat); // 0x1 + //klog("id = %c%c",M,B); + if(M!='M'||B!='B')kpanic("not a (windows) bitmap!"); + + uint32_t size=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x02 + klog("bytes = 0x%08x",size); + + // skip next 4 reserved bytes + fd_read(&dat); + fd_read(&dat); + fd_read(&dat); + fd_read(&dat); + + uint32_t off=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x0a + //klog("offset = 0x%08X",off); + + // skip next 4 bytes + fd_read(&dat); + fd_read(&dat); + fd_read(&dat); + fd_read(&dat); + + uint32_t w=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x12 + uint32_t h=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x16 + klog("width=%d,height=%d",w,h); + + for(int i=0;i=vesa_width)continue; + if(y>=vesa_height)continue; + put_pixel_alpha(dst,x,y,val); + } + } + +} + // load background image or generate one if (param == 0) void compositor_set_background(char *ppm_raw_filename) { // TODO: think about funny things to do with timer and update // some generated / or modified bg regularly // // uint64_t t=timer_get_ms()/333; // - klog("loading theme..."); fd bg=mount_file_open(ppm_raw_filename); @@ -663,33 +724,36 @@ void compositor_set_background(char *ppm_raw_filename) if(x>=vesa_width)continue; if(y>=vesa_height)continue; put_pixel(icon_data,x,y,val); + put_pixel(bgimage,x,y,val); i++; } } + klog("finished"); // generating simple background... - int center_x=vesa_width/2; - int center_y=vesa_height/2; - - int max_dist = center_x*center_x+center_y*center_y; + int center_x=vesa_width/2; + int center_y=vesa_height/2; + int max_dist = center_x*center_x+center_y*center_y; - for(int x=0;x