x265-1.8版本-encoder/bitcost.h注释

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

/*****************************************************************************
 * Copyright (C) 2013 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_BITCOST_H
#define X265_BITCOST_H

#include "common.h"
#include "threading.h"
#include "mv.h"

namespace X265_NS {
// private x265 namespace
//BitCost主要用于计算MVD-cost MVD = MV-MVP 
class BitCost //被MotionEstimate继承
{
public:

    //初始化
    BitCost() : m_cost_mvx(0), m_cost_mvy(0), m_cost(0), m_mvp(0) {}

    /** 函数功能             :建立当前qp下的MVD占用的cost:λ*bits = 2^(qp/6-2) * s_bitsizes[i]
    * \参数 qp               :当前ME下的qp大小
    * \返回                  :null * */
    void setQP(unsigned int qp);

    /** 函数功能             :设置当前的MVP,并更新以当前MVP的MVD-cost表格:如当前MV=(3,6)MVP=(1,2),则MVD=(2,4) 期MVcost = m_cost_mvx[mv.x] + m_cost_mvy[mv.y] = m_cost_mvx[3] + m_cost_mvy[6]
                                                                                                                      = m_cost[3-1] + m_cost[6-2] = m_cost[2] + m_cost[4]
    * \参数 mvp              :设置当前ME搜索时选用的MVP,以及计算MVD cost的表格
    * \返回                  :null * */
    void setMVP(const MV& mvp)                      { m_mvp = mvp; m_cost_mvx = m_cost - mvp.x; m_cost_mvy = m_cost - mvp.y; }

    // return bit cost of motion vector difference, multiplied by lambda
    /** 函数功能             :返回当前MV与MVP之间的差(MVD)占用的bits-cost
    * \参数 mv               :当前待计算的MV
    * \返回                  :null * */
    inline uint16_t mvcost(const MV& mv) const      { return m_cost_mvx[mv.x] + m_cost_mvy[mv.y]; }

    // return bit cost of motion vector difference, without lambda
    /** 函数功能             :返回当前MV与MVP之间的差(MVD)占用的bits,没有经过λ加权
    * \参数 mv               :当前待计算的MV
    * \返回                  :null * */
    inline uint32_t bitcost(const MV& mv) const
    {
        return (uint32_t)(s_bitsizes[abs(mv.x - m_mvp.x)] +
                          s_bitsizes[abs(mv.y - m_mvp.y)] + 0.5f);
    }
    /** 函数功能             :返回当前MV与MVP之间的差(MVD)占用的bits,没有经过λ加权
    * \参数 mv               :当前待计算的MV
    * \参数 mvp              :当前待计算的MVP
    * \返回                  :null * */
    static inline uint32_t bitcost(const MV& mv, const MV& mvp)
    {
        return (uint32_t)(s_bitsizes[abs(mv.x - mvp.x)] +
                          s_bitsizes[abs(mv.y - mvp.y)] + 0.5f);
    }
    /** 函数功能   : 释放空间内存
    * \返回        : null */
    static void destroy();

protected:

    uint16_t *m_cost_mvx;//计算当前MVD x坐标占用的bits-cost

    uint16_t *m_cost_mvy;//计算当前MVD y坐标占用的bits-cost

    uint16_t *m_cost;   //当前qp下的MVD占用的cost:λ*bits = 2^(qp/6-2) * s_bitsizes[i],在setQP()中进行初始化

    MV        m_mvp;    //当前ME搜索时选用的MVP

    BitCost& operator =(const BitCost&);

private:

    /* default log2_max_mv_length_horizontal and log2_max_mv_length_horizontal
     * are 15, specified in quarter-pel luma sample units. making the maximum
     * signaled ful-pel motion distance 4096, max qpel is 32768 */
    //最大整像素运动矢量为4096 1/4像素 最大为32768
    enum { BC_MAX_MV = (1 << 15) };

    enum { BC_MAX_QP = 82 };

    static float *s_bitsizes; //申请空间大小为 2*32768+1   MVD估计占用bits表格,例如:当前MV.x = 3 ,则其占用bits 为 s_bitsizes[3] 2*(log2(3+1))+e-1
    /*
    s_bitsizes[0] = e - 2   s_bitsizes[i]= 2*(log2(i+1))+e-1  log2 表示以2为底
    s_bitsizes[1] = 2log2(2) + e -1
    **/

    static uint16_t *s_costs[BC_MAX_QP];//所有的me共有,每个qp只初始化一次

    static Lock s_costCalcLock;         //多线程锁
    /** 函数功能             :建立MVD估计占用bits表格,例如:当前MV.x = 3 ,则其占用bits 为 s_bitsizes[3] 2*(log2(3+1))+e-1
    * \返回                  :null * */
    static void CalculateLogs();
};
}

#endif // ifndef X265_BITCOST_H


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值