libhwjpeg: resolve compilation errors
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos.git] / libscaler / libscaler-swscaler.cpp
1 #include "libscaler-swscaler.h"
2
3 void CScalerSW::Clear() {
4 m_pSrc[0] = NULL;
5 m_pSrc[1] = NULL;
6 m_pSrc[2] = NULL;
7 m_pDst[0] = NULL;
8 m_pDst[1] = NULL;
9 m_pDst[2] = NULL;
10
11 m_nSrcLeft = 0;
12 m_nSrcTop = 0;
13 m_nSrcWidth = 0;
14 m_nSrcHeight = 0;
15 m_nSrcStride = 0;
16 m_nDstLeft = 0;
17 m_nDstTop = 0;
18 m_nDstWidth = 0;
19 m_nDstHeight = 0;
20 m_nDstStride = 0;
21 }
22
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");
26 return false;
27 }
28
29 unsigned int h_ratio = (m_nSrcWidth << 16) / m_nDstWidth;
30 unsigned int v_ratio = (m_nSrcHeight << 16) / m_nDstHeight;
31
32 unsigned int src_x;
33 unsigned int src_y = m_nSrcTop << 16;
34
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];
41
42 if (!(x & 1)) {
43 unsigned int cx = (src_x >> 16) & ~1;
44
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];
49
50 }
51
52 src_x = LibScaler::min(src_x + h_ratio, (m_nSrcLeft + m_nSrcWidth) << 16);
53 }
54
55 src_y = LibScaler::min(src_y + v_ratio, (m_nSrcTop + m_nSrcHeight) << 16);
56 }
57
58 return true;
59 }
60
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");
65 return false;
66 }
67
68 unsigned int h_ratio = (m_nSrcWidth << 16) / m_nDstWidth;
69 unsigned int v_ratio = (m_nSrcHeight << 16) / m_nDstHeight;
70
71 unsigned int src_x;
72 unsigned int src_y = m_nSrcTop << 16;
73
74 // Luminance
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)];
79
80 src_x = LibScaler::min(src_x + h_ratio, (m_nSrcLeft + m_nSrcWidth) << 16);
81 }
82
83 src_y = LibScaler::min(src_y + v_ratio, (m_nSrcTop + m_nSrcHeight) << 16);
84 }
85
86 // Chrominance
87
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]);
91
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)];
98
99 src_x = LibScaler::min(src_x + h_ratio, ((m_nSrcLeft + m_nSrcWidth) / 2) << 16);
100 }
101
102 src_y = LibScaler::min(src_y + v_ratio, ((m_nSrcTop + m_nSrcHeight) / 2) << 16);
103 }
104
105 return true;
106 }