Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * x265: ShortYUV class for short sized YUV-style frames | |
3 | ***************************************************************************** | |
4 | * Copyright (C) 2013 x265 project | |
5 | * | |
6 | * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | |
21 | * | |
22 | * This program is also available under a commercial proprietary license. | |
23 | * For more information, contact us at license @ x265.com | |
24 | *****************************************************************************/ | |
25 | ||
26 | #ifndef X265_SHORTYUV_H | |
27 | #define X265_SHORTYUV_H | |
28 | ||
29 | #include "common.h" | |
30 | ||
31 | namespace x265 { | |
32 | // private namespace | |
33 | ||
34 | class Yuv; | |
35 | ||
36 | /* A ShortYuv instance holds int16_ts for a square CU (64x64 down to 8x8) for all three planes, | |
37 | * these are typically used to hold residual or coefficients */ | |
38 | class ShortYuv | |
39 | { | |
40 | public: | |
41 | ||
42 | int16_t* m_buf[3]; | |
43 | ||
44 | uint32_t m_size; | |
45 | uint32_t m_csize; | |
46 | ||
47 | int m_csp; | |
48 | int m_hChromaShift; | |
49 | int m_vChromaShift; | |
50 | ||
51 | ShortYuv(); | |
52 | ||
53 | bool create(uint32_t size, int csp); | |
54 | void destroy(); | |
55 | void clear(); | |
56 | ||
57 | int16_t* getLumaAddr(uint32_t absPartIdx) { return m_buf[0] + getAddrOffset(absPartIdx, m_size); } | |
58 | int16_t* getCbAddr(uint32_t absPartIdx) { return m_buf[1] + getChromaAddrOffset(absPartIdx); } | |
59 | int16_t* getCrAddr(uint32_t absPartIdx) { return m_buf[2] + getChromaAddrOffset(absPartIdx); } | |
60 | int16_t* getChromaAddr(uint32_t chromaId, uint32_t partUnitIdx) { return m_buf[chromaId] + getChromaAddrOffset(partUnitIdx); } | |
61 | ||
62 | const int16_t* getLumaAddr(uint32_t absPartIdx) const { return m_buf[0] + getAddrOffset(absPartIdx, m_size); } | |
63 | const int16_t* getCbAddr(uint32_t absPartIdx) const { return m_buf[1] + getChromaAddrOffset(absPartIdx); } | |
64 | const int16_t* getCrAddr(uint32_t absPartIdx) const { return m_buf[2] + getChromaAddrOffset(absPartIdx); } | |
65 | const int16_t* getChromaAddr(uint32_t chromaId, uint32_t partUnitIdx) const { return m_buf[chromaId] + getChromaAddrOffset(partUnitIdx); } | |
66 | ||
67 | void subtract(const Yuv& srcYuv0, const Yuv& srcYuv1, uint32_t log2Size); | |
68 | ||
69 | void copyPartToPartLuma(ShortYuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const; | |
70 | void copyPartToPartChroma(ShortYuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const; | |
71 | ||
72 | void copyPartToPartLuma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const; | |
73 | void copyPartToPartChroma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const; | |
74 | ||
75 | int getChromaAddrOffset(uint32_t idx) const | |
76 | { | |
77 | int blkX = g_zscanToPelX[idx] >> m_hChromaShift; | |
78 | int blkY = g_zscanToPelY[idx] >> m_vChromaShift; | |
79 | ||
80 | return blkX + blkY * m_csize; | |
81 | } | |
82 | ||
83 | static int getAddrOffset(uint32_t idx, uint32_t width) | |
84 | { | |
85 | int blkX = g_zscanToPelX[idx]; | |
86 | int blkY = g_zscanToPelY[idx]; | |
87 | ||
88 | return blkX + blkY * width; | |
89 | } | |
90 | }; | |
91 | } | |
92 | ||
93 | #endif // ifndef X265_SHORTYUV_H |