打印

非整数倍率YUV422图像的自由缩放DSP算法

[复制链接]
578|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
qwe890asd|  楼主 | 2017-10-26 11:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
非整数倍率YUV422图像的自由缩放DSP算法


下面的代码,实现将一幅YUV422的双通道图片(640x480大小),取中间区域(560x400大小)使用插值的办法放大至(640x480)。这个算法可以用来实现将图片外围区域截掉。
  • #define X_RATIO (8)
  • #define Y_RATIO (6)

  • PUBLIC void YUVScale(JINF_YUV_CHN_T *const yuv_ptr,const uint32 Width,const uint32 Height)
  • {
  • uint8  *const src_y_ptr = (uint16 *)yuv_ptr->y_chn_ptr;
  • uint8  *const src_uv_ptr = (uint16 *)yuv_ptr->u_chn_ptr;

  • uint32  x,y,w,h=0,xl,yl,dx,dy;

  • if ((Width%(X_RATIO<<1)!=0)||(Height%(Y_RATIO<<1)!=0))
  • {
  • TRACE("%s Width=%d,Height=%d",__func__,Width,Height);
  • return;
  • }

  • ASSERT(PNULL != yuv_ptr);

  • xl=(Width-(Width/X_RATIO))>>1;
  • yl=(Height-(Height/Y_RATIO))>>1;

  • dx=Width / (X_RATIO<<1);
  • dy=Height / (Y_RATIO<<1);

  • for (y=0; y<yl; y++,h++)
  • {
  • w = 0;

  • for (x=0; x<xl; x+=2,w+=2)
  • {
  • CopyPixel:
  • //2 Quadrant 2
  • src_y_ptr[h*Width+w] = src_y_ptr[(dy+y)*Width+dx+x];
  • src_y_ptr[h*Width+w+1] = src_y_ptr[(dy+y)*Width+dx+x+1];
  • src_uv_ptr[h*Width+w] = src_uv_ptr[(dy+y)*Width+dx+x];
  • src_uv_ptr[h*Width+w+1] = src_uv_ptr[(dy+y)*Width+dx+x+1];
  • //2 Quadrant 1
  • src_y_ptr[h*Width+(Width-w-1)] = src_y_ptr[(dy+y)*Width+(Width-dx-x-1)];
  • src_y_ptr[h*Width+(Width-w-2)] = src_y_ptr[(dy+y)*Width+(Width-dx-x-2)];
  • src_uv_ptr[h*Width+(Width-w-1)] = src_uv_ptr[(dy+y)*Width+(Width-dx-x-1)];
  • src_uv_ptr[h*Width+(Width-w-2)] = src_uv_ptr[(dy+y)*Width+(Width-dx-x-2)];
  • //2 Quadrant 4
  • src_y_ptr[(Height-h-1)*Width+(Width-w-1)] = src_y_ptr[(Height-dy-y-1)*Width+(Width-dx-x-1)];
  • src_y_ptr[(Height-h-1)*Width+(Width-w-2)] = src_y_ptr[(Height-dy-y-1)*Width+(Width-dx-x-2)];
  • src_uv_ptr[(Height-h-1)*Width+(Width-w-1)] = src_uv_ptr[(Height-dy-y-1)*Width+(Width-dx-x-1)];
  • src_uv_ptr[(Height-h-1)*Width+(Width-w-2)] = src_uv_ptr[(Height-dy-y-1)*Width+(Width-dx-x-2)];
  • //2 Quadrant 3
  • src_y_ptr[(Height-h-1)*Width+w] = src_y_ptr[(Height-dy-y-1)*Width+dx+x];
  • src_y_ptr[(Height-h-1)*Width+w+1] = src_y_ptr[(Height-dy-y-1)*Width+dx+x+1];
  • src_uv_ptr[(Height-h-1)*Width+w] = src_uv_ptr[(Height-dy-y-1)*Width+dx+x];
  • src_uv_ptr[(Height-h-1)*Width+w+1] = src_uv_ptr[(Height-dy-y-1)*Width+dx+x+1];

  • if (
  • ((w+2) % (X_RATIO<<1))==
  • ((X_RATIO<<1)-2)
  • )
  • {
  • w+=2;
  • goto CopyPixel;
  • }
  • }

  • if (((h+1) % (Y_RATIO))==(Y_RATIO-1))
  • {
  • h++;

  • memcpy(src_y_ptr+h*Width,src_y_ptr+(h-1)*Width,Width);
  • memcpy(src_uv_ptr+h*Width,src_uv_ptr+(h-1)*Width,Width);

  • memcpy(src_y_ptr+(Height-h-1)*Width,src_y_ptr+(Height-h)*Width,Width);
  • memcpy(src_uv_ptr+(Height-h-1)*Width,src_uv_ptr+(Height-h)*Width,Width);
  • }
  • }
  • }

复制代码

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

455

主题

583

帖子

5

粉丝