Imported Upstream version 1.4
[deb_x265.git] / source / common / yuv.h
CommitLineData
72b9787e
JB
1/*****************************************************************************
2 * Copyright (C) 2014 x265 project
3 *
4 * Authors: Steve Borho <steve@borho.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
19 *
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
23
24#ifndef X265_YUV_H
25#define X265_YUV_H
26
27#include "common.h"
28#include "primitives.h"
29
30namespace x265 {
31// private namespace
32
33class ShortYuv;
34class PicYuv;
35
36/* A Yuv instance holds pixels for a square CU (64x64 down to 8x8) for all three planes
37 * these are typically used to hold fenc, predictions, or reconstructed blocks */
38class Yuv
39{
40public:
41
42 pixel* m_buf[3];
43
44 uint32_t m_size;
45 uint32_t m_csize;
46 int m_part; // cached partition enum size
47
48 int m_csp;
49 int m_hChromaShift;
50 int m_vChromaShift;
51
52 Yuv();
53
54 bool create(uint32_t size, int csp);
55 void destroy();
56
57 // Copy YUV buffer to picture buffer
58 void copyToPicYuv(PicYuv& destPicYuv, uint32_t cuAddr, uint32_t absPartIdx) const;
59
60 // Copy YUV buffer from picture buffer
61 void copyFromPicYuv(const PicYuv& srcPicYuv, uint32_t cuAddr, uint32_t absPartIdx);
62
63 // Copy from same size YUV buffer
64 void copyFromYuv(const Yuv& srcYuv);
65
66 // Copy Small YUV buffer to the part of other Big YUV buffer
67 void copyToPartYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
68
69 // Copy the part of Big YUV buffer to other Small YUV buffer
70 void copyPartToYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
71
72 // Clip(srcYuv0 + srcYuv1) -> m_buf .. aka recon = clip(pred + residual)
73 void addClip(const Yuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t log2SizeL);
74
75 // (srcYuv0 + srcYuv1)/2 for YUV partition (bidir averaging)
76 void addAvg(const ShortYuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t absPartIdx, uint32_t width, uint32_t height, bool bLuma, bool bChroma);
77
78 void copyPartToPartLuma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const;
79 void copyPartToPartChroma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const;
80
81 pixel* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
82 pixel* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
83 pixel* getCrAddr(uint32_t absPartIdx) { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
84 pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
85
86 const pixel* getLumaAddr(uint32_t absPartIdx) const { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
87 const pixel* getCbAddr(uint32_t absPartIdx) const { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
88 const pixel* getCrAddr(uint32_t absPartIdx) const { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
89 const pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) const { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
90
91 int getChromaAddrOffset(uint32_t absPartIdx) const
92 {
93 int blkX = g_zscanToPelX[absPartIdx] >> m_hChromaShift;
94 int blkY = g_zscanToPelY[absPartIdx] >> m_vChromaShift;
95
96 return blkX + blkY * m_csize;
97 }
98
99 static int getAddrOffset(uint32_t absPartIdx, uint32_t width)
100 {
101 int blkX = g_zscanToPelX[absPartIdx];
102 int blkY = g_zscanToPelY[absPartIdx];
103
104 return blkX + blkY * width;
105 }
106};
107}
108
109#endif