#ifndef X265_YUV_H
#define X265_YUV_H
#include "common.h"
#include "primitives.h"
namespace X265_NS {
class ShortYuv;
class PicYuv;
class Yuv
{
public:
pixel* m_buf[3];
uint32_t m_size;
uint32_t m_csize;
int m_part;
int m_csp;
int m_hChromaShift;
int m_vChromaShift;
uint32_t *m_integral[2][MAX_NUM_REF][INTEGRAL_PLANE_NUM];
Yuv();
bool create(uint32_t size, int csp);
void destroy();
void copyToPicYuv(PicYuv& destPicYuv, uint32_t cuAddr, uint32_t absPartIdx) const;
void copyFromPicYuv(const PicYuv& srcPicYuv, uint32_t cuAddr, uint32_t absPartIdx);
void copyFromYuv(const Yuv& srcYuv);
void copyPUFromYuv(const Yuv& srcYuv, uint32_t absPartIdx, int partEnum, bool bChroma);
void copyToPartYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
void copyPartToYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
void addClip(const Yuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t log2SizeL, int picCsp);
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;
pixel* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
pixel* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
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); }
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); }
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;
}
static int getAddrOffset(uint32_t absPartIdx, uint32_t width)
{
int blkX = g_zscanToPelX[absPartIdx];
int blkY = g_zscanToPelY[absPartIdx];
return blkX + blkY * width;
}
};
}
#endif