2011-06-05 23:16:41 +08:00
|
|
|
#include <rtgui/rtgui_system.h>
|
|
|
|
#include <rtgui/driver.h>
|
|
|
|
|
|
|
|
static void _pixeldevice_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|
|
|
{
|
|
|
|
switch (rtgui_graphic_get_device()->pixel_format)
|
|
|
|
{
|
2011-06-06 17:10:13 +08:00
|
|
|
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
2011-06-05 23:16:41 +08:00
|
|
|
{
|
|
|
|
rt_uint16_t pixel;
|
|
|
|
pixel = rtgui_color_to_565(*c);
|
2011-06-06 17:10:13 +08:00
|
|
|
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
2011-06-05 23:16:41 +08:00
|
|
|
sizeof(pixel));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-06 17:10:13 +08:00
|
|
|
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
2011-06-05 23:16:41 +08:00
|
|
|
{
|
|
|
|
rt_uint32_t pixel;
|
|
|
|
pixel = rtgui_color_to_888(*c);
|
2011-06-06 17:10:13 +08:00
|
|
|
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
2011-06-05 23:16:41 +08:00
|
|
|
3);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _pixeldevice_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|
|
|
{
|
|
|
|
switch (rtgui_graphic_get_device()->pixel_format)
|
|
|
|
{
|
2011-06-06 17:10:13 +08:00
|
|
|
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
2011-06-05 23:16:41 +08:00
|
|
|
{
|
|
|
|
rt_uint16_t pixel;
|
2011-06-06 17:10:13 +08:00
|
|
|
rt_device_read(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
|
|
|
(rtgui_graphic_get_device()->bits_per_pixel/8));
|
2011-06-05 23:16:41 +08:00
|
|
|
/* get pixel from color */
|
|
|
|
*c = rtgui_color_from_565(pixel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-06 17:10:13 +08:00
|
|
|
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
2011-06-05 23:16:41 +08:00
|
|
|
{
|
|
|
|
rt_uint32_t pixel;
|
2011-06-06 17:10:13 +08:00
|
|
|
rt_device_read(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
2011-06-05 23:16:41 +08:00
|
|
|
3);
|
|
|
|
/* get pixel from color */
|
|
|
|
*c = rtgui_color_from_888(pixel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _pixeldevice_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
|
|
|
{
|
|
|
|
rt_ubase_t index;
|
|
|
|
|
|
|
|
for (index = x1; index < x2; index ++)
|
|
|
|
_pixeldevice_set_pixel(c, index, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _pixeldevice_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
|
|
|
|
{
|
|
|
|
rt_ubase_t index;
|
|
|
|
|
|
|
|
for (index = y1; index < y2; index ++)
|
|
|
|
_pixeldevice_set_pixel(c, x, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw raw hline */
|
|
|
|
static void _pixeldevice_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
|
|
|
{
|
2011-06-06 17:10:13 +08:00
|
|
|
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x1, y), pixels,
|
|
|
|
(x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
|
2011-06-05 23:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pixel device */
|
|
|
|
const struct rtgui_graphic_driver_ops _pixeldevice_ops =
|
|
|
|
{
|
|
|
|
_pixeldevice_set_pixel,
|
|
|
|
_pixeldevice_get_pixel,
|
|
|
|
_pixeldevice_draw_hline,
|
|
|
|
_pixeldevice_vline,
|
|
|
|
_pixeldevice_draw_raw_hline,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
|
|
|
|
{
|
|
|
|
return &_pixeldevice_ops;
|
|
|
|
}
|
|
|
|
|