注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

钱五哥の163空间

记录俺的生活和工作历程

 
 
 

日志

 
 
关于我

从事网络通信软件和开发管理开发多年,了解各类软件系统的架构、设计、开发和测试以及相应的开发方法。工作之余,喜欢研究一些自己感兴趣的事情,包括写写小程序、做做木工、看看连续剧、读读军事杂志、养鱼种花等等

网易考拉推荐

满屏幕的图标和变焦特效  

2015-07-26 22:41:57|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

image

Paint提供了变焦特效是个不错玩意,弄出来了很炫的效果,但是看久了比较头晕,看了一下代码,算法很简单,就是将原始像素和给定景深处像素值(和变焦参数有关系)相加,然后结合透明度重新合成新的像素点。由于存在一个点被周围2个点的平均了,因此使图像模糊,而考虑了深度,新生成的像素点都呈现向内部汇聚的效果。

 

protected unsafe override void OnRender(Rectangle[] rois, int startIndex, int length)
       {
           Surface dst = DstArgs.Surface;
           Surface src = SrcArgs.Surface;
           long w = dst.Width;
           long h = dst.Height;
           long fox = (long)(dst.Width * this.offset.First * 32768.0);
           long foy = (long)(dst.Height * this.offset.Second * 32768.0);
           long fcx = fox + (w << 15);
           long fcy = foy + (h << 15);
           long fz = this.amount;

           const int n = 64;
           for (int r = startIndex; r < startIndex + length; ++r)
           {
               Rectangle rect = rois[r];

               for (int y = rect.Top; y < rect.Bottom; ++y)
               {
                   ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
                   ColorBgra *srcPtr = src.GetPointAddressUnchecked(rect.Left, y);

                   for (int x = rect.Left; x < rect.Right; ++x)
                   {
                       long fx = (x << 16) - fcx;
                       long fy = (y << 16) - fcy;

                       int sr = 0;
                       int sg = 0;
                       int sb = 0;
                       int sa = 0;
                       int sc = 0;

                       sr += srcPtr->R * srcPtr->A;
                       sg += srcPtr->G * srcPtr->A;
                       sb += srcPtr->B * srcPtr->A;
                       sa += srcPtr->A;
                       ++sc;

                       for (int i = 0; i < n; ++i)
                       {
                           fx -= ((fx >> 4) * fz) >> 10;
                           fy -= ((fy >> 4) * fz) >> 10;

                           int u = (int)(fx + fcx + 32768 >> 16);
                           int v = (int)(fy + fcy + 32768 >> 16);

                           if (src.IsVisible(u, v))
                           {
                               ColorBgra* srcPtr2 = src.GetPointAddressUnchecked(u, v);

                               sr += srcPtr2->R * srcPtr2->A;
                               sg += srcPtr2->G * srcPtr2->A;
                               sb += srcPtr2->B * srcPtr2->A;
                               sa += srcPtr2->A;
                               ++sc;
                           }
                       }
                       if (sa != 0)
                       {
                           *dstPtr = ColorBgra.FromBgra(
                               Utility.ClampToByte(sb / sa),
                               Utility.ClampToByte(sg / sa),
                               Utility.ClampToByte(sr / sa),
                               Utility.ClampToByte(sa / sc));
                       }
                       else
                       {
                           dstPtr->Bgra = 0;
                       }

                       ++srcPtr;
                       ++dstPtr;
                   }
               }
           }

}

  评论这张
 
阅读(61)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017