BREW中几种常用的效果(淡淡浅出、半透明)

简介:

主要是给自己一个备份哈,谁需要谁拿去。代码如下:

 
  1. /*****************************************************    
  2.   Function:FadeIn    
  3.   Desc:从0增加R,G,B颜色值,实现淡入效果    
  4.  Input:pDst-目标位图,16位色,xdst,ydst-目标位图位置,pSrc-源位图,16位色,width,height-源位图大小,必须确保ydst+height<pDst>Height,xdst+width<pDst->Width,    
  5.    step-步长    
  6.   Output:pDst-经过处理的位图    
  7.   Return:    
  8. *****************************************************/    
  9. void FadeIn(IBitmap *pDst,int xdst,int ydst,IBitmap *pSrc,int width,int height,int step)     
  10. {     
  11.   int x,y;     
  12.   int offset1,offset2;     
  13.   int offdst;     
  14.   int offsrc;     
  15.   uint16 dstcolor,srccolor;     
  16.   uint8 r,g,b;     
  17.     
  18.   IDIB *dstdib = (IDIB*)pDst;     
  19.   IDIB *srcdib = (IDIB*)pSrc;     
  20.        
  21.   // 获得实际的图片点阵数据     
  22.   uint16 *pDstBmp = (uint16*)dstdib->pBmp;      
  23.   uint16 *pSrcBmp=(uint16 *)srcdib->pBmp;     
  24.     
  25.   if(dstdib->nDepth!=16 || srcdib->nDepth!=16)     
  26.     return;     
  27.     // 一般手机屏幕都是16位,565格式     
  28.     if(dstdib->nColorScheme == IDIB_COLORSCHEME_565)     
  29.     {     
  30.     offset1=((ydst*dstdib->nPitch)>>1)+xdst;     
  31.     offset2=0;     
  32.     for(y=0;y<height;y++)     
  33.     {     
  34.       offdst=offset1;     
  35.       offsrc=offset2;     
  36.       for(x=0;x<width;x++)     
  37.       {     
  38.         dstcolor=pDstBmp[offdst];     
  39.         srccolor=pSrcBmp[offsrc];     
  40.         if(srccolor!=63519)     
  41.         {     
  42.           r=srccolor>>11;     
  43.           g=(srccolor>>5) & 0x3f;     
  44.           b=srccolor & 0x1f;     
  45.           if(step<r)     
  46.             r=step;     
  47.           if(step<g)     
  48.             g=step;     
  49.           if(step<b)     
  50.             b=step;     
  51.           pDstBmp[offdst]=r<<11 | g<<5 | b;     
  52.         }     
  53.         offsrc++;     
  54.         offdst++;     
  55.       }     
  56.       offset1+=(dstdib->nPitch>>1);     
  57.       offset2+=(srcdib->nPitch>>1);     
  58.     }     
  59.   }     
  60. }     
  61.     
  62. /*****************************************************    
  63.   Function:Alpha256Bmp    
  64.   Desc:256色位图alpha混合,修改调色板,只适用256色位图,加快速度用。    
  65.  Input:pDst-目标位图,xdst,ydst-位置,width,height-半透明处理位图大小,pSrc-256色位图,xscr,yscr-源位置,R,G,B半透明颜色值,alpha    
  66.   Output:    
  67.   Return:    
  68. ******************************************************/    
  69. void Alpha256Bmp(IBitmap *pDst,int xdst,int ydst,int width,int height,IBitmap *pSrc,     
  70.                  int xsrc,int ysrc,uint8 r, uint8 g, uint8 b,float alpha)     
  71. {     
  72.   uint8 dstcolor;     
  73.   uint32 *pPalette;     
  74.   uint32 *pBackup;     
  75.   byte   *pOrigBytes;     
  76.   byte   *pNowBytes;     
  77.   int    i;     
  78.     
  79.   IDIB *srcdib = (IDIB*)pSrc;     
  80.   if(srcdib->nColorScheme>0)     
  81.     return;     
  82.   if(srcdib->cntRGB==0)     
  83.     return;     
  84.   pPalette=(uint32*)MALLOC(sizeof(uint32)*255);     
  85.   pNowBytes=(byte*)pPalette;     
  86.   pOrigBytes=(byte *)srcdib->pRGB;     
  87.   pBackup=srcdib->pRGB;     
  88.   for(i=0;i<srcdib->cntRGB;i++)     
  89.   {     
  90.     dstcolor=(*pOrigBytes++);     
  91.     dstcolor=(uint8)(dstcolor+(alpha*(r-dstcolor)));     
  92.     *pNowBytes++=dstcolor;     
  93.     dstcolor=(*pOrigBytes++);     
  94.     dstcolor=(uint8)(dstcolor+(alpha*(g-dstcolor)));     
  95.     *pNowBytes++=dstcolor;     
  96.     dstcolor=(*pOrigBytes++);     
  97.     dstcolor=(uint8)(dstcolor+(alpha*(b-dstcolor)));     
  98.     *pNowBytes++=dstcolor;     
  99.     pNowBytes++;     
  100.     pOrigBytes++;     
  101.   }     
  102.   srcdib->pRGB=pPalette;     
  103.   IBITMAP_BltIn(pDst,xdst,ydst,width,height,pSrc,xsrc,ysrc,AEE_RO_COPY);     
  104.   srcdib->pRGB=pBackup;     
  105.   FREE(pPalette);     
  106. }     
  107.     
  108. /*****************************************************    
  109.   Function:SpecialAlpha256Bmp    
  110.   Desc:256色位图alpha混合,修改调色板,只适用256色位图,加快速度用。    
  111.  Input:pDst-目标位图,xdst,ydst-位置,width,height-半透明处理位图大小,    
  112.         pSrc-256色位图,xscr,yscr-源位置,R,G,B半透明颜色值,alpha    
  113.   Output:    
  114.   Return:    
  115. ******************************************************/    
  116. void SpecialAlpha256Bmp(IBitmap *pDst,int xdst,int ydst,int width,int height,IBitmap *pSrc,     
  117.                  int xsrc,int ysrc,uint8 r, uint8 g, uint8 b)     
  118. {     
  119.   uint8 dstcolor;     
  120.   uint32 *pPalette;     
  121.   uint32 *pBackup;     
  122.   byte   *pOrigBytes;     
  123.   byte   *pNowBytes;     
  124.   int    i;     
  125.     
  126.   IDIB *srcdib = (IDIB*)pSrc;     
  127.   if(srcdib->nColorScheme>0)     
  128.     return;     
  129.   if(srcdib->cntRGB==0)     
  130.     return;     
  131.   pPalette=(uint32*)MALLOC(sizeof(uint32)*255);     
  132.   pNowBytes=(byte*)pPalette;     
  133.   pOrigBytes=(byte *)srcdib->pRGB;     
  134.   pBackup=srcdib->pRGB;     
  135.   for(i=0;i<srcdib->cntRGB;i++)     
  136.   {     
  137.     dstcolor=(*pOrigBytes++);     
  138.     dstcolor=(uint8)(dstcolor+((r-dstcolor)>>1));     
  139.     *pNowBytes++=dstcolor;     
  140.     dstcolor=(*pOrigBytes++);     
  141.     dstcolor=(uint8)(g>>1);     
  142.     *pNowBytes++=dstcolor;     
  143.     dstcolor=(*pOrigBytes++);     
  144.     dstcolor=(uint8)(b>>1);     
  145.     *pNowBytes++=dstcolor;     
  146.     pNowBytes++;     
  147.     pOrigBytes++;     
  148.   }     
  149.   srcdib->pRGB=pPalette;     
  150.   IBITMAP_BltIn(pDst,xdst,ydst,width,height,pSrc,xsrc,ysrc,AEE_RO_COPY);     
  151.   srcdib->pRGB=pBackup;     
  152.   FREE(pPalette);     
  153. }     
  154.     
  155. /*****************************************************    
  156.   Function:SpecialAlpha    
  157.   Desc:实现和某种颜色的半透明    
  158.  Input:pDst-目标位图,16位色,xdst,ydst-目标位图位置,width,height-半透明处理位图大小,必须确保ydst+height<pDst->Height,xdst+width<pDst->Width,R,G,B半透明颜色值    
  159.  Output:pDst-经过处理的位图    
  160.  Return:    
  161. *****************************************************/    
  162. void SpecialAlpha(IBitmap *pDst,int xdst,int ydst,int width,int height,     
  163.                  uint8 r, uint8 g, uint8 b)     
  164. {     
  165.   int x,y;     
  166.   int offset1;     
  167.   int offdst;     
  168.   uint16 dstcolor;     
  169.   uint8 dstr,dstg,dstb;     
  170.     
  171.   IDIB *dstdib = (IDIB*)pDst;     
  172.        
  173.   uint16 *pDstBmp = (uint16*)dstdib->pBmp; // 获得实际的图片点阵数据。     
  174.     
  175.   if(dstdib->nDepth!=16)     
  176.     return;     
  177.   // 一般手机屏幕都是16位,565格式     
  178.   r=r & 0x1f;     
  179.   g=(g & 0x3f);     
  180.   b=b & 0x1f;     
  181.     if(dstdib->nColorScheme == IDIB_COLORSCHEME_565)     
  182.     {     
  183.     offset1=((ydst*dstdib->nPitch)>>1)+xdst;     
  184.     for(y=0;y<height;y++)     
  185.     {     
  186.       if(y==height-1)     
  187.         offdst=0;     
  188.       offdst=offset1;     
  189.       for(x=0;x<width;x++)     
  190.       {     
  191.         dstcolor=pDstBmp[offdst];     
  192.         dstr=dstcolor>>11;     
  193.         dstr=(uint8)(dstr+((r-dstr)>>1));     
  194.         dstg=(dstcolor>>5) & 0x3f;     
  195.         dstg=(uint8)(g>>1);     
  196.         dstb=dstcolor & 0x1f;     
  197.         dstb=(uint8)(b>>1);     
  198.         pDstBmp[offdst]=dstr<<11 | dstg<<5 | dstb;     
  199.         offdst++;     
  200.       }     
  201.       offset1+=(dstdib->nPitch>>1);     
  202.     }     
  203.   }     
  204. }     
  205.     
  206. /*****************************************************    
  207.   Function:FastAlpha    
  208.   Desc:实现和某种颜色的半透明    
  209.  Input:pDst-目标位图,16位色,xdst,ydst-目标位图位置,width,height-半透明处理位图大小,必须确保ydst+height<pDst->Height,xdst+width<pDst->Width,R,G,B半透明颜色值    
  210.   Output:pDst-经过处理的位图    
  211.   Return:    
  212. *****************************************************/    
  213. void FastAlpha(IBitmap *pDst,int xdst,int ydst,int width,int height,     
  214.                  uint8 r, uint8 g, uint8 b)     
  215. {     
  216.   int x,y;     
  217.   int offset1;     
  218.   int offdst;     
  219.   uint16 dstcolor;     
  220.   uint8 dstr,dstg,dstb;     
  221.     
  222.   IDIB *dstdib = (IDIB*)pDst;     
  223.   // 获得实际的图片点阵数据。     
  224.   uint16 *pDstBmp = (uint16*)dstdib->pBmp;      
  225.   if(dstdib->nDepth!=16)     
  226.     return;     
  227.  // 一般手机屏幕都是16位,565格式     
  228.   r=r & 0x1f;     
  229.   g=(g & 0x3f);     
  230.   b=b & 0x1f;     
  231.     if(dstdib->nColorScheme == IDIB_COLORSCHEME_565)     
  232.     {     
  233.     offset1=((ydst*dstdib->nPitch)>>1)+xdst;     
  234.     for(y=0;y<height;y++)     
  235.     {     
  236.       if(y==height-1)     
  237.         offdst=0;     
  238.       offdst=offset1;     
  239.       for(x=0;x<width;x++)     
  240.       {     
  241.         dstcolor=pDstBmp[offdst];     
  242.         dstr=dstcolor>>11;     
  243.         dstr=(uint8)(dstr+((r-dstr)>>1));     
  244.         dstg=(dstcolor>>5) & 0x3f;     
  245.         dstg=(uint8)(dstg+((g-dstg)>>1));     
  246.         dstb=dstcolor & 0x1f;     
  247.         dstb=(uint8)(dstb+((b-dstb)>>1));     
  248.         pDstBmp[offdst]=dstr<<11 | dstg<<5 | dstb;     
  249.         offdst++;     
  250.       }     
  251.       offset1+=(dstdib->nPitch>>1);     
  252.     }     
  253.   }     
  254. }     
  255.     
  256. /*****************************************************    
  257.   Function:AlphaBlend    
  258.   Desc:实现和某种颜色的半透明    
  259.  Input:pDst-目标位图,16位色,xdst,ydst-目标位图位置,width,height-半透明处理位图大小,必须确保ydst+height<pDst->Height,xdst+width<pDst->Width,R,G,B半透明颜色值,alpha-半透明因子    
  260.   Output:pDst-经过处理的位图    
  261.   Return:    
  262. *****************************************************/    
  263. void AlphaBlend(IBitmap *pDst,int xdst,int ydst,int width,int height,     
  264.                  uint8 r, uint8 g, uint8 b,float alpha)     
  265. {     
  266.   int x,y;     
  267.   int offset1;     
  268.   int offdst;     
  269.   uint16 dstcolor;     
  270.   uint8 dstr,dstg,dstb;     
  271.     
  272.   IDIB *dstdib = (IDIB*)pDst;     
  273.        
  274.   uint16 *pDstBmp = (uint16*)dstdib->pBmp;      
  275.   if(dstdib->nDepth!=16)     
  276.     return;     
  277.          
  278.   r=r & 0x1f;     
  279.   g=(g & 0x3f);     
  280.   b=b & 0x1f;     
  281.     if(dstdib->nColorScheme == IDIB_COLORSCHEME_565)     
  282.     {     
  283.     offset1=((ydst*dstdib->nPitch)>>1)+xdst;     
  284.     for(y=0;y<height;y++)     
  285.     {     
  286.       if(y==height-1)     
  287.         offdst=0;     
  288.       offdst=offset1;     
  289.       for(x=0;x<width;x++)     
  290.       {     
  291.         dstcolor=pDstBmp[offdst];     
  292.         dstr=dstcolor>>11;     
  293.         dstr=(uint8)(dstr+(alpha*(r-dstr)));     
  294.         dstg=(dstcolor>>5) & 0x3f;     
  295.         dstg=(uint8)(dstg+(alpha*(g-dstg)));     
  296.         dstb=dstcolor & 0x1f;     
  297.         dstb=(uint8)(dstb+(alpha*(b-dstb)));     
  298.         pDstBmp[offdst]=dstr<<11 | dstg<<5 | dstb;     
  299.         offdst++;     
  300.       }     
  301.       offset1+=(dstdib->nPitch>>1);     
  302.     }     
  303.   }     
  304. }  

 



本文转自 yarin 51CTO博客,原文链接:http://blog.51cto.com/yarin/380000,如需转载请自行联系原作者

相关文章
|
3月前
如何用Qt抠一个圆形头像出来
如何用Qt抠一个圆形头像出来
|
4月前
|
JavaScript
Cesium第一次搭建环境出不来地球的问题
Cesium第一次搭建环境出不来地球的问题
52 0
|
8月前
|
小程序 前端开发 程序员
让别人的小程序长成自己的样子-更换window上下颜色--【浅入深出系列001】
让别人的小程序长成自己的样子-更换window上下颜色--【浅入深出系列001】 这是我的CSDN 的文章 转过来,可能有些许错误。请留言
|
11月前
|
Python
python植物大战僵尸一之绘制背景
python植物大战僵尸一之绘制背景
180 0
|
编解码 前端开发 JavaScript
手摸手带你实现一个时间轴组件
本文给大家带来一个时间轴的组件开发教程
586 0
|
前端开发
UGUI系列-屏幕自适应多分配率适配(Untiy3D)
1、Canvas的属性配置 2、Canvas Scaler的属性配置 3、根据不同的屏幕的比例动态修改缩放基准
|
Java Android开发
PopupWindow 使用详解(二) Popwindow 制作常见花哨效果
PopupWindow 详解的第二篇,制作一些相对简单的效果。
4720 0
|
图形学
【UGUI】 (一)------- 放大镜
在许多游戏或应用中,我们常常看到放大镜的身影,而在Unity里面,制作一个简易的放大镜是非常简单的。                    一. 创建一个3DObject 创建一个Cube或者 Cylinder,这里为了更像放大镜一些,笔者创建了一个Cylinder。
1878 0
通通玩blend美工(1)——荧光Button
原文:通通玩blend美工(1)——荧光Button   最近老大出差去了,光做项目也有点烦,写点教程消遣消遣(注:此乃初级教程,所以第一个消遣是本人消遣,第二个是指供各位看官消遣...)   看着各位大虾出系列文章貌似挺好玩的,本人耍了2个月的Wpf,有点见解,希望各位看官笑纳。
1026 0