• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

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

时间:2015年04月02日 15:40:47    来源:魔法猪系统重装大师官网    人气:13253

下面的代码,实现将一幅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{
w = 0;

for (x=0; x{
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);
}
}
}


编写这个算法的好处是,在不改变图片原始大小的情况下去除照片的边框。

非,整数,倍率,YUV422,图像,的,自由,缩放,算法,
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部