双立方绘图

时间:2016-07-10 12:19:35

标签: c++ image-processing

我在程序中制作了双线性绘图功能。

void bilinear_Plot(float2 temppos,float4 color)
{
  float2 p;
  p.x=Frac(temppos.x);
  p.y=Frac(temppos.y);
  float weights[] = {(1.0f-p.x)*(1.0f-p.y), p.x*(1.0f-p.y), (1.0f-p.x)*p.y, p.x*p.y};
  int2 _position = int2(floor(temppos.x),floor(temppos.y)); 
  writepixel(_position.x,_position.y,color*weights[0]);
  writepixel(_position.x+1,_position.y,color*weights[1]);
  writepixel(_position.x,_position.y+1,color*weights[2]);
  writepixel(_position.x+1,_position.y+1,color*weights[3]);
}

但我想添加Bicubic绘图。 这是一种有点天真的方法,看起来不对,并且没有规范化。

void bicubic_Plot(float2 temppos,float4 color)
{
  float2 p;
  p.x=Frac(temppos.x);
  p.y=Frac(temppos.y);
  float weights[] = {(2.0f-p.x)*(2.0f-p.y), (1.0f-p.x)*(2.0f-p.y), (p.x)*(2.0f-p.y), 
                     (2.0f-p.x)*(1.0f-p.y),         (1.0f-p.x)*(1.0f-p.y),        p.x*(1.0f-p.y),
                     (2.0f-p.x)*p.y,  (1.0f-p.x)*p.y, p.x*p.y
                     };

  int2 _position = int2(floor(temppos.x),floor(temppos.y)); 
  writepixel(_position.x,_position.y,color*weights[0]);
  writepixel(_position.x-1,_position.y,color*weights[1]);
  writepixel(_position.x+1,_position.y,color*weights[2]);

  writepixel(_position.x,_position.y-1,color*weights[3]);
  writepixel(_position.x-1,_position.y-1,color*weights[4]);
  writepixel(_position.x+1,_position.y-1,color*weights[5]);

  writepixel(_position.x,_position.y+1,color*weights[6]);
  writepixel(_position.x-1,_position.y+1,color*weights[7]);
  writepixel(_position.x+1,_position.y+1,color*weights[8]);
}

这是否是接近双三次绘图的错误方法?

0 个答案:

没有答案
相关问题