Exemplo n.º 1
0
static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
    struct rtgui_graphic_driver *drv = rtgui_graphic_get_device();
    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));
        }
}
Exemplo n.º 2
0
static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
{
    struct rtgui_graphic_driver *drv;
    rt_uint8_t *dst;
    rt_uint16_t pixel;
    rt_ubase_t index;

    drv = rtgui_graphic_get_device();
    pixel = rtgui_color_to_565p(*c);
    dst = GET_PIXEL(drv, x, y1, rt_uint8_t);
    for (index = y1; index < y2; index ++)
    {
        *(rt_uint16_t *)dst = pixel;
        dst += drv->pitch;
    }
}
Exemplo n.º 3
0
static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
    int 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 ++;
    }
}
Exemplo n.º 4
0
static void rtgui_image_png_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect)
{
    rt_uint16_t x, y, w, h;
    rtgui_color_t *ptr;
    struct rtgui_image_png *png;
    int fg_maxsample;
    int ialpha;
    float alpha;
    rtgui_color_t color;
    rtgui_color_t c, bgcolor;
    int fc[3], bc[3];
    struct rtgui_graphic_driver *hwdev = rtgui_graphic_get_device();

    RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
    RT_ASSERT(image->data != RT_NULL);

    png = (struct rtgui_image_png *) image->data;

	w = _UI_MIN(image->w, rtgui_rect_width(*rect));
	h = _UI_MIN(image->h, rtgui_rect_height(*rect));

    fg_maxsample = (1 << png->info_ptr->bit_depth) - 1;

    if (png->pixels != RT_NULL)
    {
        ptr = (rtgui_color_t *)png->pixels;
        bgcolor = RTGUI_DC_BC(dc);
        bc[0] = RTGUI_RGB_R(bgcolor);
        bc[1] = RTGUI_RGB_G(bgcolor);
        bc[2] = RTGUI_RGB_B(bgcolor);

        /* draw each point within dc */
        for (y = 0; y < h; y ++)
        {
            for (x = 0; x < w; x++)
            {
                c = *ptr;
                ialpha = RTGUI_RGB_A(c);
                if (ialpha == 0)
                {
                    /*
                     * Foreground image is transparent hear.
                     * If the background image is already in the frame
                     * buffer, there is nothing to do.
                     */
                }
                else if (ialpha == fg_maxsample)
                {
                    /*
                     * Copy foreground pixel to frame buffer.
                     */
                    rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, c);
                }
                else
                {
                    /* output = alpha * foreground + (1-alpha) * background */
                    /*
                     * Compositing is necessary.
                     * Get floating-point alpha and its complement.
                     * Note: alpha is always linear: gamma does not
                     * affect it.
                     */
                    fc[0] = RTGUI_RGB_R(c);
                    fc[1] = RTGUI_RGB_G(c);
                    fc[2] = RTGUI_RGB_B(c);

                    alpha = (float) ialpha / fg_maxsample;
                    color = RTGUI_RGB((rt_uint8_t)(fc[0] * alpha + bc[0] * (1 - alpha)),
                                      (rt_uint8_t)(fc[1] * alpha + bc[1] * (1 - alpha)),
                                      (rt_uint8_t)(fc[2] * alpha + bc[2] * (1 - alpha)));
                    rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, color);
                }
                /* move to next color buffer */
                ptr ++;
            }
        }
    }
    else
    {
        png_bytep row;
        png_bytep data;

        row = (png_bytep) rtgui_malloc(png_get_rowbytes(png->png_ptr, png->info_ptr));
        if (row == RT_NULL) return ;

        switch (png->info_ptr->color_type)
        {
		case PNG_COLOR_TYPE_RGB:
			for (y = 0; y < h; y++)
			{
				png_read_row(png->png_ptr, row, png_bytep_NULL);
				for (x = 0; x < w; x++)
				{
					data = &(row[x * 3]);
					rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1,
											  RTGUI_RGB(data[0], data[1], data[2]));
				}
			}
			break;
			
        case PNG_COLOR_TYPE_RGBA:
            for (y = 0; y < h; y++)
            {
                png_read_row(png->png_ptr, row, png_bytep_NULL);
                for (x = 0; x < w; x++)
                {
                    data = &(row[x * 4]);
                    if (data[3] != 0)
                    {
                        rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1,
                                                  RTGUI_ARGB(data[3], data[0], data[1], data[2]));
                    }
                }
            }

            break;

        case PNG_COLOR_TYPE_PALETTE:
            for (y = 0; y < h; y++)
            {
                png_read_row(png->png_ptr, row, png_bytep_NULL);
                for (x = 0; x < w; x++)
                {
                    data = &(row[x]);

                    rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1,
                                              RTGUI_ARGB(0, png->info_ptr->palette[data[0]].red,
                                                         png->info_ptr->palette[data[0]].green,
                                                         png->info_ptr->palette[data[0]].blue));
                }
            }

        default:
            break;
        };

        rtgui_free(row);
    }
}
Exemplo n.º 5
0
static void _argb888_get_pixel(rtgui_color_t *c, int x, int y)
{
    *c = (rtgui_color_t)*GET_PIXEL(rtgui_graphic_get_device(), x, y, rtgui_color_t);
}
Exemplo n.º 6
0
static void _rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
{
    *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
}
Exemplo n.º 7
0
static void _rgb888_set_pixel(rtgui_color_t *c, int x, int y)
{
    *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint32_t) = rtgui_color_to_888(*c);
}