/src/x265/source/common/yuv.h
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
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 | | |
30 | | namespace X265_NS { |
31 | | // private namespace |
32 | | |
33 | | class ShortYuv; |
34 | | class 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 */ |
38 | | class Yuv |
39 | | { |
40 | | public: |
41 | | pixel* m_buf[3]; |
42 | | |
43 | | uint32_t m_size; |
44 | | uint32_t m_csize; |
45 | | int m_part; // cached partition enum size |
46 | | |
47 | | int m_csp; |
48 | | int m_hChromaShift; |
49 | | int m_vChromaShift; |
50 | | uint32_t *m_integral[2][MAX_NUM_REF][INTEGRAL_PLANE_NUM]; |
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 portion of srcYuv into ME prediction buffer |
67 | | void copyPUFromYuv(const Yuv& srcYuv, uint32_t absPartIdx, int partEnum, bool bChroma); |
68 | | |
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, int picCsp); |
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 | 13.7M | pixel* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); } |
85 | 1.62M | pixel* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); } |
86 | 1.62M | pixel* getCrAddr(uint32_t absPartIdx) { return m_buf[2] + getChromaAddrOffset(absPartIdx); } |
87 | 15.4M | pixel* getChromaAddr(uint32_t chromaId, uint32_t absPartIdx) { return m_buf[chromaId] + getChromaAddrOffset(absPartIdx); } |
88 | | |
89 | 8.84M | const pixel* getLumaAddr(uint32_t absPartIdx) const { return m_buf[0] + getAddrOffset(absPartIdx, m_size); } |
90 | 1.18M | const pixel* getCbAddr(uint32_t absPartIdx) const { return m_buf[1] + getChromaAddrOffset(absPartIdx); } |
91 | 1.18M | const pixel* getCrAddr(uint32_t absPartIdx) const { return m_buf[2] + getChromaAddrOffset(absPartIdx); } |
92 | 7.72M | 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 | 29.6M | { |
96 | 29.6M | int blkX = g_zscanToPelX[absPartIdx] >> m_hChromaShift; |
97 | 29.6M | int blkY = g_zscanToPelY[absPartIdx] >> m_vChromaShift; |
98 | | |
99 | 29.6M | return blkX + blkY * m_csize; |
100 | 29.6M | } |
101 | | |
102 | | static int getAddrOffset(uint32_t absPartIdx, uint32_t width) |
103 | 23.0M | { |
104 | 23.0M | int blkX = g_zscanToPelX[absPartIdx]; |
105 | 23.0M | int blkY = g_zscanToPelY[absPartIdx]; |
106 | | |
107 | 23.0M | return blkX + blkY * width; |
108 | 23.0M | } |
109 | | }; |
110 | | } |
111 | | |
112 | | #endif |