123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #include <rtgui/rtgui_system.h>
- #include <rtgui/driver.h>
- #define GET_PIXEL(dst, x, y, type) \
- (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * (dst)->byte_per_pixel)
- static void _rgb565_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565(*c);
- }
- static void _rgb565_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- rt_uint16_t pixel;
- pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
- /* get pixel from color */
- *c = rtgui_color_from_565(pixel);
- }
- static void _rgb565_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
- {
- rt_ubase_t index;
- rt_uint16_t pixel;
- rt_uint16_t *pixel_ptr;
- /* get pixel from color */
- pixel = rtgui_color_to_565(*c);
- /* get pixel pointer in framebuffer */
- pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
-
- for (index = x1; index < x2; index ++)
- {
- *pixel_ptr = pixel;
- pixel_ptr ++;
- }
- }
- static void _rgb565_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
- {
- rt_uint8_t *dst;
- rt_uint16_t pixel;
- rt_ubase_t index;
- pixel = rtgui_color_to_565(*c);
- dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
- for (index = y1; index < y2; index ++)
- {
- *(rt_uint16_t*)dst = pixel;
- dst += rtgui_graphic_get_device()->pitch;
- }
- }
- static void _rgb565p_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
- }
- static void _rgb565p_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- rt_uint16_t pixel;
- pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
- /* get pixel from color */
- *c = rtgui_color_from_565p(pixel);
- }
- static void _rgb565p_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
- {
- rt_ubase_t index;
- rt_uint16_t pixel;
- rt_uint16_t *pixel_ptr;
- /* get pixel from color */
- pixel = rtgui_color_to_565p(*c);
- /* get pixel pointer in framebuffer */
- pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
-
- for (index = x1; index < x2; index ++)
- {
- *pixel_ptr = pixel;
- pixel_ptr ++;
- }
- }
- static void _rgb565p_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
- {
- rt_uint8_t *dst;
- rt_uint16_t pixel;
- rt_ubase_t index;
- pixel = rtgui_color_to_565p(*c);
- dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
- for (index = y1; index < y2; index ++)
- {
- *(rt_uint16_t*)dst = pixel;
- dst += rtgui_graphic_get_device()->pitch;
- }
- }
- /* draw raw hline */
- static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
- {
- rt_uint8_t *dst;
- dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
- rt_memcpy(dst, pixels, (x2 - x1) * rtgui_graphic_get_device()->byte_per_pixel);
- }
- const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
- {
- _rgb565_set_pixel,
- _rgb565_get_pixel,
- _rgb565_draw_hline,
- _rgb565_draw_vline,
- framebuffer_draw_raw_hline,
- };
- const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
- {
- _rgb565p_set_pixel,
- _rgb565p_get_pixel,
- _rgb565p_draw_hline,
- _rgb565p_draw_vline,
- framebuffer_draw_raw_hline,
- };
- #define FRAMEBUFFER (rtgui_graphic_get_device()->framebuffer)
- #define MONO_PIXEL(framebuffer, x, y) \
- ((rt_uint8_t**)(framebuffer))[y/8][x]
- static void _mono_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- if (*c == white)
- MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y%8));
- else
- MONO_PIXEL(FRAMEBUFFER, x, y) |= (1 << (y%8));
- }
- static void _mono_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
- {
- if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y%8)))
- *c = black;
- else
- *c = white;
- }
- static void _mono_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
- {
- rt_ubase_t index;
-
- if (*c == white)
- for (index = x1; index < x2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
- }
- else
- for (index = x1; index < x2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
- }
- }
- static void _mono_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
- {
- rt_ubase_t index;
-
- if (*c == white)
- for (index = y1; index < y2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, x, index) &= ~(1 << (index%8));
- }
- else
- for (index = y1; index < y2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, x, index) |= (1 << (index%8));
- }
- }
- /* draw raw hline */
- static void _mono_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
- {
- rt_ubase_t index;
- for (index = x1; index < x2; index ++)
- {
- if (pixels[index/8] && (1 << (index % 8)))
- MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
- else
- MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
- }
- }
- const struct rtgui_graphic_driver_ops _framebuffer_mono_ops =
- {
- _mono_set_pixel,
- _mono_get_pixel,
- _mono_draw_hline,
- _mono_draw_vline,
- _mono_draw_raw_hline,
- };
- const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format)
- {
- switch (pixel_format)
- {
- case PIXEL_FORMAT_MONO:
- return &_framebuffer_mono_ops;
- case PIXEL_FORMAT_GRAY4:
- break;
- case PIXEL_FORMAT_GRAY16:
- break;
- case PIXEL_FORMAT_RGB565:
- return &_framebuffer_rgb565_ops;
- case PIXEL_FORMAT_RGB565P:
- return &_framebuffer_rgb565p_ops;
- }
- return RT_NULL;
- }
|