gbasys
diff src/gfx.c @ 3:06726f0b8cd3
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 08 Mar 2012 14:37:17 +0200 |
parents | c50064b181c2 |
children | f77381b12726 |
line diff
1.1 --- a/src/gfx.c Wed Mar 07 06:11:51 2012 +0200 1.2 +++ b/src/gfx.c Thu Mar 08 14:37:17 2012 +0200 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 -Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 1.6 +Copyright 2004-2012 John Tsiombikas <nuclear@member.fsf.org> 1.7 1.8 This file is part of gbasys, a library for GameBoy Advance development. 1.9 1.10 @@ -21,6 +21,7 @@ 1.11 #include "config.h" 1.12 1.13 #include <stdlib.h> 1.14 +#include <string.h> 1.15 #include "gfx.h" 1.16 1.17 #define FRAME_SEL_BIT 0x10 1.18 @@ -134,6 +135,42 @@ 1.19 dma_copy32(3, dst->pixels, src->pixels, words); 1.20 } 1.21 1.22 +#define MIN(a, b) ((a) < (b) ? (a) : (b)) 1.23 + 1.24 +void blit(struct pixel_buffer *src, int src_x, int src_y, int src_w, int src_h, 1.25 + struct pixel_buffer *dst, int dst_x, int dst_y) 1.26 +{ 1.27 + int i, pixsize, width, height, dstride, sstride; 1.28 + unsigned char *dptr, *sptr; 1.29 + 1.30 + if(dst->bpp != src->bpp) 1.31 + return; 1.32 + 1.33 + if(src_w <= 0) 1.34 + src_w = src->x; 1.35 + if(src_h <= 0) 1.36 + src_h = src->y; 1.37 + 1.38 + width = MIN(src_w, MIN(src->x - src_x, dst->x - dst_x)); 1.39 + height = MIN(src_h, MIN(src->y - src_y, dst->y - dst_y)); 1.40 + 1.41 + if(width <= 0 || height <= 0) 1.42 + return; 1.43 + 1.44 + pixsize = dst->bpp / 8; 1.45 + dptr = (unsigned char*)dst->pixels + (dst_y * dst->x + dst_x) * pixsize; 1.46 + sptr = (unsigned char*)src->pixels + (src_y * src->x + src_x) * pixsize; 1.47 + 1.48 + dstride = dst->x * pixsize; 1.49 + sstride = src->x * pixsize; 1.50 + 1.51 + for(i=0; i<height; i++) { 1.52 + memcpy(dptr, sptr, width * pixsize); 1.53 + sptr += sstride; 1.54 + dptr += dstride; 1.55 + } 1.56 +} 1.57 + 1.58 1.59 void draw_line(int x1, int y1, int x2, int y2, unsigned short col, struct pixel_buffer *pbuf) { 1.60 int dx, dy, dx2, dy2;