1 /*! 2 * \copy 3 * Copyright (c) 2011-2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * \file : downsample.h 32 * 33 * \brief : downsample class of wels video processor class 34 * 35 * \date : 2011/03/33 36 * 37 * \description : 1. rewrite the package code of downsample class 38 * 39 ************************************************************************************* 40 */ 41 42 #ifndef WELSVP_DOWNSAMPLE_H 43 #define WELSVP_DOWNSAMPLE_H 44 45 #include "util.h" 46 #include "WelsFrameWork.h" 47 #include "IWelsVP.h" 48 #include "macros.h" 49 50 WELSVP_NAMESPACE_BEGIN 51 52 53 typedef void (HalveDownsampleFunc) (uint8_t* pDst, const int32_t kiDstStride, 54 uint8_t* pSrc, const int32_t kiSrcStride, 55 const int32_t kiSrcWidth, const int32_t kiSrcHeight); 56 57 typedef void (SpecificDownsampleFunc) (uint8_t* pDst, const int32_t kiDstStride, 58 uint8_t* pSrc, const int32_t kiSrcStride, 59 const int32_t kiSrcWidth, const int32_t kiHeight); 60 61 typedef void (GeneralDownsampleFunc) (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, 62 const int32_t kiDstHeight, 63 uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight); 64 65 typedef HalveDownsampleFunc* PHalveDownsampleFunc; 66 typedef SpecificDownsampleFunc* PSpecificDownsampleFunc; 67 typedef GeneralDownsampleFunc* PGeneralDownsampleFunc; 68 69 HalveDownsampleFunc DyadicBilinearDownsampler_c; 70 GeneralDownsampleFunc GeneralBilinearFastDownsampler_c; 71 GeneralDownsampleFunc GeneralBilinearAccurateDownsampler_c; 72 SpecificDownsampleFunc DyadicBilinearOneThirdDownsampler_c; 73 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_c; 74 75 typedef struct { 76 PHalveDownsampleFunc pfHalfAverageWidthx32; 77 PHalveDownsampleFunc pfHalfAverageWidthx16; 78 PSpecificDownsampleFunc pfOneThirdDownsampler; 79 PSpecificDownsampleFunc pfQuarterDownsampler; 80 PGeneralDownsampleFunc pfGeneralRatioLuma; 81 PGeneralDownsampleFunc pfGeneralRatioChroma; 82 } SDownsampleFuncs; 83 84 85 #ifdef X86_ASM 86 WELSVP_EXTERN_C_BEGIN 87 // used for scr width is multipler of 8 pixels 88 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx8_sse; 89 // iSrcWidth= x16 pixels 90 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx16_sse; 91 // iSrcWidth= x32 pixels 92 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_sse; 93 // used for scr width is multipler of 16 pixels 94 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx16_ssse3; 95 // iSrcWidth= x32 pixels 96 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_ssse3; 97 98 GeneralDownsampleFunc GeneralBilinearFastDownsamplerWrap_sse2; 99 GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_sse2; 100 GeneralDownsampleFunc GeneralBilinearFastDownsamplerWrap_ssse3; 101 GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_sse41; 102 #ifdef HAVE_AVX2 103 GeneralDownsampleFunc GeneralBilinearFastDownsamplerWrap_avx2; 104 GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_avx2; 105 #endif 106 107 SpecificDownsampleFunc DyadicBilinearOneThirdDownsampler_ssse3; 108 SpecificDownsampleFunc DyadicBilinearOneThirdDownsampler_sse4; 109 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_sse; 110 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_ssse3; 111 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_sse4; 112 113 void GeneralBilinearFastDownsampler_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, 114 const int32_t kiDstHeight, uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, 115 const uint32_t kuiScaleY); 116 void GeneralBilinearAccurateDownsampler_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, 117 const int32_t kiDstHeight, uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, 118 const uint32_t kuiScaleY); 119 void GeneralBilinearFastDownsampler_ssse3 (uint8_t* pDst, int32_t iDstStride, int32_t iDstWidth, 120 int32_t iDstHeight, uint8_t* pSrc, int32_t iSrcStride, uint32_t uiScaleX, 121 uint32_t uiScaleY); 122 void GeneralBilinearAccurateDownsampler_sse41 (uint8_t* pDst, int32_t iDstStride, int32_t iDstWidth, 123 int32_t iDstHeight, uint8_t* pSrc, int32_t iSrcStride, uint32_t uiScaleX, 124 uint32_t uiScaleY); 125 #ifdef HAVE_AVX2 126 void GeneralBilinearFastDownsampler_avx2 (uint8_t* pDst, int32_t iDstStride, int32_t iDstWidth, 127 int32_t iDstHeight, uint8_t* pSrc, int32_t iSrcStride, uint32_t uiScaleX, 128 uint32_t uiScaleY); 129 void GeneralBilinearAccurateDownsampler_avx2 (uint8_t* pDst, int32_t iDstStride, int32_t iDstWidth, 130 int32_t iDstHeight, uint8_t* pSrc, int32_t iSrcStride, uint32_t uiScaleX, 131 uint32_t uiScaleY); 132 #endif 133 134 WELSVP_EXTERN_C_END 135 #endif 136 137 #ifdef HAVE_NEON 138 WELSVP_EXTERN_C_BEGIN 139 // iSrcWidth no limitation 140 HalveDownsampleFunc DyadicBilinearDownsampler_neon; 141 // iSrcWidth = x32 pixels 142 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_neon; 143 144 GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_neon; 145 146 SpecificDownsampleFunc DyadicBilinearOneThirdDownsampler_neon; 147 148 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_neon; 149 150 void GeneralBilinearAccurateDownsampler_neon (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, 151 const int32_t kiDstHeight, 152 uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, const uint32_t kuiScaleY); 153 154 WELSVP_EXTERN_C_END 155 #endif 156 157 #ifdef HAVE_NEON_AARCH64 158 WELSVP_EXTERN_C_BEGIN 159 // iSrcWidth no limitation 160 HalveDownsampleFunc DyadicBilinearDownsampler_AArch64_neon; 161 // iSrcWidth = x32 pixels 162 HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_AArch64_neon; 163 164 GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_AArch64_neon; 165 166 SpecificDownsampleFunc DyadicBilinearOneThirdDownsampler_AArch64_neon; 167 168 SpecificDownsampleFunc DyadicBilinearQuarterDownsampler_AArch64_neon; 169 170 void GeneralBilinearAccurateDownsampler_AArch64_neon (uint8_t* pDst, const int32_t kiDstStride, 171 const int32_t kiDstWidth, const int32_t kiDstHeight, 172 uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, const uint32_t kuiScaleY); 173 174 WELSVP_EXTERN_C_END 175 #endif 176 177 178 class CDownsampling : public IStrategy { 179 public: 180 CDownsampling (int32_t iCpuFlag); 181 ~CDownsampling(); 182 183 EResult Process (int32_t iType, SPixMap* pSrc, SPixMap* pDst); 184 185 private: 186 void InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag); 187 188 void DownsampleHalfAverage (uint8_t* pDst, int32_t iDstStride, 189 uint8_t* pSrc, int32_t iSrcStride, int32_t iSrcWidth, int32_t iSrcHeight); 190 bool AllocateSampleBuffer(); 191 void FreeSampleBuffer(); 192 private: 193 SDownsampleFuncs m_pfDownsample; 194 int32_t m_iCPUFlag; 195 uint8_t *m_pSampleBuffer[2][3]; 196 bool m_bNoSampleBuffer; 197 }; 198 199 WELSVP_NAMESPACE_END 200 201 #endif 202