/** * 将色彩类型为RGBA的前景图像,覆盖至色彩类型为RGB的目标背景图像中 * param back * 背景图像 * param des_rect * 背景图像中的写入区域 * param fore * 前景图像 * param src_pos * 前景图像中的读取区域的坐标 * warning * 此函数不会对传入的参数进行有效性判断,因为此函数主要被Graph_Replace函 * 数调用,Graph_Replace函数会预先进行参数有效性判断 */ static int Graph_RGBAReplaceRGB( LCUI_Graph *back, LCUI_Rect des_rect, LCUI_Graph *fore, LCUI_Pos src_pos ) { int x, y; int src_n, des_n; int des_row_start, src_row_start; LCUI_Graph *src, *des; src = Graph_GetQuote(fore); des = Graph_GetQuote(back); src_row_start = src_pos.y * src->w + src_pos.x; des_row_start = des_rect.y * des->w + des_rect.x; for(y=0; y<des_rect.height; ++y) { des_n = des_row_start; src_n = src_row_start; for(x=0; x<des_rect.width; ++x) { des->rgba[0][des_n] = _ALPHA_BLEND( src->rgba[0][src_n], 255, src->rgba[3][src_n] ); des->rgba[1][des_n] = _ALPHA_BLEND( src->rgba[1][src_n], 255, src->rgba[3][src_n] ); des->rgba[2][des_n] = _ALPHA_BLEND( src->rgba[2][src_n], 255, src->rgba[3][src_n] ); ++src_n; ++des_n; } des_row_start += des->w; src_row_start += src->w; } return 0; }
static void CloseButton_OnUpdate( LCUI_Widget *widget ) { LCUI_Graph img; LCUI_Color color; LCUI_Widget *wnd; Graph_Init( &img ); LoadCloseButtonIMG( &img ); wnd = Widget_GetParent( widget, WIDGET_WINDOW ); if( wnd ) { /* 若所在窗口并未获得焦点 */ if( !Widget_GetFocus(wnd) ) { color = RGB(200,200,200); } else { LCUI_Window *wnd_data; wnd_data = (LCUI_Window*)Widget_GetPrivateData( wnd ); color = wnd_data->theme_color; } } else { color = RGB(255,0,0); } switch(widget->state) { case WIDGET_STATE_NORMAL: Graph_FillColor( &img, RGB(150,150,150) ); Widget_SetBackgroundImage( widget, &img ); Widget_SetBackgroundLayout( widget, LAYOUT_CENTER ); Widget_SetBackgroundTransparent( widget, TRUE ); break; case WIDGET_STATE_ACTIVE: color.red = _ALPHA_BLEND( 0, color.red, 100 ); color.green = _ALPHA_BLEND( 0, color.green, 100 ); color.blue = _ALPHA_BLEND( 0, color.blue, 100 ); Graph_FillColor( &img, RGB(255,255,255) ); Widget_SetBackgroundImage( widget, &img ); Widget_SetBackgroundColor( widget, color ); Widget_SetBackgroundLayout( widget, LAYOUT_CENTER ); Widget_SetBackgroundTransparent( widget, FALSE ); break; case WIDGET_STATE_OVERLAY: Graph_FillColor( &img, RGB(255,255,255) ); Widget_SetBackgroundImage( widget, &img ); Widget_SetBackgroundColor( widget, color ); Widget_SetBackgroundLayout( widget, LAYOUT_CENTER ); Widget_SetBackgroundTransparent( widget, FALSE ); case WIDGET_STATE_DISABLE: default:break; } Graph_Free( &img ); }
/** * 将色彩类型为RGBA的前景图像,覆盖至色彩类型为RGB的目标背景图像中 * 当背景图像没有alpha通道时,该函数使用白色背景与前景图像进行混合,并将源图像 * 的全局透明度计算在内 * param back * 背景图像 * param des_rect * 背景图像中的写入区域 * param fore * 前景图像 * param src_pos * 前景图像中的读取区域的坐标 * warning * 此函数不会对传入的参数进行有效性判断,因为此函数主要被Graph_Replace函 * 数调用,Graph_Replace函数会预先进行参数有效性判断 */ static int Graph_RGBAReplaceRGBWithGlobalAlpha( LCUI_Graph *back, LCUI_Rect des_rect, LCUI_Graph *fore, LCUI_Pos src_pos ) { int x, y; double k; uchar_t alpha; int src_n, des_n; int des_row_start, src_row_start; LCUI_Graph *src, *des; src = Graph_GetQuote(fore); des = Graph_GetQuote(back); k = 1.0 / src->alpha; src_row_start = src_pos.y * src->w + src_pos.x; des_row_start = des_rect.y * des->w + des_rect.x; for(y=0; y<des_rect.height; ++y) { des_n = des_row_start; src_n = src_row_start; for(x=0; x<des_rect.width; ++x) { alpha = src->alpha * k; des->rgba[0][des_n] = _ALPHA_BLEND( src->rgba[0][src_n], 255, alpha ); des->rgba[1][des_n] = _ALPHA_BLEND( src->rgba[1][src_n], 255, alpha ); des->rgba[2][des_n] = _ALPHA_BLEND( src->rgba[2][src_n], 255, alpha ); ++src->w; ++des->w; } des_row_start += des->w; src_row_start += src->w; } return 0; }
static void Graph_RGBMixARGB( LCUI_Graph *des, LCUI_Rect des_rect, const LCUI_Graph *src, LCUI_Pos src_pos ) { int x, y; uchar_t a; LCUI_ARGB *px, *px_row; uchar_t *rowbytep, *bytep; /* 计算并保存第一行的首个像素的位置 */ px_row = src->argb + src_pos.y*src->w + src_pos.x; rowbytep = des->bytes + des_rect.y*des->bytes_per_row; rowbytep += des_rect.x*des->bytes_per_pixel; if( src->opacity < 1.0 ) { for( y=0; y<des_rect.h; ++y ) { px = px_row; bytep = rowbytep; for( x=0; x<des_rect.w; ++x,++px ) { a = px->a * src->opacity; *bytep = _ALPHA_BLEND( *bytep, px->b, a ); ++bytep; *bytep = _ALPHA_BLEND( *bytep, px->g, a ); ++bytep; *bytep = _ALPHA_BLEND( *bytep, px->r, a ); ++bytep; } rowbytep += des->bytes_per_row; px_row += src->w; } } for( y=0; y<des_rect.h; ++y ) { px = px_row; bytep = rowbytep; for( x=0; x<des_rect.w; ++x,++px ) { *bytep = _ALPHA_BLEND( *bytep, px->b, px->a ); ++bytep; *bytep = _ALPHA_BLEND( *bytep, px->g, px->a ); ++bytep; *bytep = _ALPHA_BLEND( *bytep, px->r, px->a ); ++bytep; } rowbytep += des->bytes_per_row; px_row += src->w; } }