Showing the changes to codec/processing/src/downsample (2 of 2 files). Show all
Unified · Split
| @@ -34,7 +34,8 @@ · 33 unmodified lines | |||
| 34 | #include "cpu.h" | 34 | #include "cpu.h" |
| 35 | 35 | ||
| 36 | WELSVP_NAMESPACE_BEGIN | 36 | WELSVP_NAMESPACE_BEGIN |
| 37 | 37 | #define MAX_SAMPLE_WIDTH 1920 | |
| 38 | #define MAX_SAMPLE_HEIGHT 1088 | ||
| 38 | 39 | ||
| 39 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 41 | ||
| @@ -43,11 +44,37 @@ CDownsampling::CDownsampling (int32_t iCpuFlag) { · 2 unmodified lines | |||
| 43 | m_eMethod = METHOD_DOWNSAMPLE; | 44 | m_eMethod = METHOD_DOWNSAMPLE; |
| 44 | WelsMemset (&m_pfDownsample, 0, sizeof (m_pfDownsample)); | 45 | WelsMemset (&m_pfDownsample, 0, sizeof (m_pfDownsample)); |
| 45 | InitDownsampleFuncs (m_pfDownsample, m_iCPUFlag); | 46 | InitDownsampleFuncs (m_pfDownsample, m_iCPUFlag); |
| 47 | m_bNoSampleBuffer = AllocateSampleBuffer(); | ||
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | CDownsampling::~CDownsampling() { | 50 | CDownsampling::~CDownsampling() { |
| 51 | FreeSampleBuffer(); | ||
| 49 | } | 52 | } |
| 53 | bool CDownsampling::AllocateSampleBuffer() { | ||
| 54 | for (int32_t i = 0; i < 2; i++) { | ||
| 55 | m_pSampleBuffer[i][0] = (uint8_t*)WelsMalloc (MAX_SAMPLE_WIDTH * MAX_SAMPLE_HEIGHT); | ||
| 56 | if (!m_pSampleBuffer[i][0]) | ||
| 57 | goto FREE_RET; | ||
| 58 | m_pSampleBuffer[i][1] = (uint8_t*)WelsMalloc (MAX_SAMPLE_WIDTH * MAX_SAMPLE_HEIGHT / 4); | ||
| 59 | if (!m_pSampleBuffer[i][1]) | ||
| 60 | goto FREE_RET; | ||
| 61 | m_pSampleBuffer[i][2] = (uint8_t*)WelsMalloc (MAX_SAMPLE_WIDTH * MAX_SAMPLE_HEIGHT / 4); | ||
| 62 | if (!m_pSampleBuffer[i][2]) | ||
| 63 | goto FREE_RET; | ||
| 64 | } | ||
| 65 | return false; | ||
| 66 | FREE_RET: | ||
| 67 | FreeSampleBuffer(); | ||
| 68 | return true; | ||
| 50 | 69 | ||
| 70 | } | ||
| 71 | void CDownsampling::FreeSampleBuffer() { | ||
| 72 | for (int32_t i = 0; i < 2; i++) { | ||
| 73 | WelsFree (m_pSampleBuffer[i][0]); | ||
| 74 | WelsFree (m_pSampleBuffer[i][1]); | ||
| 75 | WelsFree (m_pSampleBuffer[i][2]); | ||
| 76 | } | ||
| 77 | } | ||
| 51 | void CDownsampling::InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag) { | 78 | void CDownsampling::InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag) { |
| 52 | sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsampler_c; | 79 | sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsampler_c; |
| 53 | sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsampler_c; | 80 | sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsampler_c; |
| @@ -123,49 +150,132 @@ EResult CDownsampling::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pDs · 69 unmodified lines | |||
| 123 | if (iSrcWidthY <= iDstWidthY || iSrcHeightY <= iDstHeightY) { | 150 | if (iSrcWidthY <= iDstWidthY || iSrcHeightY <= iDstHeightY) { |
| 124 | return RET_INVALIDPARAM; | 151 | return RET_INVALIDPARAM; |
| 125 | } | 152 | } |
| 153 | if (iSrcWidthY > MAX_SAMPLE_WIDTH || iSrcHeightY > MAX_SAMPLE_HEIGHT || m_bNoSampleBuffer) { | ||
| 154 | if ((iSrcWidthY >> 1) == iDstWidthY && (iSrcHeightY >> 1) == iDstHeightY) { | ||
| 155 | // use half average functions | ||
| 156 | uint8_t iAlignIndex = GetAlignedIndex (iSrcWidthY); | ||
| 157 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | ||
| 158 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | ||
| 126 | 159 | ||
| 127 | if ((iSrcWidthY >> 1) == iDstWidthY && (iSrcHeightY >> 1) == iDstHeightY) { | 160 | iAlignIndex = GetAlignedIndex (iSrcWidthUV); |
| 128 | // use half average functions | 161 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], |
| 129 | uint8_t iAlignIndex = GetAlignedIndex (iSrcWidthY); | 162 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); |
| 130 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | 163 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], |
| 131 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | 164 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); |
| 165 | } else if ((iSrcWidthY >> 2) == iDstWidthY && (iSrcHeightY >> 2) == iDstHeightY) { | ||
| 132 | 166 | ||
| 133 | iAlignIndex = GetAlignedIndex (iSrcWidthUV); | 167 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], |
| 134 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], | 168 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); |
| 135 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); | ||
| 136 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | ||
| 137 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | ||
| 138 | } else if ((iSrcWidthY >> 2) == iDstWidthY && (iSrcHeightY >> 2) == iDstHeightY) { | ||
| 139 | 169 | ||
| 140 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | 170 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], |
| 141 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | 171 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); |
| 172 | |||
| 173 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | ||
| 174 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | ||
| 142 | 175 | ||
| 143 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], | 176 | } else if ((iSrcWidthY / 3) == iDstWidthY && (iSrcHeightY / 3) == iDstHeightY) { |
| 144 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); | ||
| 145 | 177 | ||
| 146 | m_pfDownsample.pfQuarterDownsampler ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | 178 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], |
| 147 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | 179 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iDstHeightY); |
| 148 | 180 | ||
| 149 | } else if ((iSrcWidthY / 3) == iDstWidthY && (iSrcHeightY / 3) == iDstHeightY) { | 181 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], |
| 182 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iDstHeightUV); | ||
| 150 | 183 | ||
| 151 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | 184 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], |
| 152 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iDstHeightY); | 185 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iDstHeightUV); |
| 153 | 186 | ||
| 154 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], | 187 | } else { |
| 155 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iDstHeightUV); | 188 | m_pfDownsample.pfGeneralRatioLuma ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], iDstWidthY, iDstHeightY, |
| 189 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | ||
| 156 | 190 | ||
| 157 | m_pfDownsample.pfOneThirdDownsampler ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | 191 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], iDstWidthUV, iDstHeightUV, |
| 158 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iDstHeightUV); | 192 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); |
| 159 | 193 | ||
| 194 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], iDstWidthUV, iDstHeightUV, | ||
| 195 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | ||
| 196 | } | ||
| 160 | } else { | 197 | } else { |
| 161 | m_pfDownsample.pfGeneralRatioLuma ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], iDstWidthY, iDstHeightY, | ||
| 162 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | ||
| 163 | 198 | ||
| 164 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], iDstWidthUV, iDstHeightUV, | 199 | int32_t iIdx = 0; |
| 165 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); | 200 | int32_t iHalfSrcWidth = iSrcWidthY >> 1; |
| 201 | int32_t iHalfSrcHeight = iSrcHeightY >> 1; | ||
| 202 | uint8_t* pSrcY = (uint8_t*)pSrcPixMap->pPixel[0]; | ||
| 203 | uint8_t* pSrcU = (uint8_t*)pSrcPixMap->pPixel[1]; | ||
| 204 | uint8_t* pSrcV = (uint8_t*)pSrcPixMap->pPixel[2]; | ||
| 205 | int32_t iSrcStrideY = pSrcPixMap->iStride[0]; | ||
| 206 | int32_t iSrcStrideU = pSrcPixMap->iStride[1]; | ||
| 207 | int32_t iSrcStrideV = pSrcPixMap->iStride[2]; | ||
| 208 | |||
| 209 | int32_t iDstStrideY = pDstPixMap->iStride[0]; | ||
| 210 | int32_t iDstStrideU = pDstPixMap->iStride[1]; | ||
| 211 | int32_t iDstStrideV = pDstPixMap->iStride[2]; | ||
| 212 | |||
| 213 | uint8_t* pDstY = (uint8_t*)m_pSampleBuffer[iIdx][0]; | ||
| 214 | uint8_t* pDstU = (uint8_t*)m_pSampleBuffer[iIdx][1]; | ||
| 215 | uint8_t* pDstV = (uint8_t*)m_pSampleBuffer[iIdx][2]; | ||
| 216 | iIdx++; | ||
| 217 | do { | ||
| 218 | if ((iHalfSrcWidth == iDstWidthY) && (iHalfSrcHeight == iDstHeightY)) { //end | ||
| 219 | // use half average functions | ||
| 220 | uint8_t iAlignIndex = GetAlignedIndex (iSrcWidthY); | ||
| 221 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | ||
| 222 | (uint8_t*)pSrcY, iSrcStrideY, iSrcWidthY, iSrcHeightY); | ||
| 223 | |||
| 224 | iAlignIndex = GetAlignedIndex (iSrcWidthUV); | ||
| 225 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], | ||
| 226 | (uint8_t*)pSrcU, iSrcStrideU, iSrcWidthUV, iSrcHeightUV); | ||
| 227 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | ||
| 228 | (uint8_t*)pSrcV, iSrcStrideV, iSrcWidthUV, iSrcHeightUV); | ||
| 229 | break; | ||
| 230 | } else if (((iHalfSrcWidth >> 1) >= iDstWidthY) && ((iHalfSrcHeight >> 1) >= iDstHeightY)) { | ||
| 231 | // use half average functions | ||
| 232 | iDstStrideY = iHalfSrcWidth; | ||
| 233 | iDstStrideU = iHalfSrcWidth >> 1; | ||
| 234 | iDstStrideV = iHalfSrcWidth >> 1; | ||
| 235 | uint8_t iAlignIndex = GetAlignedIndex (iSrcWidthY); | ||
| 236 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstY, iDstStrideY, | ||
| 237 | (uint8_t*)pSrcY, iSrcStrideY, iSrcWidthY, iSrcHeightY); | ||
| 238 | |||
| 239 | iAlignIndex = GetAlignedIndex (iSrcWidthUV); | ||
| 240 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstU, iDstStrideU, | ||
| 241 | (uint8_t*)pSrcU, iSrcStrideU, iSrcWidthUV, iSrcHeightUV); | ||
| 242 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstV, iDstStrideV, | ||
| 243 | (uint8_t*)pSrcV, iSrcStrideV, iSrcWidthUV, iSrcHeightUV); | ||
| 244 | |||
| 245 | pSrcY = (uint8_t*)pDstY; | ||
| 246 | pSrcU = (uint8_t*)pDstU; | ||
| 247 | pSrcV = (uint8_t*)pDstV; | ||
| 248 | |||
| 249 | |||
| 250 | iSrcWidthY = iHalfSrcWidth; | ||
| 251 | iSrcWidthUV = iHalfSrcWidth >> 1; | ||
| 252 | iSrcHeightY = iHalfSrcHeight; | ||
| 253 | iSrcHeightUV = iHalfSrcHeight >> 1; | ||
| 254 | |||
| 255 | iSrcStrideY = iSrcWidthY; | ||
| 256 | iSrcStrideU = iSrcWidthUV; | ||
| 257 | iSrcStrideV = iSrcWidthUV; | ||
| 258 | |||
| 259 | iHalfSrcWidth >>= 1; | ||
| 260 | iHalfSrcHeight >>= 1; | ||
| 261 | |||
| 262 | iIdx = iIdx % 2; | ||
| 263 | pDstY = (uint8_t*)m_pSampleBuffer[iIdx][0]; | ||
| 264 | pDstU = (uint8_t*)m_pSampleBuffer[iIdx][1]; | ||
| 265 | pDstV = (uint8_t*)m_pSampleBuffer[iIdx][2]; | ||
| 266 | iIdx++; | ||
| 267 | } else { | ||
| 268 | m_pfDownsample.pfGeneralRatioLuma ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], iDstWidthY, iDstHeightY, | ||
| 269 | (uint8_t*)pSrcY, iSrcStrideY, iSrcWidthY, iSrcHeightY); | ||
| 270 | |||
| 271 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], iDstWidthUV, iDstHeightUV, | ||
| 272 | (uint8_t*)pSrcU, iSrcStrideU, iSrcWidthUV, iSrcHeightUV); | ||
| 166 | 273 | ||
| 167 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], iDstWidthUV, iDstHeightUV, | 274 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], iDstWidthUV, iDstHeightUV, |
| 168 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | 275 | (uint8_t*)pSrcV, iSrcStrideV, iSrcWidthUV, iSrcHeightUV); |
| 276 | break; | ||
| 277 | } | ||
| 278 | } while (true); | ||
| 169 | } | 279 | } |
| 170 | return RET_SUCCESS; | 280 | return RET_SUCCESS; |
| 171 | } | 281 | } |
| @@ -170,10 +170,13 @@ class CDownsampling : public IStrategy { · 169 unmodified lines | |||
| 170 | void InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag); | 170 | void InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag); |
| 171 | 171 | ||
| 172 | int32_t GetAlignedIndex (const int32_t kiSrcWidth); | 172 | int32_t GetAlignedIndex (const int32_t kiSrcWidth); |
| 173 | 173 | bool AllocateSampleBuffer(); | |
| 174 | void FreeSampleBuffer(); | ||
| 174 | private: | 175 | private: |
| 175 | SDownsampleFuncs m_pfDownsample; | 176 | SDownsampleFuncs m_pfDownsample; |
| 176 | int32_t m_iCPUFlag; | 177 | int32_t m_iCPUFlag; |
| 178 | uint8_t *m_pSampleBuffer[2][3]; | ||
| 179 | bool m_bNoSampleBuffer; | ||
| 177 | }; | 180 | }; |
| 178 | 181 | ||
| 179 | WELSVP_NAMESPACE_END | 182 | WELSVP_NAMESPACE_END |