[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 |
---|
[916] | 4 | * granted under this license. |
---|
[313] | 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 TDecGop.cpp |
---|
| 35 | \brief GOP decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecGop.h" |
---|
| 39 | #include "TDecCAVLC.h" |
---|
| 40 | #include "TDecSbac.h" |
---|
| 41 | #include "TDecBinCoder.h" |
---|
| 42 | #include "TDecBinCoderCABAC.h" |
---|
| 43 | #include "libmd5/MD5.h" |
---|
| 44 | #include "TLibCommon/SEI.h" |
---|
| 45 | #if SVC_EXTENSION |
---|
| 46 | #include "TDecTop.h" |
---|
[928] | 47 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 48 | #include <algorithm> |
---|
[313] | 49 | #endif |
---|
[928] | 50 | #endif |
---|
[313] | 51 | |
---|
| 52 | #include <time.h> |
---|
| 53 | |
---|
| 54 | extern Bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem |
---|
| 55 | |
---|
[928] | 56 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[931] | 57 | Bool pocCompareFunction( const TComPic &pic1, const TComPic &pic2 ) |
---|
[928] | 58 | { |
---|
[931] | 59 | return (const_cast<TComPic&>(pic1).getPOC() < const_cast<TComPic&>(pic2).getPOC()); |
---|
[928] | 60 | } |
---|
| 61 | #endif |
---|
| 62 | |
---|
[313] | 63 | //! \ingroup TLibDecoder |
---|
| 64 | //! \{ |
---|
[916] | 65 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI); |
---|
[856] | 66 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 67 | static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 ); |
---|
| 68 | static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI |
---|
| 69 | #endif |
---|
[313] | 70 | // ==================================================================================================================== |
---|
| 71 | // Constructor / destructor / initialization / destroy |
---|
| 72 | // ==================================================================================================================== |
---|
| 73 | |
---|
| 74 | TDecGop::TDecGop() |
---|
| 75 | { |
---|
| 76 | m_dDecTime = 0; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | TDecGop::~TDecGop() |
---|
| 80 | { |
---|
[916] | 81 | |
---|
[313] | 82 | } |
---|
| 83 | |
---|
| 84 | #if SVC_EXTENSION |
---|
| 85 | Void TDecGop::create(UInt layerId) |
---|
| 86 | { |
---|
| 87 | m_layerId = layerId; |
---|
| 88 | } |
---|
| 89 | #else |
---|
| 90 | Void TDecGop::create() |
---|
| 91 | { |
---|
[916] | 92 | |
---|
[313] | 93 | } |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | Void TDecGop::destroy() |
---|
| 97 | { |
---|
| 98 | } |
---|
[916] | 99 | |
---|
[313] | 100 | #if SVC_EXTENSION |
---|
[916] | 101 | Void TDecGop::init( TDecTop** ppcDecTop, |
---|
| 102 | TDecEntropy* pcEntropyDecoder, |
---|
[313] | 103 | #else |
---|
[916] | 104 | Void TDecGop::init( TDecEntropy* pcEntropyDecoder, |
---|
[313] | 105 | #endif |
---|
[916] | 106 | TDecSbac* pcSbacDecoder, |
---|
[313] | 107 | TDecBinCABAC* pcBinCABAC, |
---|
[916] | 108 | TDecCavlc* pcCavlcDecoder, |
---|
| 109 | TDecSlice* pcSliceDecoder, |
---|
[313] | 110 | TComLoopFilter* pcLoopFilter, |
---|
| 111 | TComSampleAdaptiveOffset* pcSAO |
---|
| 112 | ) |
---|
| 113 | { |
---|
| 114 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 115 | m_pcSbacDecoder = pcSbacDecoder; |
---|
| 116 | m_pcBinCABAC = pcBinCABAC; |
---|
| 117 | m_pcCavlcDecoder = pcCavlcDecoder; |
---|
| 118 | m_pcSliceDecoder = pcSliceDecoder; |
---|
| 119 | m_pcLoopFilter = pcLoopFilter; |
---|
| 120 | m_pcSAO = pcSAO; |
---|
| 121 | #if SVC_EXTENSION |
---|
| 122 | m_ppcTDecTop = ppcDecTop; |
---|
| 123 | #endif |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | // ==================================================================================================================== |
---|
| 128 | // Private member functions |
---|
| 129 | // ==================================================================================================================== |
---|
| 130 | // ==================================================================================================================== |
---|
| 131 | // Public member functions |
---|
| 132 | // ==================================================================================================================== |
---|
| 133 | |
---|
[916] | 134 | Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic) |
---|
[313] | 135 | { |
---|
[916] | 136 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[313] | 137 | // Table of extracted substreams. |
---|
| 138 | // These must be deallocated AND their internal fifos, too. |
---|
| 139 | TComInputBitstream **ppcSubstreams = NULL; |
---|
| 140 | |
---|
| 141 | //-- For time output for each slice |
---|
[916] | 142 | clock_t iBeforeTime = clock(); |
---|
[313] | 143 | m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); |
---|
| 144 | m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); |
---|
| 145 | |
---|
[916] | 146 | const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1; |
---|
| 147 | // const UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumberOfSubstreamSizes()+1 : pcSlice->getPPS()->getNumSubstreams(); |
---|
[313] | 148 | |
---|
| 149 | // init each couple {EntropyDecoder, Substream} |
---|
| 150 | ppcSubstreams = new TComInputBitstream*[uiNumSubstreams]; |
---|
| 151 | for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ ) |
---|
| 152 | { |
---|
[916] | 153 | ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft()); |
---|
[313] | 154 | } |
---|
| 155 | |
---|
[916] | 156 | m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder); |
---|
[313] | 157 | // deallocate all created substreams, including internal buffers. |
---|
| 158 | for (UInt ui = 0; ui < uiNumSubstreams; ui++) |
---|
| 159 | { |
---|
| 160 | ppcSubstreams[ui]->deleteFifo(); |
---|
| 161 | delete ppcSubstreams[ui]; |
---|
| 162 | } |
---|
| 163 | delete[] ppcSubstreams; |
---|
| 164 | |
---|
| 165 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 166 | } |
---|
| 167 | |
---|
[916] | 168 | Void TDecGop::filterPicture(TComPic* pcPic) |
---|
[313] | 169 | { |
---|
[916] | 170 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[313] | 171 | |
---|
| 172 | //-- For time output for each slice |
---|
[916] | 173 | clock_t iBeforeTime = clock(); |
---|
[313] | 174 | |
---|
| 175 | // deblocking filter |
---|
| 176 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 177 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
[916] | 178 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 179 | |
---|
[313] | 180 | if( pcSlice->getSPS()->getUseSAO() ) |
---|
| 181 | { |
---|
[916] | 182 | m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam()); |
---|
| 183 | m_pcSAO->SAOProcess(pcPic); |
---|
| 184 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
[313] | 185 | } |
---|
[916] | 186 | |
---|
| 187 | pcPic->compressMotion(); |
---|
[313] | 188 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
| 189 | if (!pcSlice->isReferenced()) c += 32; |
---|
| 190 | |
---|
| 191 | //-- For time output for each slice |
---|
| 192 | #if SVC_EXTENSION |
---|
[921] | 193 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP%3d ) ", pcSlice->getPOC(), |
---|
[916] | 194 | pcPic->getLayerId(), |
---|
[313] | 195 | pcSlice->getTLayer(), |
---|
| 196 | c, |
---|
[588] | 197 | NaluToStr( pcSlice->getNalUnitType() ).data(), |
---|
[313] | 198 | pcSlice->getSliceQp() ); |
---|
| 199 | #else |
---|
[916] | 200 | printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(), |
---|
| 201 | pcSlice->getTLayer(), |
---|
| 202 | c, |
---|
| 203 | pcSlice->getSliceQp() ); |
---|
| 204 | |
---|
[313] | 205 | #endif |
---|
| 206 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 207 | printf ("[DT %6.3f] ", m_dDecTime ); |
---|
| 208 | m_dDecTime = 0; |
---|
| 209 | |
---|
| 210 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 211 | { |
---|
| 212 | printf ("[L%d ", iRefList); |
---|
| 213 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 214 | { |
---|
[442] | 215 | #if SVC_EXTENSION |
---|
| 216 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
[313] | 217 | if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) ) |
---|
| 218 | { |
---|
[840] | 219 | UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId(); |
---|
[890] | 220 | UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId); |
---|
[840] | 221 | assert( g_posScalingFactor[refLayerIdc][0] ); |
---|
| 222 | assert( g_posScalingFactor[refLayerIdc][1] ); |
---|
| 223 | |
---|
[841] | 224 | printf( "%d(%d, {%1.2f, %1.2f}x)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), refLayerId, 65536.0/g_posScalingFactor[refLayerIdc][0], 65536.0/g_posScalingFactor[refLayerIdc][1] ); |
---|
[313] | 225 | } |
---|
| 226 | else |
---|
[442] | 227 | { |
---|
| 228 | printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
| 229 | } |
---|
[313] | 230 | #endif |
---|
[442] | 231 | if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() ) |
---|
| 232 | { |
---|
| 233 | printf( "c" ); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | printf( " " ); |
---|
| 237 | #else |
---|
[313] | 238 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
[442] | 239 | #endif |
---|
[313] | 240 | } |
---|
| 241 | printf ("] "); |
---|
| 242 | } |
---|
| 243 | if (m_decodedPictureHashSEIEnabled) |
---|
| 244 | { |
---|
[916] | 245 | SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH ); |
---|
[313] | 246 | const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL; |
---|
| 247 | if (pictureHashes.size() > 1) |
---|
| 248 | { |
---|
| 249 | printf ("Warning: Got multiple decoded picture hash SEI messages. Using first."); |
---|
| 250 | } |
---|
[916] | 251 | calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash); |
---|
[313] | 252 | } |
---|
[928] | 253 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 254 | if( this->getLayerDec(pcPic->getLayerId())->getConfModeFlag() ) |
---|
| 255 | { |
---|
| 256 | // Add this reconstructed picture to the parallel buffer. |
---|
| 257 | std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerId()))->getConfListPic(); |
---|
| 258 | thisLayerBuffer->push_back(*pcPic); |
---|
| 259 | std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction ); |
---|
| 260 | } |
---|
| 261 | #endif |
---|
[856] | 262 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 263 | if (m_colourRemapSEIEnabled) |
---|
| 264 | { |
---|
[916] | 265 | SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO ); |
---|
[856] | 266 | const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL; |
---|
| 267 | if (colourRemappingInfo.size() > 1) |
---|
| 268 | { |
---|
| 269 | printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first."); |
---|
| 270 | } |
---|
[916] | 271 | applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfo |
---|
[856] | 272 | #if SVC_EXTENSION |
---|
[916] | 273 | , pcPic->getLayerId() |
---|
[856] | 274 | #endif |
---|
| 275 | ); |
---|
| 276 | } |
---|
| 277 | #endif |
---|
[313] | 278 | |
---|
[916] | 279 | printf("\n"); |
---|
| 280 | |
---|
| 281 | pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false); |
---|
| 282 | pcPic->setReconMark(true); |
---|
[313] | 283 | } |
---|
| 284 | |
---|
| 285 | /** |
---|
| 286 | * Calculate and print hash for pic, compare to picture_digest SEI if |
---|
| 287 | * present in seis. seis may be NULL. Hash is printed to stdout, in |
---|
| 288 | * a manner suitable for the status line. Theformat is: |
---|
| 289 | * [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)] |
---|
| 290 | * Where, x..x is the hash |
---|
| 291 | * yyy has the following meanings: |
---|
| 292 | * OK - calculated hash matches the SEI message |
---|
| 293 | * ***ERROR*** - calculated hash does not match the SEI message |
---|
| 294 | * unk - no SEI message was available for comparison |
---|
| 295 | */ |
---|
[916] | 296 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI) |
---|
[313] | 297 | { |
---|
| 298 | /* calculate MD5sum for entire reconstructed picture */ |
---|
[916] | 299 | TComDigest recon_digest; |
---|
[313] | 300 | Int numChar=0; |
---|
| 301 | const Char* hashType = "\0"; |
---|
| 302 | |
---|
| 303 | if (pictureHashSEI) |
---|
| 304 | { |
---|
| 305 | switch (pictureHashSEI->method) |
---|
| 306 | { |
---|
[916] | 307 | case SEIDecodedPictureHash::MD5: |
---|
| 308 | { |
---|
| 309 | hashType = "MD5"; |
---|
| 310 | numChar = calcMD5(pic, recon_digest); |
---|
| 311 | break; |
---|
| 312 | } |
---|
| 313 | case SEIDecodedPictureHash::CRC: |
---|
| 314 | { |
---|
| 315 | hashType = "CRC"; |
---|
| 316 | numChar = calcCRC(pic, recon_digest); |
---|
| 317 | break; |
---|
| 318 | } |
---|
| 319 | case SEIDecodedPictureHash::CHECKSUM: |
---|
| 320 | { |
---|
| 321 | hashType = "Checksum"; |
---|
| 322 | numChar = calcChecksum(pic, recon_digest); |
---|
| 323 | break; |
---|
| 324 | } |
---|
| 325 | default: |
---|
| 326 | { |
---|
| 327 | assert (!"unknown hash type"); |
---|
| 328 | break; |
---|
| 329 | } |
---|
[313] | 330 | } |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | /* compare digest against received version */ |
---|
| 334 | const Char* ok = "(unk)"; |
---|
| 335 | Bool mismatch = false; |
---|
| 336 | |
---|
| 337 | if (pictureHashSEI) |
---|
| 338 | { |
---|
| 339 | ok = "(OK)"; |
---|
[916] | 340 | if (recon_digest != pictureHashSEI->m_digest) |
---|
[313] | 341 | { |
---|
[916] | 342 | ok = "(***ERROR***)"; |
---|
| 343 | mismatch = true; |
---|
[313] | 344 | } |
---|
| 345 | } |
---|
| 346 | |
---|
[916] | 347 | printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar).c_str(), ok); |
---|
[313] | 348 | |
---|
| 349 | if (mismatch) |
---|
| 350 | { |
---|
| 351 | g_md5_mismatch = true; |
---|
[916] | 352 | printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->m_digest, numChar).c_str()); |
---|
[313] | 353 | } |
---|
| 354 | } |
---|
[856] | 355 | |
---|
| 356 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 357 | Void xInitColourRemappingLut( const Int bitDepthY, const Int bitDepthC, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI ) |
---|
| 358 | { |
---|
| 359 | for ( Int c=0 ; c<3 ; c++ ) |
---|
| 360 | { |
---|
| 361 | Int bitDepth = c ? bitDepthC : bitDepthY ; |
---|
| 362 | preLut[c].resize(1 << bitDepth); |
---|
[868] | 363 | postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth); |
---|
[856] | 364 | |
---|
[868] | 365 | Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth; |
---|
| 366 | Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth) |
---|
[856] | 367 | if( bitDepthDiff<0 ) |
---|
[868] | 368 | printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth); |
---|
| 369 | bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth; |
---|
| 370 | Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth) |
---|
[856] | 371 | if( bitDepthDiff<0 ) |
---|
[868] | 372 | printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth); |
---|
[856] | 373 | |
---|
| 374 | //Fill preLut |
---|
| 375 | for ( Int k=0 ; k<(1<<bitDepth) ; k++ ) |
---|
| 376 | { |
---|
| 377 | Int iSample = k << iShift1 ; |
---|
| 378 | for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ ) |
---|
| 379 | { |
---|
[868] | 380 | Int iCodedPrev = pCriSEI->m_preLutCodedValue[c][iPivot] << iShift2; //Coded in CRInputBitdepth |
---|
| 381 | Int iCodedNext = pCriSEI->m_preLutCodedValue[c][iPivot+1] << iShift2; //Coded in CRInputBitdepth |
---|
| 382 | Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot]; //Coded in CRBitdepth |
---|
| 383 | Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth |
---|
[856] | 384 | if ( iCodedPrev <= iSample && iSample <= iCodedNext ) |
---|
| 385 | { |
---|
| 386 | Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev); |
---|
| 387 | preLut[c][k] = (Int)( 0.5f + fInterpol ); |
---|
| 388 | iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1; |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | //Fill postLut |
---|
[868] | 394 | for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ ) |
---|
[856] | 395 | { |
---|
| 396 | Int iSample = k; |
---|
| 397 | for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ ) |
---|
| 398 | { |
---|
[868] | 399 | Int iCodedPrev = pCriSEI->m_postLutCodedValue[c][iPivot]; //Coded in CRBitdepth |
---|
| 400 | Int iCodedNext = pCriSEI->m_postLutCodedValue[c][iPivot+1]; //Coded in CRBitdepth |
---|
| 401 | Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot]; //Coded in CRBitdepth |
---|
| 402 | Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth |
---|
[856] | 403 | if ( iCodedPrev <= iSample && iSample <= iCodedNext ) |
---|
| 404 | { |
---|
| 405 | Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ; |
---|
| 406 | postLut[c][k] = (Int)( 0.5f + fInterpol ); |
---|
| 407 | iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1; |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
[916] | 414 | static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId ) |
---|
[856] | 415 | { |
---|
| 416 | if( !storeCriSEI.size() ) |
---|
| 417 | #if SVC_EXTENSION |
---|
| 418 | storeCriSEI.resize(MAX_LAYERS); |
---|
| 419 | #else |
---|
| 420 | storeCriSEI.resize(1); |
---|
| 421 | #endif |
---|
| 422 | |
---|
| 423 | if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management) |
---|
| 424 | storeCriSEI[layerId] = *pCriSEI; |
---|
| 425 | |
---|
| 426 | if( !storeCriSEI[layerId].m_colourRemapCancelFlag ) |
---|
| 427 | { |
---|
[916] | 428 | Int iHeight = pic.getHeight(COMPONENT_Y); |
---|
| 429 | Int iWidth = pic.getWidth(COMPONENT_Y); |
---|
| 430 | Int iStride = pic.getStride(COMPONENT_Y); |
---|
| 431 | Int iCStride = pic.getStride(COMPONENT_Cb); |
---|
[856] | 432 | |
---|
| 433 | Pel *YUVIn[3], *YUVOut[3]; |
---|
[916] | 434 | YUVIn[0] = pic.getAddr(COMPONENT_Y); |
---|
| 435 | YUVIn[1] = pic.getAddr(COMPONENT_Cb); |
---|
| 436 | YUVIn[2] = pic.getAddr(COMPONENT_Cr); |
---|
[856] | 437 | |
---|
| 438 | TComPicYuv picColourRemapped; |
---|
| 439 | #if SVC_EXTENSION |
---|
[916] | 440 | picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL ); |
---|
[856] | 441 | #else |
---|
[916] | 442 | picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
[856] | 443 | #endif |
---|
[916] | 444 | YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y); |
---|
| 445 | YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb); |
---|
| 446 | YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr); |
---|
[856] | 447 | |
---|
| 448 | #if SVC_EXTENSION |
---|
[916] | 449 | Int bitDepthY = g_bitDepthLayer[CHANNEL_TYPE_LUMA][layerId]; |
---|
| 450 | Int bitDepthC = g_bitDepthLayer[CHANNEL_TYPE_CHROMA][layerId]; |
---|
[856] | 451 | |
---|
[916] | 452 | assert( g_bitDepth[CHANNEL_TYPE_LUMA] == bitDepthY ); |
---|
| 453 | assert( g_bitDepth[CHANNEL_TYPE_CHROMA] == bitDepthC ); |
---|
[856] | 454 | #else |
---|
[916] | 455 | Int bitDepthY = g_bitDepth[CHANNEL_TYPE_LUMA]; |
---|
| 456 | Int bitDepthC = g_bitDepth[CHANNEL_TYPE_CHROMA]; |
---|
[856] | 457 | #endif |
---|
| 458 | |
---|
| 459 | std::vector<Int> preLut[3]; |
---|
| 460 | std::vector<Int> postLut[3]; |
---|
| 461 | xInitColourRemappingLut( bitDepthY, bitDepthC, preLut, postLut, &storeCriSEI[layerId] ); |
---|
| 462 | |
---|
| 463 | Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1)); |
---|
| 464 | |
---|
| 465 | for( Int y = 0; y < iHeight ; y++ ) |
---|
| 466 | { |
---|
| 467 | for( Int x = 0; x < iWidth ; x++ ) |
---|
| 468 | { |
---|
| 469 | Int YUVPre[3], YUVMat[3]; |
---|
| 470 | YUVPre[0] = preLut[0][ YUVIn[0][x] ]; |
---|
| 471 | YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ]; |
---|
| 472 | YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ]; |
---|
| 473 | |
---|
| 474 | YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0] |
---|
| 475 | + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1] |
---|
| 476 | + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2] |
---|
| 477 | + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom ); |
---|
[868] | 478 | YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] ); |
---|
[856] | 479 | YUVOut[0][x] = postLut[0][ YUVMat[0] ]; |
---|
| 480 | |
---|
| 481 | if( (y&1) && (x&1) ) |
---|
| 482 | { |
---|
| 483 | for(Int c=1 ; c<3 ; c++) |
---|
| 484 | { |
---|
| 485 | YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0] |
---|
| 486 | + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1] |
---|
| 487 | + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2] |
---|
| 488 | + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom ); |
---|
[868] | 489 | YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] ); |
---|
[856] | 490 | YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ]; |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | YUVIn[0] += iStride; |
---|
| 495 | YUVOut[0] += iStride; |
---|
| 496 | if( y&1 ) |
---|
| 497 | { |
---|
| 498 | YUVIn[1] += iCStride; |
---|
| 499 | YUVIn[2] += iCStride; |
---|
| 500 | YUVOut[1] += iCStride; |
---|
| 501 | YUVOut[2] += iCStride; |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | //Write remapped picture in decoding order |
---|
| 506 | Char cTemp[255]; |
---|
[868] | 507 | sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth ); |
---|
| 508 | picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth ); |
---|
[856] | 509 | |
---|
| 510 | picColourRemapped.destroy(); |
---|
| 511 | |
---|
| 512 | storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | #endif |
---|
[313] | 516 | //! \} |
---|