Просмотр исходного кода

Merge pull request #30 from yangfasheng/master

update image_jpg.c and blit.c
yangfasheng 7 лет назад
Родитель
Сommit
38d459d5c2
2 измененных файлов с 28 добавлено и 24 удалено
  1. 22 21
      src/blit.c
  2. 6 3
      src/image_jpg.c

+ 22 - 21
src/blit.c

@@ -891,35 +891,36 @@ static void BlitRGBtoRGBSurfaceAlpha(struct rtgui_blit_info *info)
     {
         BlitRGBtoRGBSurfaceAlpha128(info);
     }
-    else
+    else if (alpha)
     {
         int width = info->dst_w;
         int height = info->dst_h;
-        rt_uint32_t *srcp = (rt_uint32_t *)info->src;
-        int srcskip = info->src_skip >> 2;
-        rt_uint32_t *dstp = (rt_uint32_t *)info->dst;
-        int dstskip = info->dst_skip >> 2;
+        rt_uint8_t *srcp = (rt_uint8_t *)info->src;
+        int srcskip = info->src_skip;
+        rt_uint8_t *dstp = (rt_uint8_t *)info->dst;
+        int dstskip = info->dst_skip;
+        int inverse_alpha = 257 - alpha;
 
         while(height--)
         {
             DUFFS_LOOP4(
             {
-                rt_uint32_t s;
-                rt_uint32_t d;
-                rt_uint32_t s1;
-                rt_uint32_t d1;
-                s = *srcp;
-                d = *dstp;
-                s1 = s & 0xff00ff;
-                d1 = d & 0xff00ff;
-                d1 = (d1 + ((s1 - d1) * alpha >> 8))
-                & 0xff00ff;
-                s &= 0xff00;
-                d &= 0xff00;
-                d = (d + ((s - d) * alpha >> 8)) & 0xff00;
-                *dstp = d1 | d | 0xff000000;
-                ++srcp;
-                ++dstp;
+                if (alpha == 255)
+                {
+                    *dstp++ = *(srcp + 2);
+                    *dstp++ = *(srcp + 1);
+                    *dstp++ = *(srcp);
+                    *dstp++ = alpha;
+                    srcp += 3;
+                }
+                else if (alpha)
+                {
+                    *dstp++ = ((*(srcp + 2) * alpha) + (inverse_alpha * (*dstp))) >> 8;
+                    *dstp++ = ((*(srcp + 1) * alpha) + (inverse_alpha * (*dstp))) >> 8;
+                    *dstp++ = ((*(srcp) * alpha) + (inverse_alpha * (*dstp))) >> 8;
+                    *dstp++ = alpha + ((255 - alpha) * (*dstp)) / 255;
+                    srcp += 3;
+                }
             }, width);
             srcp += srcskip;
             dstp += dstskip;

+ 6 - 3
src/image_jpg.c

@@ -821,7 +821,8 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_f
             jpeg->filerw = RT_NULL;
         }
         res = RT_TRUE;
-    } while (0);
+    }
+    while (0);
 
     if (jpeg && (!res || jpeg->is_loaded))
     {
@@ -950,11 +951,11 @@ static void rtgui_image_jpeg_blit(struct rtgui_image *image,
 
             buffer = (struct rtgui_dc_buffer*)dc;
 
-            info.src = jpeg->pixels + yoff * image->w * jpeg->byte_per_pixel + xoff + jpeg->byte_per_pixel;
+            info.src = jpeg->pixels + yoff * image->w * jpeg->byte_per_pixel + xoff * jpeg->byte_per_pixel;
             info.src_h = rtgui_rect_height(*dst_rect);
             info.src_w = rtgui_rect_width(*dst_rect);
             info.src_fmt = (jpeg->tjpgd.format == 0? RTGRAPHIC_PIXEL_FORMAT_RGB888 : RTGRAPHIC_PIXEL_FORMAT_RGB565);
-            info.src_pitch = info.src_w * jpeg->byte_per_pixel;
+            info.src_pitch = image->w * jpeg->byte_per_pixel;
             info.src_skip = info.src_pitch - info.src_w * jpeg->byte_per_pixel;
 
             info.dst = rtgui_dc_buffer_get_pixel(RTGUI_DC(buffer)) + dst_rect->y1 * buffer->pitch +
@@ -965,6 +966,8 @@ static void rtgui_image_jpeg_blit(struct rtgui_image *image,
             info.dst_pitch = buffer->pitch;
             info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(buffer->pixel_format);
 
+            info.a = 255;
+
             rtgui_blit(&info);
         }
     }