0b95f0ec87de7a1dec8282c5796a39cc1dbf3fda
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com>
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.
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.
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.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com
22 *****************************************************************************/
27 #include "primitives.h"
40 bool ShortYuv::create(uint32_t size
, int csp
)
43 m_hChromaShift
= CHROMA_H_SHIFT(csp
);
44 m_vChromaShift
= CHROMA_V_SHIFT(csp
);
47 m_csize
= size
>> m_hChromaShift
;
49 size_t sizeL
= size
* size
;
50 size_t sizeC
= sizeL
>> (m_hChromaShift
+ m_vChromaShift
);
51 X265_CHECK((sizeC
& 15) == 0, "invalid size");
53 CHECKED_MALLOC(m_buf
[0], int16_t, sizeL
+ sizeC
* 2);
54 m_buf
[1] = m_buf
[0] + sizeL
;
55 m_buf
[2] = m_buf
[0] + sizeL
+ sizeC
;
62 void ShortYuv::destroy()
67 void ShortYuv::clear()
69 ::memset(m_buf
[0], 0, (m_size
* m_size
) * sizeof(int16_t));
70 ::memset(m_buf
[1], 0, (m_csize
* m_csize
) * sizeof(int16_t));
71 ::memset(m_buf
[2], 0, (m_csize
* m_csize
) * sizeof(int16_t));
74 void ShortYuv::subtract(const Yuv
& srcYuv0
, const Yuv
& srcYuv1
, uint32_t log2Size
)
76 const int sizeIdx
= log2Size
- 2;
77 primitives
.luma_sub_ps
[sizeIdx
](m_buf
[0], m_size
, srcYuv0
.m_buf
[0], srcYuv1
.m_buf
[0], srcYuv0
.m_size
, srcYuv1
.m_size
);
78 primitives
.chroma
[m_csp
].sub_ps
[sizeIdx
](m_buf
[1], m_csize
, srcYuv0
.m_buf
[1], srcYuv1
.m_buf
[1], srcYuv0
.m_csize
, srcYuv1
.m_csize
);
79 primitives
.chroma
[m_csp
].sub_ps
[sizeIdx
](m_buf
[2], m_csize
, srcYuv0
.m_buf
[2], srcYuv1
.m_buf
[2], srcYuv0
.m_csize
, srcYuv1
.m_csize
);
82 void ShortYuv::copyPartToPartLuma(ShortYuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2Size
) const
84 const int16_t* src
= getLumaAddr(absPartIdx
);
85 int16_t* dst
= dstYuv
.getLumaAddr(absPartIdx
);
87 primitives
.luma_copy_ss
[log2Size
- 2](dst
, dstYuv
.m_size
, src
, m_size
);
90 void ShortYuv::copyPartToPartLuma(Yuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2Size
) const
92 const int16_t* src
= getLumaAddr(absPartIdx
);
93 pixel
* dst
= dstYuv
.getLumaAddr(absPartIdx
);
95 primitives
.luma_copy_sp
[log2Size
- 2](dst
, dstYuv
.m_size
, src
, m_size
);
98 void ShortYuv::copyPartToPartChroma(ShortYuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2SizeL
) const
100 int part
= partitionFromLog2Size(log2SizeL
);
101 const int16_t* srcU
= getCbAddr(absPartIdx
);
102 const int16_t* srcV
= getCrAddr(absPartIdx
);
103 int16_t* dstU
= dstYuv
.getCbAddr(absPartIdx
);
104 int16_t* dstV
= dstYuv
.getCrAddr(absPartIdx
);
106 primitives
.chroma
[m_csp
].copy_ss
[part
](dstU
, dstYuv
.m_csize
, srcU
, m_csize
);
107 primitives
.chroma
[m_csp
].copy_ss
[part
](dstV
, dstYuv
.m_csize
, srcV
, m_csize
);
110 void ShortYuv::copyPartToPartChroma(Yuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2SizeL
) const
112 int part
= partitionFromLog2Size(log2SizeL
);
113 const int16_t* srcU
= getCbAddr(absPartIdx
);
114 const int16_t* srcV
= getCrAddr(absPartIdx
);
115 pixel
* dstU
= dstYuv
.getCbAddr(absPartIdx
);
116 pixel
* dstV
= dstYuv
.getCrAddr(absPartIdx
);
118 primitives
.chroma
[m_csp
].copy_sp
[part
](dstU
, dstYuv
.m_csize
, srcU
, m_csize
);
119 primitives
.chroma
[m_csp
].copy_sp
[part
](dstV
, dstYuv
.m_csize
, srcV
, m_csize
);