注:问号以及未注释部分 会在x265-1.9版本内更新

/*****************************************************************************
* Copyright (C) 2013 x265 project
*
* Authors: Gopu Govindaswamy <gopu@multicorewareinc.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at license @ x265.com.
*****************************************************************************/
#include "picyuv.h"
#include "lowres.h"
#include "mv.h"
using namespace X265_NS;
//本文件提供关于视频图像下采样的一个功能接口
//Lowres 申请空间、释放内存、初始化、下采样图像及扩边等
/** 函数功能   : 初始化数据,并申请空间内存
/*  调用范围   : 只Frame::create函数中被调用
* \参数 origPic: Frame.m_fencPic 原始帧YUV数据
* \返回        : 是否申请内存成功 */
bool Lowres::create(PicYuv *origPic, int _bframes, bool bAQEnabled)
{
isLowres = true;                  //告知父类ReferencePlanes 当前是lowresolution
bframes = _bframes;
width = origPic->m_picWidth / 2; //1/2下采样宽度
lines = origPic->m_picHeight / 2;//1/2下采样高度
lumaStride = width + 2 * origPic->m_lumaMarginX;
if (lumaStride & 31)
lumaStride += 32 - (lumaStride & 31);   //保证当前下采样视频步长时32的整数倍
maxBlocksInRow = (width + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
maxBlocksInCol = (lines + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
int cuCount = maxBlocksInRow * maxBlocksInCol;
/* rounding the width to multiple of lowres CU size */
width = maxBlocksInRow * X265_LOWRES_CU_SIZE;
lines = maxBlocksInCol * X265_LOWRES_CU_SIZE;
size_t planesize = lumaStride * (lines + 2 * origPic->m_lumaMarginY);
size_t padoffset = lumaStride * origPic->m_lumaMarginY + origPic->m_lumaMarginX;
if (bAQEnabled)
{
CHECKED_MALLOC(qpAqOffset, double, cuCount);
CHECKED_MALLOC(invQscaleFactor, int, cuCount);
CHECKED_MALLOC(qpCuTreeOffset, double, cuCount);
}
CHECKED_MALLOC(propagateCost, uint16_t, cuCount);
/* allocate lowres buffers */
CHECKED_MALLOC_ZERO(buffer[0], pixel, 4 * planesize); //这里需要申请4个buffer ,因为将要通过4 hpel下采样得到4份1/2亮度
buffer[1] = buffer[0] + planesize;
buffer[2] = buffer[1] + planesize;
buffer[3] = buffer[2] + planesize;
lowresPlane[0] = buffer[0] + padoffset;
lowresPlane[1] = buffer[1] + padoffset;
lowresPlane[2] = buffer[2] + padoffset;
lowresPlane[3] = buffer[3] + padoffset;
CHECKED_MALLOC(intraCost, int32_t, cuCount);
CHECKED_MALLOC(intraMode, uint8_t, cuCount);
for (int i = 0; i < bframes + 2; i++)
{
for (int j = 0; j < bframes + 2; j++)
{
CHECKED_MALLOC(rowSatds[i][j], int32_t, maxBlocksInCol);
CHECKED_MALLOC(lowresCosts[i][j], uint16_t, cuCount);
}
}
for (int i = 0; i < bframes + 1; i++)
{
CHECKED_MALLOC(lowresMvs[0][i], MV, cuCount);
CHECKED_MALLOC(lowresMvs[1][i], MV, cuCount);
CHECKED_MALLOC(lowresMvCosts[0][i], int32_t, cuCount);
CHECKED_MALLOC(lowresMvCosts[1][i], int32_t, cuCount);
}
return true;
fail:
return false;
}
/** 函数功能   : 释放空间内存
/*  调用范围   : 只Frame::destroy函数中被调用
* \返回        : null */
void Lowres::destroy()
{
X265_FREE(buffer[0]);
X265_FREE(intraCost);
X265_FREE(intraMode);
for (int i = 0; i < bframes + 2; i++)
{
for (int j = 0; j < bframes + 2; j++)
{
X265_FREE(rowSatds[i][j]);
X265_FREE(lowresCosts[i][j]);
}
}
for (int i = 0; i < bframes + 1; i++)
{
X265_FREE(lowresMvs[0][i]);
X265_FREE(lowresMvs[1][i]);
X265_FREE(lowresMvCosts[0][i]);
X265_FREE(lowresMvCosts[1][i]);
}
X265_FREE(qpAqOffset);
X265_FREE(invQscaleFactor);
X265_FREE(qpCuTreeOffset);
X265_FREE(propagateCost);
}
/** 函数功能   : 初始化信息,并进行下采样和扩边
/*  调用范围   : 只void PreLookaheadGroup::processTasks函数中被调用
* \返回        : null */
// (re) initialize lowres state
void Lowres::init(PicYuv *origPic, int poc)
{
bLastMiniGopBFrame = false;
bScenecut = false;  // could be a scene-cut, until ruled out by flash detection
bKeyframe = false; // Not a keyframe unless identified by lookahead
frameNum = poc;
leadingBframes = 0;
indB = 0;
satdCost = (int64_t)-1;
memset(costEst, -1, sizeof(costEst));
memset(weightedCostDelta, 0, sizeof(weightedCostDelta));
if (qpAqOffset && invQscaleFactor)
memset(costEstAq, -1, sizeof(costEstAq));
for (int y = 0; y < bframes + 2; y++)
for (int x = 0; x < bframes + 2; x++)
rowSatds[y][x][0] = -1;
for (int i = 0; i < bframes + 1; i++)
{
lowresMvs[0][i][0].x = 0x7FFF;
lowresMvs[1][i][0].x = 0x7FFF;
}
for (int i = 0; i < bframes + 2; i++)
intraMbs[i] = 0;
/* downscale and generate 4 hpel planes for lookahead */
/* 查看 非asm函数frame_init_lowres_core
这样做的目的是更好的通过1/2下采样视频的编码估计原始视频编码状态
将亮度分四种方法进行1/2下采样
原始点:
82  89  86  86  93
85  89  99 101 113
96  97  97 100 104
106 108 107 111 109
127 156 133 139 137
0: 在行列选择偶数像素点为基准并选择相邻的右边、下边、右下机本身4个点作平均
* * + +
* * + +
- - # #
- - # #
87  94
102 104
87 = ((((82 + 85 + 1) >> 1) + ((89 + 89 + 1) >> 1) + 1) >> 1)
94 = ((((86 + 99 + 1) >> 1) + ((86 + 101 + 1) >> 1) + 1) >> 1)
102= ((((96 + 106 + 1) >> 1) + ((97 + 108 + 1) >> 1) + 1) >> 1)
104 = ((((97 + 107 + 1) >> 1) + ((100 + 111 + 1) >> 1) + 1) >> 1)
h: 在行选择偶数像素点,在列选择奇数像素点为基准并选择相邻的右边、下边、右下机本身4个点作平均
= * * = + +
= * * = + +
= - - = # #
= - - = # #
91  99
103 107
91 = ((((89 + 89 + 1) >> 1) + ((86 + 99 + 1) >> 1) + 1) >> 1)
99 = ((((86 + 101 + 1) >> 1) + ((93 + 113 + 1) >> 1) + 1) >> 1)
v: 在行选择奇数像素点,在列选择偶数像素点为基准并选择相邻的右边、下边、右下机本身4个点作平均
= = = =
* * + +
* * + +
= = = =
- - # #
- - # #
92 100
125 123
92 = ((((85 + 96 + 1) >> 1) + ((89 + 97 + 1) >> 1) + 1) >> 1)
在行列选择奇数像素点为基准并选择相邻的右边、下边、右下机本身4个点作平均
= = = = = =
= * * = + +
= * * = + +
= = = = = =
= - - = # #
= - - = # #
96 105
126 124
96 = ((((89 + 97 + 1) >> 1) + ((99 + 97 + 1) >> 1) + 1) >> 1)
**/
primitives.frameInitLowres(origPic->m_picOrg[0],
lowresPlane[0], lowresPlane[1], lowresPlane[2], lowresPlane[3],
origPic->m_stride, lumaStride, width, lines);
/* extend hpel planes for motion search */
extendPicBorder(lowresPlane[0], lumaStride, width, lines, origPic->m_lumaMarginX, origPic->m_lumaMarginY);//扩边
extendPicBorder(lowresPlane[1], lumaStride, width, lines, origPic->m_lumaMarginX, origPic->m_lumaMarginY);
extendPicBorder(lowresPlane[2], lumaStride, width, lines, origPic->m_lumaMarginX, origPic->m_lumaMarginY);
extendPicBorder(lowresPlane[3], lumaStride, width, lines, origPic->m_lumaMarginX, origPic->m_lumaMarginY);
fpelPlane[0] = lowresPlane[0];
}

x265-1.8版本-common/lowres.cpp注释相关推荐

  1. x265-1.7版本-common/lowres.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  2. x265-1.8版本-common/pixel.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  3. x265-1.7版本-common/pixel.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  4. x265-1.8版本-common/lowres.h注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  5. x265-1.7版本-common/lowres.h注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  6. x265-1.8版本-common/wavefront.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  7. x265-1.7版本-common/intrapred.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  8. x265-1.7版本-encoder/slicetype.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新 /*********************************************************************** ...

  9. x265-1.8版本-encoder/slicetype.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

最新文章

  1. Fiddler+willow使用指南
  2. python 列表筛选数据
  3. 安装go语言开发环境
  4. 未能加载文件或程序集“System.Data.SQLite, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139...
  5. java判断两个日期是否为同一天
  6. Vim案列掌握vim的基本操作——案例一:vim创建编写txt文件
  7. express不是内部命令解决办法
  8. Spring的Bean有哪些作用域?
  9. ML-Visuals机器学习、深度学习绘图模板素材分享
  10. html音乐播放器怎么有黑边框,播放不能满屏有黑边怎么办,怎么剪切视频黑边,剪切黑边...
  11. 上海黑马python培训
  12. 【小程序开发之制作首页】
  13. 诸葛——如何摆脱APP速死症?
  14. turtle绘制八边形、八角边形
  15. 本科计算机专业是机试,华东师大计算机专业复试上机复习攻略+机试技巧
  16. 番外篇:STM32之GPIO口速率配置究竟代表什么
  17. 迎双11十周年,OceanBase 2.0挑战新巅峰
  18. 现代信息技术与计算机说课,《信息技术及其发展》说课稿
  19. 面试官:useLayoutEffect和useEffect的区别
  20. 介绍c语言的英语论文,c语言中英文翻译资料毕业论文.doc

热门文章

  1. RPC(管理端口的服务)NFS软件 NFS配置文件 简单介绍
  2. matlab计算下列极限,MATLAB微积分计算极限,又快又好
  3. 如何使用Grafana轻松实现OVL数据可视化
  4. 等额本金和等额本息房贷公式推导
  5. Win10 Windows Defender添加信任文件的方法
  6. java-asc码形式输出
  7. 开关面板如何自己印字_墙壁开关上的商标是怎么印上去的
  8. 如何炼就数据分析的思维?
  9. HDU 6304 Chiaki Sequence Revisited(二分+找规律)
  10. 枸杞动态分类-大致思路