support multi layer(GUI + Camera)

This commit is contained in:
xianjimli 2020-05-18 17:36:22 +08:00
parent 30f23fd98f
commit 29c87c4f07
53 changed files with 530 additions and 97 deletions

View File

@ -205,17 +205,38 @@ inline void pixel_blend(pixel24_rgb& t, const pixel32_rgba& s, uint8_t a) {
}
}
static inline uint8_t pixel_limit_uint8(int tmp) {
if(tmp > 0xff) {
tmp = 0xff;
} else if(tmp < 0) {
tmp = 0;
}
return (uint8_t)tmp;
}
template <>
inline void pixel_blend(pixel32_rgba& t, const pixel32_rgba& s, uint8_t a) {
if (a > 0xf4) {
t.r = s.r;
t.g = s.g;
t.b = s.b;
t.a = a;
} else if (a > 0x01) {
uint8_t m_a = 0xff - a;
t.r = (s.r * a + t.r * m_a) >> 8;
t.g = (s.g * a + t.g * m_a) >> 8;
t.b = (s.b * a + t.b * m_a) >> 8;
if(t.a > 0xf4) {
t.r = (s.r * a + t.r * m_a) >> 8;
t.g = (s.g * a + t.g * m_a) >> 8;
t.b = (s.b * a + t.b * m_a) >> 8;
} else {
uint8_t out_a = pixel_limit_uint8(a + t.a - ((a * t.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (t.a * (0xff - a)) >> 8;
t.r = (s.r * a + t.r * d_a) / out_a;
t.g = (s.g * a + t.g * d_a) / out_a;
t.b = (s.b * a + t.b * d_a) / out_a;
}
t.a = out_a;
}
}
}
@ -225,11 +246,23 @@ inline void pixel_blend(pixel32_bgra& t, const pixel32_rgba& s, uint8_t a) {
t.r = s.r;
t.g = s.g;
t.b = s.b;
t.a = a;
} else if (a > 0x01) {
uint8_t m_a = 0xff - a;
t.r = (s.r * a + t.r * m_a) >> 8;
t.g = (s.g * a + t.g * m_a) >> 8;
t.b = (s.b * a + t.b * m_a) >> 8;
if(t.a > 0xf4) {
uint8_t m_a = 0xff - a;
t.r = (s.r * a + t.r * m_a) >> 8;
t.g = (s.g * a + t.g * m_a) >> 8;
t.b = (s.b * a + t.b * m_a) >> 8;
} else {
uint8_t out_a = pixel_limit_uint8(a + t.a - ((a * t.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (t.a * (0xff - a)) >> 8;
t.r = (s.r * a + t.r * d_a) / out_a;
t.g = (s.g * a + t.g * d_a) / out_a;
t.b = (s.b * a + t.b * d_a) / out_a;
}
t.a = out_a;
}
}
}

View File

@ -3,6 +3,7 @@
* 增加事件录制与重放功能,辅助手动测试和压力测试。
* 完善 text edit感谢大恒提供补丁
* 完善 system settings 和 release 脚本(感谢俊杰提供补丁)。
* 支持硬件多层合并(GUI + Camera)(感谢尧燊提供补丁)。
* 2020/05/14
* 修复 clip view 中 type 的问题(感谢尧燊提供补丁)。

View File

@ -76,6 +76,14 @@ ret_t dialog_highlighter_set_bg(dialog_highlighter_t* h, bitmap_t* img, framebuf
return RET_OK;
}
ret_t dialog_highlighter_set_bg_clip_rect(dialog_highlighter_t* h, rect_t* clip_rect) {
return_value_if_fail(h != NULL && h->vt != NULL, RET_BAD_PARAMS);
h->clip_rect = rect_init(clip_rect->x, clip_rect->y, clip_rect->w, clip_rect->h);
return RET_OK;
}
ret_t dialog_highlighter_draw(dialog_highlighter_t* h, float_t percent) {
return_value_if_fail(h != NULL && h->vt != NULL, RET_BAD_PARAMS);

View File

@ -86,6 +86,12 @@ struct _dialog_highlighter_t {
*/
widget_t* dialog;
/**
* @property {rect_t*} clip_rect
*
*/
rect_t clip_rect;
/*private*/
framebuffer_object_t fbo;
const dialog_highlighter_vtable_t* vt;
@ -113,6 +119,16 @@ dialog_highlighter_t* dialog_highlighter_create(const dialog_highlighter_vtable_
*/
ret_t dialog_highlighter_set_bg(dialog_highlighter_t* h, bitmap_t* img, framebuffer_object_t* fbo);
/**
* @method dialog_highlighter_set_bg_clip_rect
*
* @param {dialog_highlighter_t*} h
* @param {rect_t*} clip_rect
*
* @return {ret_t} RET_OK表示成功
*/
ret_t dialog_highlighter_set_bg_clip_rect(dialog_highlighter_t* h, rect_t* clip_rect);
/**
* @method dialog_highlighter_prepare
*

View File

@ -24,6 +24,16 @@
#include "tkc/color.h"
static inline uint8_t tk_pixel_limit_uint8(int32_t tmp) {
if(tmp > 0xff) {
tmp = 0xff;
} else if(tmp < 0) {
tmp = 0;
}
return (uint8_t)tmp;
}
#pragma pack(push, 1)
typedef struct _pixel_rgb565_t {
uint16_t r : 5;
@ -36,8 +46,18 @@ typedef struct _pixel_rgb565_t {
#define pixel_rgb565_format BITMAP_FMT_RGB565
#define pixel_rgb565_to_rgba(p) \
{ p.r << 3, p.g << 2, p.b << 3, 0xff }
#define pixel_rgb565_from_rgb(r, g, b) \
{ r >> 3, g >> 2, b >> 3 }
#if WITH_LCD_CLEAR_ALPHA
#define pixel_rgb565_from_rgba(r, g, b, a) \
{ (r * a) >> 11, (g * a) >> 10, (b * a) >> 11 }
#else
#define pixel_rgb565_from_rgba(r, g, b, a) \
pixel_rgb565_from_rgb(r, g, b)
#endif
static inline void pixel_rgb565_blend_rgba_dark(void* p, uint8_t a) {
uint16_t v = *(uint16_t*)p;
@ -65,9 +85,18 @@ typedef struct _pixel_bgr565_t {
#define pixel_bgr565_format BITMAP_FMT_BGR565
#define pixel_bgr565_to_rgba(p) \
{ p.r << 3, p.g << 2, p.b << 3, 0xff }
#define pixel_bgr565_from_rgb(r, g, b) \
{ b >> 3, g >> 2, r >> 3 }
#if WITH_LCD_CLEAR_ALPHA
#define pixel_bgr565_from_rgba(r, g, b, a) \
{ (b * a) >> 11, (g * a) >> 10, (r * a) >> 11 }
#else
#define pixel_bgr565_from_rgba(r, g, b, a) \
pixel_bgr565_from_rgb(r, g, b)
#endif
static inline void pixel_bgr565_blend_rgba_dark(void* p, uint8_t a) {
uint16_t v = *(uint16_t*)p;
@ -105,9 +134,18 @@ typedef struct _pixel_rgb888_t {
#define pixel_rgb888_format BITMAP_FMT_RGB888
#define pixel_rgb888_to_rgba(p) \
{ p.r, p.g, p.b, 0xff }
#define pixel_rgb888_from_rgb(r, g, b) \
{ r, g, b }
#if WITH_LCD_CLEAR_ALPHA
#define pixel_rgb888_from_rgba(r, g, b, a) \
{ (r * a) >> 8, (g * a) >> 8, (b * a) >> 8 }
#else
#define pixel_rgb888_from_rgba(r, g, b, a) \
pixel_rgb888_from_rgb(r, g, b)
#endif
static inline void pixel_rgb888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
@ -136,8 +174,17 @@ typedef struct _pixel_bgr888_t {
#define pixel_bgr888_format BITMAP_FMT_BGR888
#define pixel_bgr888_to_rgba(p) \
{ p.r, p.g, p.b, 0xff }
#define pixel_bgr888_from_rgb(r, g, b) \
{ b, g, r }
#if WITH_LCD_CLEAR_ALPHA
#define pixel_bgr888_from_rgba(r, g, b, a) \
{ (b * a) >> 8, (g * a) >> 8, (r * a) >> 8 }
#else
#define pixel_bgr888_from_rgba(r, g, b, a) \
pixel_bgr888_from_rgb(r, g, b);
#endif
static inline void pixel_bgr888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
@ -174,20 +221,44 @@ typedef struct _pixel_rgba8888_t {
static inline void pixel_rgba8888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
p[0] = (p[0] * a) >> 8;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = 0xff;
if(p[3] > 0xf4) {
p[0] = (p[0] * a) >> 8;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = 0xff;
} else {
uint8_t out_a = tk_pixel_limit_uint8(p[3] + a - ((p[3] * a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[3] * (0xff - a)) >> 8;
p[0] = (p[0] * d_a) / out_a;
p[1] = (p[1] * d_a) / out_a;
p[2] = (p[2] * d_a) / out_a;
}
p[3] = out_a;
}
}
static inline void pixel_rgba8888_blend_rgba_premulti(void* pixel, rgba_t rgba) {
uint8_t a = rgba.a;
uint8_t* p = (uint8_t*)pixel;
p[0] = ((p[0] * a) >> 8) + rgba.r;
p[1] = ((p[1] * a) >> 8) + rgba.g;
p[2] = ((p[2] * a) >> 8) + rgba.b;
p[3] = 0xff;
if(p[3] > 0xf4) {
p[0] = ((p[0] * a) >> 8) + rgba.r;
p[1] = ((p[1] * a) >> 8) + rgba.g;
p[2] = ((p[2] * a) >> 8) + rgba.b;
p[3] = 0xff;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[3] + s_a - ((p[3] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[3] * (0xff - rgba.a)) >> 8;
p[0] = (p[0] * d_a + (rgba.r << 8)) / out_a;
p[1] = (p[1] * d_a + (rgba.g << 8)) / out_a;
p[2] = (p[2] * d_a + (rgba.b << 8)) / out_a;
}
p[3] = out_a;
}
}
typedef struct _pixel_abgr8888_t {
@ -208,19 +279,45 @@ typedef struct _pixel_abgr8888_t {
{ a, b, g, r }
static inline void pixel_abgr8888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
p[0] = 0xff;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = (p[3] * a) >> 8;
if(p[3] > 0xf4) {
p[0] = 0xff;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = (p[3] * a) >> 8;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[0] + s_a - ((p[0] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[0] * (0xff - a)) >> 8;
p[1] = (p[1] * d_a) / out_a;
p[2] = (p[2] * d_a) / out_a;
p[3] = (p[3] * d_a) / out_a;
}
p[0] = out_a;
}
}
static inline void pixel_abgr8888_blend_rgba_premulti(void* pixel, rgba_t rgba) {
uint8_t a = rgba.a;
uint8_t* p = (uint8_t*)pixel;
p[0] = 0xff;
p[1] = ((p[1] * a) >> 8) + rgba.b;
p[2] = ((p[2] * a) >> 8) + rgba.g;
p[3] = ((p[3] * a) >> 8) + rgba.r;
if(p[3] > 0xf4) {
p[0] = 0xff;
p[1] = ((p[1] * a) >> 8) + rgba.b;
p[2] = ((p[2] * a) >> 8) + rgba.g;
p[3] = ((p[3] * a) >> 8) + rgba.r;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[0] + s_a - ((p[0] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[0] * (0xff - rgba.a)) >> 8;
p[1] = (p[1] * d_a + (rgba.b << 8)) / out_a;
p[2] = (p[2] * d_a + (rgba.g << 8)) / out_a;
p[3] = (p[3] * d_a + (rgba.r << 8)) / out_a;
}
p[0] = out_a;
}
}
typedef struct _pixel_bgra8888_t {
@ -242,20 +339,44 @@ typedef struct _pixel_bgra8888_t {
static inline void pixel_bgra8888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
p[0] = (p[0] * a) >> 8;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = 0xff;
if(p[3] > 0xf4) {
p[0] = (p[0] * a) >> 8;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = 0xff;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[3] + s_a - ((p[3] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[3] * (0xff - a)) >> 8;
p[0] = (p[0] * d_a) / out_a;
p[1] = (p[1] * d_a) / out_a;
p[2] = (p[2] * d_a) / out_a;
}
p[3] = out_a;
}
}
static inline void pixel_bgra8888_blend_rgba_premulti(void* pixel, rgba_t rgba) {
uint8_t a = rgba.a;
uint8_t* p = (uint8_t*)pixel;
p[0] = ((p[0] * a) >> 8) + rgba.b;
p[1] = ((p[1] * a) >> 8) + rgba.g;
p[2] = ((p[2] * a) >> 8) + rgba.r;
p[3] = 0xff;
if(p[3] > 0xf4) {
p[0] = ((p[0] * a) >> 8) + rgba.b;
p[1] = ((p[1] * a) >> 8) + rgba.g;
p[2] = ((p[2] * a) >> 8) + rgba.r;
p[3] = 0xff;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[3] + s_a - ((p[3] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[3] * (0xff - rgba.a)) >> 8;
p[0] = (p[0] * d_a + (rgba.b << 8)) / out_a;
p[1] = (p[1] * d_a + (rgba.g << 8)) / out_a;
p[2] = (p[2] * d_a + (rgba.r << 8)) / out_a;
}
p[3] = out_a;
}
}
typedef struct _pixel_argb8888_t {
@ -276,19 +397,45 @@ typedef struct _pixel_argb8888_t {
{ 0xff, r, g, b }
static inline void pixel_argb8888_blend_rgba_dark(void* pixel, uint8_t a) {
uint8_t* p = (uint8_t*)pixel;
p[0] = 0xff;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = (p[3] * a) >> 8;
if(p[3] > 0xf4) {
p[0] = 0xff;
p[1] = (p[1] * a) >> 8;
p[2] = (p[2] * a) >> 8;
p[3] = (p[3] * a) >> 8;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[0] + s_a - ((p[0] *s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[0] * (0xff - a)) >> 8;
p[1] = (p[1] * d_a) / out_a;
p[2] = (p[2] * d_a) / out_a;
p[3] = (p[3] * d_a) / out_a;
}
p[0] = out_a;
}
}
static inline void pixel_argb8888_blend_rgba_premulti(void* pixel, rgba_t rgba) {
uint8_t a = rgba.a;
uint8_t* p = (uint8_t*)pixel;
p[0] = 0xff;
p[1] = ((p[1] * a) >> 8) + rgba.r;
p[2] = ((p[2] * a) >> 8) + rgba.g;
p[3] = ((p[3] * a) >> 8) + rgba.b;
if(p[3] > 0xf4) {
p[0] = 0xff;
p[1] = ((p[1] * a) >> 8) + rgba.r;
p[2] = ((p[2] * a) >> 8) + rgba.g;
p[3] = ((p[3] * a) >> 8) + rgba.b;
} else {
uint8_t s_a = 0xff - a;
uint8_t out_a = tk_pixel_limit_uint8(p[0] + s_a - ((p[0] * s_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (p[0] * (0xff - rgba.a)) >> 8;
p[1] = (p[1] * d_a + (rgba.r << 8)) / out_a;
p[2] = (p[2] * d_a + (rgba.g << 8)) / out_a;
p[3] = (p[3] * d_a + (rgba.b << 8)) / out_a;
}
p[0] = out_a;
}
}
typedef uint8_t pixel_gray_t;

View File

@ -501,7 +501,7 @@ ret_t widget_set_pointer_cursor(widget_t* widget, const char* cursor) {
return widget_set_prop_str(wm, WIDGET_PROP_CURSOR, cursor);
}
#ifndef WITHOUT_WINDOW_ANIMATORS
#ifndef WITHOUT_WIDGET_ANIMATORS
ret_t widget_set_animation(widget_t* widget, const char* animation) {
return_value_if_fail(widget != NULL && animation != NULL, RET_BAD_PARAMS);

View File

@ -27,7 +27,8 @@
#define pixel_dst_format pixel_bgr565_format
#define pixel_dst_to_rgba pixel_bgr565_to_rgba
#define pixel_dst_from_rgb pixel_bgr565_from_rgb
#define pixel_dst_from_rgba(r, g, b, a) pixel_bgr565_from_rgb(r, g, b)
#define pixel_dst_from_rgba pixel_bgr565_from_rgba
//#define pixel_dst_from_rgba(r, g, b, a) pixel_bgr565_from_rgb(r, g, b)
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -35,6 +36,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
static inline void blend_a_bgr565_bgra8888(uint8_t* dst, uint8_t* src, uint8_t a) {

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr565_format
#define pixel_dst_to_rgba pixel_bgr565_to_rgba
#define pixel_dst_from_rgb pixel_bgr565_from_rgb
#define pixel_dst_from_rgba pixel_bgr565_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
static inline void blend_a_bgr565_bgra8888(uint8_t* dst, uint8_t* src, uint8_t alpha) {

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr565_format
#define pixel_dst_to_rgba pixel_bgr565_to_rgba
#define pixel_dst_from_rgb pixel_bgr565_from_rgb
#define pixel_dst_from_rgba pixel_bgr565_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr565_format
#define pixel_dst_to_rgba pixel_bgr565_to_rgba
#define pixel_dst_from_rgb pixel_bgr565_from_rgb
#define pixel_dst_from_rgba pixel_bgr565_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
static inline void blend_a_bgr565_rgba8888(uint8_t* dst, uint8_t* src, uint8_t alpha) {

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
#define pixel_src_t pixel_bgr888_t
#define pixel_src_format pixel_bgr888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgra8888_format
#define pixel_dst_to_rgba pixel_bgra8888_to_rgba
#define pixel_dst_from_rgb pixel_bgra8888_from_rgb
#define pixel_dst_from_rgba pixel_bgra8888_from_rgba
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgra8888_format
#define pixel_dst_to_rgba pixel_bgra8888_to_rgba
#define pixel_dst_from_rgb pixel_bgra8888_from_rgb
#define pixel_dst_from_rgba pixel_bgra8888_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgra8888_format
#define pixel_dst_to_rgba pixel_bgra8888_to_rgba
#define pixel_dst_from_rgb pixel_bgra8888_from_rgb
#define pixel_dst_from_rgba pixel_bgra8888_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_bgra8888_format
#define pixel_dst_to_rgba pixel_bgra8888_to_rgba
#define pixel_dst_from_rgb pixel_bgra8888_from_rgb
#define pixel_dst_from_rgba pixel_bgra8888_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb565_format
#define pixel_dst_to_rgba pixel_rgb565_to_rgba
#define pixel_dst_from_rgb pixel_rgb565_from_rgb
#define pixel_dst_from_rgba pixel_rgb565_from_rgba
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb565_format
#define pixel_dst_to_rgba pixel_rgb565_to_rgba
#define pixel_dst_from_rgb pixel_rgb565_from_rgb
#define pixel_dst_from_rgba pixel_rgb565_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb565_format
#define pixel_dst_to_rgba pixel_rgb565_to_rgba
#define pixel_dst_from_rgb pixel_rgb565_from_rgb
#define pixel_dst_from_rgba pixel_rgb565_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb565_format
#define pixel_dst_to_rgba pixel_rgb565_to_rgba
#define pixel_dst_from_rgb pixel_rgb565_from_rgb
#define pixel_dst_from_rgba pixel_rgb565_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
#define pixel_src_t pixel_rgb888_t
#define pixel_src_format pixel_rgb888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgba8888_format
#define pixel_dst_to_rgba pixel_rgba8888_to_rgba
#define pixel_dst_from_rgb pixel_rgba8888_from_rgb
#define pixel_dst_from_rgba pixel_rgba8888_from_rgba
#define pixel_src_t pixel_bgr565_t
#define pixel_src_format pixel_bgr565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgba8888_format
#define pixel_dst_to_rgba pixel_rgba8888_to_rgba
#define pixel_dst_from_rgb pixel_rgba8888_from_rgb
#define pixel_dst_from_rgba pixel_rgba8888_from_rgba
#define pixel_src_t pixel_bgra8888_t
#define pixel_src_format pixel_bgra8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgba8888_format
#define pixel_dst_to_rgba pixel_rgba8888_to_rgba
#define pixel_dst_from_rgb pixel_rgba8888_from_rgb
#define pixel_dst_from_rgba pixel_rgba8888_from_rgba
#define pixel_src_t pixel_rgb565_t
#define pixel_src_format pixel_rgb565_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -27,6 +27,7 @@
#define pixel_dst_format pixel_rgba8888_format
#define pixel_dst_to_rgba pixel_rgba8888_to_rgba
#define pixel_dst_from_rgb pixel_rgba8888_from_rgb
#define pixel_dst_from_rgba pixel_rgba8888_from_rgba
#define pixel_src_t pixel_rgba8888_t
#define pixel_src_format pixel_rgba8888_format
@ -34,6 +35,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#include "pixel_ops.inc"

View File

@ -11,7 +11,7 @@ static ret_t clear_image(bitmap_t* dst, rect_t* dst_r, color_t c) {
pixel_dst_t data = pixel_dst_from_rgba(c.rgba.r, c.rgba.g, c.rgba.b, c.rgba.a);
dst_data = bitmap_lock_buffer_for_write(dst);
return_value_if_fail(dst_data != NULL, RET_BAD_PARAMS);
return_value_if_fail(dst_data != NULL && dst_r->w > 0 && dst_r->h > 0, RET_BAD_PARAMS);
if (dst->w == dst_r->w && (dst->w * bpp) == line_length && dst->h == dst_r->h) {
uint32_t size = w * h;
@ -50,7 +50,7 @@ static ret_t fill_image(bitmap_t* dst, rect_t* dst_r, color_t c) {
uint32_t a = c.rgba.a;
if (a > 0xf8) {
clear_image(dst, dst_r, c);
return clear_image(dst, dst_r, c);
} else {
int x = 0;
int y = 0;
@ -70,7 +70,7 @@ static ret_t fill_image(bitmap_t* dst, rect_t* dst_r, color_t c) {
rgba.a = minus_a;
dst_data = bitmap_lock_buffer_for_write(dst);
return_value_if_fail(dst_data != NULL, RET_BAD_PARAMS);
return_value_if_fail(dst_data != NULL && dst_r->w > 0 && dst_r->h > 0, RET_BAD_PARAMS);
for (y = 0; y < h; y++) {
p = (pixel_dst_t*)(dst_data + (dst_r->y + y) * line_length + dst_r->x * bpp);

View File

@ -31,6 +31,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_abgr8888_blend_rgba_dark

View File

@ -31,6 +31,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_argb8888_blend_rgba_dark

View File

@ -27,10 +27,12 @@
#define pixel_dst_format pixel_bgr565_format
#define pixel_dst_to_rgba pixel_bgr565_to_rgba
#define pixel_dst_from_rgb pixel_bgr565_from_rgb
#define pixel_dst_from_rgba(r, g, b, a) pixel_bgr565_from_rgb(r, g, b)
#define pixel_dst_from_rgba pixel_bgr565_from_rgba
// #define pixel_dst_from_rgba(r, g, b, a) pixel_bgr565_from_rgb(r, g, b)
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_bgr565_blend_rgba_dark
#define pixel_blend_rgba_premulti pixel_bgr565_blend_rgba_premulti

View File

@ -27,10 +27,12 @@
#define pixel_dst_format pixel_bgr888_format
#define pixel_dst_to_rgba pixel_bgr888_to_rgba
#define pixel_dst_from_rgb pixel_bgr888_from_rgb
#define pixel_dst_from_rgba(r, g, b, a) pixel_bgr888_from_rgb(r, g, b)
#define pixel_dst_from_rgba pixel_bgr888_from_rgba
// #define pixel_dst_from_rgba(r, g, b, a) pixel_bgr888_from_rgb(r, g, b)
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_bgr888_blend_rgba_dark
#define pixel_blend_rgba_premulti pixel_bgr888_blend_rgba_premulti

View File

@ -31,6 +31,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_bgra8888_blend_rgba_dark

View File

@ -27,10 +27,12 @@
#define pixel_dst_format pixel_rgb565_format
#define pixel_dst_to_rgba pixel_rgb565_to_rgba
#define pixel_dst_from_rgb pixel_rgb565_from_rgb
#define pixel_dst_from_rgba(r, g, b, a) pixel_rgb565_from_rgb(r, g, b)
#define pixel_dst_from_rgba pixel_rgb565_from_rgba
// #define pixel_dst_from_rgba(r, g, b, a) pixel_rgb565_from_rgb(r, g, b)
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_rgb565_blend_rgba_dark
#define pixel_blend_rgba_premulti pixel_rgb565_blend_rgba_premulti

View File

@ -27,10 +27,12 @@
#define pixel_dst_format pixel_rgb888_format
#define pixel_dst_to_rgba pixel_rgb888_to_rgba
#define pixel_dst_from_rgb pixel_rgb888_from_rgb
#define pixel_dst_from_rgba(r, g, b, a) pixel_rgb888_from_rgb(r, g, b)
#define pixel_dst_from_rgba pixel_rgb888_from_rgba
// #define pixel_dst_from_rgba(r, g, b, a) pixel_rgb888_from_rgb(r, g, b)
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_rgb888_blend_rgba_dark
#define pixel_blend_rgba_premulti pixel_rgb888_blend_rgba_premulti

View File

@ -31,6 +31,7 @@
#define pixel_t pixel_dst_t
#define pixel_from_rgb pixel_dst_from_rgb
#define pixel_from_rgba pixel_dst_from_rgba
#define pixel_to_rgba pixel_dst_to_rgba
#define pixel_blend_rgba_dark pixel_rgba8888_blend_rgba_dark

View File

@ -19,15 +19,40 @@
*
*/
static inline uint8_t tk_pixel_ops_limit_uint8(int32_t tmp) {
if(tmp > 0xff) {
tmp = 0xff;
} else if(tmp < 0) {
tmp = 0;
}
return (uint8_t)tmp;
}
static inline pixel_t blend_color(color_t bg, color_t fg, uint8_t a) {
uint8_t minus_a = 0xff - a;
if(a > 0xf4) {
uint8_t minus_a = 0xff - a;
uint8_t r = (bg.rgba.r * minus_a + fg.rgba.r * a) >> 8;
uint8_t g = (bg.rgba.g * minus_a + fg.rgba.g * a) >> 8;
uint8_t b = (bg.rgba.b * minus_a + fg.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
uint8_t r = (bg.rgba.r * minus_a + fg.rgba.r * a) >> 8;
uint8_t g = (bg.rgba.g * minus_a + fg.rgba.g * a) >> 8;
uint8_t b = (bg.rgba.b * minus_a + fg.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
return p;
} else {
uint8_t fg_a = (fg.rgba.a * a) >> 8;
uint8_t out_a = tk_pixel_ops_limit_uint8(bg.rgba.a + fg_a - ((bg.rgba.a * fg_a) >> 8));
if(out_a > 0) {
uint8_t d_a = (bg.rgba.a * (0xff - fg_a)) >> 8;
uint8_t r = (bg.rgba.r * d_a + fg.rgba.r * fg_a) / out_a;
uint8_t g = (bg.rgba.g * d_a + fg.rgba.g * fg_a) / out_a;
uint8_t b = (bg.rgba.b * d_a + fg.rgba.b * fg_a) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}
static inline pixel_t blend_pixel(pixel_t pixel, color_t c) {
@ -35,49 +60,125 @@ static inline pixel_t blend_pixel(pixel_t pixel, color_t c) {
uint8_t minus_a = 0xff - a;
rgba_t rgba = pixel_to_rgba(pixel);
uint8_t r = (rgba.r * minus_a + c.rgba.r * a) >> 8;
uint8_t g = (rgba.g * minus_a + c.rgba.g * a) >> 8;
uint8_t b = (rgba.b * minus_a + c.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
if(rgba.a > 0xf4) {
uint8_t r = (rgba.r * minus_a + c.rgba.r * a) >> 8;
uint8_t g = (rgba.g * minus_a + c.rgba.g * a) >> 8;
uint8_t b = (rgba.b * minus_a + c.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
return p;
} else {
uint8_t out_a = tk_pixel_ops_limit_uint8(c.rgba.a + rgba.a - ((c.rgba.a * rgba.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (rgba.a * (0xff - c.rgba.a)) >> 8;
uint8_t r = (rgba.r * d_a + c.rgba.r * c.rgba.a) / out_a;
uint8_t g = (rgba.g * d_a + c.rgba.g * c.rgba.a) / out_a;
uint8_t b = (rgba.b * d_a + c.rgba.b * c.rgba.a) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}
static inline pixel_t blend_alpha(color_t fg, uint8_t a) {
uint8_t r = (fg.rgba.r * a) >> 8;
uint8_t g = (fg.rgba.g * a) >> 8;
uint8_t b = (fg.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
if(fg.rgba.a > 0xf4) {
uint8_t r = (fg.rgba.r * a) >> 8;
uint8_t g = (fg.rgba.g * a) >> 8;
uint8_t b = (fg.rgba.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
return p;
} else {
uint8_t out_a =tk_pixel_ops_limit_uint8(a + fg.rgba.a - ((a * fg.rgba.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (fg.rgba.a * (0xff - a)) >> 8;
uint8_t r = (fg.rgba.r * d_a) / out_a;
uint8_t g = (fg.rgba.g * d_a) / out_a;
uint8_t b = (fg.rgba.b * d_a) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}
static inline pixel_t blend_rgba(rgba_t d, rgba_t s, uint8_t a) {
uint8_t minus_a = 0xff - a;
uint8_t r = (d.r * minus_a + s.r * a) >> 8;
uint8_t g = (d.g * minus_a + s.g * a) >> 8;
uint8_t b = (d.b * minus_a + s.b * a) >> 8;
pixel_t p = pixel_from_rgb(r, g, b);
if(d.a > 0xf4) {
uint8_t minus_a = 0xff - a;
uint8_t r = (d.r * minus_a + s.r * a) >> 8;
uint8_t g = (d.g * minus_a + s.g * a) >> 8;
uint8_t b = (d.b * minus_a + s.b * a) >> 8;
return p;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
} else {
uint8_t out_a = tk_pixel_ops_limit_uint8(s.a + d.a - ((s.a * d.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (d.a * (0xff - s.a)) >> 8;
uint8_t r = (d.r * d_a + s.r * s.a) / out_a;
uint8_t g = (d.g * d_a + s.g * s.a) / out_a;
uint8_t b = (d.b * d_a + s.b * s.a) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}
static inline pixel_t blend_rgba_premulti(rgba_t d, rgba_t s, uint8_t a) {
uint8_t r = ((d.r * a) >> 8) + s.r;
uint8_t g = ((d.g * a) >> 8) + s.g;
uint8_t b = ((d.b * a) >> 8) + s.b;
if(d.a > 0xf4) {
uint8_t r = ((d.r * a) >> 8) + s.r;
uint8_t g = ((d.g * a) >> 8) + s.g;
uint8_t b = ((d.b * a) >> 8) + s.b;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
pixel_t p = pixel_from_rgb(r, g, b);
return p;
} else {
uint8_t out_a = tk_pixel_ops_limit_uint8(s.a + d.a - ((s.a * d.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (d.a * (0xff - s.a)) >> 8;
uint8_t r = (d.r * d_a + s.r) / out_a;
uint8_t g = (d.g * d_a + s.g) / out_a;
uint8_t b = (d.b * d_a + s.b) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}
static inline pixel_t blend_rgba_dark(rgba_t d, uint8_t a) {
uint8_t r = ((d.r * a) >> 8);
uint8_t g = ((d.g * a) >> 8);
uint8_t b = ((d.b * a) >> 8);
if(d.a > 0xf4) {
uint8_t r = ((d.r * a) >> 8);
uint8_t g = ((d.g * a) >> 8);
uint8_t b = ((d.b * a) >> 8);
pixel_t p = pixel_from_rgb(r, g, b);
pixel_t p = pixel_from_rgb(r, g, b);
return p;
return p;
} else {
uint8_t out_a =tk_pixel_ops_limit_uint8(a + d.a - ((a * d.a) >> 8));
if(out_a > 0) {
uint8_t d_a = (d.a * (0xff - a)) >> 8;
uint8_t r = (d.r * d_a) / out_a;
uint8_t g = (d.g * d_a) / out_a;
uint8_t b = (d.b * d_a) / out_a;
pixel_t p = pixel_from_rgba(r, g, b, out_a);
return p;
} else {
pixel_t p = pixel_from_rgba(0x0, 0x0, 0x0, 0x0);
return p;
}
}
}

View File

@ -53,6 +53,8 @@ static ret_t dialog_highlighter_default_prepare(dialog_highlighter_t* h, canvas_
}
static ret_t dialog_highlighter_default_draw(dialog_highlighter_t* h, float_t percent) {
rect_t r;
rect_t save_r;
canvas_t* c = h->canvas;
bitmap_t* img = &(h->img);
rect_t src = rect_init(0, 0, img->w, img->h);
@ -64,7 +66,11 @@ static ret_t dialog_highlighter_default_draw(dialog_highlighter_t* h, float_t pe
canvas_draw_image(c, img, &src, &dst);
window_manager_paint_system_bar(window_manager(), c);
} else {
lcd_draw_image(c->lcd, img, &src, &dst);
canvas_get_clip_rect(c, &save_r);
r = rect_intersect(&save_r, &h->clip_rect);
canvas_set_clip_rect(c, &r);
canvas_draw_image(c, img, &src, &dst);
canvas_set_clip_rect(c, &save_r);
}
/*

View File

@ -1,4 +1,4 @@
/**
/**
* File: lcd_mem.c
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: mem implemented lcd interface
@ -74,7 +74,21 @@ static bitmap_t* lcd_mem_init_online_fb(lcd_t* lcd, bitmap_t* fb, lcd_orientatio
}
static ret_t lcd_mem_begin_frame(lcd_t* lcd, rect_t* dirty_rect) {
#if WITH_LCD_CLEAR_ALPHA
rect_t r;
bitmap_t fb;
if (lcd->draw_mode == LCD_DRAW_OFFLINE || dirty_rect == NULL) {
r = rect_init(0, 0, lcd->w, lcd->h);
} else {
r = rect_init(dirty_rect->x, dirty_rect->y, dirty_rect->w, dirty_rect->h);
}
lcd_mem_init_drawing_fb(lcd, &fb);
return image_clear(&fb, &r, color_init(0x0, 0x0, 0x0, 0x0));
#else
return RET_OK;
#endif
}
static ret_t lcd_mem_fill_rect_with_color(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h, color_t c) {

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_bgr565_BPP
#define pixel_to_rgba pixel_bgr565_to_rgba
#define pixel_from_rgb pixel_bgr565_from_rgb
#define pixel_from_rgba pixel_bgr565_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_bgr888_BPP
#define pixel_to_rgba pixel_bgr888_to_rgba
#define pixel_from_rgb pixel_bgr888_from_rgb
#define pixel_from_rgba pixel_bgr888_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_bgra8888_BPP
#define pixel_to_rgba pixel_bgra8888_to_rgba
#define pixel_from_rgb pixel_bgra8888_from_rgb
#define pixel_from_rgba pixel_bgra8888_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_rgb565_BPP
#define pixel_to_rgba pixel_rgb565_to_rgba
#define pixel_from_rgb pixel_rgb565_from_rgb
#define pixel_from_rgba pixel_rgb565_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_rgb888_BPP
#define pixel_to_rgba pixel_rgb888_to_rgba
#define pixel_from_rgb pixel_rgb888_from_rgb
#define pixel_from_rgba pixel_rgb888_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -29,6 +29,7 @@
#define pixel_bpp pixel_rgba8888_BPP
#define pixel_to_rgba pixel_rgba8888_to_rgba
#define pixel_from_rgb pixel_rgba8888_from_rgb
#define pixel_from_rgba pixel_rgba8888_from_rgba
#include "blend/pixel_ops.inc"
#include "lcd/lcd_mem.inc"

View File

@ -31,7 +31,7 @@
static ret_t lcd_mem_special_begin_frame(lcd_t* lcd, rect_t* dr) {
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
lcd_t* mem = (lcd_t*)(special->lcd_mem);
mem->draw_mode = lcd->draw_mode;
mem->begin_frame(mem, dr);
return RET_OK;

View File

@ -11,8 +11,14 @@ static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, uint
}
static inline void vgcanvas_nanovg_set_offline_fb(vgcanvas_nanovg_t* canvas, uint32_t w,
uint32_t h) {
uint32_t h, rect_t* dirty_rect) {
GLint default_fbo = 0;
#if WITH_LCD_CLEAR_ALPHA
rect_t r;
system_info_t* info = system_info();
#endif
vgcanvas_nanovg_offline_fb_t* offline_fb = canvas->offline_fb;
if (offline_fb != NULL) {
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &default_fbo);
@ -30,6 +36,33 @@ static inline void vgcanvas_nanovg_set_offline_fb(vgcanvas_nanovg_t* canvas, uin
// 去除这两行注释就可以显示脏矩形的工作原理。
// glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
#if WITH_LCD_CLEAR_ALPHA
switch (info->lcd_orientation) {
case LCD_ORIENTATION_0:
r = rect_init(dirty_rect->x, h - dirty_rect->h - dirty_rect->y, dirty_rect->w, dirty_rect->h);
break;
case LCD_ORIENTATION_90:
r = rect_init(w - dirty_rect->h - dirty_rect->y, h - dirty_rect->w - dirty_rect->x, dirty_rect->h, dirty_rect->w);
break;
case LCD_ORIENTATION_180:
r = rect_init(w - dirty_rect->w - dirty_rect->x, dirty_rect->y, dirty_rect->w, dirty_rect->h);
break;
case LCD_ORIENTATION_270:
r = rect_init(dirty_rect->y, dirty_rect->x, dirty_rect->h, dirty_rect->w);
break;
}
// 把脏矩形的区域刷新为黑色透明度为0的颜色
glScissor(r.x, r.y, r.w, r.h);
glEnable(GL_SCISSOR_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
#else
(void)dirty_rect;
#endif
}
}
}
@ -44,7 +77,7 @@ static inline void vgcanvas_nanovg_offline_fb_flush(vgcanvas_nanovg_t* canvas) {
glViewport(0, 0, info->lcd_w * info->device_pixel_ratio,
info->lcd_h * info->device_pixel_ratio);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glUseProgram(shader_info->program_object);
@ -91,8 +124,6 @@ static ret_t vgcanvas_nanovg_begin_frame(vgcanvas_t* vgcanvas, rect_t* dirty_rec
native_window_gl_make_current(canvas->window);
vgcanvas_nanovg_set_offline_fb(canvas, info->lcd_w * info->device_pixel_ratio,
info->lcd_h * info->device_pixel_ratio);
if (dirty_rect != NULL) {
canvas->base.dirty_rect = rect_init(dirty_rect->x, dirty_rect->y, dirty_rect->w, dirty_rect->h);
} else {
@ -104,6 +135,9 @@ static ret_t vgcanvas_nanovg_begin_frame(vgcanvas_t* vgcanvas, rect_t* dirty_rec
}
}
vgcanvas_nanovg_set_offline_fb(canvas, info->lcd_w * info->device_pixel_ratio,
info->lcd_h * info->device_pixel_ratio, &canvas->base.dirty_rect);
nvgBeginFrame(canvas->vg, info->lcd_w, info->lcd_h, info->device_pixel_ratio);
switch (info->lcd_orientation) {
@ -183,9 +217,11 @@ static ret_t vgcanvas_nanovg_bind_fbo(vgcanvas_t* vgcanvas, framebuffer_object_t
NVGLUframebuffer* handle = (NVGLUframebuffer*)fbo->handle;
vgcanvas->dirty_rect = rect_init(0, 0, fbo->w, fbo->h);
nvgluBindFramebuffer(handle);
glClearColor(0, 0, 0, 0);
glViewport(0, 0, fbo->w * fbo->ratio, fbo->h * fbo->ratio);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
nvgBeginFrame(vg, fbo->w, fbo->h, fbo->ratio);
return RET_OK;

View File

@ -153,11 +153,10 @@ ret_t window_manager_default_snap_curr_window(widget_t* widget, widget_t* curr_w
ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_win, bitmap_t* img,
framebuffer_object_t* fbo, bool_t auto_rotate) {
rect_t r = {0};
canvas_t* c = NULL;
#ifdef WITH_NANOVG_GPU
vgcanvas_t* vg = NULL;
#else
rect_t r = {0};
#endif /*WITH_NANOVG_GPU*/
window_manager_default_t* wm = WINDOW_MANAGER_DEFAULT(widget);
@ -178,11 +177,13 @@ ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_w
}
WIDGET_FOR_EACH_CHILD_END()
r = rect_init(prev_win->x, prev_win->y, prev_win->w, prev_win->h);
#ifdef WITH_NANOVG_GPU
vg = lcd_get_vgcanvas(c->lcd);
ENSURE(vgcanvas_create_fbo(vg, fbo) == RET_OK);
ENSURE(vgcanvas_bind_fbo(vg, fbo) == RET_OK);
canvas_set_clip_rect(c, NULL);
canvas_set_clip_rect(c, &r);
ENSURE(widget_on_paint_background(widget, c) == RET_OK);
window_manager_paint_system_bar(widget, c);
{
@ -203,7 +204,6 @@ ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_w
ENSURE(vgcanvas_unbind_fbo(vg, fbo) == RET_OK);
fbo_to_img(fbo, img);
#else
r = rect_init(prev_win->x, prev_win->y, prev_win->w, prev_win->h);
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_OFFLINE) == RET_OK);
canvas_set_clip_rect(c, &r);
ENSURE(widget_on_paint_background(widget, c) == RET_OK);
@ -229,6 +229,7 @@ ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_w
if (dialog_highlighter != NULL) {
dialog_highlighter_set_bg(dialog_highlighter, img, fbo);
dialog_highlighter_set_bg_clip_rect(dialog_highlighter, &r);
}
wm->curr_win = NULL;
return RET_OK;