[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[56] | 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TComRom.cpp |
---|
| 35 | \brief global variables & functions |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TComRom.h" |
---|
| 39 | #include <memory.h> |
---|
| 40 | #include <stdlib.h> |
---|
| 41 | #include <stdio.h> |
---|
| 42 | // ==================================================================================================================== |
---|
| 43 | // Initialize / destroy functions |
---|
| 44 | // ==================================================================================================================== |
---|
| 45 | |
---|
[56] | 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
[2] | 49 | // initialize ROM variables |
---|
| 50 | Void initROM() |
---|
| 51 | { |
---|
| 52 | Int i, c; |
---|
| 53 | |
---|
| 54 | // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ... |
---|
| 55 | ::memset( g_aucConvertToBit, -1, sizeof( g_aucConvertToBit ) ); |
---|
| 56 | c=0; |
---|
| 57 | for ( i=4; i<MAX_CU_SIZE; i*=2 ) |
---|
| 58 | { |
---|
| 59 | g_aucConvertToBit[ i ] = c; |
---|
| 60 | c++; |
---|
| 61 | } |
---|
| 62 | g_aucConvertToBit[ i ] = c; |
---|
| 63 | |
---|
| 64 | // g_auiFrameScanXY[ g_aucConvertToBit[ transformSize ] ]: zigzag scan array for transformSize |
---|
| 65 | c=2; |
---|
| 66 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
| 67 | { |
---|
| 68 | g_auiFrameScanXY[ i ] = new UInt[ c*c ]; |
---|
| 69 | g_auiFrameScanX [ i ] = new UInt[ c*c ]; |
---|
| 70 | g_auiFrameScanY [ i ] = new UInt[ c*c ]; |
---|
| 71 | initFrameScanXY( g_auiFrameScanXY[i], g_auiFrameScanX[i], g_auiFrameScanY[i], c, c ); |
---|
| 72 | g_auiSigLastScan[0][i] = new UInt[ c*c ]; |
---|
| 73 | g_auiSigLastScan[1][i] = new UInt[ c*c ]; |
---|
| 74 | g_auiSigLastScan[2][i] = new UInt[ c*c ]; |
---|
[56] | 75 | g_auiSigLastScan[3][i] = new UInt[ c*c ]; |
---|
| 76 | initSigLastScan( g_auiSigLastScan[0][i], g_auiSigLastScan[1][i], g_auiSigLastScan[2][i], g_auiSigLastScan[3][i], c, c, i); |
---|
[2] | 77 | |
---|
| 78 | c <<= 1; |
---|
| 79 | } |
---|
[56] | 80 | |
---|
| 81 | g_sigScanNSQT[0] = new UInt[ 64 ]; // 4x16 |
---|
| 82 | g_sigScanNSQT[1] = new UInt[ 256 ]; // 8x32 |
---|
| 83 | g_sigScanNSQT[2] = new UInt[ 64 ]; // 16x4 |
---|
| 84 | g_sigScanNSQT[3] = new UInt[ 256 ]; // 32x8 |
---|
| 85 | |
---|
| 86 | static int diagScanX[ 16 ] = |
---|
| 87 | { |
---|
| 88 | 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 1, 2, 3, 2, 3, 3 |
---|
| 89 | }; |
---|
| 90 | static int diagScanY[ 16 ] = |
---|
| 91 | { |
---|
| 92 | 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 3, 2, 3 |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | Int j; |
---|
| 96 | // 4x16 scan |
---|
| 97 | for (i = 0; i < 4; i++) |
---|
| 98 | { |
---|
| 99 | for (j = 0; j < 16; j++) |
---|
| 100 | { |
---|
| 101 | g_sigScanNSQT[ 0 ][ 16 * i + j ] = 16 * i + 4 * diagScanY[ j ] + diagScanX[ j ]; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // 8x32 scan |
---|
| 106 | for (i = 0; i < 16; i++) |
---|
| 107 | { |
---|
| 108 | Int x = g_sigCGScanNSQT[ 1 ][ i ] & 1; |
---|
| 109 | Int y = g_sigCGScanNSQT[ 1 ][ i ] >> 1; |
---|
| 110 | |
---|
| 111 | for (j = 0; j < 16; j++) |
---|
| 112 | { |
---|
| 113 | g_sigScanNSQT[ 1 ][ 16 * i + j ] = 32 * y + 4 * x + 8 * diagScanY[ j ] + diagScanX[ j ]; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | // 16x4 scan |
---|
| 118 | for (i = 0; i < 4; i++) |
---|
| 119 | { |
---|
| 120 | for (j = 0; j < 16; j++) |
---|
| 121 | { |
---|
| 122 | g_sigScanNSQT[ 2 ][ 16 * i + j ] = 4 * i + 16 * diagScanY[ j ] + diagScanX[ j ]; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // 32x8 scan |
---|
| 127 | for (i = 0; i < 16; i++) |
---|
| 128 | { |
---|
| 129 | Int x = g_sigCGScanNSQT[ 3 ][ i ] & 7; |
---|
| 130 | Int y = g_sigCGScanNSQT[ 3 ][ i ] >> 3; |
---|
| 131 | |
---|
| 132 | for (j = 0; j < 16; j++) |
---|
| 133 | { |
---|
| 134 | g_sigScanNSQT[ 3 ][ 16 * i + j ] = 128 * y + 4 * x + 32 * diagScanY[ j ] + diagScanX[ j ]; |
---|
| 135 | } |
---|
| 136 | } |
---|
[2] | 137 | } |
---|
| 138 | |
---|
| 139 | Void destroyROM() |
---|
| 140 | { |
---|
| 141 | Int i; |
---|
| 142 | |
---|
| 143 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
| 144 | { |
---|
| 145 | delete[] g_auiFrameScanXY[i]; |
---|
| 146 | delete[] g_auiFrameScanX [i]; |
---|
| 147 | delete[] g_auiFrameScanY [i]; |
---|
| 148 | delete[] g_auiSigLastScan[0][i]; |
---|
| 149 | delete[] g_auiSigLastScan[1][i]; |
---|
| 150 | delete[] g_auiSigLastScan[2][i]; |
---|
[56] | 151 | delete[] g_auiSigLastScan[3][i]; |
---|
[2] | 152 | } |
---|
[56] | 153 | for (i = 0; i < 4; i++) |
---|
| 154 | { |
---|
| 155 | delete[] g_sigScanNSQT[ i ]; |
---|
| 156 | } |
---|
[2] | 157 | |
---|
[5] | 158 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 159 | if ( !g_aacWedgeLists.empty() ) |
---|
| 160 | { |
---|
| 161 | for ( UInt ui = 0; ui < g_aacWedgeLists.size(); ui++ ) |
---|
| 162 | { |
---|
| 163 | g_aacWedgeLists[ui].clear(); |
---|
| 164 | } |
---|
| 165 | g_aacWedgeLists.clear(); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | if ( !g_aacWedgeRefLists.empty() ) |
---|
| 169 | { |
---|
| 170 | for ( UInt ui = 0; ui < g_aacWedgeRefLists.size(); ui++ ) |
---|
| 171 | { |
---|
| 172 | g_aacWedgeRefLists[ui].clear(); |
---|
| 173 | } |
---|
| 174 | g_aacWedgeRefLists.clear(); |
---|
| 175 | } |
---|
[296] | 176 | |
---|
[189] | 177 | if ( !g_aacWedgeNodeLists.empty() ) |
---|
| 178 | { |
---|
| 179 | for ( UInt ui = 0; ui < g_aacWedgeNodeLists.size(); ui++ ) |
---|
| 180 | { |
---|
| 181 | g_aacWedgeNodeLists[ui].clear(); |
---|
| 182 | } |
---|
| 183 | g_aacWedgeNodeLists.clear(); |
---|
| 184 | } |
---|
[296] | 185 | |
---|
[2] | 186 | #endif |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | // ==================================================================================================================== |
---|
| 190 | // Data structure related table & variable |
---|
| 191 | // ==================================================================================================================== |
---|
| 192 | |
---|
| 193 | UInt g_uiMaxCUWidth = MAX_CU_SIZE; |
---|
| 194 | UInt g_uiMaxCUHeight = MAX_CU_SIZE; |
---|
| 195 | UInt g_uiMaxCUDepth = MAX_CU_DEPTH; |
---|
| 196 | UInt g_uiAddCUDepth = 0; |
---|
| 197 | |
---|
| 198 | UInt g_auiZscanToRaster [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 199 | UInt g_auiRasterToZscan [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 200 | UInt g_auiRasterToPelX [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 201 | UInt g_auiRasterToPelY [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
[56] | 202 | UInt g_motionRefer [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
[2] | 203 | |
---|
[56] | 204 | UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5}; |
---|
[2] | 205 | |
---|
| 206 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ) |
---|
| 207 | { |
---|
| 208 | Int iStride = 1 << ( iMaxDepth - 1 ); |
---|
| 209 | |
---|
| 210 | if ( iDepth == iMaxDepth ) |
---|
| 211 | { |
---|
| 212 | rpuiCurrIdx[0] = uiStartVal; |
---|
| 213 | rpuiCurrIdx++; |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | Int iStep = iStride >> iDepth; |
---|
| 218 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal, rpuiCurrIdx ); |
---|
| 219 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep, rpuiCurrIdx ); |
---|
| 220 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride, rpuiCurrIdx ); |
---|
| 221 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx ); |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
| 226 | { |
---|
| 227 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
| 228 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
| 229 | |
---|
| 230 | UInt uiNumPartInWidth = (UInt)uiMaxCUWidth / uiMinCUWidth; |
---|
| 231 | UInt uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight; |
---|
| 232 | |
---|
| 233 | for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
| 234 | { |
---|
| 235 | g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i; |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | |
---|
[56] | 239 | /** generate motion data compression mapping table |
---|
| 240 | * \param uiMaxCUWidth, width of LCU |
---|
| 241 | * \param uiMaxCUHeight, hight of LCU |
---|
| 242 | * \param uiMaxDepth, max depth of LCU |
---|
| 243 | * \returns Void |
---|
| 244 | */ |
---|
| 245 | Void initMotionReferIdx ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
| 246 | { |
---|
| 247 | Int minCUWidth = (Int)uiMaxCUWidth >> ( (Int)uiMaxDepth - 1 ); |
---|
| 248 | Int minCUHeight = (Int)uiMaxCUHeight >> ( (Int)uiMaxDepth - 1 ); |
---|
| 249 | |
---|
| 250 | Int numPartInWidth = (Int)uiMaxCUWidth / (Int)minCUWidth; |
---|
| 251 | Int numPartInHeight = (Int)uiMaxCUHeight / (Int)minCUHeight; |
---|
| 252 | |
---|
| 253 | for ( Int i = 0; i < numPartInWidth*numPartInHeight; i++ ) |
---|
| 254 | { |
---|
| 255 | g_motionRefer[i] = i; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | Int compressionNum = 2; |
---|
| 259 | |
---|
| 260 | for ( Int i = numPartInWidth*(numPartInHeight-1); i < numPartInWidth*numPartInHeight; i += compressionNum*2) |
---|
| 261 | { |
---|
| 262 | for ( Int j = 1; j < compressionNum; j++ ) |
---|
| 263 | { |
---|
| 264 | g_motionRefer[g_auiRasterToZscan[i+j]] = g_auiRasterToZscan[i]; |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | for ( Int i = numPartInWidth*(numPartInHeight-1)+compressionNum*2-1; i < numPartInWidth*numPartInHeight; i += compressionNum*2) |
---|
| 269 | { |
---|
| 270 | for ( Int j = 1; j < compressionNum; j++ ) |
---|
| 271 | { |
---|
| 272 | g_motionRefer[g_auiRasterToZscan[i-j]] = g_auiRasterToZscan[i]; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
[2] | 277 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
| 278 | { |
---|
| 279 | UInt i; |
---|
| 280 | |
---|
| 281 | UInt* uiTempX = &g_auiRasterToPelX[0]; |
---|
| 282 | UInt* uiTempY = &g_auiRasterToPelY[0]; |
---|
| 283 | |
---|
| 284 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
| 285 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
| 286 | |
---|
| 287 | UInt uiNumPartInWidth = uiMaxCUWidth / uiMinCUWidth; |
---|
| 288 | UInt uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight; |
---|
| 289 | |
---|
| 290 | uiTempX[0] = 0; uiTempX++; |
---|
| 291 | for ( i = 1; i < uiNumPartInWidth; i++ ) |
---|
| 292 | { |
---|
| 293 | uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++; |
---|
| 294 | } |
---|
| 295 | for ( i = 1; i < uiNumPartInHeight; i++ ) |
---|
| 296 | { |
---|
| 297 | memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth); |
---|
| 298 | uiTempX += uiNumPartInWidth; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
| 302 | { |
---|
| 303 | uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth; |
---|
| 304 | } |
---|
| 305 | }; |
---|
| 306 | |
---|
[189] | 307 | #if RWTH_SDC_DLT_B0036 |
---|
[296] | 308 | UInt g_auiSDCPredModes[RWTH_SDC_NUM_PRED_MODES] = { DC_IDX, DMM_WEDGE_FULL_IDX, PLANAR_IDX }; |
---|
[189] | 309 | #endif |
---|
[2] | 310 | |
---|
[56] | 311 | Int g_quantScales[6] = |
---|
[2] | 312 | { |
---|
[56] | 313 | 26214,23302,20560,18396,16384,14564 |
---|
| 314 | }; |
---|
[2] | 315 | |
---|
[56] | 316 | Int g_invQuantScales[6] = |
---|
[2] | 317 | { |
---|
[56] | 318 | 40,45,51,57,64,72 |
---|
[2] | 319 | }; |
---|
| 320 | |
---|
[56] | 321 | const short g_aiT4[4][4] = |
---|
[2] | 322 | { |
---|
[56] | 323 | { 64, 64, 64, 64}, |
---|
| 324 | { 83, 36,-36,-83}, |
---|
| 325 | { 64,-64,-64, 64}, |
---|
| 326 | { 36,-83, 83,-36} |
---|
[2] | 327 | }; |
---|
| 328 | |
---|
[56] | 329 | const short g_aiT8[8][8] = |
---|
[2] | 330 | { |
---|
[56] | 331 | { 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
| 332 | { 89, 75, 50, 18,-18,-50,-75,-89}, |
---|
| 333 | { 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
| 334 | { 75,-18,-89,-50, 50, 89, 18,-75}, |
---|
| 335 | { 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
| 336 | { 50,-89, 18, 75,-75,-18, 89,-50}, |
---|
| 337 | { 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
| 338 | { 18,-50, 75,-89, 89,-75, 50,-18} |
---|
[2] | 339 | }; |
---|
| 340 | |
---|
[56] | 341 | const short g_aiT16[16][16] = |
---|
[2] | 342 | { |
---|
[56] | 343 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
| 344 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90}, |
---|
| 345 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
| 346 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87}, |
---|
| 347 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
| 348 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80}, |
---|
| 349 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
| 350 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70}, |
---|
| 351 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
| 352 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57}, |
---|
| 353 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
| 354 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43}, |
---|
| 355 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
| 356 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25}, |
---|
| 357 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
| 358 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9} |
---|
[2] | 359 | }; |
---|
| 360 | |
---|
[56] | 361 | const short g_aiT32[32][32] = |
---|
[2] | 362 | { |
---|
[56] | 363 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
| 364 | { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4, -4,-13,-22,-31,-38,-46,-54,-61,-67,-73,-78,-82,-85,-88,-90,-90}, |
---|
| 365 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90,-90,-87,-80,-70,-57,-43,-25, -9, 9, 25, 43, 57, 70, 80, 87, 90}, |
---|
| 366 | { 90, 82, 67, 46, 22, -4,-31,-54,-73,-85,-90,-88,-78,-61,-38,-13, 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4,-22,-46,-67,-82,-90}, |
---|
| 367 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89, 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
| 368 | { 88, 67, 31,-13,-54,-82,-90,-78,-46, -4, 38, 73, 90, 85, 61, 22,-22,-61,-85,-90,-73,-38, 4, 46, 78, 90, 82, 54, 13,-31,-67,-88}, |
---|
| 369 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87,-87,-57, -9, 43, 80, 90, 70, 25,-25,-70,-90,-80,-43, 9, 57, 87}, |
---|
| 370 | { 85, 46,-13,-67,-90,-73,-22, 38, 82, 88, 54, -4,-61,-90,-78,-31, 31, 78, 90, 61, 4,-54,-88,-82,-38, 22, 73, 90, 67, 13,-46,-85}, |
---|
| 371 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
| 372 | { 82, 22,-54,-90,-61, 13, 78, 85, 31,-46,-90,-67, 4, 73, 88, 38,-38,-88,-73, -4, 67, 90, 46,-31,-85,-78,-13, 61, 90, 54,-22,-82}, |
---|
| 373 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80,-80, -9, 70, 87, 25,-57,-90,-43, 43, 90, 57,-25,-87,-70, 9, 80}, |
---|
| 374 | { 78, -4,-82,-73, 13, 85, 67,-22,-88,-61, 31, 90, 54,-38,-90,-46, 46, 90, 38,-54,-90,-31, 61, 88, 22,-67,-85,-13, 73, 82, 4,-78}, |
---|
| 375 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75, 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
| 376 | { 73,-31,-90,-22, 78, 67,-38,-90,-13, 82, 61,-46,-88, -4, 85, 54,-54,-85, 4, 88, 46,-61,-82, 13, 90, 38,-67,-78, 22, 90, 31,-73}, |
---|
| 377 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70,-70, 43, 87, -9,-90,-25, 80, 57,-57,-80, 25, 90, 9,-87,-43, 70}, |
---|
| 378 | { 67,-54,-78, 38, 85,-22,-90, 4, 90, 13,-88,-31, 82, 46,-73,-61, 61, 73,-46,-82, 31, 88,-13,-90, -4, 90, 22,-85,-38, 78, 54,-67}, |
---|
| 379 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
| 380 | { 61,-73,-46, 82, 31,-88,-13, 90, -4,-90, 22, 85,-38,-78, 54, 67,-67,-54, 78, 38,-85,-22, 90, 4,-90, 13, 88,-31,-82, 46, 73,-61}, |
---|
| 381 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57,-57, 80, 25,-90, 9, 87,-43,-70, 70, 43,-87, -9, 90,-25,-80, 57}, |
---|
| 382 | { 54,-85, -4, 88,-46,-61, 82, 13,-90, 38, 67,-78,-22, 90,-31,-73, 73, 31,-90, 22, 78,-67,-38, 90,-13,-82, 61, 46,-88, 4, 85,-54}, |
---|
| 383 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50, 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
| 384 | { 46,-90, 38, 54,-90, 31, 61,-88, 22, 67,-85, 13, 73,-82, 4, 78,-78, -4, 82,-73,-13, 85,-67,-22, 88,-61,-31, 90,-54,-38, 90,-46}, |
---|
| 385 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43,-43, 90,-57,-25, 87,-70, -9, 80,-80, 9, 70,-87, 25, 57,-90, 43}, |
---|
| 386 | { 38,-88, 73, -4,-67, 90,-46,-31, 85,-78, 13, 61,-90, 54, 22,-82, 82,-22,-54, 90,-61,-13, 78,-85, 31, 46,-90, 67, 4,-73, 88,-38}, |
---|
| 387 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
| 388 | { 31,-78, 90,-61, 4, 54,-88, 82,-38,-22, 73,-90, 67,-13,-46, 85,-85, 46, 13,-67, 90,-73, 22, 38,-82, 88,-54, -4, 61,-90, 78,-31}, |
---|
| 389 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25,-25, 70,-90, 80,-43, -9, 57,-87, 87,-57, 9, 43,-80, 90,-70, 25}, |
---|
| 390 | { 22,-61, 85,-90, 73,-38, -4, 46,-78, 90,-82, 54,-13,-31, 67,-88, 88,-67, 31, 13,-54, 82,-90, 78,-46, 4, 38,-73, 90,-85, 61,-22}, |
---|
| 391 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18, 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
| 392 | { 13,-38, 61,-78, 88,-90, 85,-73, 54,-31, 4, 22,-46, 67,-82, 90,-90, 82,-67, 46,-22, -4, 31,-54, 73,-85, 90,-88, 78,-61, 38,-13}, |
---|
| 393 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9, -9, 25,-43, 57,-70, 80,-87, 90,-90, 87,-80, 70,-57, 43,-25, 9}, |
---|
| 394 | { 4,-13, 22,-31, 38,-46, 54,-61, 67,-73, 78,-82, 85,-88, 90,-90, 90,-90, 88,-85, 82,-78, 73,-67, 61,-54, 46,-38, 31,-22, 13, -4} |
---|
[2] | 395 | }; |
---|
| 396 | |
---|
| 397 | const UChar g_aucChromaScale[52]= |
---|
| 398 | { |
---|
| 399 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, |
---|
| 400 | 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, |
---|
| 401 | 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37, |
---|
| 402 | 37,38,38,38,39,39,39,39 |
---|
| 403 | }; |
---|
| 404 | |
---|
| 405 | |
---|
| 406 | // Mode-Dependent DCT/DST |
---|
| 407 | const short g_as_DST_MAT_4 [4][4]= |
---|
| 408 | { |
---|
| 409 | {29, 55, 74, 84}, |
---|
| 410 | {74, 74, 0 , -74}, |
---|
| 411 | {84, -29, -74, 55}, |
---|
| 412 | {55, -84, 74, -29}, |
---|
| 413 | }; |
---|
[56] | 414 | |
---|
| 415 | |
---|
[2] | 416 | |
---|
| 417 | // ==================================================================================================================== |
---|
| 418 | // ADI |
---|
| 419 | // ==================================================================================================================== |
---|
| 420 | |
---|
| 421 | #if FAST_UDI_USE_MPM |
---|
| 422 | const UChar g_aucIntraModeNumFast[7] = |
---|
| 423 | { |
---|
| 424 | 3, // 2x2 |
---|
| 425 | 8, // 4x4 |
---|
| 426 | 8, // 8x8 |
---|
| 427 | 3, // 16x16 |
---|
| 428 | 3, // 32x32 |
---|
| 429 | 3, // 64x64 |
---|
| 430 | 3 // 128x128 |
---|
| 431 | }; |
---|
| 432 | #else // FAST_UDI_USE_MPM |
---|
| 433 | const UChar g_aucIntraModeNumFast[7] = |
---|
| 434 | { |
---|
| 435 | 3, // 2x2 |
---|
| 436 | 9, // 4x4 |
---|
| 437 | 9, // 8x8 |
---|
| 438 | 4, // 16x16 33 |
---|
| 439 | 4, // 32x32 33 |
---|
| 440 | 5, // 64x64 33 |
---|
| 441 | 4 // 128x128 33 |
---|
| 442 | }; |
---|
| 443 | #endif // FAST_UDI_USE_MPM |
---|
| 444 | |
---|
| 445 | // chroma |
---|
| 446 | |
---|
| 447 | const UChar g_aucConvertTxtTypeToIdx[4] = { 0, 1, 1, 2 }; |
---|
| 448 | |
---|
| 449 | |
---|
[56] | 450 | // ==================================================================================================================== |
---|
| 451 | // Bit-depth |
---|
| 452 | // ==================================================================================================================== |
---|
[2] | 453 | |
---|
[56] | 454 | UInt g_uiBitDepth = 8; // base bit-depth |
---|
| 455 | UInt g_uiBitIncrement = 0; // increments |
---|
| 456 | UInt g_uiIBDI_MAX = 255; // max. value after IBDI |
---|
| 457 | UInt g_uiBASE_MAX = 255; // max. value before IBDI |
---|
| 458 | |
---|
| 459 | UInt g_uiPCMBitDepthLuma = 8; // PCM bit-depth |
---|
| 460 | UInt g_uiPCMBitDepthChroma = 8; // PCM bit-depth |
---|
| 461 | |
---|
| 462 | // ==================================================================================================================== |
---|
| 463 | // Depth model modes |
---|
| 464 | // ==================================================================================================================== |
---|
[5] | 465 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 466 | Int g_iDeltaDCsQuantOffset = 0; |
---|
| 467 | |
---|
[2] | 468 | const WedgeResolution g_aeWedgeResolutionList[5] = |
---|
| 469 | { |
---|
| 470 | HALF_PEL, // 4x4 |
---|
| 471 | HALF_PEL, // 8x8 |
---|
| 472 | FULL_PEL, // 16x16 |
---|
| 473 | DOUBLE_PEL, // 32x32 |
---|
| 474 | DOUBLE_PEL // 64x64 |
---|
| 475 | }; |
---|
| 476 | |
---|
| 477 | const UChar g_aucWedgeFullBitsListIdx[7] = |
---|
| 478 | { |
---|
| 479 | 0, // 2x2 |
---|
| 480 | 7, // 4x4 WedgeListSize[ HALF_PEL] 86 |
---|
| 481 | 10, // 8x8 WedgeListSize[ HALF_PEL] 782 |
---|
| 482 | 11, // 16x16 WedgeListSize[ FULL_PEL] 1394 |
---|
| 483 | 11, // 32x32 WedgeListSize[DOUBLE_PEL] 1503 |
---|
| 484 | 13, // 64x64 WedgeListSize[DOUBLE_PEL] 6079 |
---|
| 485 | 0 // 128x128 |
---|
| 486 | }; |
---|
| 487 | |
---|
[296] | 488 | #if LGE_DMM3_SIMP_C0044 |
---|
| 489 | const UChar g_aucWedgeTexPredBitsListIdx[7] = |
---|
| 490 | { |
---|
| 491 | 0, // 2x2 |
---|
| 492 | 6, // 4x4 |
---|
| 493 | 9, // 8x8 |
---|
| 494 | 9, // 16x16 |
---|
| 495 | 9, // 32x32 |
---|
| 496 | 0, // 64x64 |
---|
| 497 | 0 // 128x128 |
---|
| 498 | }; |
---|
| 499 | #endif |
---|
| 500 | |
---|
[2] | 501 | const UChar g_aucIntraSizeIdxToWedgeSize[7] = |
---|
| 502 | { |
---|
| 503 | 2, |
---|
| 504 | 4, |
---|
| 505 | 8, |
---|
| 506 | 16, |
---|
| 507 | 32, |
---|
| 508 | 64, |
---|
[56] | 509 | 128 |
---|
[2] | 510 | }; |
---|
| 511 | #endif |
---|
| 512 | |
---|
| 513 | // ==================================================================================================================== |
---|
[56] | 514 | // Misc. |
---|
[2] | 515 | // ==================================================================================================================== |
---|
| 516 | |
---|
| 517 | Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; |
---|
| 518 | |
---|
| 519 | #if ENC_DEC_TRACE |
---|
| 520 | FILE* g_hTrace = NULL; |
---|
| 521 | const Bool g_bEncDecTraceEnable = true; |
---|
| 522 | const Bool g_bEncDecTraceDisable = false; |
---|
| 523 | Bool g_bJustDoIt = false; |
---|
| 524 | UInt64 g_nSymbolCounter = 0; |
---|
| 525 | #endif |
---|
| 526 | // ==================================================================================================================== |
---|
| 527 | // Scanning order & context model mapping |
---|
| 528 | // ==================================================================================================================== |
---|
| 529 | |
---|
| 530 | // scanning order table |
---|
| 531 | UInt* g_auiFrameScanXY[ MAX_CU_DEPTH ]; |
---|
| 532 | UInt* g_auiFrameScanX [ MAX_CU_DEPTH ]; |
---|
| 533 | UInt* g_auiFrameScanY [ MAX_CU_DEPTH ]; |
---|
[56] | 534 | UInt* g_auiSigLastScan[4][ MAX_CU_DEPTH ]; |
---|
| 535 | UInt *g_sigScanNSQT[ 4 ]; // scan for non-square partitions |
---|
| 536 | UInt g_sigCGScanNSQT[ 4 ][ 16 ] = |
---|
| 537 | { |
---|
| 538 | { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
| 539 | { 0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 15 }, |
---|
| 540 | { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
| 541 | { 0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15 } |
---|
| 542 | }; |
---|
[2] | 543 | |
---|
[56] | 544 | const UInt g_sigLastScan8x8[ 4 ][ 4 ] = |
---|
[2] | 545 | { |
---|
[56] | 546 | {0, 1, 2, 3}, |
---|
| 547 | {0, 1, 2, 3}, |
---|
| 548 | {0, 1, 2, 3}, |
---|
| 549 | {0, 2, 1, 3} |
---|
[2] | 550 | }; |
---|
[56] | 551 | UInt g_sigLastScanCG32x32[ 64 ]; |
---|
[2] | 552 | |
---|
[56] | 553 | UInt* g_auiNonSquareSigLastScan[ 4 ]; |
---|
| 554 | |
---|
| 555 | const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24}; |
---|
| 556 | const UInt g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9}; |
---|
| 557 | const UInt g_uiLastCtx[ 28 ] = |
---|
[2] | 558 | { |
---|
[56] | 559 | 0, 1, 2, 2, // 4x4 4 |
---|
| 560 | 3, 4, 5, 5, 2, 2, // 8x8 6 |
---|
| 561 | 6, 7, 8, 8, 9, 9, 2, 2, // 16x16 8 |
---|
| 562 | 10, 11, 12, 12, 13, 13, 14, 14, 2, 2 // 32x32 10 |
---|
[2] | 563 | }; |
---|
| 564 | |
---|
[56] | 565 | // Rice parameters for absolute transform levels |
---|
| 566 | const UInt g_auiGoRiceRange[5] = |
---|
| 567 | { |
---|
| 568 | 7, 14, 26, 46, 78 |
---|
| 569 | }; |
---|
[2] | 570 | |
---|
[56] | 571 | const UInt g_auiGoRicePrefixLen[5] = |
---|
| 572 | { |
---|
| 573 | 8, 7, 6, 5, 4 |
---|
| 574 | }; |
---|
[2] | 575 | |
---|
[56] | 576 | const UInt g_aauiGoRiceUpdate[5][24] = |
---|
| 577 | { |
---|
| 578 | { |
---|
| 579 | 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
| 580 | }, |
---|
| 581 | { |
---|
| 582 | 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
| 583 | }, |
---|
| 584 | { |
---|
| 585 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
| 586 | }, |
---|
| 587 | { |
---|
| 588 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
| 589 | }, |
---|
| 590 | { |
---|
| 591 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 |
---|
| 592 | } |
---|
| 593 | }; |
---|
[2] | 594 | |
---|
| 595 | // initialize g_auiFrameScanXY |
---|
| 596 | Void initFrameScanXY( UInt* pBuff, UInt* pBuffX, UInt* pBuffY, Int iWidth, Int iHeight ) |
---|
| 597 | { |
---|
| 598 | Int x, y, c = 0; |
---|
| 599 | |
---|
| 600 | // starting point |
---|
| 601 | pBuffX[ c ] = 0; |
---|
| 602 | pBuffY[ c ] = 0; |
---|
| 603 | pBuff[ c++ ] = 0; |
---|
| 604 | |
---|
| 605 | // loop |
---|
| 606 | x=1; y=0; |
---|
| 607 | while (1) |
---|
| 608 | { |
---|
| 609 | // decrease loop |
---|
| 610 | while ( x>=0 ) |
---|
| 611 | { |
---|
| 612 | if ( x >= 0 && x < iWidth && y >= 0 && y < iHeight ) |
---|
| 613 | { |
---|
| 614 | pBuffX[ c ] = x; |
---|
| 615 | pBuffY[ c ] = y; |
---|
| 616 | pBuff[ c++ ] = x+y*iWidth; |
---|
| 617 | } |
---|
| 618 | x--; y++; |
---|
| 619 | } |
---|
| 620 | x=0; |
---|
| 621 | |
---|
| 622 | // increase loop |
---|
| 623 | while ( y>=0 ) |
---|
| 624 | { |
---|
| 625 | if ( x >= 0 && x < iWidth && y >= 0 && y < iHeight ) |
---|
| 626 | { |
---|
| 627 | pBuffX[ c ] = x; |
---|
| 628 | pBuffY[ c ] = y; |
---|
| 629 | pBuff[ c++ ] = x+y*iWidth; |
---|
| 630 | } |
---|
| 631 | x++; y--; |
---|
| 632 | } |
---|
| 633 | y=0; |
---|
| 634 | |
---|
| 635 | // termination condition |
---|
| 636 | if ( c >= iWidth*iHeight ) break; |
---|
[56] | 637 | } |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | Void initSigLastScan(UInt* pBuffZ, UInt* pBuffH, UInt* pBuffV, UInt* pBuffD, Int iWidth, Int iHeight, Int iDepth) |
---|
| 641 | { |
---|
| 642 | const UInt uiNumScanPos = UInt( iWidth * iWidth ); |
---|
| 643 | UInt uiNextScanPos = 0; |
---|
| 644 | |
---|
| 645 | if( iWidth < 16 ) |
---|
| 646 | { |
---|
| 647 | UInt* pBuffTemp = pBuffD; |
---|
| 648 | if( iWidth == 8 ) |
---|
| 649 | { |
---|
| 650 | pBuffTemp = g_sigLastScanCG32x32; |
---|
[2] | 651 | } |
---|
[56] | 652 | for( UInt uiScanLine = 0; uiNextScanPos < uiNumScanPos; uiScanLine++ ) |
---|
| 653 | { |
---|
| 654 | int iPrimDim = int( uiScanLine ); |
---|
| 655 | int iScndDim = 0; |
---|
| 656 | while( iPrimDim >= iWidth ) |
---|
| 657 | { |
---|
| 658 | iScndDim++; |
---|
| 659 | iPrimDim--; |
---|
| 660 | } |
---|
| 661 | while( iPrimDim >= 0 && iScndDim < iWidth ) |
---|
| 662 | { |
---|
| 663 | pBuffTemp[ uiNextScanPos ] = iPrimDim * iWidth + iScndDim ; |
---|
| 664 | uiNextScanPos++; |
---|
| 665 | iScndDim++; |
---|
| 666 | iPrimDim--; |
---|
| 667 | } |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | if( iWidth > 4 ) |
---|
| 671 | { |
---|
| 672 | UInt uiNumBlkSide = iWidth >> 2; |
---|
| 673 | UInt uiNumBlks = uiNumBlkSide * uiNumBlkSide; |
---|
| 674 | UInt log2Blk = g_aucConvertToBit[ uiNumBlkSide ] + 1; |
---|
| 675 | |
---|
| 676 | for( UInt uiBlk = 0; uiBlk < uiNumBlks; uiBlk++ ) |
---|
| 677 | { |
---|
| 678 | uiNextScanPos = 0; |
---|
| 679 | UInt initBlkPos = g_auiSigLastScan[ SCAN_DIAG ][ log2Blk ][ uiBlk ]; |
---|
| 680 | if( iWidth == 32 ) |
---|
| 681 | { |
---|
| 682 | initBlkPos = g_sigLastScanCG32x32[ uiBlk ]; |
---|
| 683 | } |
---|
| 684 | UInt offsetY = initBlkPos / uiNumBlkSide; |
---|
| 685 | UInt offsetX = initBlkPos - offsetY * uiNumBlkSide; |
---|
| 686 | UInt offsetD = 4 * ( offsetX + offsetY * iWidth ); |
---|
| 687 | UInt offsetScan = 16 * uiBlk; |
---|
| 688 | for( UInt uiScanLine = 0; uiNextScanPos < 16; uiScanLine++ ) |
---|
| 689 | { |
---|
| 690 | int iPrimDim = int( uiScanLine ); |
---|
| 691 | int iScndDim = 0; |
---|
| 692 | while( iPrimDim >= 4 ) |
---|
| 693 | { |
---|
| 694 | iScndDim++; |
---|
| 695 | iPrimDim--; |
---|
| 696 | } |
---|
| 697 | while( iPrimDim >= 0 && iScndDim < 4 ) |
---|
| 698 | { |
---|
| 699 | pBuffD[ uiNextScanPos + offsetScan ] = iPrimDim * iWidth + iScndDim + offsetD; |
---|
| 700 | uiNextScanPos++; |
---|
| 701 | iScndDim++; |
---|
| 702 | iPrimDim--; |
---|
| 703 | } |
---|
| 704 | } |
---|
| 705 | } |
---|
| 706 | } |
---|
[2] | 707 | |
---|
[56] | 708 | memcpy(pBuffZ, g_auiFrameScanXY[iDepth], sizeof(UInt)*iWidth*iHeight); |
---|
| 709 | |
---|
| 710 | UInt uiCnt = 0; |
---|
| 711 | for(Int iY=0; iY < iHeight; iY++) |
---|
[2] | 712 | { |
---|
[56] | 713 | for(Int iX=0; iX < iWidth; iX++) |
---|
[2] | 714 | { |
---|
[56] | 715 | pBuffH[uiCnt] = iY*iWidth + iX; |
---|
| 716 | uiCnt ++; |
---|
[2] | 717 | } |
---|
| 718 | } |
---|
[56] | 719 | |
---|
| 720 | uiCnt = 0; |
---|
| 721 | for(Int iX=0; iX < iWidth; iX++) |
---|
| 722 | { |
---|
| 723 | for(Int iY=0; iY < iHeight; iY++) |
---|
| 724 | { |
---|
| 725 | pBuffV[uiCnt] = iY*iWidth + iX; |
---|
| 726 | uiCnt ++; |
---|
| 727 | } |
---|
| 728 | } |
---|
[2] | 729 | } |
---|
| 730 | |
---|
[56] | 731 | Void initNonSquareSigLastScan(UInt* pBuffZ, UInt uiWidth, UInt uiHeight) |
---|
[2] | 732 | { |
---|
| 733 | |
---|
[56] | 734 | Int x, y, c = 0; |
---|
[2] | 735 | |
---|
[56] | 736 | // starting point |
---|
| 737 | pBuffZ[ c++ ] = 0; |
---|
| 738 | |
---|
| 739 | // loop |
---|
| 740 | if ( uiWidth > uiHeight ) |
---|
| 741 | { |
---|
| 742 | x=0; y=1; |
---|
| 743 | while (1) |
---|
[2] | 744 | { |
---|
[56] | 745 | // increase loop |
---|
| 746 | while ( y>=0 ) |
---|
[2] | 747 | { |
---|
[56] | 748 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
| 749 | { |
---|
| 750 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
| 751 | } |
---|
| 752 | x++; |
---|
| 753 | y--; |
---|
[2] | 754 | } |
---|
[56] | 755 | y=0; |
---|
| 756 | |
---|
| 757 | // decrease loop |
---|
| 758 | while ( x>=0 ) |
---|
| 759 | { |
---|
| 760 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
| 761 | { |
---|
| 762 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
| 763 | } |
---|
| 764 | x--; |
---|
| 765 | y++; |
---|
| 766 | } |
---|
| 767 | x=0; |
---|
| 768 | |
---|
| 769 | // termination condition |
---|
| 770 | if ( c >= uiWidth * uiHeight ) |
---|
| 771 | break; |
---|
[2] | 772 | } |
---|
[56] | 773 | } |
---|
| 774 | else |
---|
| 775 | { |
---|
| 776 | x=1; y=0; |
---|
| 777 | while (1) |
---|
[2] | 778 | { |
---|
[56] | 779 | // increase loop |
---|
| 780 | while ( x>=0 ) |
---|
[2] | 781 | { |
---|
[56] | 782 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
| 783 | { |
---|
| 784 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
| 785 | } |
---|
| 786 | x--; |
---|
| 787 | y++; |
---|
[2] | 788 | } |
---|
[56] | 789 | x=0; |
---|
| 790 | |
---|
| 791 | // decrease loop |
---|
| 792 | while ( y>=0 ) |
---|
| 793 | { |
---|
| 794 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
| 795 | { |
---|
| 796 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
| 797 | } |
---|
| 798 | x++; |
---|
| 799 | y--; |
---|
| 800 | } |
---|
| 801 | y=0; |
---|
| 802 | |
---|
| 803 | // termination condition |
---|
| 804 | if ( c >= uiWidth * uiHeight ) |
---|
| 805 | break; |
---|
[2] | 806 | } |
---|
[56] | 807 | } |
---|
[2] | 808 | } |
---|
| 809 | |
---|
[56] | 810 | Int g_quantIntraDefault4x4[16] = |
---|
[2] | 811 | { |
---|
[56] | 812 | 16,16,17,21, |
---|
| 813 | 16,17,20,25, |
---|
| 814 | 17,20,30,41, |
---|
| 815 | 21,25,41,70 |
---|
[2] | 816 | }; |
---|
[56] | 817 | Int g_quantInterDefault4x4[16] = |
---|
| 818 | { |
---|
| 819 | 16,16,17,21, |
---|
| 820 | 16,17,21,24, |
---|
| 821 | 17,21,24,36, |
---|
| 822 | 21,24,36,57 |
---|
| 823 | }; |
---|
| 824 | |
---|
| 825 | Int g_quantIntraDefault8x8[64] = |
---|
| 826 | { |
---|
| 827 | 16,16,16,16,17,18,21,24, |
---|
| 828 | 16,16,16,16,17,19,22,25, |
---|
| 829 | 16,16,17,18,20,22,25,29, |
---|
| 830 | 16,16,18,21,24,27,31,36, |
---|
| 831 | 17,17,20,24,30,35,41,47, |
---|
| 832 | 18,19,22,27,35,44,54,65, |
---|
| 833 | 21,22,25,31,41,54,70,88, |
---|
| 834 | 24,25,29,36,47,65,88,115 |
---|
| 835 | }; |
---|
| 836 | |
---|
| 837 | Int g_quantInterDefault8x8[64] = |
---|
| 838 | { |
---|
| 839 | 16,16,16,16,17,18,20,24, |
---|
| 840 | 16,16,16,17,18,20,24,25, |
---|
| 841 | 16,16,17,18,20,24,25,28, |
---|
| 842 | 16,17,18,20,24,25,28,33, |
---|
| 843 | 17,18,20,24,25,28,33,41, |
---|
| 844 | 18,20,24,25,28,33,41,54, |
---|
| 845 | 20,24,25,28,33,41,54,71, |
---|
| 846 | 24,25,28,33,41,54,71,91 |
---|
| 847 | }; |
---|
| 848 | UInt g_scalingListSize [4] = {16,64,256,1024}; |
---|
| 849 | UInt g_scalingListSizeX [4] = { 4, 8, 16, 32}; |
---|
| 850 | UInt g_scalingListNum[SCALING_LIST_SIZE_NUM]={6,6,6,2}; |
---|
| 851 | Int g_eTTable[4] = {0,3,1,2}; |
---|
[2] | 852 | |
---|
[5] | 853 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 854 | std::vector< std::vector<TComWedgelet> > g_aacWedgeLists; |
---|
| 855 | std::vector< std::vector<TComWedgeRef> > g_aacWedgeRefLists; |
---|
[2] | 856 | |
---|
[189] | 857 | std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3; |
---|
| 858 | std::vector< std::vector< TComWedgeNode> > g_aacWedgeNodeLists; |
---|
| 859 | |
---|
[2] | 860 | Void initWedgeLists() |
---|
| 861 | { |
---|
| 862 | for( UInt ui = g_aucConvertToBit[DMM_WEDGEMODEL_MIN_SIZE]; ui < (g_aucConvertToBit[DMM_WEDGEMODEL_MAX_SIZE]+1); ui++ ) |
---|
| 863 | { |
---|
| 864 | UInt uiWedgeBlockSize = ((UInt)DMM_WEDGEMODEL_MIN_SIZE)<<ui; |
---|
| 865 | std::vector<TComWedgelet> acWedgeList; |
---|
| 866 | std::vector<TComWedgeRef> acWedgeRefList; |
---|
| 867 | createWedgeList( uiWedgeBlockSize, uiWedgeBlockSize, acWedgeList, acWedgeRefList, g_aeWedgeResolutionList[ui] ); |
---|
| 868 | g_aacWedgeLists.push_back( acWedgeList ); |
---|
| 869 | g_aacWedgeRefLists.push_back( acWedgeRefList ); |
---|
[189] | 870 | |
---|
| 871 | // create WedgeNodeList |
---|
| 872 | std::vector<TComWedgeNode> acWedgeNodeList; |
---|
| 873 | for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ ) |
---|
| 874 | { |
---|
| 875 | if( acWedgeList[uiPos].getIsCoarse() ) |
---|
| 876 | { |
---|
| 877 | TComWedgeNode cWedgeNode; |
---|
| 878 | cWedgeNode.setPatternIdx( uiPos ); |
---|
| 879 | |
---|
| 880 | // set refinement idxs |
---|
| 881 | UInt uiRefPos = 0; |
---|
| 882 | for( Int iOffS = -1; iOffS <= 1; iOffS++ ) |
---|
| 883 | { |
---|
| 884 | for( Int iOffE = -1; iOffE <= 1; iOffE++ ) |
---|
| 885 | { |
---|
| 886 | if( iOffS == 0 && iOffE == 0 ) { continue; } |
---|
| 887 | |
---|
| 888 | Int iSx = (Int)acWedgeList[uiPos].getStartX(); |
---|
| 889 | Int iSy = (Int)acWedgeList[uiPos].getStartY(); |
---|
| 890 | Int iEx = (Int)acWedgeList[uiPos].getEndX(); |
---|
| 891 | Int iEy = (Int)acWedgeList[uiPos].getEndY(); |
---|
| 892 | |
---|
| 893 | switch( acWedgeList[uiPos].getOri() ) |
---|
| 894 | { |
---|
| 895 | case( 0 ): { iSx += iOffS; iEy += iOffE; } break; |
---|
| 896 | case( 1 ): { iSy += iOffS; iEx -= iOffE; } break; |
---|
| 897 | case( 2 ): { iSx -= iOffS; iEy -= iOffE; } break; |
---|
| 898 | case( 3 ): { iSy -= iOffS; iEx += iOffE; } break; |
---|
| 899 | case( 4 ): { iSx += iOffS; iEx += iOffE; } break; |
---|
| 900 | case( 5 ): { iSy += iOffS; iEy += iOffE; } break; |
---|
| 901 | default: assert( 0 ); |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | for( UInt k = 0; k < acWedgeRefList.size(); k++ ) |
---|
| 905 | { |
---|
| 906 | if( iSx == (Int)acWedgeRefList[k].getStartX() && |
---|
| 907 | iSy == (Int)acWedgeRefList[k].getStartY() && |
---|
| 908 | iEx == (Int)acWedgeRefList[k].getEndX() && |
---|
| 909 | iEy == (Int)acWedgeRefList[k].getEndY() ) |
---|
| 910 | { |
---|
| 911 | if( acWedgeRefList[k].getRefIdx() != cWedgeNode.getPatternIdx() ) |
---|
| 912 | { |
---|
| 913 | Bool bNew = true; |
---|
| 914 | for( UInt m = 0; m < uiRefPos; m++ ) { if( acWedgeRefList[k].getRefIdx() == cWedgeNode.getRefineIdx( m ) ) { bNew = false; break; } } |
---|
| 915 | |
---|
| 916 | if( bNew ) |
---|
| 917 | { |
---|
| 918 | cWedgeNode.setRefineIdx( acWedgeRefList[k].getRefIdx(), uiRefPos ); |
---|
| 919 | uiRefPos++; |
---|
| 920 | break; |
---|
| 921 | } |
---|
| 922 | } |
---|
| 923 | } |
---|
| 924 | } |
---|
| 925 | } |
---|
| 926 | } |
---|
| 927 | acWedgeNodeList.push_back( cWedgeNode ); |
---|
| 928 | } |
---|
| 929 | } |
---|
| 930 | g_aacWedgeNodeLists.push_back( acWedgeNodeList ); |
---|
[296] | 931 | |
---|
[2] | 932 | } |
---|
| 933 | return; |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes ) |
---|
| 937 | { |
---|
| 938 | assert( uiWidth == uiHeight ); |
---|
| 939 | |
---|
[77] | 940 | UChar uhStartX = 0, uhStartY = 0, uhEndX = 0, uhEndY = 0; |
---|
| 941 | Int iStepStartX = 0, iStepStartY = 0, iStepEndX = 0, iStepEndY = 0; |
---|
[56] | 942 | |
---|
[2] | 943 | UInt uiBlockSize = 0; |
---|
| 944 | switch( eWedgeRes ) |
---|
| 945 | { |
---|
| 946 | case( DOUBLE_PEL ): { uiBlockSize = (uiWidth>>1); break; } |
---|
| 947 | case( FULL_PEL ): { uiBlockSize = uiWidth; break; } |
---|
| 948 | case( HALF_PEL ): { uiBlockSize = (uiWidth<<1); break; } |
---|
| 949 | } |
---|
| 950 | |
---|
| 951 | TComWedgelet cTempWedgelet( uiWidth, uiHeight ); |
---|
| 952 | for( UInt uiOri = 0; uiOri < 6; uiOri++ ) |
---|
| 953 | { |
---|
| 954 | // init the edge line parameters for each of the 6 wedgelet types |
---|
| 955 | switch( uiOri ) |
---|
| 956 | { |
---|
| 957 | case( 0 ): { uhStartX = 0; uhStartY = 0; uhEndX = 0; uhEndY = 0; iStepStartX = +1; iStepStartY = 0; iStepEndX = 0; iStepEndY = +1; break; } |
---|
| 958 | case( 1 ): { uhStartX = (uiBlockSize-1); uhStartY = 0; uhEndX = (uiBlockSize-1); uhEndY = 0; iStepStartX = 0; iStepStartY = +1; iStepEndX = -1; iStepEndY = 0; break; } |
---|
| 959 | case( 2 ): { uhStartX = (uiBlockSize-1); uhStartY = (uiBlockSize-1); uhEndX = (uiBlockSize-1); uhEndY = (uiBlockSize-1); iStepStartX = -1; iStepStartY = 0; iStepEndX = 0; iStepEndY = -1; break; } |
---|
| 960 | case( 3 ): { uhStartX = 0; uhStartY = (uiBlockSize-1); uhEndX = 0; uhEndY = (uiBlockSize-1); iStepStartX = 0; iStepStartY = -1; iStepEndX = +1; iStepEndY = 0; break; } |
---|
| 961 | case( 4 ): { uhStartX = 0; uhStartY = 0; uhEndX = 0; uhEndY = (uiBlockSize-1); iStepStartX = +1; iStepStartY = 0; iStepEndX = +1; iStepEndY = 0; break; } |
---|
| 962 | case( 5 ): { uhStartX = (uiBlockSize-1); uhStartY = 0; uhEndX = 0; uhEndY = 0; iStepStartX = 0; iStepStartY = +1; iStepEndX = 0; iStepEndY = +1; break; } |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | for( Int iK = 0; iK < uiBlockSize; iK++ ) |
---|
| 966 | { |
---|
| 967 | for( Int iL = 0; iL < uiBlockSize; iL++ ) |
---|
[56] | 968 | { |
---|
[189] | 969 | cTempWedgelet.setWedgelet( uhStartX + (iK*iStepStartX) , uhStartY + (iK*iStepStartY), uhEndX + (iL*iStepEndX), uhEndY + (iL*iStepEndY), (UChar)uiOri, eWedgeRes, ((iL%2)==0 && (iK%2)==0) ); |
---|
[56] | 970 | addWedgeletToList( cTempWedgelet, racWedgeList, racWedgeRefList ); |
---|
| 971 | } |
---|
| 972 | } |
---|
| 973 | } |
---|
[189] | 974 | UInt uiThrSz = DMM3_SIMPLIFY_TR; |
---|
| 975 | |
---|
| 976 | std::vector< std::vector<UInt> > auiWdgListSz; |
---|
| 977 | for( Int idxM=2; idxM<=34 ; idxM++) |
---|
| 978 | { |
---|
| 979 | std::vector<UInt> auiWdgList; |
---|
| 980 | for( Int idxW=0; idxW<racWedgeList.size(); idxW++) |
---|
| 981 | { |
---|
| 982 | UInt uiAbsDiff = abs(idxM-(Int)racWedgeList[idxW].getAng()); |
---|
| 983 | if( uiAbsDiff <= uiThrSz ) |
---|
| 984 | { |
---|
| 985 | auiWdgList.push_back(idxW); |
---|
| 986 | } |
---|
| 987 | } |
---|
| 988 | auiWdgListSz.push_back(auiWdgList); |
---|
| 989 | } |
---|
| 990 | g_aauiWdgLstM3.push_back(auiWdgListSz); |
---|
[56] | 991 | } |
---|
[2] | 992 | |
---|
[56] | 993 | Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList ) |
---|
| 994 | { |
---|
| 995 | Bool bValid = cWedgelet.checkNotPlain(); |
---|
| 996 | if( bValid ) |
---|
| 997 | { |
---|
| 998 | for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ ) |
---|
| 999 | { |
---|
| 1000 | if( cWedgelet.checkIdentical( racWedgeList[uiPos].getPattern() ) ) |
---|
| 1001 | { |
---|
| 1002 | TComWedgeRef cWedgeRef; |
---|
| 1003 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos ); |
---|
| 1004 | racWedgeRefList.push_back( cWedgeRef ); |
---|
| 1005 | bValid = false; |
---|
| 1006 | return; |
---|
[2] | 1007 | } |
---|
| 1008 | } |
---|
| 1009 | } |
---|
[56] | 1010 | if( bValid ) |
---|
| 1011 | { |
---|
| 1012 | for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ ) |
---|
| 1013 | { |
---|
| 1014 | if( cWedgelet.checkInvIdentical( racWedgeList[uiPos].getPattern() ) ) |
---|
| 1015 | { |
---|
| 1016 | TComWedgeRef cWedgeRef; |
---|
| 1017 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos ); |
---|
| 1018 | racWedgeRefList.push_back( cWedgeRef ); |
---|
| 1019 | bValid = false; |
---|
| 1020 | return; |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | } |
---|
| 1024 | if( bValid ) |
---|
| 1025 | { |
---|
[296] | 1026 | cWedgelet.findClosetAngle(); |
---|
[56] | 1027 | racWedgeList.push_back( cWedgelet ); |
---|
| 1028 | TComWedgeRef cWedgeRef; |
---|
| 1029 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), (UInt)(racWedgeList.size()-1) ); |
---|
| 1030 | racWedgeRefList.push_back( cWedgeRef ); |
---|
| 1031 | } |
---|
[2] | 1032 | } |
---|
[296] | 1033 | #endif //HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 1034 | |
---|
| 1035 | //! \} |
---|