From b96da47a09e6d2d79c7399bfa3178b44eca3a7bc Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 16 Apr 2014 16:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E5=83=8F=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=B7=B2?= =?UTF-8?q?=E7=9F=A5BUG=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/LCUI_Graph.c | 94 +++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/src/LCUI_Graph.c b/src/LCUI_Graph.c index a34304e2..79ba5038 100755 --- a/src/LCUI_Graph.c +++ b/src/LCUI_Graph.c @@ -75,6 +75,7 @@ LCUI_API void Graph_Init( LCUI_Graph *graph ) graph->quote = FALSE; graph->src = NULL; + graph->palette = NULL; graph->color_type = COLOR_TYPE_RGB; graph->bytes = NULL; graph->alpha = 255; @@ -249,23 +250,23 @@ int Graph_FillRectRGB( LCUI_Graph *graph, LCUI_Color color, LCUI_Rect rect ) { int x, y, n; LCUI_Rect rect_src; - uchar_t *byte; + uchar_t *rowbytep, *bytep; if(!Graph_IsValid(graph)) { return -1; } rect_src = Graph_GetValidRect( graph ); graph = Graph_GetQuote( graph ); + n = ((rect_src.y+rect.y)*graph->w+rect.x+rect_src.x)*3; + rowbytep = graph->bytes + n; for( y=0; yw; - n += rect.x + rect_src.x; - n *= 3; - byte = graph->bytes + n; + bytep = rowbytep; for( x=0; xw*3; } return 0; } @@ -391,8 +392,8 @@ static int Graph_MixARGB( LCUI_Graph *des, LCUI_Rect des_rect, /* 先得出透明度比例,避免在循环中进行除法运算 */ k = src->alpha / 255.0; /* 计算并保存第一行的首个像素的位置 */ - px_row_src = src->argb + src_pos.y * src->w + src_pos.x; - px_row_des = des->argb + des_rect.y * des->w + des_rect.x; + px_row_src = src->argb + src_pos.y*src->w + src_pos.x; + px_row_des = des->argb + des_rect.y*des->w + des_rect.x; if( src->alpha != 255 ) { for( y=0; yalpha / 255.0; - byte_row_src = src->bytes + (src_pos.y * src->w + src_pos.x)*3; - byte_row_des = des->bytes + (des_rect.y * des->w + des_rect.x)*3; + px_row_src = src->argb + src_pos.y*src->w + src_pos.x; + px_row_des = des->argb + des_rect.y*des->w + des_rect.x; if( src->alpha != 255 ) { for( y=0; yb = px_src->b; + px_des->g = px_src->g; + px_des->r = px_src->r; + px_des->a = k*px_src->a; } - byte_row_src += src->w*4; - byte_row_des += des->w*4; + px_row_src += src->w; + px_row_des += des->w; } return 0; } - - row_bytes = sizeof(uchar_t)*4*des_rect.w; + row_size = sizeof(LCUI_ARGB)*des_rect.w; for( y=0; yw*4; - byte_row_des += des->w*4; + memcpy( px_row_des, px_row_src, row_size ); + px_row_src += src->w; + px_row_des += des->w; } return 0; } @@ -526,25 +525,28 @@ static int Graph_FillRectARGB( LCUI_Graph *graph, LCUI_Color color, { int x, y; LCUI_Rect rect_src; - LCUI_ARGB *pixel; + LCUI_ARGB *px_p, *px_row_p; if(!Graph_IsValid(graph)) { return -1; } rect_src = Graph_GetValidRect( graph ); graph = Graph_GetQuote( graph ); + px_row_p = graph->argb + (rect_src.y+rect.y)*graph->w; + px_row_p += rect.x + rect_src.x; for( y=0; yargb; - pixel += (rect_src.y + rect.y + y)*graph->w; - pixel += rect.x + rect_src.x; + px_p = px_row_p; for( x=0; xb = color.b; + px_p->g = color.g; + px_p->r = color.r; + ++px_p; } + px_row_p += graph->w; } return 0; } - static int Graph_ZoomARGB( const LCUI_Graph *graph, LCUI_Graph *buff, LCUI_BOOL keep_scale, LCUI_Size size ) { @@ -717,6 +719,7 @@ LCUI_API int Graph_Quote( LCUI_Graph *des, LCUI_Graph *src, LCUI_Rect area ) des->w = area.width; des->h = area.height; des->alpha = 255; + des->color_type = src->color_type; des->quote = TRUE; return 0; } @@ -838,12 +841,11 @@ LCUI_API const LCUI_Graph* Graph_GetQuoteConst( const LCUI_Graph *graph ) return graph; } - LCUI_API int Graph_SetAlphaBits( LCUI_Graph *graph, uchar_t *a, size_t size ) { size_t i; if( size > (size_t)(graph->w*graph->h) ) { - return -1; + size = (size_t)(graph->w*graph->h); } if( graph->color_type != COLOR_TYPE_ARGB ) { return -2; @@ -860,7 +862,7 @@ LCUI_API int Graph_SetRedBits( LCUI_Graph *graph, uchar_t *r, size_t size ) uchar_t *pByte; if( size > (size_t)(graph->w*graph->h) ) { - return -1; + size = (size_t)(graph->w*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { for( i=0; i (size_t)(graph->w*graph->h) ) { - return -1; + size = (size_t)(graph->w*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { for( i=0; i (size_t)(graph->w*graph->h) ) { - return -1; + size = (size_t)(graph->w*graph->h); } if( graph->color_type == COLOR_TYPE_ARGB ) { for( i=0; i des->w || pos.y > des->h) { return -3; @@ -1161,8 +1158,7 @@ LCUI_API int Graph_Replace( LCUI_Graph *bg, const LCUI_Graph *fg, LCUI_Size box_size; LCUI_Pos src_pos; - if( !Graph_IsValid(bg) - || !Graph_IsValid(fg) ) { + if( !Graph_IsValid(bg) || !Graph_IsValid(fg) ) { return -1; }