[313] | 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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 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 | */ |
---|
| 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 | |
---|
| 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
| 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; |
---|
[442] | 57 | for ( i=4; i<=MAX_CU_SIZE; i*=2 ) |
---|
[313] | 58 | { |
---|
| 59 | g_aucConvertToBit[ i ] = c; |
---|
| 60 | c++; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | c=2; |
---|
| 64 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
| 65 | { |
---|
| 66 | g_auiSigLastScan[0][i] = new UInt[ c*c ]; |
---|
| 67 | g_auiSigLastScan[1][i] = new UInt[ c*c ]; |
---|
| 68 | g_auiSigLastScan[2][i] = new UInt[ c*c ]; |
---|
| 69 | initSigLastScan( g_auiSigLastScan[0][i], g_auiSigLastScan[1][i], g_auiSigLastScan[2][i], c, c); |
---|
| 70 | |
---|
| 71 | c <<= 1; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | Void destroyROM() |
---|
| 76 | { |
---|
| 77 | for (Int i=0; i<MAX_CU_DEPTH; i++ ) |
---|
| 78 | { |
---|
| 79 | delete[] g_auiSigLastScan[0][i]; |
---|
| 80 | delete[] g_auiSigLastScan[1][i]; |
---|
| 81 | delete[] g_auiSigLastScan[2][i]; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // ==================================================================================================================== |
---|
| 86 | // Data structure related table & variable |
---|
| 87 | // ==================================================================================================================== |
---|
[595] | 88 | |
---|
[313] | 89 | UInt g_uiMaxCUWidth = MAX_CU_SIZE; |
---|
| 90 | UInt g_uiMaxCUHeight = MAX_CU_SIZE; |
---|
| 91 | UInt g_uiMaxCUDepth = MAX_CU_DEPTH; |
---|
| 92 | UInt g_uiAddCUDepth = 0; |
---|
| 93 | UInt g_auiZscanToRaster [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 94 | UInt g_auiRasterToZscan [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 95 | UInt g_auiRasterToPelX [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 96 | UInt g_auiRasterToPelY [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
| 97 | |
---|
| 98 | UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5}; |
---|
| 99 | |
---|
| 100 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ) |
---|
| 101 | { |
---|
| 102 | Int iStride = 1 << ( iMaxDepth - 1 ); |
---|
| 103 | |
---|
| 104 | if ( iDepth == iMaxDepth ) |
---|
| 105 | { |
---|
| 106 | rpuiCurrIdx[0] = uiStartVal; |
---|
| 107 | rpuiCurrIdx++; |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | Int iStep = iStride >> iDepth; |
---|
| 112 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal, rpuiCurrIdx ); |
---|
| 113 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep, rpuiCurrIdx ); |
---|
| 114 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride, rpuiCurrIdx ); |
---|
| 115 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx ); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
| 120 | { |
---|
| 121 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
| 122 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
| 123 | |
---|
| 124 | UInt uiNumPartInWidth = (UInt)uiMaxCUWidth / uiMinCUWidth; |
---|
| 125 | UInt uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight; |
---|
| 126 | |
---|
| 127 | for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
| 128 | { |
---|
| 129 | g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
| 134 | { |
---|
| 135 | UInt i; |
---|
| 136 | |
---|
| 137 | UInt* uiTempX = &g_auiRasterToPelX[0]; |
---|
| 138 | UInt* uiTempY = &g_auiRasterToPelY[0]; |
---|
| 139 | |
---|
| 140 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
| 141 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
| 142 | |
---|
| 143 | UInt uiNumPartInWidth = uiMaxCUWidth / uiMinCUWidth; |
---|
| 144 | UInt uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight; |
---|
| 145 | |
---|
| 146 | uiTempX[0] = 0; uiTempX++; |
---|
| 147 | for ( i = 1; i < uiNumPartInWidth; i++ ) |
---|
| 148 | { |
---|
| 149 | uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++; |
---|
| 150 | } |
---|
| 151 | for ( i = 1; i < uiNumPartInHeight; i++ ) |
---|
| 152 | { |
---|
| 153 | memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth); |
---|
| 154 | uiTempX += uiNumPartInWidth; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
| 158 | { |
---|
| 159 | uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth; |
---|
| 160 | } |
---|
| 161 | }; |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | Int g_quantScales[6] = |
---|
| 165 | { |
---|
| 166 | 26214,23302,20560,18396,16384,14564 |
---|
| 167 | }; |
---|
| 168 | |
---|
| 169 | Int g_invQuantScales[6] = |
---|
| 170 | { |
---|
| 171 | 40,45,51,57,64,72 |
---|
| 172 | }; |
---|
| 173 | |
---|
| 174 | const Short g_aiT4[4][4] = |
---|
| 175 | { |
---|
| 176 | { 64, 64, 64, 64}, |
---|
| 177 | { 83, 36,-36,-83}, |
---|
| 178 | { 64,-64,-64, 64}, |
---|
| 179 | { 36,-83, 83,-36} |
---|
| 180 | }; |
---|
| 181 | |
---|
| 182 | const Short g_aiT8[8][8] = |
---|
| 183 | { |
---|
| 184 | { 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
| 185 | { 89, 75, 50, 18,-18,-50,-75,-89}, |
---|
| 186 | { 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
| 187 | { 75,-18,-89,-50, 50, 89, 18,-75}, |
---|
| 188 | { 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
| 189 | { 50,-89, 18, 75,-75,-18, 89,-50}, |
---|
| 190 | { 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
| 191 | { 18,-50, 75,-89, 89,-75, 50,-18} |
---|
| 192 | }; |
---|
| 193 | |
---|
| 194 | const Short g_aiT16[16][16] = |
---|
| 195 | { |
---|
| 196 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
| 197 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90}, |
---|
| 198 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
| 199 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87}, |
---|
| 200 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
| 201 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80}, |
---|
| 202 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
| 203 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70}, |
---|
| 204 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
| 205 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57}, |
---|
| 206 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
| 207 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43}, |
---|
| 208 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
| 209 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25}, |
---|
| 210 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
| 211 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9} |
---|
| 212 | }; |
---|
| 213 | |
---|
| 214 | const Short g_aiT32[32][32] = |
---|
| 215 | { |
---|
| 216 | { 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}, |
---|
| 217 | { 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}, |
---|
| 218 | { 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}, |
---|
| 219 | { 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}, |
---|
| 220 | { 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}, |
---|
| 221 | { 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}, |
---|
| 222 | { 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}, |
---|
| 223 | { 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}, |
---|
| 224 | { 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}, |
---|
| 225 | { 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}, |
---|
| 226 | { 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}, |
---|
| 227 | { 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}, |
---|
| 228 | { 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}, |
---|
| 229 | { 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}, |
---|
| 230 | { 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}, |
---|
| 231 | { 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}, |
---|
| 232 | { 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}, |
---|
| 233 | { 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}, |
---|
| 234 | { 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}, |
---|
| 235 | { 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}, |
---|
| 236 | { 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}, |
---|
| 237 | { 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}, |
---|
| 238 | { 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}, |
---|
| 239 | { 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}, |
---|
| 240 | { 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}, |
---|
| 241 | { 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}, |
---|
| 242 | { 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}, |
---|
| 243 | { 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}, |
---|
| 244 | { 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}, |
---|
| 245 | { 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}, |
---|
| 246 | { 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}, |
---|
| 247 | { 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} |
---|
| 248 | }; |
---|
| 249 | |
---|
| 250 | const UChar g_aucChromaScale[58]= |
---|
| 251 | { |
---|
| 252 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, |
---|
| 253 | 17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32, |
---|
| 254 | 33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44, |
---|
| 255 | 45,46,47,48,49,50,51 |
---|
| 256 | }; |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | // Mode-Dependent DCT/DST |
---|
| 260 | const Short g_as_DST_MAT_4 [4][4]= |
---|
| 261 | { |
---|
| 262 | {29, 55, 74, 84}, |
---|
| 263 | {74, 74, 0 , -74}, |
---|
| 264 | {84, -29, -74, 55}, |
---|
| 265 | {55, -84, 74, -29}, |
---|
| 266 | }; |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | // ==================================================================================================================== |
---|
| 270 | // ADI |
---|
| 271 | // ==================================================================================================================== |
---|
| 272 | |
---|
| 273 | #if FAST_UDI_USE_MPM |
---|
[442] | 274 | const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] = |
---|
[313] | 275 | { |
---|
| 276 | 3, // 2x2 |
---|
| 277 | 8, // 4x4 |
---|
| 278 | 8, // 8x8 |
---|
| 279 | 3, // 16x16 |
---|
| 280 | 3, // 32x32 |
---|
[442] | 281 | 3 // 64x64 |
---|
[313] | 282 | }; |
---|
| 283 | #else // FAST_UDI_USE_MPM |
---|
[442] | 284 | const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] = |
---|
[313] | 285 | { |
---|
| 286 | 3, // 2x2 |
---|
| 287 | 9, // 4x4 |
---|
| 288 | 9, // 8x8 |
---|
| 289 | 4, // 16x16 33 |
---|
| 290 | 4, // 32x32 33 |
---|
[442] | 291 | 5 // 64x64 33 |
---|
[313] | 292 | }; |
---|
| 293 | #endif // FAST_UDI_USE_MPM |
---|
| 294 | |
---|
| 295 | // chroma |
---|
| 296 | |
---|
| 297 | const UChar g_aucConvertTxtTypeToIdx[4] = { 0, 1, 1, 2 }; |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | // ==================================================================================================================== |
---|
| 301 | // Bit-depth |
---|
| 302 | // ==================================================================================================================== |
---|
| 303 | |
---|
| 304 | Int g_bitDepthY = 8; |
---|
| 305 | Int g_bitDepthC = 8; |
---|
| 306 | |
---|
| 307 | UInt g_uiPCMBitDepthLuma = 8; // PCM bit-depth |
---|
| 308 | UInt g_uiPCMBitDepthChroma = 8; // PCM bit-depth |
---|
| 309 | |
---|
| 310 | // ==================================================================================================================== |
---|
| 311 | // Misc. |
---|
| 312 | // ==================================================================================================================== |
---|
| 313 | |
---|
| 314 | Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; |
---|
| 315 | |
---|
| 316 | #if ENC_DEC_TRACE |
---|
| 317 | FILE* g_hTrace = NULL; |
---|
| 318 | const Bool g_bEncDecTraceEnable = true; |
---|
| 319 | const Bool g_bEncDecTraceDisable = false; |
---|
| 320 | Bool g_HLSTraceEnable = true; |
---|
| 321 | Bool g_bJustDoIt = false; |
---|
| 322 | UInt64 g_nSymbolCounter = 0; |
---|
| 323 | #endif |
---|
| 324 | // ==================================================================================================================== |
---|
| 325 | // Scanning order & context model mapping |
---|
| 326 | // ==================================================================================================================== |
---|
| 327 | |
---|
| 328 | // scanning order table |
---|
| 329 | UInt* g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ]; |
---|
| 330 | |
---|
| 331 | const UInt g_sigLastScan8x8[ 3 ][ 4 ] = |
---|
| 332 | { |
---|
| 333 | {0, 2, 1, 3}, |
---|
| 334 | {0, 1, 2, 3}, |
---|
| 335 | {0, 2, 1, 3} |
---|
| 336 | }; |
---|
| 337 | UInt g_sigLastScanCG32x32[ 64 ]; |
---|
| 338 | |
---|
| 339 | const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24}; |
---|
| 340 | 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}; |
---|
| 341 | |
---|
| 342 | Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight) |
---|
| 343 | { |
---|
| 344 | const UInt uiNumScanPos = UInt( iWidth * iWidth ); |
---|
| 345 | UInt uiNextScanPos = 0; |
---|
| 346 | |
---|
| 347 | if( iWidth < 16 ) |
---|
| 348 | { |
---|
| 349 | UInt* pBuffTemp = pBuffD; |
---|
| 350 | if( iWidth == 8 ) |
---|
| 351 | { |
---|
| 352 | pBuffTemp = g_sigLastScanCG32x32; |
---|
| 353 | } |
---|
| 354 | for( UInt uiScanLine = 0; uiNextScanPos < uiNumScanPos; uiScanLine++ ) |
---|
| 355 | { |
---|
| 356 | Int iPrimDim = Int( uiScanLine ); |
---|
| 357 | Int iScndDim = 0; |
---|
| 358 | while( iPrimDim >= iWidth ) |
---|
| 359 | { |
---|
| 360 | iScndDim++; |
---|
| 361 | iPrimDim--; |
---|
| 362 | } |
---|
| 363 | while( iPrimDim >= 0 && iScndDim < iWidth ) |
---|
| 364 | { |
---|
| 365 | pBuffTemp[ uiNextScanPos ] = iPrimDim * iWidth + iScndDim ; |
---|
| 366 | uiNextScanPos++; |
---|
| 367 | iScndDim++; |
---|
| 368 | iPrimDim--; |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | if( iWidth > 4 ) |
---|
| 373 | { |
---|
| 374 | UInt uiNumBlkSide = iWidth >> 2; |
---|
| 375 | UInt uiNumBlks = uiNumBlkSide * uiNumBlkSide; |
---|
| 376 | UInt log2Blk = g_aucConvertToBit[ uiNumBlkSide ] + 1; |
---|
| 377 | |
---|
| 378 | for( UInt uiBlk = 0; uiBlk < uiNumBlks; uiBlk++ ) |
---|
| 379 | { |
---|
| 380 | uiNextScanPos = 0; |
---|
| 381 | UInt initBlkPos = g_auiSigLastScan[ SCAN_DIAG ][ log2Blk ][ uiBlk ]; |
---|
| 382 | if( iWidth == 32 ) |
---|
| 383 | { |
---|
| 384 | initBlkPos = g_sigLastScanCG32x32[ uiBlk ]; |
---|
| 385 | } |
---|
| 386 | UInt offsetY = initBlkPos / uiNumBlkSide; |
---|
| 387 | UInt offsetX = initBlkPos - offsetY * uiNumBlkSide; |
---|
| 388 | UInt offsetD = 4 * ( offsetX + offsetY * iWidth ); |
---|
| 389 | UInt offsetScan = 16 * uiBlk; |
---|
| 390 | for( UInt uiScanLine = 0; uiNextScanPos < 16; uiScanLine++ ) |
---|
| 391 | { |
---|
| 392 | Int iPrimDim = Int( uiScanLine ); |
---|
| 393 | Int iScndDim = 0; |
---|
| 394 | while( iPrimDim >= 4 ) |
---|
| 395 | { |
---|
| 396 | iScndDim++; |
---|
| 397 | iPrimDim--; |
---|
| 398 | } |
---|
| 399 | while( iPrimDim >= 0 && iScndDim < 4 ) |
---|
| 400 | { |
---|
| 401 | pBuffD[ uiNextScanPos + offsetScan ] = iPrimDim * iWidth + iScndDim + offsetD; |
---|
| 402 | uiNextScanPos++; |
---|
| 403 | iScndDim++; |
---|
| 404 | iPrimDim--; |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | UInt uiCnt = 0; |
---|
| 411 | if( iWidth > 2 ) |
---|
| 412 | { |
---|
| 413 | UInt numBlkSide = iWidth >> 2; |
---|
| 414 | for(Int blkY=0; blkY < numBlkSide; blkY++) |
---|
| 415 | { |
---|
| 416 | for(Int blkX=0; blkX < numBlkSide; blkX++) |
---|
| 417 | { |
---|
| 418 | UInt offset = blkY * 4 * iWidth + blkX * 4; |
---|
| 419 | for(Int y=0; y < 4; y++) |
---|
| 420 | { |
---|
| 421 | for(Int x=0; x < 4; x++) |
---|
| 422 | { |
---|
| 423 | pBuffH[uiCnt] = y*iWidth + x + offset; |
---|
| 424 | uiCnt ++; |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | uiCnt = 0; |
---|
| 431 | for(Int blkX=0; blkX < numBlkSide; blkX++) |
---|
| 432 | { |
---|
| 433 | for(Int blkY=0; blkY < numBlkSide; blkY++) |
---|
| 434 | { |
---|
| 435 | UInt offset = blkY * 4 * iWidth + blkX * 4; |
---|
| 436 | for(Int x=0; x < 4; x++) |
---|
| 437 | { |
---|
| 438 | for(Int y=0; y < 4; y++) |
---|
| 439 | { |
---|
| 440 | pBuffV[uiCnt] = y*iWidth + x + offset; |
---|
| 441 | uiCnt ++; |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | else |
---|
| 448 | { |
---|
| 449 | for(Int iY=0; iY < iHeight; iY++) |
---|
| 450 | { |
---|
| 451 | for(Int iX=0; iX < iWidth; iX++) |
---|
| 452 | { |
---|
| 453 | pBuffH[uiCnt] = iY*iWidth + iX; |
---|
| 454 | uiCnt ++; |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | uiCnt = 0; |
---|
| 459 | for(Int iX=0; iX < iWidth; iX++) |
---|
| 460 | { |
---|
| 461 | for(Int iY=0; iY < iHeight; iY++) |
---|
| 462 | { |
---|
| 463 | pBuffV[uiCnt] = iY*iWidth + iX; |
---|
| 464 | uiCnt ++; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | Int g_quantTSDefault4x4[16] = |
---|
| 471 | { |
---|
| 472 | 16,16,16,16, |
---|
| 473 | 16,16,16,16, |
---|
| 474 | 16,16,16,16, |
---|
| 475 | 16,16,16,16 |
---|
| 476 | }; |
---|
| 477 | |
---|
| 478 | Int g_quantIntraDefault8x8[64] = |
---|
| 479 | { |
---|
| 480 | 16,16,16,16,17,18,21,24, |
---|
| 481 | 16,16,16,16,17,19,22,25, |
---|
| 482 | 16,16,17,18,20,22,25,29, |
---|
| 483 | 16,16,18,21,24,27,31,36, |
---|
| 484 | 17,17,20,24,30,35,41,47, |
---|
| 485 | 18,19,22,27,35,44,54,65, |
---|
| 486 | 21,22,25,31,41,54,70,88, |
---|
| 487 | 24,25,29,36,47,65,88,115 |
---|
| 488 | }; |
---|
| 489 | |
---|
| 490 | Int g_quantInterDefault8x8[64] = |
---|
| 491 | { |
---|
| 492 | 16,16,16,16,17,18,20,24, |
---|
| 493 | 16,16,16,17,18,20,24,25, |
---|
| 494 | 16,16,17,18,20,24,25,28, |
---|
| 495 | 16,17,18,20,24,25,28,33, |
---|
| 496 | 17,18,20,24,25,28,33,41, |
---|
| 497 | 18,20,24,25,28,33,41,54, |
---|
| 498 | 20,24,25,28,33,41,54,71, |
---|
| 499 | 24,25,28,33,41,54,71,91 |
---|
| 500 | }; |
---|
| 501 | UInt g_scalingListSize [4] = {16,64,256,1024}; |
---|
| 502 | UInt g_scalingListSizeX [4] = { 4, 8, 16, 32}; |
---|
| 503 | UInt g_scalingListNum[SCALING_LIST_SIZE_NUM]={6,6,6,2}; |
---|
| 504 | Int g_eTTable[4] = {0,3,1,2}; |
---|
| 505 | |
---|
[442] | 506 | #if SVC_EXTENSION |
---|
[595] | 507 | #if FAST_INTRA_SHVC |
---|
| 508 | UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; |
---|
| 509 | UInt g_predefSetIntraModes[NUM_INTRA_MODE-1] = {26,10,18,34,2,22,14,30,6,24,12,28,8,20,16,32,4,17,19,15,21,13,23,11,25,9,27,7,29,5,31,3,33,0,2}; |
---|
| 510 | #endif |
---|
| 511 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
| 512 | Int g_bitDepthYLayer[MAX_LAYERS]; |
---|
| 513 | Int g_bitDepthCLayer[MAX_LAYERS]; |
---|
| 514 | |
---|
| 515 | UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS]; // PCM bit-depth |
---|
| 516 | UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS]; // PCM bit-depth |
---|
| 517 | #endif |
---|
| 518 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
| 519 | void * g_refWeightACDCParam; // type=wpACDCParam |
---|
| 520 | #endif |
---|
[313] | 521 | Int g_mvScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}}; |
---|
| 522 | Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}}; |
---|
[588] | 523 | |
---|
| 524 | std::string NaluToStr( NalUnitType nalu ) |
---|
| 525 | { |
---|
| 526 | switch( nalu ) |
---|
| 527 | { |
---|
| 528 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
| 529 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
| 530 | return "TRAIL"; |
---|
| 531 | |
---|
| 532 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
| 533 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
| 534 | return " TSA"; |
---|
| 535 | |
---|
| 536 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
| 537 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
| 538 | return " STSA"; |
---|
| 539 | |
---|
| 540 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
| 541 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
| 542 | return " RADL"; |
---|
| 543 | |
---|
| 544 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
| 545 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
| 546 | return " RASL"; |
---|
| 547 | |
---|
| 548 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
| 549 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
| 550 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
| 551 | return " BLA"; |
---|
| 552 | |
---|
| 553 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
| 554 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
| 555 | return " IDR"; |
---|
| 556 | |
---|
| 557 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
| 558 | return " CRA"; |
---|
| 559 | |
---|
| 560 | default: |
---|
| 561 | return " "; |
---|
| 562 | }; |
---|
| 563 | } |
---|
[595] | 564 | #if LAYER_CTB |
---|
| 565 | UInt g_auiLayerMaxCUWidth[MAX_LAYERS]; |
---|
| 566 | UInt g_auiLayerMaxCUHeight[MAX_LAYERS]; |
---|
| 567 | UInt g_auiLayerMaxCUDepth[MAX_LAYERS]; |
---|
| 568 | UInt g_auiLayerAddCUDepth[MAX_LAYERS]; |
---|
| 569 | UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 570 | UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 571 | UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 572 | UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
[313] | 573 | #endif |
---|
[595] | 574 | #endif //SVC_EXTENSION |
---|
[313] | 575 | |
---|
| 576 | //! \} |
---|