Imported Upstream version 1.4+222+hg5f9f7194267b
[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
b53f7c52
JB
66 // Copy portion of srcYuv into ME prediction buffer
67 void copyPUFromYuv(const Yuv& srcYuv, uint32_t absPartIdx, int partEnum, bool bChroma);
68
72b9787e
JB
69 // Copy Small YUV buffer to the part of other Big YUV buffer
70 void copyToPartYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
71
72 // Copy the part of Big YUV buffer to other Small YUV buffer
73 void copyPartToYuv(Yuv& dstYuv, uint32_t absPartIdx) const;
74
75 // Clip(srcYuv0 + srcYuv1) -> m_buf .. aka recon = clip(pred + residual)
76 void addClip(const Yuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t log2SizeL);
77
78 // (srcYuv0 + srcYuv1)/2 for YUV partition (bidir averaging)
79 void addAvg(const ShortYuv& srcYuv0, const ShortYuv& srcYuv1, uint32_t absPartIdx, uint32_t width, uint32_t height, bool bLuma, bool bChroma);
80
81 void copyPartToPartLuma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const;
82 void copyPartToPartChroma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const;
83
84 pixel* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
85 pixel* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
86 pixel* getCrAddr(uint32_t absPartIdx) { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
87 pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
88
89 const pixel* getLumaAddr(uint32_t absPartIdx) const { return m_buf[0] + getAddrOffset(absPartIdx, m_size); }
90 const pixel* getCbAddr(uint32_t absPartIdx) const { return m_buf[1] + getChromaAddrOffset(absPartIdx); }
91 const pixel* getCrAddr(uint32_t absPartIdx) const { return m_buf[2] + getChromaAddrOffset(absPartIdx); }
92 const pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) const { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); }
93
94 int getChromaAddrOffset(uint32_t absPartIdx) const
95 {
96 int blkX = g_zscanToPelX[absPartIdx] >> m_hChromaShift;
97 int blkY = g_zscanToPelY[absPartIdx] >> m_vChromaShift;
98
99 return blkX + blkY * m_csize;
100 }
101
102 static int getAddrOffset(uint32_t absPartIdx, uint32_t width)
103 {
104 int blkX = g_zscanToPelX[absPartIdx];
105 int blkY = g_zscanToPelY[absPartIdx];
106
107 return blkX + blkY * width;
108 }
109};
110}
111
112#endif