﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-foxriver</title><link>http://www.cppblog.com/foxriver/</link><description>Keep It Simple and Stupid.</description><language>zh-cn</language><lastBuildDate>Fri, 10 Apr 2026 02:40:55 GMT</lastBuildDate><pubDate>Fri, 10 Apr 2026 02:40:55 GMT</pubDate><ttl>60</ttl><item><title>vc2005编译webkit</title><link>http://www.cppblog.com/foxriver/archive/2011/12/31/163214.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Fri, 30 Dec 2011 16:55:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/12/31/163214.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/163214.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/12/31/163214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/163214.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/163214.html</trackback:ping><description><![CDATA[<pre>1. 解压http://builds.nightly.webkit.org/files/trunk/src/WebKit-r100089.tar.bz2到cygwin目录下
2. 下载win32预编译依赖库: ./Tools/Scripts/update-webkit
3. 修改WebKitLibraries\win\tools\vsprops\common.vsprops(DisableSpecificWarnings=4819), 解决在中文操作系统里编译与某些英文符号不兼容问题。某些新版本的WebCore\platform\DefaultLocalizationStrategy.cpp中引号也要修改一下。

4. 检查系统环境变量: 
WEBKITLIBRARIESDIR  D:\cygwin\WebKit-r100089\WebKitLibraries\win
WEBKITOUTPUTDIR     D:\cygwin\WebKit-r100089\WebKitBuild
DXSDK_DIR           D:\cygwin\WebKit-r100089\DXSDK_Feb10
SystemDrive         D:

其中SystemDrive对应cygwin安装盘符，DXSDK_DIR是dx9sdk的路径，还需要安装QuickTime SDK。

5. 开始命令行编译：./Tools/Scripts/build-webkit --debug，全部通过之后再用vc2005 ide打开项目并调试，否则某些脚本会有问题。
6. 安装Safari，复制相关运行时文件到WEBKITOUTPUTDIR子目录，运行MiniBrowser

ps1: vc2005需要安装sp1, 否则stl链接会出错。智能分析造成cpu太卡，可通过改名C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages\feacp.dll来屏蔽。
ps2: dx9sdk可以用比较老的版本，但链接时需要删除common.vsprops里的/SAFESEH。
ps3: 编译Cairo版本: ./Tools/Scripts/build-webkit --debug --wincairo, 需要vista以上系统运行，否则会报WSAPoll找不到。




http://www.cnblogs.com/coffeestone/archive/2011/01/10/1931872.html
http://blog.csdn.net/elfylin/article/details/6769747

</pre><img src ="http://www.cppblog.com/foxriver/aggbug/163214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-12-31 00:55 <a href="http://www.cppblog.com/foxriver/archive/2011/12/31/163214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何用vc6编译ffmpeg, 并单步调试。</title><link>http://www.cppblog.com/foxriver/archive/2011/12/17/162254.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Fri, 16 Dec 2011 18:09:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/12/17/162254.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/162254.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/12/17/162254.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/162254.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/162254.html</trackback:ping><description><![CDATA[<p>目前官方ffmpeg的最新版本为0.9, 我们就以此为例：<br /><br /></p>
<p>1. 下载最新git版本的源代码(<a href="http://ffmpeg.zeranoe.com/builds/">http://ffmpeg.zeranoe.com/builds/</a>, 本例下载的是2011-12-12版本)<br />2. 放到MSYS环境里配置，生成config.h文件。mingw gcc是能顺利编译通过整个项目的，并生成最新版的ffmpeg。<br />3. 建立vc6工程，把相关代码都加入到工程中。由于在vc生成的obj都在一个目录下，所以需要修改文件名，让其不重名。<br />4. 安装intel compiler 11编译器，单独提取其icl.exe及相关include目录，替换掉vc6自带的cl.exe, 在工程设置里加上/Qstd=c99，用于支持C99语法。<br />5. 安装intel compiler 10编译器，单独提取lib目录，因为此版本调试库的结构能完美支持vc6的调试信息。<br />6. 在vc6的options里设置include/exe/lib查找目录，指向intel编译器。<br />7. 开始修改代码，添加C99的相关linux头文件, 用于支持vc6, (unistd.h, stdint.h, inttypes.h, getopt.h)<br />8. 添加C99和linux的相关实现代码，ffmpeg需要用到: getopt_long, strtoll, gettimeofday, atoll, usleep等<br />9. 修改windows的相关兼容代码，GetWindowLongPtr -&gt; GetWindowLong, GWLP_USERDATA<br />10. 去除硬件加速libavcodec代码，和依赖库代码。选择所需要的模块，修改相关的allcodec.c, alldevices.c, allfilters.c, allformats.c<br />11. 加上链接库，sdl.lib, winmm.lib, dxguid.lib, wsock32.lib<br />12. 在os_support.c里，把&lt;winsock2.h&gt;移动到文件最前面。<br />13. 如果是ffmpeg, 已经能顺利编译了。如果是ffplay，还需要编译静态sdl, 并链接。<br />14. 等等，音频运行不正确？有雪花声？因为还需要替换所有文件里的&lt;math.h&gt;为&lt;mathimf.h&gt;, 默认的rint等数学函数和gcc不兼容。<br />15. ok, 大功告成，纯C版本完美运行。<br />16. 由于ffmpeg0.9在c文件里，添加了一些intel compiler不支持的mmx语法，所以编译mmx/sse加速版本时，一小部分.c文件需要依赖mingw gcc编译成.o文件，再通过vc6的lib.exe工具转换成lib，让vc6链接上。当然还要加上yasm编译的很多汇编obj.<br />17. 有兴趣的，可以继续以此方法编译x264库，官方最新代码MMX版也可以顺利通过。<br /></p><img src ="http://www.cppblog.com/foxriver/aggbug/162254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-12-17 02:09 <a href="http://www.cppblog.com/foxriver/archive/2011/12/17/162254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>图片压缩算法笔记</title><link>http://www.cppblog.com/foxriver/archive/2011/12/06/161546.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Mon, 05 Dec 2011 17:57:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/12/06/161546.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/161546.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/12/06/161546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/161546.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/161546.html</trackback:ping><description><![CDATA[<p>普通jpeg<br />8x8块编码DCT，熵编码=Huffman, </p>
<p>jpeg2000<br />有小波浮点或整数两种变换算法, 熵编码=MQ-Code，中等压缩比有良好的表现，衍生格式为ecw，用于压缩卫星图片。</p>
<p>jpeg-xr<br />john carmack在rage资源中使用的格式，他推荐的一般都不会差。微软定义的开源算法，比jpeg2000有所进化，主要改进有DCT块的层次保存格式，块之间后期接缝处理。有无损和有损模式，适合长期保存游戏贴图。</p>
<p>h264 iframe<br />使用单帧内预测技术，图片越大，越能体现超强的压缩比。熵编码=Gobomb-Code<br /><br /></p>
<p>其他一些游戏压缩格式:<br />pvrtx<br />iphone压缩格式, 效果比较理想，不开源。</p>
<p>etc1<br />android中普遍的压缩格式。</p>
<p>dxt1, dxt3, dxt5<br />早期的经典格式, 采用块状分割，恒定压缩比，适合二次压缩。</p>
<p>bc6, bc7<br />被微软强化的dx10压缩格式，和dxt1一个压缩比，图片质量非常好。</p>
<p>其他非游戏压缩格式:<br />1. 图片扫描文件二值压缩格式, JB2(djvu), JBIG2(pdf), TIFF C4<br />2. 数码相机里RAW压缩格式, 用于近无损压缩，大部分厂商都有自己的定义:Epson ERF, SGI Log24, Nikon NEF, Kodak DCR, Pentax PEF等</p>
<p>&nbsp;<br /><br />-------------------------<br /></p>
<p>1:100的图片压缩效果对比<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/compare_jpegxr_2x.jpg" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/compare_jpegxr.jpg" width="1284" height="512" /><br /></p>
<p>&nbsp;</p>
<p>&nbsp;游戏贴图压缩质量对比图<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/compare_dds.jpg" /><br /></p><img src ="http://www.cppblog.com/foxriver/aggbug/161546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-12-06 01:57 <a href="http://www.cppblog.com/foxriver/archive/2011/12/06/161546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>插值算法，质量对比图示【原创】</title><link>http://www.cppblog.com/foxriver/archive/2011/03/21/142317.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Sun, 20 Mar 2011 17:01:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/03/21/142317.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/142317.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/03/21/142317.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/142317.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/142317.html</trackback:ping><description><![CDATA[<p>所有涉及图片放大缩小，旋转或图片扭曲的操作，都会有Resample. 而插值算法，就是为了减少走样而。其中又分卷积和后置滤波。</p>
<p>1. 卷积，通常在源图片空间采样，但有时候warp算法复杂（比如RBF径向基函数)，造成像素在源图片空间纵横比例不同，往往用后置滤波更简单。以下对比是1:1对象空间的旋转变换。</p>
<p><br>原图如下，目标质量对比图为中心旋转5度，重复72次，正好360度恢复原样。<br><br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/car_filter_01.jpg" width=802 height=678><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/car_filter_02.jpg" width=802 height=678><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/car_filter_03.jpg" width=802 height=678><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/car_filter_04.jpg" width=802 height=226> </p>
<img src ="http://www.cppblog.com/foxriver/aggbug/142317.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-03-21 01:01 <a href="http://www.cppblog.com/foxriver/archive/2011/03/21/142317.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>crysis2 dx9一帧渲染流程笔记</title><link>http://www.cppblog.com/foxriver/archive/2011/02/18/140241.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Thu, 17 Feb 2011 18:51:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/02/18/140241.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/140241.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/02/18/140241.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/140241.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/140241.html</trackback:ping><description><![CDATA[<p>crysis2 dx9一帧渲染流程：</p>
<p>1. TestCooperativeLevel()<br>2. 设置n-patch细分等级D3DRS_ADAPTIVETESS_Y<br>3. GPU同步设置，Query9::GetData(), Query9::Issue()<br>4. ShadowMap<br>5. ZPass, 生成GBuffer信息。<br>6. Depth_DownScale<br>7. SSAO<br>8. Scattering List</p>
<p>9. Deferred Lighting<br>9.1 Irradiance Volume Evaluate<br>9.2.1 Visares<br>9.2.2 Outdoor <br>9.3&nbsp;&nbsp; Deferred CubeMaps<br>9.4&nbsp;&nbsp; Deferred Lights<br>9.5&nbsp;&nbsp; SSAO_BLUR<br>9.6&nbsp;&nbsp; Deferred Lights<br>9.6.1 ShadowMap Pool</p>
<p>10. 不透明物体绘制。<br>10.1 General(BW)<br>10.2 地形(BW)<br>10.3 General(AW)<br>10.4 地形(AW)<br>10.5 细节(BW)<br>10.6 细节(AW)<br>10.7 皮肤生成<br>10.8 皮肤应用</p>
<p>11. 半透明物体绘制。<br>11.1 雾</p>
<p>12. Glow Gen(光晕生成)</p>
<p>13. HDR Post Proesss<br>13.1 Motion Blur, 运动模糊<br>13.1.1 Motion Vector Gen<br>13.1.2 Motion Vector Dilate<br>13.1.3 Motion Vector Apply<br>13.1.4 Motion Vector Apply Pass 2</p>
<p>13.2 HalfRes downsample<br>13.3 QuarterRes downsample<br>13.4 BrightPass<br>13.5 Bloom and Flares<br>13.5.1 TexBlur 16Taps<br>13.5.2 TexBlur Gaussian<br>13.5.3 TexBlur Gaussian<br>13.5.4 HDR flares</p>
<p>13.6 Sunshafts生成<br>13.7 MergeColorCharts<br>13.8 CombineColorGradingWithColorChart<br>13.9 ToneMapping</p>
<p>14. Post Effects<br>14.1 MSAA<br>14.2 3D HUD</p>
<p>15. 刷新绘制<br>16. 绘制界面<br>17. 绘制调试信息</p>
<p><br>&nbsp;<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/crysis2.jpg" width=1024 height=614></p>
<img src ="http://www.cppblog.com/foxriver/aggbug/140241.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-02-18 02:51 <a href="http://www.cppblog.com/foxriver/archive/2011/02/18/140241.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网上开源RSA实现库</title><link>http://www.cppblog.com/foxriver/archive/2011/02/10/139853.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Wed, 09 Feb 2011 23:11:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/02/10/139853.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/139853.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/02/10/139853.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/139853.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/139853.html</trackback:ping><description><![CDATA[<p>网上开源RSA实现库:</p>
<p>openssl&nbsp;&nbsp; 强大的工具集合<br>crypto++&nbsp; 过于复杂的封装，特别是rsa实现模块。</p>
<p>速度上有优势的：XySSL, CyaSSL(都使用的LibTomMath)<br>逻辑上有优势的：axcrypto, raknet<br>还有一些大数库: vlong，WinNTL</p>
<p>对于公钥签名认证, google android自带的libmincrypt有超快的实现方法，可惜代码只是为了一家优化，仅提供e=3的加速。而网上通常的ASN.1证书，都用了e=63357。<br></p>
<img src ="http://www.cppblog.com/foxriver/aggbug/139853.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-02-10 07:11 <a href="http://www.cppblog.com/foxriver/archive/2011/02/10/139853.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++ 【山寨算法】实现一个最简单bit位全文查找索引。</title><link>http://www.cppblog.com/foxriver/archive/2011/01/14/138500.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Thu, 13 Jan 2011 17:22:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/01/14/138500.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/138500.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/01/14/138500.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/138500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/138500.html</trackback:ping><description><![CDATA[<p>当QQ群聊天记录日积月累，达到一定数量级的时候，要查找某些单一文字，往往会花费10几秒甚至几分钟才有反应。除去磁盘读取的时间，是否对聊天记录做一个全局索引也是个重要的优化，这篇文章就是为了优化文本查找速度，介绍一个最简单的方法。</p>
<p>试着把QQ每条聊天记录看成SQL里单一记录，对单条记录做全文索引。这里用的方法是bit位快速匹配。假设一条聊天记录是"test", 转换成16进制，就是"74 65 73 74", 对单条记录，定义196位bit空间(占用24字节)，定义为数组A, 然后按bit层(注意不是字节)做or操作:&nbsp; (A = A or N, 把A的第N个bit设置为1)</p>
<p>初始状态：<br>A = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】</p>
<p>A = A or 0x74; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】<br>A = A or 0x65; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】<br>A = A or 0x73; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】<br>A = A or 0x74; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】</p>
<p>使用时，给需要查找的字符串建立相同大小的bit索引B，对查找数据"es"做相同处理：</p>
<p>B = 0;<br>B = B or 0x65; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】<br>B = B or 0x73; // 【0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00】</p>
<p>然后把A和B做and操作，如果结果为空（完全没有交集），则可以快速跳过这条记录，而不用去判断实际内容中是否包含了查找文本。</p>
<p>if (B &amp; A)<br>{<br>&nbsp; // 两者索引存在交集，有一定的可能性，处理进一步文字查找操作。<br>}<br>else<br>{<br>&nbsp; // 两者不可能有包含关系，直接跳过本条记录内容，判断数据库下一条记录。<br>}</p>
<p>原理很简单，就是求两者的交集，但往往简单的索引，能带来意想不到的速度提升。实际测试中，只要输入的查找文本比较短小，大约30%~60%上下浮动的数据都能直接略过，大大节省了查找总耗时。<br><br>本人实现中，中文的查找方法相当于两个单字节的英文，为了最大效率利用空间，用算法把中文每个BYTE都压缩在196bit之内。<br></p>
<img src ="http://www.cppblog.com/foxriver/aggbug/138500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-01-14 01:22 <a href="http://www.cppblog.com/foxriver/archive/2011/01/14/138500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++ 多重继承的强制类型转换。</title><link>http://www.cppblog.com/foxriver/archive/2011/01/12/138405.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Wed, 12 Jan 2011 07:53:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/01/12/138405.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/138405.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/01/12/138405.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/138405.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/138405.html</trackback:ping><description><![CDATA[算是对多重继承里，类型转换所做一个笔记。先看如下代码：<br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;A<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A()&nbsp;{&nbsp;m_data&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">A()&nbsp;{}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;m_data;<br>};<br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;B<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B()&nbsp;{&nbsp;m_data&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">B</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">B()&nbsp;{}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;m_data;<br>};<br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;C&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;A,&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;B<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C()&nbsp;{&nbsp;m_data&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">C</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">C()&nbsp;{}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;m_data;<br>};<br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;D&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;C<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D()&nbsp;{&nbsp;m_data&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">D</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">D()&nbsp;{}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;test()<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;value&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(DWORD)</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;address1&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(A</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(value);<span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;编译通过，类型转换错误（仅在在虚拟继承的情况下），正确的写法：A*&nbsp;address1&nbsp;=&nbsp;(A*)((D*)value);</span><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;address2&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(B</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(value);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;编译通过，类型转换错误，正确的写法：B*&nbsp;address2&nbsp;=&nbsp;(B*)((D*)value);<br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;address3&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(C</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(value);<br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;address4&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(value);<br></span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c&nbsp;%c&nbsp;%c&nbsp;%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;address1</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_data,&nbsp;address2</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_data,&nbsp;address3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_data,&nbsp;address4</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_data);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;m_data;<br>};<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;D&nbsp;d;<br>&nbsp;&nbsp;d.test();<br>}</span></div>
<br>代码运行后，结果为A A C D，显然B这个类没有正确转换。<br><br>A和B都是D的父类，为什么A* address1 = (A*)value这句转换正确，而B* address2 = (B*)(value)出错呢？这就是多重继承的不可判断性。<br><br>正因为这种特性的存在，我们在实际使用中，应该尽量避免多重继承，选择单一继承这种模式。JAVA就是如此，最初设计时就只能单一继承，而多重继承则演变为纯虚接口(interface)，这样就规避了此类问题。但可惜，在C++里，WTL和QT都大量使用这种模型，想在实际项目中完全避免，也很困难。<br><br>要解决，有几种方法。<br><br>1. 把B* address2 = (B*)(value)这行，改写为B* address2 = (B*)((D*)value); 这样就能直观的传达给编译器，B正确的偏移量。<br><br>最终输出A B C D，正是我们想要的结果。<br><br>2. 显示使用static_cast，当编译器不能确定转换类型时，会提示编译错误信息。<br><br>例如：<br>B* address2 = static_cast&lt;B*&gt;(value); // 编译失败。<br>B* adddres2 = static_cast&lt;B*&gt;((D*)value); // 编译成功，并且结果正确。<br><br>3. 使用RTTI解决。<br><br><br>--------------------------------------------------<br><br>看似问题解决了，可如果一旦改写为<font color=#008000>虚拟继承</font>（class C : virtual&nbsp; public A, virtual public B）这种形式，A运行时还是会出错，必须写成A* address1 = (A*)((D*)value);。如程序里用到了多重继承，一定要小心+谨慎。<br><br>
<img src ="http://www.cppblog.com/foxriver/aggbug/138405.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-01-12 15:53 <a href="http://www.cppblog.com/foxriver/archive/2011/01/12/138405.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>图形算法 - 模糊函数比较，Blur Function Compare。</title><link>http://www.cppblog.com/foxriver/archive/2011/01/11/138316.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Mon, 10 Jan 2011 17:33:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2011/01/11/138316.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/138316.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2011/01/11/138316.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/138316.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/138316.html</trackback:ping><description><![CDATA[<p>加入比较的4种方法有：</p>
<p>1. 快速高斯模糊。<br>2. 二次Summed Area Table Blur(适合gpu, 常用于DOF，<a href="http://www.gamasutra.com/view/feature/3102/four_tricks_for_fast_blurring_in_.php">http://www.gamasutra.com/view/feature/3102/four_tricks_for_fast_blurring_in_.php</a>)<br>3. Alpha Blur(motionblur变种，优化过后的算法，严重依赖相邻像素之间累积关系，不适合gpu, <a href="http://freespace.virgin.net/hugo.elias/graphics/x_motion.htm">http://freespace.virgin.net/hugo.elias/graphics/x_motion.htm</a>)<br>4. SuperFastBoxBlur(<a href="http://incubator.quasimondo.com/processing/superfast_blur.php">http://incubator.quasimondo.com/processing/superfast_blur.php</a><a href="http://incubator.quasimondo.com/processing/fast_blur_deluxe.php"></a>)</p>
<p>其中，这四种方法内，除了高斯模糊是O(n)之外，其他都是O(1)效率。也就是说，运算速度和模糊半径没有关系，只和图片大小有关。</p>
<p><br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/foxriver/blurcompare.png" width=768 height=768><br><br>图上时间仅供参考，除了AlphaBlur代码优化过，其它方法仅仅是基本实现原理。SuperFastBoxBlur和SummedAreaTable实际使用中，要比图上更快些。<br><br>以下方法没有列入比较范围</p>
<p>1. 直接基于O(n*n)的高斯模糊核，速度太慢。图上方法采用纵向和横向高斯核分解。<br>2. Stack Blur, 比高斯快的方法，并且效果和效率兼备。(<a href="http://www.codeproject.com/KB/graphics/blurringwithcuda.aspx">http://www.codeproject.com/KB/graphics/blurringwithcuda.aspx</a><a href="http://incubator.quasimondo.com/processing/fast_blur_deluxe.php"></a>)<br>3. FFT gaussian blur<br>4. High-Dimensional Gaussian Filtering (bilateral)<br>5. constant time filters - heat diffusion.(Kass, 2006)<br>6. constant time filters - SVD, singular value decomposition (Gotsman 1994)<br>7. SAT衍生出来的一些方法，Fast Filter Spreading，Linear Filters and their Transposes。<br><br>---------------------------------------------------<br>关于2次Summed Area Table实现。<br><br>一次SAT采样4个点，二次SAT则需要9个点，三次需要16个点，以此类推。并且乘上对应的Weight Function，除以(面积^n, n = 几次). 详细公式见：Filtering By Repeated Integration<br><br></p>
<img src ="http://www.cppblog.com/foxriver/aggbug/138316.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2011-01-11 01:33 <a href="http://www.cppblog.com/foxriver/archive/2011/01/11/138316.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在c++头文件里定义数组的方法。</title><link>http://www.cppblog.com/foxriver/archive/2010/04/08/111935.html</link><dc:creator>foxriver</dc:creator><author>foxriver</author><pubDate>Thu, 08 Apr 2010 03:17:00 GMT</pubDate><guid>http://www.cppblog.com/foxriver/archive/2010/04/08/111935.html</guid><wfw:comment>http://www.cppblog.com/foxriver/comments/111935.html</wfw:comment><comments>http://www.cppblog.com/foxriver/archive/2010/04/08/111935.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cppblog.com/foxriver/comments/commentRss/111935.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foxriver/services/trackbacks/111935.html</trackback:ping><description><![CDATA[<p>#ifndef __file_h__<br>extern const char table1[];<br>#else<br>const char table1[] = "\x30\xB8\xD1\xB8\x10\x68\x3D\xBC\x09\x04\x31\x94\x5C\x91\xAF\x6C";<br>#endif</p>
<p>#ifndef __file_h__<br>#define __file_h__</p>
<p>.........function</p>
<p><br>#endif<br><br><br>--------------------<br>用以上技巧的前提是，这个.H必须被不同的CPP包含两次以上。<br><br></p>
<img src ="http://www.cppblog.com/foxriver/aggbug/111935.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foxriver/" target="_blank">foxriver</a> 2010-04-08 11:17 <a href="http://www.cppblog.com/foxriver/archive/2010/04/08/111935.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>