/src/x265/source/common/shortyuv.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> |
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 | | #include "common.h" |
25 | | #include "yuv.h" |
26 | | #include "shortyuv.h" |
27 | | #include "primitives.h" |
28 | | |
29 | | #include "x265.h" |
30 | | |
31 | | using namespace X265_NS; |
32 | | |
33 | | ShortYuv::ShortYuv() |
34 | 0 | { |
35 | 0 | m_buf[0] = NULL; |
36 | 0 | m_buf[1] = NULL; |
37 | 0 | m_buf[2] = NULL; |
38 | 0 | } |
39 | | |
40 | | bool ShortYuv::create(uint32_t size, int csp) |
41 | 0 | { |
42 | 0 | m_csp = csp; |
43 | 0 | m_size = size; |
44 | 0 | m_hChromaShift = CHROMA_H_SHIFT(csp); |
45 | 0 | m_vChromaShift = CHROMA_V_SHIFT(csp); |
46 | 0 | size_t sizeL = size * size; |
47 | |
|
48 | 0 | if (csp != X265_CSP_I400) |
49 | 0 | { |
50 | 0 | m_csize = size >> m_hChromaShift; |
51 | 0 | size_t sizeC = sizeL >> (m_hChromaShift + m_vChromaShift); |
52 | 0 | X265_CHECK((sizeC & 15) == 0, "invalid size"); |
53 | |
|
54 | 0 | CHECKED_MALLOC(m_buf[0], int16_t, sizeL + sizeC * 2); |
55 | 0 | m_buf[1] = m_buf[0] + sizeL; |
56 | 0 | m_buf[2] = m_buf[0] + sizeL + sizeC; |
57 | 0 | } |
58 | 0 | else |
59 | 0 | { |
60 | 0 | CHECKED_MALLOC(m_buf[0], int16_t, sizeL); |
61 | 0 | m_buf[1] = m_buf[2] = NULL; |
62 | 0 | } |
63 | 0 | return true; |
64 | | |
65 | 0 | fail: |
66 | 0 | return false; |
67 | 0 | } |
68 | | |
69 | | void ShortYuv::destroy() |
70 | 0 | { |
71 | 0 | X265_FREE(m_buf[0]); |
72 | 0 | } |
73 | | |
74 | | void ShortYuv::clear() |
75 | 0 | { |
76 | 0 | memset(m_buf[0], 0, (m_size * m_size) * sizeof(int16_t)); |
77 | 0 | memset(m_buf[1], 0, (m_csize * m_csize) * sizeof(int16_t)); |
78 | 0 | memset(m_buf[2], 0, (m_csize * m_csize) * sizeof(int16_t)); |
79 | 0 | } |
80 | | |
81 | | void ShortYuv::subtract(const Yuv& srcYuv0, const Yuv& srcYuv1, uint32_t log2Size, int picCsp) |
82 | 0 | { |
83 | 0 | const int sizeIdx = log2Size - 2; |
84 | 0 | primitives.cu[sizeIdx].sub_ps(m_buf[0], m_size, srcYuv0.m_buf[0], srcYuv1.m_buf[0], srcYuv0.m_size, srcYuv1.m_size); |
85 | 0 | if (m_csp != X265_CSP_I400 && picCsp != X265_CSP_I400) |
86 | 0 | { |
87 | 0 | primitives.chroma[m_csp].cu[sizeIdx].sub_ps(m_buf[1], m_csize, srcYuv0.m_buf[1], srcYuv1.m_buf[1], srcYuv0.m_csize, srcYuv1.m_csize); |
88 | 0 | primitives.chroma[m_csp].cu[sizeIdx].sub_ps(m_buf[2], m_csize, srcYuv0.m_buf[2], srcYuv1.m_buf[2], srcYuv0.m_csize, srcYuv1.m_csize); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | void ShortYuv::copyPartToPartLuma(ShortYuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const |
93 | 0 | { |
94 | 0 | const int16_t* src = getLumaAddr(absPartIdx); |
95 | 0 | int16_t* dst = dstYuv.getLumaAddr(absPartIdx); |
96 | |
|
97 | 0 | primitives.cu[log2Size - 2].copy_ss(dst, dstYuv.m_size, src, m_size); |
98 | 0 | } |
99 | | |
100 | | void ShortYuv::copyPartToPartLuma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2Size) const |
101 | 0 | { |
102 | 0 | const int16_t* src = getLumaAddr(absPartIdx); |
103 | 0 | pixel* dst = dstYuv.getLumaAddr(absPartIdx); |
104 | |
|
105 | 0 | primitives.cu[log2Size - 2].copy_sp(dst, dstYuv.m_size, src, m_size); |
106 | 0 | } |
107 | | |
108 | | void ShortYuv::copyPartToPartChroma(ShortYuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const |
109 | 0 | { |
110 | 0 | int part = partitionFromLog2Size(log2SizeL); |
111 | 0 | const int16_t* srcU = getCbAddr(absPartIdx); |
112 | 0 | const int16_t* srcV = getCrAddr(absPartIdx); |
113 | 0 | int16_t* dstU = dstYuv.getCbAddr(absPartIdx); |
114 | 0 | int16_t* dstV = dstYuv.getCrAddr(absPartIdx); |
115 | |
|
116 | 0 | primitives.chroma[m_csp].cu[part].copy_ss(dstU, dstYuv.m_csize, srcU, m_csize); |
117 | 0 | primitives.chroma[m_csp].cu[part].copy_ss(dstV, dstYuv.m_csize, srcV, m_csize); |
118 | 0 | } |
119 | | |
120 | | void ShortYuv::copyPartToPartChroma(Yuv& dstYuv, uint32_t absPartIdx, uint32_t log2SizeL) const |
121 | 0 | { |
122 | 0 | int part = partitionFromLog2Size(log2SizeL); |
123 | 0 | const int16_t* srcU = getCbAddr(absPartIdx); |
124 | 0 | const int16_t* srcV = getCrAddr(absPartIdx); |
125 | 0 | pixel* dstU = dstYuv.getCbAddr(absPartIdx); |
126 | 0 | pixel* dstV = dstYuv.getCrAddr(absPartIdx); |
127 | |
|
128 | 0 | primitives.chroma[m_csp].cu[part].copy_sp(dstU, dstYuv.m_csize, srcU, m_csize); |
129 | 0 | primitives.chroma[m_csp].cu[part].copy_sp(dstV, dstYuv.m_csize, srcV, m_csize); |
130 | 0 | } |