case GDX2D_FORMAT_ALPHA: \r
return color & 0xff;\r
case GDX2D_FORMAT_LUMINANCE_ALPHA: \r
- return (color & 0xff00) >> 8 | (color & 0xff) << 8;\r
+ return (color & 0xffff);\r
case GDX2D_FORMAT_RGB888:\r
return color & 0xffffff;\r
case GDX2D_FORMAT_RGBA8888:\r
case GDX2D_FORMAT_ALPHA: \r
return (color & 0xff) | 0xffffff00;\r
case GDX2D_FORMAT_LUMINANCE_ALPHA: \r
- return ((color & 0xff) << 24) | ((color & 0xff) << 16) | (color & 0xffff);\r
+ return ((color & 0xff00) << 16) | ((color & 0xff00) << 8) | (color & 0xffff);\r
case GDX2D_FORMAT_RGB888:\r
return (color << 8) | 0x000000ff;\r
case GDX2D_FORMAT_RGBA8888:\r
pixel_addr[2] = (color & 0xff);\r
}\r
\r
-inline void set_pixel_RGBA8888(unsigned char *pixel_addr, uint32_t color) { \r
- if(!gdx2d_blend) {\r
- *(uint32_t*)pixel_addr = ((color & 0xff000000) >> 24) |\r
- ((color & 0xff0000) >> 8) |\r
- ((color & 0xff00) << 8) |\r
- ((color & 0xff) << 24);\r
- } else { \r
- int32_t src_r = (color & 0xff000000) >> 24;\r
- int32_t src_g = (color & 0xff0000) >> 16;\r
- int32_t src_b = (color & 0xff00) >> 8;\r
- int32_t src_a = (color & 0xff);\r
- \r
- int32_t dst = *(uint32_t*)pixel_addr; \r
- int32_t dst_r = (dst & 0xff);\r
- int32_t dst_g = (dst & 0xff00) >> 8;\r
- int32_t dst_b = (dst & 0xff0000) >> 16;\r
- \r
- dst_r = dst_r + src_a * (src_r - dst_r) / 255;\r
- dst_g = dst_g + src_a * (src_g - dst_g) / 255;\r
- dst_b = dst_b + src_a * (src_b - dst_b) / 255;\r
- *(uint32_t*)pixel_addr = (uint32_t)(dst_r | (dst_g << 8) | (dst_b << 16) | (src_a << 24)); \r
- } \r
+inline void set_pixel_RGBA8888(unsigned char *pixel_addr, uint32_t color) { \r
+ *(uint32_t*)pixel_addr = ((color & 0xff000000) >> 24) |\r
+ ((color & 0xff0000) >> 8) |\r
+ ((color & 0xff00) << 8) |\r
+ ((color & 0xff) << 24);\r
}\r
\r
inline void set_pixel_RGB565(unsigned char *pixel_addr, uint32_t color) {\r
*(uint16_t*)pixel_addr = (uint16_t)(color);\r
}\r
\r
-inline void set_pixel_RGBA4444(unsigned char *pixel_addr, uint32_t color) {\r
- if(!gdx2d_blend) {\r
- *(uint16_t*)pixel_addr = (uint16_t)(color);\r
- } else {\r
- uint16_t src_a = color & 0xf;\r
- uint16_t src_r = (color & 0xf000) >> 12;\r
- uint16_t src_g = (color & 0xf00) >> 8;\r
- uint16_t src_b = (color & 0xf0) >> 4;\r
-\r
- uint16_t dst = *(uint16_t*)pixel_addr;\r
- uint16_t dst_r = (dst & 0xf000) >> 12;\r
- uint16_t dst_g = (dst & 0xf00) >> 8;\r
- uint16_t dst_b = (dst & 0xf0) >> 4;\r
- \r
- dst_r = dst_r + src_a * (src_r - dst_r) / 15;\r
- dst_g = dst_g + src_a * (src_g - dst_g) / 15;\r
- dst_b = dst_b + src_a * (src_b - dst_b) / 15;\r
- *(uint16_t*)pixel_addr = (uint16_t)((dst_r << 12) | (dst_g << 8) | (dst_b << 4) | src_a); \r
- }\r
+inline void set_pixel_RGBA4444(unsigned char *pixel_addr, uint32_t color) { \r
+ *(uint16_t*)pixel_addr = (uint16_t)(color); \r
}\r
\r
inline set_pixel_func set_pixel_func_ptr(uint32_t format) {\r
}\r
}\r
\r
+inline uint32_t blend(uint32_t src, uint32_t dst) {\r
+ int32_t src_r = (src & 0xff000000) >> 24;\r
+ int32_t src_g = (src & 0xff0000) >> 16;\r
+ int32_t src_b = (src & 0xff00) >> 8;\r
+ int32_t src_a = (src & 0xff);\r
+ \r
+ int32_t dst_r = (dst & 0xff);\r
+ int32_t dst_g = (dst & 0xff00) >> 8;\r
+ int32_t dst_b = (dst & 0xff0000) >> 16;\r
+ \r
+ dst_r = dst_r + src_a * (src_r - dst_r) / 255;\r
+ dst_g = dst_g + src_a * (src_g - dst_g) / 255;\r
+ dst_b = dst_b + src_a * (src_b - dst_b) / 255;\r
+ return (uint32_t)((dst_r << 24) | (dst_g << 16) | (dst_b << 8) | src_a); \r
+}\r
+\r
inline uint32_t get_pixel_alpha(unsigned char *pixel_addr) {\r
return *pixel_addr;\r
}\r
}\r
\r
void gdx2d_clear(const gdx2d_pixmap* pixmap, uint32_t col) { \r
- \r
+ col = to_format(pixmap->format, col);\r
+\r
switch(pixmap->format) {\r
case GDX2D_FORMAT_ALPHA:\r
clear_alpha(pixmap, col);\r
}\r
\r
void gdx2d_set_pixel(const gdx2d_pixmap* pixmap, int32_t x, int32_t y, uint32_t col) {\r
+ col = to_format(pixmap->format, col);\r
set_pixel((unsigned char*)pixmap->pixels, pixmap->width, pixmap->height, bytes_per_pixel(pixmap->format), set_pixel_func_ptr(pixmap->format), x, y, col);\r
}\r
\r
if(!in_pixmap(pixmap, x, y)) \r
return 0;\r
unsigned char* ptr = (unsigned char*)pixmap->pixels + (x + pixmap->height * y) * bytes_per_pixel(pixmap->format);\r
- return get_pixel_func_ptr(pixmap->format)(ptr);\r
+ return to_RGBA8888(pixmap->format, get_pixel_func_ptr(pixmap->format)(ptr));\r
}\r
\r
void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t col) { \r