1 #include "libscaler-swscaler.h"
3 void CScalerSW::Clear() {
23 bool CScalerSW_YUYV::Scale() {
24 if (((m_nSrcLeft
| m_nSrcWidth
| m_nDstWidth
| m_nSrcStride
) % 2) != 0) {
25 SC_LOGE("Width of YUV422 should be even");
29 unsigned int h_ratio
= (m_nSrcWidth
<< 16) / m_nDstWidth
;
30 unsigned int v_ratio
= (m_nSrcHeight
<< 16) / m_nDstHeight
;
33 unsigned int src_y
= m_nSrcTop
<< 16;
35 // Luminance + Chrominance at once
36 for (unsigned int y
= m_nDstTop
; y
< (m_nDstTop
+ m_nDstHeight
); y
++) {
37 src_x
= m_nSrcLeft
<< 16;
38 for (unsigned int x
= m_nDstLeft
; x
< (m_nDstLeft
+ m_nDstWidth
); x
++) {
39 m_pDst
[0][y
* (m_nDstStride
* 2) + x
* 2] =
40 m_pSrc
[0][(src_y
>> 16) * (m_nSrcStride
* 2) + (src_x
>> 16) * 2];
43 unsigned int cx
= (src_x
>> 16) & ~1;
45 m_pDst
[0][y
* (m_nDstStride
* 2) + x
* 2 + 1] =
46 m_pSrc
[0][(src_y
>> 16) * (m_nSrcStride
* 2) + cx
* 2 + 1];
47 m_pDst
[0][y
* (m_nDstStride
* 2) + x
* 2 + 3] =
48 m_pSrc
[0][(src_y
>> 16) * (m_nSrcStride
* 2) + cx
* 2 + 3];
52 src_x
= LibScaler::min(src_x
+ h_ratio
, (m_nSrcLeft
+ m_nSrcWidth
) << 16);
55 src_y
= LibScaler::min(src_y
+ v_ratio
, (m_nSrcTop
+ m_nSrcHeight
) << 16);
61 bool CScalerSW_NV12::Scale() {
62 if (((m_nSrcLeft
| m_nSrcTop
| m_nSrcWidth
| m_nSrcHeight
| m_nSrcStride
|
63 m_nDstLeft
| m_nDstTop
| m_nDstWidth
| m_nDstHeight
| m_nDstStride
) % 2) != 0) {
64 SC_LOGE("Both of width and height of YUV420 should be even");
68 unsigned int h_ratio
= (m_nSrcWidth
<< 16) / m_nDstWidth
;
69 unsigned int v_ratio
= (m_nSrcHeight
<< 16) / m_nDstHeight
;
72 unsigned int src_y
= m_nSrcTop
<< 16;
75 for (unsigned int y
= m_nDstTop
; y
< (m_nDstTop
+ m_nDstHeight
); y
++) {
76 src_x
= m_nSrcLeft
<< 16;
77 for (unsigned int x
= m_nDstLeft
; x
< (m_nDstLeft
+ m_nDstWidth
); x
++) {
78 m_pDst
[0][y
* m_nDstStride
+ x
] = m_pSrc
[0][(src_y
>> 16) * m_nSrcStride
+ (src_x
>> 16)];
80 src_x
= LibScaler::min(src_x
+ h_ratio
, (m_nSrcLeft
+ m_nSrcWidth
) << 16);
83 src_y
= LibScaler::min(src_y
+ v_ratio
, (m_nSrcTop
+ m_nSrcHeight
) << 16);
88 // change pointers to 1-byte to pointers to 2-byte storage.
89 unsigned short *src
= reinterpret_cast<unsigned short *>(m_pSrc
[1]);
90 unsigned short *dst
= reinterpret_cast<unsigned short *>(m_pDst
[1]);
92 src_y
= (m_nSrcTop
/ 2) << 16;
93 for (unsigned int y
= m_nDstTop
/ 2; y
< ((m_nDstTop
+ m_nDstHeight
) / 2); y
++) {
94 // Move 2 pixels at once (CbCr)
95 src_x
= (m_nSrcLeft
/ 2) << 16;
96 for (unsigned int x
= m_nDstLeft
/ 2; x
< ((m_nDstLeft
+ m_nDstWidth
) / 2); x
++) {
97 dst
[y
* (m_nDstStride
/ 2) + x
] = src
[(src_y
>> 16) * (m_nSrcStride
/ 2) + (src_x
>> 16)];
99 src_x
= LibScaler::min(src_x
+ h_ratio
, ((m_nSrcLeft
+ m_nSrcWidth
) / 2) << 16);
102 src_y
= LibScaler::min(src_y
+ v_ratio
, ((m_nSrcTop
+ m_nSrcHeight
) / 2) << 16);