optimize fill color

This commit is contained in:
xianjimli 2018-05-26 08:02:44 +08:00
parent da12ee1a54
commit be985332a0
4 changed files with 84 additions and 4 deletions

View File

@ -217,3 +217,44 @@ const char* ftk_ftoa(char* str, int len, float_t value) {
}
char* ftk_strcpy(char* dst, const char* src) { return strcpy(dst, src); }
uint16_t* tk_memset16(uint16_t* buff, uint16_t val, uint32_t size) {
return_value_if_fail(buff != NULL, NULL);
if(size < 8) {
uint32_t i = 0;
for(i = 0; i < size; i++) {
buff[i] = val;
}
return buff;
} else {
uint32_t* p = NULL;
uint32_t* end = NULL;
uint32_t val32 = (val << 16) | val;
uint8_t pad1 = ((size_t)buff) & 0x03;
uint8_t pad2 = pad1 ? (size & 0x01) == 0 : (size & 0x01) == 1;
if(pad1) {
buff[0] = val;
p = (uint32_t*)(buff+1);
} else {
p = (uint32_t*)(buff);
}
if(pad2) {
buff[size-1] = val;
end = (uint32_t*)(buff + size - 1);
} else {
end = (uint32_t*)(buff + size);
}
while(p < end) {
*p++ = val32;
}
}
return buff;
}

View File

@ -32,6 +32,8 @@ const char* ftk_itoa(char* str, int len, int n);
const char* ftk_ftoa(char* str, int len, float_t f);
long ftk_strtol(const char* str, const char** end, int base);
uint16_t* tk_memset16(uint16_t* buff, uint16_t val, uint32_t size);
#define str_fast_equal(s1, s2) (*(s1) == *(s2) && strcmp((s1), (s2)) == 0)
END_C_DECLS

View File

@ -19,6 +19,7 @@
*
*/
#include "base/utils.h"
#include "blend/soft_g2d.h"
#include "blend/pixel_pack_unpack.h"
@ -60,14 +61,13 @@ ret_t soft_fill_rect(bitmap_t* fb, rect_t* dst, color_t c) {
bpp = fb->format == BITMAP_FMT_RGB565 ? 2 : 4;
p = (uint32_t*)((fb->data) + (dst->y * fb->w + dst->x) * bpp);
if (fb->format == BITMAP_FMT_RGB565) {
uint32_t fbw = fb->w;
uint16_t* p16 = (uint16_t*)p;
uint16_t d16 = rgb_to_565(c.rgba.r, c.rgba.g, c.rgba.b);
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
*p16++ = d16;
}
p16 += offset;
tk_memset16(p16, d16, w);
p16 += fbw;
}
return RET_OK;

View File

@ -7,3 +7,40 @@ TEST(Utils, basic) {
ASSERT_EQ(ftk_atoi("100"), 100);
ASSERT_EQ(strcmp(ftk_itoa(str, sizeof(str), ftk_atoi("100")), "100"), 0);
}
static void check_buff(uint16_t* buff, uint16_t val, uint32_t size) {
uint32_t i = 0;
for(i = 0; i < size; i++) {
assert(buff[i] == val);
}
}
TEST(Utils, tk_memset16) {
uint16_t buff[32];
uint16_t val = 0x1234;
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff, val, 1);
check_buff(buff, val, 1);
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff, val, 7);
check_buff(buff, val, 7);
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff+1, val, 10);
check_buff(buff+1, val, 10);
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff+1, val, 11);
check_buff(buff+1, val, 11);
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff, val, 10);
check_buff(buff, val, 10);
memset(buff, 0x00, sizeof(buff));
tk_memset16(buff, val, 11);
check_buff(buff, val, 11);
}