X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;ds=sidebyside;f=src%2Fgfx.cc;h=5c04d1edb3b2856719071f2f0ea75d1d34842cf0;hb=5449bf8fbca1d2cfbefa0386df7109afb2a5aa34;hp=54ed7f96a757d847ba852e93871e4dd02563b851;hpb=0860ce537422597075fbc63ddcc9a73303362a93;p=winnie diff --git a/src/gfx.cc b/src/gfx.cc index 54ed7f9..5c04d1e 100644 --- a/src/gfx.cc +++ b/src/gfx.cc @@ -14,7 +14,7 @@ #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT) -static unsigned char* framebuffer; +static unsigned char *framebuffer; static int dev_fd = -1; static Rect screen_rect; @@ -58,14 +58,19 @@ bool init_gfx() void destroy_gfx() { - close(dev_fd); + clear_screen(0, 0, 0); + + if(dev_fd != -1) { + close(dev_fd); + } + dev_fd = -1; munmap(framebuffer, FRAMEBUFFER_SIZE(screen_rect.width, screen_rect.height, color_depth)); framebuffer = 0; } -unsigned char* get_framebuffer() +unsigned char *get_framebuffer() { return framebuffer; } @@ -82,12 +87,19 @@ int get_color_depth() void clear_screen(int r, int g, int b) { - unsigned char* fb = framebuffer; - for(int i=0; i= dest_rect.width) { + width -= xend - dest_rect.width; + } + + int yend = dest_y + height; + if(yend >= dest_rect.height) { + height -= yend - dest_rect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i= dest_rect.width) { + width -= xend - dest_rect.width; + } + + int yend = dest_y + height; + if(yend >= dest_rect.height) { + height -= yend - dest_rect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i