Created
January 7, 2014 14:34
-
-
Save albertnetymk/8300148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MIN(a,b) (((a)<(b))?(a):(b)) | |
typedef unsigned int uint; | |
typedef struct { | |
uint red:5; | |
uint green:6; | |
uint blue:5; | |
} f_pixel; | |
typedef struct { | |
uint red:8; | |
uint green:8; | |
uint blue:8; | |
uint alpha:8; | |
} m_pixel; | |
static uint alpha_blend(uint fg, uint bg, uint alpha) | |
{ | |
return (alpha * fg + (255-alpha) * bg)/255; | |
} | |
void overlay_mouse_pointer(f_pixel *frame_buffer, m_pixel *mouse_pointer_buffer, int x_coordinate, int y_coordinate) | |
{ | |
int y_max = MIN(y_coordinate+32, 480); | |
int x_max = MIN(x_coordinate+32, 640); | |
uint fg, bg; | |
uint alpha; | |
for (int i=y_coordinate; i<y_max; ++i) { | |
for (int j=x_coordinate; j<x_max; ++j) { | |
// normalize to 255 | |
bg = frame_buffer[i*640+j].red << (8-5); | |
fg = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].red; | |
alpha = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].alpha; | |
frame_buffer[i*640+j].red = alpha_blend(fg, bg, alpha) >> (8-5); | |
bg = frame_buffer[i*640+j].green << (8-6); | |
fg = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].green; | |
alpha = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].alpha; | |
frame_buffer[i*640+j].green = alpha_blend(fg, bg, alpha) >> (8-6); | |
bg = frame_buffer[i*640+j].blue << (8-5); | |
fg = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].blue; | |
alpha = mouse_pointer_buffer[(i-y_coordinate)*32+(j-x_coordinate)].alpha; | |
frame_buffer[i*640+j].blue = alpha_blend(fg, bg, alpha) >> (8-5); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment