いくつかの画像補間アルゴリズムを HLSL コードに移植しようとしています。
float2 texSize;
float scale;
int method;
sampler TextureSampler : register(s0);
float4 PixelShader(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float2 newTexSize = texSize * scale;
float4 tex2;
if(texCoord[0] * texSize[0] > newTexSize[0] ||
texCoord[1] * texSize[1] > newTexSize[1])
{
tex2 = float4( 0, 0, 0, 0 );
} else {
if (method == 0) {
tex2 = tex2D(TextureSampler, float2(texCoord[0]/scale, texCoord[1]/scale));
} else {
float2 step = float2(1/texSize[0], 1/texSize[1]);
float4 px1 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale-step[1]));
float4 px2 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale-step[1]));
float4 px3 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale-step[1]));
float4 px4 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale ));
float4 px5 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale ));
float4 px6 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale+step[1]));
float4 px7 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale+step[1]));
float4 px8 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale+step[1]));
tex2 = (px1+px2+px3+px4+px5+px6+px7+px8)/8;
tex2.a = 1;
}
}
return tex2;
}
technique Resample
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShader();
}
}
問題は、現在の位置を制御できず、ピクセルを介した実際のループの「内部」部分しか制御できないため、ピクセルシェーダーのプログラミングには異なるアプローチが必要になることです。
私はほぼ一日中グーグルで検索してきましたが、ループで使用されるスケーリングアルゴリズムを備えたオープンソースライブラリは見つかりませんでした。いくつかのメソッドを移植できるライブラリはありますか?
http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspxを見つけましたが、問題に対する彼のアプローチを本当に理解していません。それを移植するのは面倒です...
ウィキペディアは数学的なアプローチを示しています。私の質問は次のとおりです。単純なスケーリング アルゴリズムを含む、移植が容易なグラフィック オープン ソース ライブラリはどこにありますか? もちろん、そのようなライブラリが存在する場合でも。