注:问号以及未注释部分 会在x265-1.9版本内更新
/*****************************************************************************
* Copyright (C) 2015 x265 project
*
* Authors: Steve Borho <steve@borho.org>
*
* 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.
*****************************************************************************/
#ifndef X265_YUV_H
#define X265_YUV_H
#include "common.h"
#include "primitives.h"
namespace X265_NS {
// private namespace
class ShortYuv;
class PicYuv;
/* A Yuv instance holds pixels for a square CU (64x64 down to 8x8) for all three planes
* these are typically used to hold fenc, predictions, or reconstructed blocks */
class Yuv
{
public:
pixel* m_buf[3]; //存储空间
uint32_t m_size; //当前yuv的size大小,一般是一个CTU 大小为64
uint32_t m_csize; //当前yuv色度的size大小,一般是一个CTU 大小为64
int m_part; // cached partition enum size 当前块标号:如:LUMA_4x4, LUMA_8x8, LUMA_16x16, LUMA_32x32, LUMA_64x64....
int m_csp; //图像格式 420、444:400
int m_hChromaShift; //根据图像格式,色度宽度需要移位个数 如420格式 就是1
int m_vChromaShift; //根据图像格式,色度高度需要移位个数 如420格式 就是1
/** 函数功能 :初始化YUV
* \返回值 :null */
Yuv();
/** 函数功能 : 初始化数据,并申请空间内存
/*\参数 size: 申请空间大小的size
* \参数 csp: 图像格式
* \返回 : 是否申请内存成功 */
bool create(uint32_t size, int csp);
/** 函数功能 : 释放空间内存
* \返回 : null */
void destroy();
// Copy YUV buffer to picture buffer
void copyToPicYuv(PicYuv& destPicYuv, uint32_t cuAddr, uint32_t absPartIdx) const;
// Copy YUV buffer from picture buffer
void copyFromPicYuv(const PicYuv& srcPicYuv, uint32_t cuAddr, uint32_t absPartIdx);
// Copy from same size YUV buffer
void copyFromYuv(const Yuv& srcYuv);
// Copy portion of srcYuv into ME prediction buffer
void copyPUFromYuv(const Yuv& srcYuv, uint32_t absPartIdx, int partEnum, bool bChroma);
// Copy Small YUV buffer to the part of other Big YUV buffer
/** 函数功能 : 将源数据按照标号位置的部分copy到目标yuv中
* \参数 dstYuv : 目标yuv存储地址
* \参数 absPartIdx : 当前CU在LCU中4x4 zizag地址
* 返回值 : null**/
void copyToPartYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
// Copy the part of Big YUV buffer to other Small YUV buffer
void copyPartToYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
// Clip(srcYuv0 + srcYuv1) -> m_buf .. aka recon = clip(pred + residual)
void addClip(const Yuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t log2SizeL);
// (srcYuv0 + srcYuv1)/2 for YUV partition (bidir averaging)
void addAvg(const ShortYuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t absPartIdx, uint32_t width, uint32_t height, bool bLuma, bool bChroma);
void copyPartToPartLuma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const;
void copyPartToPartChroma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const;
/** 函数功能 : 获取当前亮度当前PU的地址
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* 返回值 : 返回当前亮度当前PU的地址**/
pixel* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
/** 函数功能 : 获取当前色度当前PU的地址
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* 返回值 : 返回当前色度当前PU的地址**/
pixel* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
/** 函数功能 : 获取当前色度当前PU的地址
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* 返回值 : 返回当前色度当前PU的地址**/
pixel* getCrAddr(uint32_t absPartIdx) { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
/** 函数功能 : 获取当前亮度当前PU的地址
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* 返回值 : 返回当前亮度当前PU的地址**/
const pixel* getLumaAddr(uint32_t absPartIdx) const { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
const pixel* getCbAddr(uint32_t absPartIdx) const { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
const pixel* getCrAddr(uint32_t absPartIdx) const { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
const pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) const { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
/** 函数功能 : 获取当前块左上角zigzag标号位置相对当前CU首地址的色度偏移量
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* \参数 width : yuv的宽度(可以理解为步长)
* 返回值 : 返回当前块左上角zigzag标号位置相对当前CU首地址的色度偏移量**/
int getChromaAddrOffset(uint32_t absPartIdx) const
{
int blkX = g_zscanToPelX[absPartIdx] >> m_hChromaShift;
int blkY = g_zscanToPelY[absPartIdx] >> m_vChromaShift;
return blkX + blkY * m_csize;
}
/** 函数功能 : 获取当前块左上角zigzag标号位置相对当前CU首地址的偏移量
* \参数 absPartIdx : 当前块相对于当前CU的zigzag标号
* \参数 width : yuv的宽度(可以理解为步长)
* 返回值 : 返回当前块左上角zigzag标号位置相对当前CU首地址的偏移量**/
static int getAddrOffset(uint32_t absPartIdx, uint32_t width)
{
int blkX = g_zscanToPelX[absPartIdx];
int blkY = g_zscanToPelY[absPartIdx];
return blkX + blkY * width;
}
};
}
#endif