最近寫一個圖像縮放的接口,考慮到自己有現成的opengl圖像處理引擎,還是直接寫shader用gpu實作友善。為了效果好一些,采用了雙三次插值算法。
算法相關公式可參考這篇文章:
<a href="http://blog.csdn.net/lichengyu/article/details/8526629">http://blog.csdn.net/lichengyu/article/details/8526629</a>
詳細實作代碼見:
<a href="https://github.com/jxt1234/simple3d/blob/master/src/gl/glbicubicwork.cpp">https://github.com/jxt1234/simple3d/blob/master/src/gl/glbicubicwork.cpp</a>
測試代碼見:
<a href="https://github.com/jxt1234/simple3d/blob/master/gltest/glbitmapworktest.cpp">https://github.com/jxt1234/simple3d/blob/master/gltest/glbitmapworktest.cpp</a>
要內建到其他項目中,隻需要 vertex shader 和 fragment shader 兩部分的代碼,畢竟不同的圖像引擎在如何加載shader,如何傳參數,如何上傳紋理的邏輯都是不同的。
bicubic.vex
生成的 fragment shader:
bicubic.fra