update on blit function.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@844 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
a385dc3940
commit
084a39897f
|
@ -27,18 +27,16 @@ static void rtgui_blit_line_3_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
|
|||
/* 4 bpp to 1 bpp */
|
||||
static void rtgui_blit_line_4_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
||||
{
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr = (rt_uint8_t)(((*src_ptr & 0x00E00000)>>16)|
|
||||
((*(src_ptr + 1) & 0x0000E000)>>11) |
|
||||
((*(src_ptr + 2) & 0x000000C0)>>6));
|
||||
|
||||
src_ptr += 4;
|
||||
dst_ptr ++;
|
||||
line --;
|
||||
struct _color {rt_uint8_t r, g, b, a;} *c;
|
||||
|
||||
c = (struct _color*)src_ptr;
|
||||
while (line-- > 0)
|
||||
{
|
||||
*dst_ptr = (c->r & 0xe0) | (c->g & 0xc0) >> 3 | (c->b & 0xe0) >> 5 ;
|
||||
|
||||
c ++;
|
||||
dst_ptr ++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* 1 bpp to 2 bpp */
|
||||
|
@ -72,22 +70,20 @@ static void rtgui_blit_line_3_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
|
|||
/* 4 bpp to 2 bpp */
|
||||
static void rtgui_blit_line_4_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
||||
{
|
||||
rt_uint16_t* dst;
|
||||
|
||||
dst = (rt_uint16_t*)dst_ptr;
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst = (((*(src_ptr + 1) << 8) & 0x0000F800) |
|
||||
((*(src_ptr + 1) << 3) & 0x000007E0) |
|
||||
((*src_ptr >> 3) & 0x0000001F));
|
||||
|
||||
src_ptr += 4; /* skip alpha */
|
||||
dst ++;
|
||||
line --;
|
||||
}
|
||||
|
||||
return;
|
||||
struct _color {rt_uint8_t r, g, b, a;} *c;
|
||||
rt_uint16_t* ptr;
|
||||
|
||||
c = (struct _color*)src_ptr;
|
||||
ptr = (rt_uint16_t*)dst_ptr;
|
||||
|
||||
line = line / 4;
|
||||
while (line-- > 0)
|
||||
{
|
||||
*ptr = ((c->r & 0xf8) << 8) | ((c->g & 0xfc) << 3) | (c->b >> 3);
|
||||
|
||||
c ++;
|
||||
ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_blit_line_1_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
||||
|
@ -253,11 +249,16 @@ void rtgui_blit_line_direct(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
|||
rt_memcpy(dst_ptr, src_ptr, line);
|
||||
}
|
||||
|
||||
/* convert 4bpp to 3bpp */
|
||||
static void rtgui_blit_line_4_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
||||
{
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
src_ptr ++;
|
||||
line --;
|
||||
}
|
||||
}
|
||||
|
@ -270,9 +271,18 @@ static void rtgui_blit_line_2_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
|
|||
{
|
||||
}
|
||||
|
||||
/* convert 3bpp to 4bpp */
|
||||
static void rtgui_blit_line_3_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
|
||||
{
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = 0;
|
||||
line --;
|
||||
}
|
||||
}
|
||||
|
||||
static const rtgui_blit_line_func _blit_table[5][5] =
|
||||
|
@ -291,8 +301,8 @@ static const rtgui_blit_line_func _blit_table[5][5] =
|
|||
|
||||
const rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp)
|
||||
{
|
||||
RT_ASSERT(dst_bpp>1 && dst_bpp < 5);
|
||||
RT_ASSERT(src_bpp>1 && src_bpp < 5);
|
||||
RT_ASSERT(dst_bpp>0 && dst_bpp < 5);
|
||||
RT_ASSERT(src_bpp>0 && src_bpp < 5);
|
||||
|
||||
return _blit_table[dst_bpp][src_bpp];
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/blit.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/color.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
@ -207,45 +208,6 @@ static void rtgui_dc_buffer_fill_rect (struct rtgui_dc* self, struct rtgui_rect*
|
|||
}
|
||||
}
|
||||
|
||||
/* rtgui_color to RGB323 */
|
||||
rt_inline void rtgui_blit_line_1(rtgui_color_t* color, rt_uint8_t* dest, int line)
|
||||
{
|
||||
struct _color {rt_uint8_t r, g, b, a;} *c;
|
||||
|
||||
c = (struct _color*)color;
|
||||
while (line-- > 0)
|
||||
{
|
||||
*dest = (c->r & 0xe0) | (c->g & 0xc0) >> 3 | (c->b & 0xe0) >> 5 ;
|
||||
|
||||
c ++;
|
||||
dest ++;
|
||||
}
|
||||
}
|
||||
|
||||
/* rtgui_color to RGB565 */
|
||||
rt_inline void rtgui_blit_line_2(rtgui_color_t* color, rt_uint8_t* dest, int line)
|
||||
{
|
||||
struct _color {rt_uint8_t r, g, b, a;} *c;
|
||||
rt_uint16_t* ptr;
|
||||
|
||||
c = (struct _color*)color;
|
||||
ptr = (rt_uint16_t*)dest;
|
||||
|
||||
while (line-- > 0)
|
||||
{
|
||||
*ptr = ((c->r & 0xf8) << 8) | ((c->g & 0xfc) << 3) | (c->b >> 3);
|
||||
|
||||
c ++;
|
||||
ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
/* rtgui_color to RGB888 */
|
||||
rt_inline void rtgui_blit_line_4(rtgui_color_t* color, rt_uint8_t* dest, int line)
|
||||
{
|
||||
rt_memcpy(dest, color, line * 4);
|
||||
}
|
||||
|
||||
/* blit a dc to a hardware dc */
|
||||
static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect)
|
||||
{
|
||||
|
@ -259,7 +221,9 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
|
|||
rtgui_color_t* pixel;
|
||||
rt_uint8_t *line_ptr;
|
||||
rt_uint16_t rect_width, rect_height, index;
|
||||
void (*blit_line)(rtgui_color_t* color, rt_uint8_t* dest, int line);
|
||||
rtgui_blit_line_func blit_line;
|
||||
|
||||
if (rtgui_dc_get_visible(hw) == RT_FALSE) return;
|
||||
|
||||
/* calculate correct width and height */
|
||||
if (rtgui_rect_width(*rect) > (dc->width - dc_point->x))
|
||||
|
@ -273,23 +237,7 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
|
|||
rect_height = rtgui_rect_height(*rect);
|
||||
|
||||
/* get blit line function */
|
||||
switch (rtgui_graphic_driver_get_default()->byte_per_pixel)
|
||||
{
|
||||
case 1:
|
||||
blit_line = rtgui_blit_line_1;
|
||||
break;
|
||||
case 2:
|
||||
blit_line = rtgui_blit_line_2;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
blit_line = rtgui_blit_line_4;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* not support byte per pixel */
|
||||
return;
|
||||
}
|
||||
blit_line = rtgui_blit_line_get(rtgui_graphic_driver_get_default()->byte_per_pixel, 4);
|
||||
|
||||
/* create line buffer */
|
||||
line_ptr = (rt_uint8_t*) rtgui_malloc(rect_width * rtgui_graphic_driver_get_default()->byte_per_pixel);
|
||||
|
@ -297,11 +245,14 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
|
|||
/* prepare pixel line */
|
||||
pixel = (rtgui_color_t*)(dc->pixel + dc_point->y * dc->pitch + dc_point->x * sizeof(rtgui_color_t));
|
||||
|
||||
/* calculate pitch */
|
||||
rect_width = rect_width * rtgui_graphic_driver_get_default()->byte_per_pixel;
|
||||
|
||||
/* draw each line */
|
||||
for (index = rect->y1; index < rect->y1 + rect_height; index ++)
|
||||
{
|
||||
/* blit on line buffer */
|
||||
blit_line(pixel, line_ptr, rect_width);
|
||||
blit_line(line_ptr, (rt_uint8_t*)pixel, rect_width);
|
||||
pixel += dc->width;
|
||||
|
||||
/* draw on hardware dc */
|
||||
|
@ -313,7 +264,6 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void rtgui_dc_buffer_set_gc(struct rtgui_dc* self, rtgui_gc_t *gc)
|
||||
{
|
||||
struct rtgui_dc_buffer* dc = (struct rtgui_dc_buffer*)self;
|
||||
|
|
Loading…
Reference in New Issue