Showing the changes to codec/encoder/core/src/encode_mb_aux.cpp (1 of 308 files). Show all
Unified · Split
| @@ -0,0 +1,608 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + */ | |
| 32 | + | |
| 33 | +#include <string.h> | |
| 34 | + | |
| 35 | +#include "macros.h" | |
| 36 | +#include "ls_defines.h" | |
| 37 | +#include "encode_mb_aux.h" | |
| 38 | +#include "cpu_core.h" | |
| 39 | +#include "as264_common.h" | |
| 40 | +#include "svc_encode_mb.h" | |
| 41 | +namespace WelsSVCEnc { | |
| 42 | + | |
| 43 | +__align16( int16_t, g_kiQuantInterFF[58][8] )= | |
| 44 | +{ | |
| 45 | +/* 0*/ { 0, 1, 0, 1, 1, 1, 1, 1 }, | |
| 46 | +/* 1*/ { 0, 1, 0, 1, 1, 1, 1, 1 }, | |
| 47 | +/* 2*/ { 1, 1, 1, 1, 1, 1, 1, 1 }, | |
| 48 | +/* 3*/ { 1, 1, 1, 1, 1, 1, 1, 1 }, | |
| 49 | +/* 4*/ { 1, 1, 1, 1, 1, 2, 1, 2 }, | |
| 50 | +/* 5*/ { 1, 1, 1, 1, 1, 2, 1, 2 }, | |
| 51 | +/* 6*/ { 1, 1, 1, 1, 1, 2, 1, 2 }, | |
| 52 | +/* 7*/ { 1, 1, 1, 1, 1, 2, 1, 2 }, | |
| 53 | +/* 8*/ { 1, 2, 1, 2, 2, 3, 2, 3 }, | |
| 54 | +/* 9*/ { 1, 2, 1, 2, 2, 3, 2, 3 }, | |
| 55 | +/*10*/ { 1, 2, 1, 2, 2, 3, 2, 3 }, | |
| 56 | +/*11*/ { 1, 2, 1, 2, 2, 4, 2, 4 }, | |
| 57 | +/*12*/ { 2, 3, 2, 3, 3, 4, 3, 4 }, | |
| 58 | +/*13*/ { 2, 3, 2, 3, 3, 5, 3, 5 }, | |
| 59 | +/*14*/ { 2, 3, 2, 3, 3, 5, 3, 5 }, | |
| 60 | +/*15*/ { 2, 4, 2, 4, 4, 6, 4, 6 }, | |
| 61 | +/*16*/ { 3, 4, 3, 4, 4, 7, 4, 7 }, | |
| 62 | +/*17*/ { 3, 5, 3, 5, 5, 8, 5, 8 }, | |
| 63 | +/*18*/ { 3, 5, 3, 5, 5, 8, 5, 8 }, | |
| 64 | +/*19*/ { 4, 6, 4, 6, 6, 9, 6, 9 }, | |
| 65 | +/*20*/ { 4, 7, 4, 7, 7, 10, 7, 10 }, | |
| 66 | +/*21*/ { 5, 8, 5, 8, 8, 12, 8, 12 }, | |
| 67 | +/*22*/ { 5, 8, 5, 8, 8, 13, 8, 13 }, | |
| 68 | +/*23*/ { 6, 10, 6, 10, 10, 15, 10, 15 }, | |
| 69 | +/*24*/ { 7, 11, 7, 11, 11, 17, 11, 17 }, | |
| 70 | +/*25*/ { 7, 12, 7, 12, 12, 19, 12, 19 }, | |
| 71 | +/*26*/ { 9, 13, 9, 13, 13, 21, 13, 21 }, | |
| 72 | +/*27*/ { 9, 15, 9, 15, 15, 24, 15, 24 }, | |
| 73 | +/*28*/ { 11, 17, 11, 17, 17, 26, 17, 26 }, | |
| 74 | +/*29*/ { 12, 19, 12, 19, 19, 30, 19, 30 }, | |
| 75 | +/*30*/ { 13, 22, 13, 22, 22, 33, 22, 33 }, | |
| 76 | +/*31*/ { 15, 23, 15, 23, 23, 38, 23, 38 }, | |
| 77 | +/*32*/ { 17, 27, 17, 27, 27, 42, 27, 42 }, | |
| 78 | +/*33*/ { 19, 30, 19, 30, 30, 48, 30, 48 }, | |
| 79 | +/*34*/ { 21, 33, 21, 33, 33, 52, 33, 52 }, | |
| 80 | +/*35*/ { 24, 38, 24, 38, 38, 60, 38, 60 }, | |
| 81 | +/*36*/ { 27, 43, 27, 43, 43, 67, 43, 67 }, | |
| 82 | +/*37*/ { 29, 47, 29, 47, 47, 75, 47, 75 }, | |
| 83 | +/*38*/ { 35, 53, 35, 53, 53, 83, 53, 83 }, | |
| 84 | +/*39*/ { 37, 60, 37, 60, 60, 96, 60, 96 }, | |
| 85 | +/*40*/ { 43, 67, 43, 67, 67, 104, 67, 104 }, | |
| 86 | +/*41*/ { 48, 77, 48, 77, 77, 121, 77, 121 }, | |
| 87 | +/*42*/ { 53, 87, 53, 87, 87, 133, 87, 133 }, | |
| 88 | +/*43*/ { 59, 93, 59, 93, 93, 150, 93, 150 }, | |
| 89 | +/*44*/ { 69, 107, 69, 107, 107, 167, 107, 167 }, | |
| 90 | +/*45*/ { 75, 120, 75, 120, 120, 192, 120, 192 }, | |
| 91 | +/*46*/ { 85, 133, 85, 133, 133, 208, 133, 208 }, | |
| 92 | +/*47*/ { 96, 153, 96, 153, 153, 242, 153, 242 }, | |
| 93 | +/*48*/ { 107, 173, 107, 173, 173, 267, 173, 267 }, | |
| 94 | +/*49*/ { 117, 187, 117, 187, 187, 300, 187, 300 }, | |
| 95 | +/*50*/ { 139, 213, 139, 213, 213, 333, 213, 333 }, | |
| 96 | +/*51*/ { 149, 240, 149, 240, 240, 383, 240, 383 }, | |
| 97 | +/* from here below is only for intra */ | |
| 98 | +/*46*/ { 171, 267, 171, 267, 267, 417, 267, 417 }, | |
| 99 | +/*47*/ { 192, 307, 192, 307, 307, 483, 307, 483 }, | |
| 100 | +/*48*/ { 213, 347, 213, 347, 347, 533, 347, 533 }, | |
| 101 | +/*49*/ { 235, 373, 235, 373, 373, 600, 373, 600 }, | |
| 102 | +/*50*/ { 277, 427, 277, 427, 427, 667, 427, 667 }, | |
| 103 | +/*51*/ { 299, 480, 299, 480, 480, 767, 480, 767 }, | |
| 104 | +}; | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | +__align16( int16_t, g_kiQuantMF[52][8]) = { | |
| 109 | +/* 0*/ {26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486 }, | |
| 110 | +/* 1*/ {23832, 14980, 23832, 14980, 14980, 9320, 14980, 9320 }, | |
| 111 | +/* 2*/ {20164, 13108, 20164, 13108, 13108, 8388, 13108, 8388 }, | |
| 112 | +/* 3*/ {18724, 11650, 18724, 11650, 11650, 7294, 11650, 7294 }, | |
| 113 | +/* 4*/ {16384, 10486, 16384, 10486, 10486, 6710, 10486, 6710 }, | |
| 114 | +/* 5*/ {14564, 9118, 14564, 9118, 9118, 5786, 9118, 5786 }, | |
| 115 | +/* 6*/ {13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243 }, | |
| 116 | +/* 7*/ {11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660 }, | |
| 117 | +/* 8*/ {10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194 }, | |
| 118 | +/* 9*/ { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647 }, | |
| 119 | +/*10*/ { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355 }, | |
| 120 | +/*11*/ { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893 }, | |
| 121 | +/*12*/ { 6554, 4033, 6554, 4033, 4033, 2622, 4033, 2622 }, | |
| 122 | +/*13*/ { 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330 }, | |
| 123 | +/*14*/ { 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097 }, | |
| 124 | +/*15*/ { 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824 }, | |
| 125 | +/*16*/ { 4096, 2622, 4096, 2622, 2622, 1678, 2622, 1678 }, | |
| 126 | +/*17*/ { 3641, 2280, 3641, 2280, 2280, 1447, 2280, 1447 }, | |
| 127 | +/*18*/ { 3277, 2017, 3277, 2017, 2017, 1311, 2017, 1311 }, | |
| 128 | +/*19*/ { 2979, 1873, 2979, 1873, 1873, 1165, 1873, 1165 }, | |
| 129 | +/*20*/ { 2521, 1639, 2521, 1639, 1639, 1049, 1639, 1049 }, | |
| 130 | +/*21*/ { 2341, 1456, 2341, 1456, 1456, 912, 1456, 912 }, | |
| 131 | +/*22*/ { 2048, 1311, 2048, 1311, 1311, 839, 1311, 839 }, | |
| 132 | +/*23*/ { 1821, 1140, 1821, 1140, 1140, 723, 1140, 723 }, | |
| 133 | +/*24*/ { 1638, 1008, 1638, 1008, 1008, 655, 1008, 655 }, | |
| 134 | +/*25*/ { 1490, 936, 1490, 936, 936, 583, 936, 583 }, | |
| 135 | +/*26*/ { 1260, 819, 1260, 819, 819, 524, 819, 524 }, | |
| 136 | +/*27*/ { 1170, 728, 1170, 728, 728, 456, 728, 456 }, | |
| 137 | +/*28*/ { 1024, 655, 1024, 655, 655, 419, 655, 419 }, | |
| 138 | +/*29*/ { 910, 570, 910, 570, 570, 362, 570, 362 }, | |
| 139 | +/*30*/ { 819, 504, 819, 504, 504, 328, 504, 328 }, | |
| 140 | +/*31*/ { 745, 468, 745, 468, 468, 291, 468, 291 }, | |
| 141 | +/*32*/ { 630, 410, 630, 410, 410, 262, 410, 262 }, | |
| 142 | +/*33*/ { 585, 364, 585, 364, 364, 228, 364, 228 }, | |
| 143 | +/*34*/ { 512, 328, 512, 328, 328, 210, 328, 210 }, | |
| 144 | +/*35*/ { 455, 285, 455, 285, 285, 181, 285, 181 }, | |
| 145 | +/*36*/ { 410, 252, 410, 252, 252, 164, 252, 164 }, | |
| 146 | +/*37*/ { 372, 234, 372, 234, 234, 146, 234, 146 }, | |
| 147 | +/*38*/ { 315, 205, 315, 205, 205, 131, 205, 131 }, | |
| 148 | +/*39*/ { 293, 182, 293, 182, 182, 114, 182, 114 }, | |
| 149 | +/*40*/ { 256, 164, 256, 164, 164, 105, 164, 105 }, | |
| 150 | +/*41*/ { 228, 142, 228, 142, 142, 90, 142, 90 }, | |
| 151 | +/*42*/ { 205, 126, 205, 126, 126, 82, 126, 82 }, | |
| 152 | +/*43*/ { 186, 117, 186, 117, 117, 73, 117, 73 }, | |
| 153 | +/*44*/ { 158, 102, 158, 102, 102, 66, 102, 66 }, | |
| 154 | +/*45*/ { 146, 91, 146, 91, 91, 57, 91, 57 }, | |
| 155 | +/*46*/ { 128, 82, 128, 82, 82, 52, 82, 52 }, | |
| 156 | +/*47*/ { 114, 71, 114, 71, 71, 45, 71, 45 }, | |
| 157 | +/*48*/ { 102, 63, 102, 63, 63, 41, 63, 41 }, | |
| 158 | +/*49*/ { 93, 59, 93, 59, 59, 36, 59, 36 }, | |
| 159 | +/*50*/ { 79, 51, 79, 51, 51, 33, 51, 33 }, | |
| 160 | +/*51*/ { 73, 46, 73, 46, 46, 28, 46, 28 } | |
| 161 | +}; | |
| 162 | + | |
| 163 | +/**************************************************************************** | |
| 164 | + * HDM and Quant functions | |
| 165 | + ****************************************************************************/ | |
| 166 | +#define WELS_ABS_LC(a) ((iSign ^ (int32_t)(a)) - iSign) | |
| 167 | +#define NEW_QUANT(pDct, iFF, iMF) (((iFF)+ WELS_ABS_LC(pDct))*(iMF)) >>16 | |
| 168 | +#define WELS_NEW_QUANT(pDct,iFF,iMF) WELS_ABS_LC(NEW_QUANT(pDct, iFF, iMF)) | |
| 169 | +void WelsQuant4x4_c(int16_t *pDct, int16_t* pFF, int16_t *pMF) | |
| 170 | +{ | |
| 171 | + int32_t i, j, iSign; | |
| 172 | + for( i = 0; i < 16; i+=4 ) | |
| 173 | + { | |
| 174 | + j = i & 0x07; | |
| 175 | + iSign = WELS_SIGN(pDct[i]); | |
| 176 | + pDct[i] = WELS_NEW_QUANT(pDct[i], pFF[j], pMF[j]); | |
| 177 | + iSign = WELS_SIGN(pDct[i+1]); | |
| 178 | + pDct[i+1] = WELS_NEW_QUANT(pDct[i+1], pFF[j+1], pMF[j+1]); | |
| 179 | + iSign = WELS_SIGN(pDct[i+2]); | |
| 180 | + pDct[i+2] = WELS_NEW_QUANT(pDct[i+2], pFF[j+2], pMF[j+2]); | |
| 181 | + iSign = WELS_SIGN(pDct[i+3]); | |
| 182 | + pDct[i+3] = WELS_NEW_QUANT(pDct[i+3], pFF[j+3], pMF[j+3]); | |
| 183 | + } | |
| 184 | +} | |
| 185 | + | |
| 186 | +void WelsQuant4x4Dc_c(int16_t *pDct, int16_t iFF, int16_t iMF) | |
| 187 | +{ | |
| 188 | + int32_t i, iSign; | |
| 189 | + for(i = 0; i < 16; i+=4) | |
| 190 | + { | |
| 191 | + iSign = WELS_SIGN(pDct[i]); | |
| 192 | + pDct[i] = WELS_NEW_QUANT(pDct[i], iFF, iMF); | |
| 193 | + iSign = WELS_SIGN(pDct[i+1]); | |
| 194 | + pDct[i+1] = WELS_NEW_QUANT(pDct[i+1], iFF, iMF); | |
| 195 | + iSign = WELS_SIGN(pDct[i+2]); | |
| 196 | + pDct[i+2] = WELS_NEW_QUANT(pDct[i+2], iFF, iMF); | |
| 197 | + iSign = WELS_SIGN(pDct[i+3]); | |
| 198 | + pDct[i+3] = WELS_NEW_QUANT(pDct[i+3], iFF, iMF); | |
| 199 | + } | |
| 200 | +} | |
| 201 | + | |
| 202 | +void WelsQuantFour4x4_c(int16_t *pDct, int16_t* pFF, int16_t *pMF) | |
| 203 | +{ | |
| 204 | + int32_t i, j, iSign; | |
| 205 | + | |
| 206 | + for( i = 0; i < 64; i+=4 ) | |
| 207 | + { | |
| 208 | + j = i & 0x07; | |
| 209 | + iSign = WELS_SIGN(pDct[i]); | |
| 210 | + pDct[i] = WELS_NEW_QUANT(pDct[i], pFF[j], pMF[j]); | |
| 211 | + iSign = WELS_SIGN(pDct[i+1]); | |
| 212 | + pDct[i+1] = WELS_NEW_QUANT(pDct[i+1], pFF[j+1], pMF[j+1]); | |
| 213 | + iSign = WELS_SIGN(pDct[i+2]); | |
| 214 | + pDct[i+2] = WELS_NEW_QUANT(pDct[i+2], pFF[j+2], pMF[j+2]); | |
| 215 | + iSign = WELS_SIGN(pDct[i+3]); | |
| 216 | + pDct[i+3] = WELS_NEW_QUANT(pDct[i+3], pFF[j+3], pMF[j+3]); | |
| 217 | + } | |
| 218 | +} | |
| 219 | + | |
| 220 | +void WelsQuantFour4x4Max_c(int16_t *pDct, int16_t* pFF, int16_t *pMF, int16_t *pMax) | |
| 221 | +{ | |
| 222 | + int32_t i, j, k, iSign; | |
| 223 | + int16_t iMaxAbs; | |
| 224 | + for( k = 0; k < 4; k++) | |
| 225 | + { | |
| 226 | + iMaxAbs = 0; | |
| 227 | + for( i = 0; i < 16; i++ ) | |
| 228 | + { | |
| 229 | + j = i & 0x07; | |
| 230 | + iSign = WELS_SIGN(pDct[i]); | |
| 231 | + pDct[i] = NEW_QUANT(pDct[i], pFF[j], pMF[j]); | |
| 232 | + if( iMaxAbs < pDct[i]) iMaxAbs = pDct[i]; | |
| 233 | + pDct[i] = WELS_ABS_LC(pDct[i]); | |
| 234 | + } | |
| 235 | + pDct += 16; | |
| 236 | + pMax[k] = iMaxAbs; | |
| 237 | + } | |
| 238 | +} | |
| 239 | + | |
| 240 | +int32_t WelsHadamardQuant2x2Skip_c(int16_t *pRs, int16_t iFF, int16_t iMF) | |
| 241 | +{ | |
| 242 | + int16_t pDct[4], s[4]; | |
| 243 | + int16_t iThreshold = ((1<<16)-1)/iMF - iFF; | |
| 244 | + | |
| 245 | + s[0] = pRs[0] + pRs[32]; | |
| 246 | + s[1] = pRs[0] - pRs[32]; | |
| 247 | + s[2] = pRs[16] + pRs[48]; | |
| 248 | + s[3] = pRs[16] - pRs[48]; | |
| 249 | + | |
| 250 | + pDct[0] = s[0] + s[2]; | |
| 251 | + pDct[1] = s[0] - s[2]; | |
| 252 | + pDct[2] = s[1] + s[3]; | |
| 253 | + pDct[3] = s[1] - s[3]; | |
| 254 | + | |
| 255 | + return ((WELS_ABS(pDct[0]) > iThreshold) || (WELS_ABS(pDct[1]) > iThreshold) || (WELS_ABS(pDct[2]) > iThreshold) || (WELS_ABS(pDct[3]) > iThreshold)); | |
| 256 | +} | |
| 257 | + | |
| 258 | +int32_t WelsHadamardQuant2x2_c(int16_t *pRs, const int16_t iFF, int16_t iMF, int16_t * pDct, int16_t * pBlock) | |
| 259 | +{ | |
| 260 | + int16_t s[4]; | |
| 261 | + int32_t iSign, i, iDcNzc = 0; | |
| 262 | + | |
| 263 | + s[0] = pRs[0] + pRs[32]; | |
| 264 | + s[1] = pRs[0] - pRs[32]; | |
| 265 | + s[2] = pRs[16] + pRs[48]; | |
| 266 | + s[3] = pRs[16] - pRs[48]; | |
| 267 | + | |
| 268 | + pRs[0] = 0; | |
| 269 | + pRs[16] = 0; | |
| 270 | + pRs[32] = 0; | |
| 271 | + pRs[48] = 0; | |
| 272 | + | |
| 273 | + pDct[0] = s[0] + s[2]; | |
| 274 | + pDct[1] = s[0] - s[2]; | |
| 275 | + pDct[2] = s[1] + s[3]; | |
| 276 | + pDct[3] = s[1] - s[3]; | |
| 277 | + | |
| 278 | + iSign = WELS_SIGN(pDct[0]); | |
| 279 | + pDct[0] = WELS_NEW_QUANT(pDct[0], iFF, iMF); | |
| 280 | + iSign = WELS_SIGN(pDct[1]); | |
| 281 | + pDct[1] = WELS_NEW_QUANT(pDct[1], iFF, iMF); | |
| 282 | + iSign = WELS_SIGN(pDct[2]); | |
| 283 | + pDct[2] = WELS_NEW_QUANT(pDct[2], iFF, iMF); | |
| 284 | + iSign = WELS_SIGN(pDct[3]); | |
| 285 | + pDct[3] = WELS_NEW_QUANT(pDct[3], iFF, iMF); | |
| 286 | + | |
| 287 | + ST64( pBlock, LD64(pDct) ); | |
| 288 | + | |
| 289 | + for(i=0; i<4; i++) | |
| 290 | + iDcNzc += (pBlock[i] != 0); | |
| 291 | + return iDcNzc; | |
| 292 | +} | |
| 293 | + | |
| 294 | +/* dc value pick up and hdm_4x4 */ | |
| 295 | +void WelsHadamardT4Dc_c( int16_t *pLumaDc, int16_t *pDct) | |
| 296 | +{ | |
| 297 | + int32_t p[16], s[4]; | |
| 298 | + int32_t i, iIdx; | |
| 299 | + | |
| 300 | + for(i = 0 ; i < 16 ; i +=4) | |
| 301 | + { | |
| 302 | + iIdx = ((i&0x08) << 4) +((i&0x04) << 3); | |
| 303 | + s[0] = pDct[iIdx ] + pDct[iIdx+80]; | |
| 304 | + s[3] = pDct[iIdx ] - pDct[iIdx+80]; | |
| 305 | + s[1] = pDct[iIdx+16] + pDct[iIdx+64]; | |
| 306 | + s[2] = pDct[iIdx+16] - pDct[iIdx+64]; | |
| 307 | + | |
| 308 | + p[i ] = s[0] + s[1]; | |
| 309 | + p[i+2] = s[0] - s[1]; | |
| 310 | + p[i+1] = s[3] + s[2]; | |
| 311 | + p[i+3] = s[3] - s[2]; | |
| 312 | + } | |
| 313 | + | |
| 314 | + for(i = 0 ; i < 4 ; i ++) | |
| 315 | + { | |
| 316 | + s[0] = p[i ] + p[i+12]; | |
| 317 | + s[3] = p[i ] - p[i+12]; | |
| 318 | + s[1] = p[i+4] + p[i+ 8]; | |
| 319 | + s[2] = p[i+4] - p[i+ 8]; | |
| 320 | + | |
| 321 | + pLumaDc[i ] = WELS_CLIP3((s[0] + s[1] + 1) >> 1, -32768, 32767); | |
| 322 | + pLumaDc[i+8 ] = WELS_CLIP3((s[0] - s[1] + 1) >> 1, -32768, 32767); | |
| 323 | + pLumaDc[i+4 ] = WELS_CLIP3((s[3] + s[2] + 1) >> 1, -32768, 32767); | |
| 324 | + pLumaDc[i+12] = WELS_CLIP3((s[3] - s[2] + 1) >> 1, -32768, 32767); | |
| 325 | + } | |
| 326 | +} | |
| 327 | + | |
| 328 | +/**************************************************************************** | |
| 329 | + * DCT functions | |
| 330 | + ****************************************************************************/ | |
| 331 | +void WelsDctT4_c( int16_t *pDct, uint8_t *pPixel1, int32_t iStride1, uint8_t *pPixel2, int32_t iStride2 ) | |
| 332 | +{ | |
| 333 | + int16_t i, pData[16], s[4]; | |
| 334 | + for(i = 0 ; i < 16 ; i +=4) | |
| 335 | + { | |
| 336 | + const int32_t kiI1= 1 + i; | |
| 337 | + const int32_t kiI2= 2 + i; | |
| 338 | + const int32_t kiI3= 3 + i; | |
| 339 | + | |
| 340 | + pData[i ] = pPixel1[0] - pPixel2[0]; | |
| 341 | + pData[kiI1] = pPixel1[1] - pPixel2[1]; | |
| 342 | + pData[kiI2] = pPixel1[2] - pPixel2[2]; | |
| 343 | + pData[kiI3] = pPixel1[3] - pPixel2[3]; | |
| 344 | + | |
| 345 | + pPixel1 += iStride1; | |
| 346 | + pPixel2 += iStride2; | |
| 347 | + | |
| 348 | + /*horizontal transform */ | |
| 349 | + s[0] = pData[i] + pData[kiI3]; | |
| 350 | + s[3] = pData[i] - pData[kiI3]; | |
| 351 | + s[1] = pData[kiI1] + pData[kiI2]; | |
| 352 | + s[2] = pData[kiI1] - pData[kiI2]; | |
| 353 | + | |
| 354 | + pDct[i ] = s[0] + s[1]; | |
| 355 | + pDct[kiI2] = s[0] - s[1]; | |
| 356 | + pDct[kiI1] = (s[3] << 1) + s[2]; | |
| 357 | + pDct[kiI3] = s[3] - (s[2] << 1); | |
| 358 | + } | |
| 359 | + | |
| 360 | + /* vertical transform */ | |
| 361 | + for(i = 0 ; i < 4 ; i ++) | |
| 362 | + { | |
| 363 | + const int32_t kiI4 = 4 + i; | |
| 364 | + const int32_t kiI8 = 8 + i; | |
| 365 | + const int32_t kiI12 = 12 + i; | |
| 366 | + | |
| 367 | + s[0] = pDct[i ] + pDct[kiI12]; | |
| 368 | + s[3] = pDct[i ] - pDct[kiI12]; | |
| 369 | + s[1] = pDct[kiI4] + pDct[kiI8 ]; | |
| 370 | + s[2] = pDct[kiI4] - pDct[kiI8 ]; | |
| 371 | + | |
| 372 | + pDct[i ] = s[0] + s[1]; | |
| 373 | + pDct[kiI8 ] = s[0] - s[1]; | |
| 374 | + pDct[kiI4 ] = (s[3] << 1) + s[2]; | |
| 375 | + pDct[kiI12] = s[3] - (s[2] << 1); | |
| 376 | + } | |
| 377 | +} | |
| 378 | + | |
| 379 | +void WelsDctFourT4_c(int16_t *pDct, uint8_t *pPixel1, int32_t iStride1, uint8_t *pPixel2, int32_t iStride2 ) | |
| 380 | +{ | |
| 381 | + int32_t stride_1 = iStride1 << 2; | |
| 382 | + int32_t stride_2 = iStride2 << 2; | |
| 383 | + | |
| 384 | + WelsDctT4_c( pDct, &pPixel1[0], iStride1, &pPixel2[0], iStride2 ); | |
| 385 | + WelsDctT4_c( pDct + 16, &pPixel1[4], iStride1, &pPixel2[4], iStride2 ); | |
| 386 | + WelsDctT4_c( pDct + 32, &pPixel1[stride_1 ], iStride1, &pPixel2[stride_2 ], iStride2 ); | |
| 387 | + WelsDctT4_c( pDct + 48, &pPixel1[stride_1+4], iStride1, &pPixel2[stride_2+4], iStride2 ); | |
| 388 | +} | |
| 389 | + | |
| 390 | +/**************************************************************************** | |
| 391 | + * Scan and Score functions | |
| 392 | + ****************************************************************************/ | |
| 393 | +void WelsScan4x4DcAc_c( int16_t* pLevel, int16_t *pDct ) | |
| 394 | +{ | |
| 395 | + ST32( pLevel, LD32(pDct) ); | |
| 396 | + pLevel[2] = pDct[4]; | |
| 397 | + pLevel[3] = pDct[8]; | |
| 398 | + pLevel[4] = pDct[5]; | |
| 399 | + ST32( pLevel+5, LD32(pDct+2) ); | |
| 400 | + pLevel[7] = pDct[6]; | |
| 401 | + pLevel[8] = pDct[9]; | |
| 402 | + ST32( pLevel+9, LD32(pDct+12) ); | |
| 403 | + pLevel[11] = pDct[10]; | |
| 404 | + pLevel[12] = pDct[7]; | |
| 405 | + pLevel[13] = pDct[11]; | |
| 406 | + ST32( pLevel+14, LD32(pDct+14) ); | |
| 407 | +} | |
| 408 | + | |
| 409 | +void WelsScan4x4Ac_c( int16_t* pLevel, int16_t* pDct ) | |
| 410 | +{ | |
| 411 | + pLevel[0] = pDct[1]; | |
| 412 | + pLevel[1] = pDct[4]; | |
| 413 | + pLevel[2] = pDct[8]; | |
| 414 | + pLevel[3] = pDct[5]; | |
| 415 | + ST32( &pLevel[4], LD32(&pDct[2]) ); | |
| 416 | + pLevel[6] = pDct[6]; | |
| 417 | + pLevel[7] = pDct[9]; | |
| 418 | + ST32( &pLevel[8], LD32(&pDct[12]) ); | |
| 419 | + pLevel[10] = pDct[10]; | |
| 420 | + pLevel[11] = pDct[7]; | |
| 421 | + pLevel[12] = pDct[11]; | |
| 422 | + ST32( &pLevel[13], LD32(&pDct[14]) ); | |
| 423 | + pLevel[15] = 0; | |
| 424 | +} | |
| 425 | + | |
| 426 | +void WelsScan4x4Dc( int16_t* pLevel, int16_t* pDct ) | |
| 427 | +{ | |
| 428 | + ST32( pLevel, LD32(pDct) ); | |
| 429 | + pLevel[2] = pDct[4]; | |
| 430 | + pLevel[3] = pDct[8]; | |
| 431 | + pLevel[4] = pDct[5]; | |
| 432 | + ST32( pLevel+5, LD32(pDct+2) ); | |
| 433 | + pLevel[7] = pDct[6]; | |
| 434 | + pLevel[8] = pDct[9]; | |
| 435 | + ST32( pLevel+9, LD32(pDct+12) ); | |
| 436 | + pLevel[11] = pDct[10]; | |
| 437 | + pLevel[12] = pDct[7]; | |
| 438 | + pLevel[13] = pDct[11]; | |
| 439 | + ST32( pLevel+14, LD32(pDct+14) ); | |
| 440 | +} | |
| 441 | + | |
| 442 | +//refer to JVT-O079 | |
| 443 | +int32_t WelsCalculateSingleCtr4x4_c( int16_t *pDct) | |
| 444 | +{ | |
| 445 | + static const int32_t kiTRunTable[16] = { 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |
| 446 | + | |
| 447 | + int32_t iSingleCtr = 0; | |
| 448 | + int32_t iIdx = 15; | |
| 449 | + int32_t iRun; | |
| 450 | + | |
| 451 | + while( iIdx >= 0 && pDct[iIdx] == 0 ) --iIdx; | |
| 452 | + | |
| 453 | + while( iIdx >= 0 ) | |
| 454 | + { | |
| 455 | + -- iIdx; | |
| 456 | + iRun = iIdx; | |
| 457 | + while( iIdx >= 0 && pDct[iIdx] == 0 ) --iIdx; | |
| 458 | + iRun -= iIdx; | |
| 459 | + iSingleCtr += kiTRunTable[iRun]; | |
| 460 | + } | |
| 461 | + return iSingleCtr; | |
| 462 | +} | |
| 463 | + | |
| 464 | +/**************************************************************************** | |
| 465 | + * Copy functions | |
| 466 | + ****************************************************************************/ | |
| 467 | +void WelsCopy4x4( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS ) | |
| 468 | +{ | |
| 469 | + const int32_t kiSrcStride2 = iStrideS << 1; | |
| 470 | + const int32_t kiSrcStride3 = iStrideS + kiSrcStride2; | |
| 471 | + const int32_t kiDstStride2 = iStrideD << 1; | |
| 472 | + const int32_t kiDstStride3 = iStrideD + kiDstStride2; | |
| 473 | + | |
| 474 | + ST32( pDst, LD32(pSrc) ); | |
| 475 | + ST32( pDst+iStrideD, LD32(pSrc+iStrideS) ); | |
| 476 | + ST32( pDst+kiDstStride2, LD32(pSrc+kiSrcStride2) ); | |
| 477 | + ST32( pDst+kiDstStride3, LD32(pSrc+kiSrcStride3) ); | |
| 478 | +} | |
| 479 | +void WelsCopy8x8_c( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS ) | |
| 480 | +{ | |
| 481 | + int32_t i; | |
| 482 | + for( i = 0; i < 4; i++) | |
| 483 | + { | |
| 484 | + ST32( pDst, LD32(pSrc )); ST32( pDst + 4 , LD32(pSrc + 4 )); | |
| 485 | + ST32( pDst + iStrideD, LD32(pSrc + iStrideS)); ST32( pDst + iStrideD + 4 , LD32(pSrc + iStrideS + 4)); | |
| 486 | + pDst += iStrideD << 1; | |
| 487 | + pSrc += iStrideS << 1; | |
| 488 | + } | |
| 489 | +} | |
| 490 | +void WelsCopy8x16_c( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS ) | |
| 491 | +{ | |
| 492 | + int32_t i; | |
| 493 | + for( i = 0; i < 8; ++i ) | |
| 494 | + { | |
| 495 | + ST32( pDst, LD32(pSrc )); ST32( pDst + 4 , LD32(pSrc + 4 )); | |
| 496 | + ST32( pDst + iStrideD, LD32(pSrc + iStrideS)); ST32( pDst + iStrideD + 4 , LD32(pSrc + iStrideS + 4)); | |
| 497 | + pDst += iStrideD << 1; | |
| 498 | + pSrc += iStrideS << 1; | |
| 499 | + } | |
| 500 | +} | |
| 501 | +void WelsCopy16x8_c( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS ) | |
| 502 | +{ | |
| 503 | + int32_t i; | |
| 504 | + for( i = 0; i < 8; i++) | |
| 505 | + { | |
| 506 | + ST32( pDst, LD32(pSrc )); ST32( pDst + 4 , LD32(pSrc + 4 )); | |
| 507 | + ST32( pDst + 8 ,LD32(pSrc + 8 )); ST32( pDst + 12 , LD32(pSrc + 12)); | |
| 508 | + pDst += iStrideD ; | |
| 509 | + pSrc += iStrideS; | |
| 510 | + } | |
| 511 | +} | |
| 512 | +void WelsCopy16x16_c( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS ) | |
| 513 | +{ | |
| 514 | + int32_t i; | |
| 515 | + for( i = 0; i < 16; i++) | |
| 516 | + { | |
| 517 | + ST32( pDst, LD32(pSrc )); ST32( pDst + 4 , LD32(pSrc + 4 )); | |
| 518 | + ST32( pDst + 8 ,LD32(pSrc + 8 )); ST32( pDst + 12 , LD32(pSrc + 12)); | |
| 519 | + pDst += iStrideD ; | |
| 520 | + pSrc += iStrideS; | |
| 521 | + } | |
| 522 | +} | |
| 523 | + | |
| 524 | +int32_t WelsGetNoneZeroCount_c(int16_t * pLevel) | |
| 525 | +{ | |
| 526 | + int32_t iCnt = 0; | |
| 527 | + int32_t iIdx = 0; | |
| 528 | + | |
| 529 | + while (iIdx < 16) { | |
| 530 | + iCnt += (pLevel[ iIdx] == 0); | |
| 531 | + iCnt += (pLevel[1+iIdx] == 0); | |
| 532 | + iCnt += (pLevel[2+iIdx] == 0); | |
| 533 | + iCnt += (pLevel[3+iIdx] == 0); | |
| 534 | + | |
| 535 | + iIdx += 4; | |
| 536 | + } | |
| 537 | + return (16 - iCnt); | |
| 538 | +} | |
| 539 | + | |
| 540 | +void WelsInitEncodingFuncs( SWelsFuncPtrList *pFuncList, uint32_t uiCpuFlag ) | |
| 541 | +{ | |
| 542 | + pFuncList->pfCopy8x8Aligned = WelsCopy8x8_c; | |
| 543 | + pFuncList->pfCopy16x16Aligned = | |
| 544 | + pFuncList->pfCopy16x16NotAligned = WelsCopy16x16_c; | |
| 545 | + pFuncList->pfCopy16x8NotAligned = WelsCopy16x8_c; | |
| 546 | + pFuncList->pfCopy8x16Aligned = WelsCopy8x16_c; | |
| 547 | + | |
| 548 | + pFuncList->pfQuantizationHadamard2x2 = WelsHadamardQuant2x2_c; | |
| 549 | + pFuncList->pfQuantizationHadamard2x2Skip = WelsHadamardQuant2x2Skip_c; | |
| 550 | + pFuncList->pfTransformHadamard4x4Dc = WelsHadamardT4Dc_c; | |
| 551 | + | |
| 552 | + pFuncList->pfDctT4 = WelsDctT4_c; | |
| 553 | + pFuncList->pfDctFourT4 = WelsDctFourT4_c; | |
| 554 | + | |
| 555 | + pFuncList->pfScan4x4 = WelsScan4x4DcAc_c; | |
| 556 | + pFuncList->pfScan4x4Ac = WelsScan4x4Ac_c; | |
| 557 | + pFuncList->pfCalculateSingleCtr4x4 = WelsCalculateSingleCtr4x4_c; | |
| 558 | + | |
| 559 | + pFuncList->pfGetNoneZeroCount = WelsGetNoneZeroCount_c; | |
| 560 | + | |
| 561 | + pFuncList->pfQuantization4x4 = WelsQuant4x4_c; | |
| 562 | + pFuncList->pfQuantizationDc4x4 = WelsQuant4x4Dc_c; | |
| 563 | + pFuncList->pfQuantizationFour4x4 = WelsQuantFour4x4_c; | |
| 564 | + pFuncList->pfQuantizationFour4x4Max = WelsQuantFour4x4Max_c; | |
| 565 | + | |
| 566 | +#if defined(X86_ASM) | |
| 567 | + if ( uiCpuFlag & WELS_CPU_MMXEXT ) | |
| 568 | + { | |
| 569 | + | |
| 570 | + pFuncList->pfQuantizationHadamard2x2 = WelsHadamardQuant2x2_mmx; | |
| 571 | + pFuncList->pfQuantizationHadamard2x2Skip = WelsHadamardQuant2x2Skip_mmx; | |
| 572 | + | |
| 573 | + pFuncList->pfDctT4 = WelsDctT4_mmx; | |
| 574 | + | |
| 575 | + pFuncList->pfCopy8x8Aligned = WelsCopy8x8_mmx; | |
| 576 | + pFuncList->pfCopy8x16Aligned = WelsCopy8x16_mmx; | |
| 577 | + } | |
| 578 | + if ( uiCpuFlag & WELS_CPU_SSE2 ) | |
| 579 | + { | |
| 580 | + pFuncList->pfGetNoneZeroCount = WelsGetNoneZeroCount_sse2; | |
| 581 | + pFuncList->pfTransformHadamard4x4Dc = WelsHadamardT4Dc_sse2; | |
| 582 | + | |
| 583 | + pFuncList->pfQuantization4x4 = WelsQuant4x4_sse2; | |
| 584 | + pFuncList->pfQuantizationDc4x4 = WelsQuant4x4Dc_sse2; | |
| 585 | + pFuncList->pfQuantizationFour4x4 = WelsQuantFour4x4_sse2; | |
| 586 | + pFuncList->pfQuantizationFour4x4Max = WelsQuantFour4x4Max_sse2; | |
| 587 | + | |
| 588 | + pFuncList->pfCopy16x16Aligned = WelsCopy16x16_sse2; | |
| 589 | + pFuncList->pfCopy16x16NotAligned = WelsCopy16x16NotAligned_sse2; | |
| 590 | + pFuncList->pfCopy16x8NotAligned = WelsCopy16x8NotAligned_sse2; | |
| 591 | + | |
| 592 | + pFuncList->pfScan4x4 = WelsScan4x4DcAc_sse2; | |
| 593 | + pFuncList->pfScan4x4Ac = WelsScan4x4Ac_sse2; | |
| 594 | + pFuncList->pfCalculateSingleCtr4x4 = WelsCalculateSingleCtr4x4_sse2; | |
| 595 | + | |
| 596 | + pFuncList->pfDctFourT4 = WelsDctFourT4_sse2; | |
| 597 | + } | |
| 598 | +//#ifndef MACOS | |
| 599 | + if ( uiCpuFlag & WELS_CPU_SSSE3 ) | |
| 600 | + { | |
| 601 | + pFuncList->pfScan4x4 = WelsScan4x4DcAc_ssse3; | |
| 602 | + } | |
| 603 | + | |
| 604 | +//#endif//MACOS | |
| 605 | + | |
| 606 | +#endif//X86_ASM | |
| 607 | +} | |
| 608 | +} | |