双线性插值C++ 放大整数 计算

174次阅读
没有评论

共计 786 个字符,预计需要花费 2 分钟才能阅读完成。

double pos;
short* RowOffset = (short*)malloc(NewWidth * sizeof(short));
short* RowPartXX = (short*)malloc(NewWidth * sizeof(short));

for (int X = 0; X < NewWidth; X++)
{
  pos = (double)X * (Width - 1) / (double)NewWidth;
  RowOffset[X] = pos;
  RowPartXX[X] = (pos - (int)pos) * 2048;
}
for (int Y = 0; Y < NewHeight; Y++)
{
  unsigned char* LinearDest = Dest + Y * NewWidth;
  pos = Y * (Height - 1) / NewHeight;
  int PartYY = (pos - (int)pos) * 2048;
  int InvertYY = 2048 - PartYY;
  int ColOffset = int(pos);
  unsigned char* LinearSrc = Src + ColOffset * Width;
  unsigned char* LinearSrc1 = Src + (ColOffset + 1) * Width;
  for (int X = 0; X < NewWidth - 1; X++)
  {
    int PartXX = RowPartXX[X];
    int InvertXX = 2048 - PartXX;
    LinearDest[X] = ((LinearSrc[RowOffset[X]] * InvertXX +
      LinearSrc[RowOffset[X + 1]] * PartXX) * InvertYY +
      (LinearSrc1[RowOffset[X]] * InvertXX +
        LinearSrc1[RowOffset[X + 1]] * PartXX) * PartYY) >> 22;
  }
}



free(RowOffset);
free(RowPartXX);

 

正文完
 
admin
版权声明:本站原创文章,由 admin 2022-10-03发表,共计786字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码