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 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
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 TComPic.cpp |
---|
35 | \brief picture class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TComPic.h" |
---|
39 | #include "SEI.h" |
---|
40 | |
---|
41 | //! \ingroup TLibCommon |
---|
42 | //! \{ |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / create / destroy |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | TComPic::TComPic() |
---|
49 | : m_uiTLayer (0) |
---|
50 | #if SVC_EXTENSION |
---|
51 | , m_layerId( 0 ) |
---|
52 | #endif |
---|
53 | , m_bUsedByCurr (false) |
---|
54 | , m_bIsLongTerm (false) |
---|
55 | , m_bIsUsedAsLongTerm (false) |
---|
56 | , m_apcPicSym (NULL) |
---|
57 | , m_pcPicYuvPred (NULL) |
---|
58 | , m_pcPicYuvResi (NULL) |
---|
59 | , m_bReconstructed (false) |
---|
60 | , m_bNeededForOutput (false) |
---|
61 | , m_uiCurrSliceIdx (0) |
---|
62 | , m_pSliceSUMap (NULL) |
---|
63 | , m_pbValidSlice (NULL) |
---|
64 | , m_sliceGranularityForNDBFilter (0) |
---|
65 | , m_bIndependentSliceBoundaryForNDBFilter (false) |
---|
66 | , m_bIndependentTileBoundaryForNDBFilter (false) |
---|
67 | , m_pNDBFilterYuvTmp (NULL) |
---|
68 | , m_bCheckLTMSB (false) |
---|
69 | { |
---|
70 | #if SVC_EXTENSION |
---|
71 | memset( m_pcFullPelBaseRec, NULL, sizeof( m_pcFullPelBaseRec ) ); |
---|
72 | memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) ); |
---|
73 | #endif |
---|
74 | m_apcPicYuv[0] = NULL; |
---|
75 | m_apcPicYuv[1] = NULL; |
---|
76 | } |
---|
77 | |
---|
78 | TComPic::~TComPic() |
---|
79 | { |
---|
80 | } |
---|
81 | #if SVC_UPSAMPLING |
---|
82 | Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, |
---|
83 | Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual) |
---|
84 | |
---|
85 | { |
---|
86 | m_apcPicSym = new TComPicSym; m_apcPicSym ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
87 | if (!bIsVirtual) |
---|
88 | { |
---|
89 | m_apcPicYuv[0] = new TComPicYuv; m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
90 | } |
---|
91 | m_apcPicYuv[1] = new TComPicYuv; m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
92 | |
---|
93 | for( Int i = 0; i < MAX_LAYERS; i++ ) |
---|
94 | { |
---|
95 | if( m_bSpatialEnhLayer[i] ) |
---|
96 | { |
---|
97 | m_pcFullPelBaseRec[i] = new TComPicYuv; m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | m_layerId = pcSps ? pcSps->getLayerId() : 0; |
---|
102 | |
---|
103 | // there are no SEI messages associated with this picture initially |
---|
104 | if (m_SEIs.size() > 0) |
---|
105 | { |
---|
106 | deleteSEIs (m_SEIs); |
---|
107 | } |
---|
108 | m_bUsedByCurr = false; |
---|
109 | |
---|
110 | /* store conformance window parameters with picture */ |
---|
111 | m_conformanceWindow = conformanceWindow; |
---|
112 | |
---|
113 | /* store display window parameters with picture */ |
---|
114 | m_defaultDisplayWindow = defaultDisplayWindow; |
---|
115 | |
---|
116 | /* store number of reorder pics with picture */ |
---|
117 | memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int)); |
---|
118 | |
---|
119 | return; |
---|
120 | } |
---|
121 | #else |
---|
122 | Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, |
---|
123 | Int *numReorderPics, Bool bIsVirtual) |
---|
124 | |
---|
125 | { |
---|
126 | m_apcPicSym = new TComPicSym; m_apcPicSym ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
127 | if (!bIsVirtual) |
---|
128 | { |
---|
129 | m_apcPicYuv[0] = new TComPicYuv; m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
130 | } |
---|
131 | m_apcPicYuv[1] = new TComPicYuv; m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
132 | |
---|
133 | // there are no SEI messages associated with this picture initially |
---|
134 | if (m_SEIs.size() > 0) |
---|
135 | { |
---|
136 | deleteSEIs (m_SEIs); |
---|
137 | } |
---|
138 | m_bUsedByCurr = false; |
---|
139 | |
---|
140 | /* store conformance window parameters with picture */ |
---|
141 | m_conformanceWindow = conformanceWindow; |
---|
142 | |
---|
143 | /* store display window parameters with picture */ |
---|
144 | m_defaultDisplayWindow = defaultDisplayWindow; |
---|
145 | |
---|
146 | /* store number of reorder pics with picture */ |
---|
147 | memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int)); |
---|
148 | |
---|
149 | return; |
---|
150 | } |
---|
151 | #endif |
---|
152 | |
---|
153 | Void TComPic::destroy() |
---|
154 | { |
---|
155 | if (m_apcPicSym) |
---|
156 | { |
---|
157 | m_apcPicSym->destroy(); |
---|
158 | delete m_apcPicSym; |
---|
159 | m_apcPicSym = NULL; |
---|
160 | } |
---|
161 | |
---|
162 | if (m_apcPicYuv[0]) |
---|
163 | { |
---|
164 | m_apcPicYuv[0]->destroy(); |
---|
165 | delete m_apcPicYuv[0]; |
---|
166 | m_apcPicYuv[0] = NULL; |
---|
167 | } |
---|
168 | |
---|
169 | if (m_apcPicYuv[1]) |
---|
170 | { |
---|
171 | m_apcPicYuv[1]->destroy(); |
---|
172 | delete m_apcPicYuv[1]; |
---|
173 | m_apcPicYuv[1] = NULL; |
---|
174 | } |
---|
175 | |
---|
176 | deleteSEIs(m_SEIs); |
---|
177 | #if SVC_EXTENSION && SVC_UPSAMPLING |
---|
178 | for( Int i = 0; i < MAX_LAYERS; i++ ) |
---|
179 | { |
---|
180 | if( m_bSpatialEnhLayer[i] ) |
---|
181 | { |
---|
182 | m_pcFullPelBaseRec[i]->destroy(); |
---|
183 | delete m_pcFullPelBaseRec[i]; |
---|
184 | m_pcFullPelBaseRec[i] = NULL; |
---|
185 | } |
---|
186 | } |
---|
187 | #endif |
---|
188 | } |
---|
189 | |
---|
190 | Void TComPic::compressMotion() |
---|
191 | { |
---|
192 | TComPicSym* pPicSym = getPicSym(); |
---|
193 | for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ ) |
---|
194 | { |
---|
195 | TComDataCU* pcCU = pPicSym->getCU(uiCUAddr); |
---|
196 | pcCU->compressMV(); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | /** Create non-deblocked filter information |
---|
201 | * \param pSliceStartAddress array for storing slice start addresses |
---|
202 | * \param numSlices number of slices in picture |
---|
203 | * \param sliceGranularityDepth slice granularity |
---|
204 | * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross". |
---|
205 | * \param numTiles number of tiles in picture |
---|
206 | * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross". |
---|
207 | */ |
---|
208 | Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth |
---|
209 | ,std::vector<Bool>* LFCrossSliceBoundary |
---|
210 | ,Int numTiles |
---|
211 | ,Bool bNDBFilterCrossTileBoundary) |
---|
212 | { |
---|
213 | UInt maxNumSUInLCU = getNumPartInCU(); |
---|
214 | UInt numLCUInPic = getNumCUsInFrame(); |
---|
215 | UInt picWidth = getSlice(0)->getSPS()->getPicWidthInLumaSamples(); |
---|
216 | UInt picHeight = getSlice(0)->getSPS()->getPicHeightInLumaSamples(); |
---|
217 | Int numLCUsInPicWidth = getFrameWidthInCU(); |
---|
218 | Int numLCUsInPicHeight= getFrameHeightInCU(); |
---|
219 | UInt maxNumSUInLCUWidth = getNumPartInWidth(); |
---|
220 | UInt maxNumSUInLCUHeight= getNumPartInHeight(); |
---|
221 | Int numSlices = (Int) sliceStartAddress.size() - 1; |
---|
222 | m_bIndependentSliceBoundaryForNDBFilter = false; |
---|
223 | if(numSlices > 1) |
---|
224 | { |
---|
225 | for(Int s=0; s< numSlices; s++) |
---|
226 | { |
---|
227 | if((*LFCrossSliceBoundary)[s] == false) |
---|
228 | { |
---|
229 | m_bIndependentSliceBoundaryForNDBFilter = true; |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | m_sliceGranularityForNDBFilter = sliceGranularityDepth; |
---|
234 | m_bIndependentTileBoundaryForNDBFilter = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false)); |
---|
235 | |
---|
236 | m_pbValidSlice = new Bool[numSlices]; |
---|
237 | for(Int s=0; s< numSlices; s++) |
---|
238 | { |
---|
239 | m_pbValidSlice[s] = true; |
---|
240 | } |
---|
241 | m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic]; |
---|
242 | |
---|
243 | //initialization |
---|
244 | for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ ) |
---|
245 | { |
---|
246 | m_pSliceSUMap[i] = -1; |
---|
247 | } |
---|
248 | for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ ) |
---|
249 | { |
---|
250 | TComDataCU* pcCU = getCU( CUAddr ); |
---|
251 | pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU)); |
---|
252 | pcCU->getNDBFilterBlocks()->clear(); |
---|
253 | } |
---|
254 | m_vSliceCUDataLink.clear(); |
---|
255 | |
---|
256 | m_vSliceCUDataLink.resize(numSlices); |
---|
257 | |
---|
258 | UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr; |
---|
259 | UInt LPelX, TPelY, LCUX, LCUY; |
---|
260 | UInt currSU; |
---|
261 | UInt startSU, endSU; |
---|
262 | |
---|
263 | for(Int s=0; s< numSlices; s++) |
---|
264 | { |
---|
265 | //1st step: decide the real start address |
---|
266 | startAddr = sliceStartAddress[s]; |
---|
267 | endAddr = sliceStartAddress[s+1] -1; |
---|
268 | |
---|
269 | startLCU = startAddr / maxNumSUInLCU; |
---|
270 | firstCUInStartLCU = startAddr % maxNumSUInLCU; |
---|
271 | |
---|
272 | endLCU = endAddr / maxNumSUInLCU; |
---|
273 | lastCUInEndLCU = endAddr % maxNumSUInLCU; |
---|
274 | |
---|
275 | uiAddr = m_apcPicSym->getCUOrderMap(startLCU); |
---|
276 | |
---|
277 | LCUX = getCU(uiAddr)->getCUPelX(); |
---|
278 | LCUY = getCU(uiAddr)->getCUPelY(); |
---|
279 | LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ]; |
---|
280 | TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ]; |
---|
281 | currSU = firstCUInStartLCU; |
---|
282 | |
---|
283 | Bool bMoveToNextLCU = false; |
---|
284 | Bool bSliceInOneLCU = (startLCU == endLCU); |
---|
285 | |
---|
286 | while(!( LPelX < picWidth ) || !( TPelY < picHeight )) |
---|
287 | { |
---|
288 | currSU ++; |
---|
289 | |
---|
290 | if(bSliceInOneLCU) |
---|
291 | { |
---|
292 | if(currSU > lastCUInEndLCU) |
---|
293 | { |
---|
294 | m_pbValidSlice[s] = false; |
---|
295 | break; |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | if(currSU >= maxNumSUInLCU ) |
---|
300 | { |
---|
301 | bMoveToNextLCU = true; |
---|
302 | break; |
---|
303 | } |
---|
304 | |
---|
305 | LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; |
---|
306 | TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; |
---|
307 | |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | if(!m_pbValidSlice[s]) |
---|
312 | { |
---|
313 | continue; |
---|
314 | } |
---|
315 | |
---|
316 | if(currSU != firstCUInStartLCU) |
---|
317 | { |
---|
318 | if(!bMoveToNextLCU) |
---|
319 | { |
---|
320 | firstCUInStartLCU = currSU; |
---|
321 | } |
---|
322 | else |
---|
323 | { |
---|
324 | startLCU++; |
---|
325 | firstCUInStartLCU = 0; |
---|
326 | assert( startLCU < getNumCUsInFrame()); |
---|
327 | } |
---|
328 | assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr); |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | //2nd step: assign NonDBFilterInfo to each processing block |
---|
333 | for(UInt i= startLCU; i <= endLCU; i++) |
---|
334 | { |
---|
335 | startSU = (i == startLCU)?(firstCUInStartLCU):(0); |
---|
336 | endSU = (i == endLCU )?(lastCUInEndLCU ):(maxNumSUInLCU -1); |
---|
337 | |
---|
338 | uiAddr = m_apcPicSym->getCUOrderMap(i); |
---|
339 | Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr); |
---|
340 | |
---|
341 | TComDataCU* pcCU = getCU(uiAddr); |
---|
342 | m_vSliceCUDataLink[s].push_back(pcCU); |
---|
343 | |
---|
344 | createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight); |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | //step 3: border availability |
---|
349 | for(Int s=0; s< numSlices; s++) |
---|
350 | { |
---|
351 | if(!m_pbValidSlice[s]) |
---|
352 | { |
---|
353 | continue; |
---|
354 | } |
---|
355 | |
---|
356 | for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++) |
---|
357 | { |
---|
358 | TComDataCU* pcCU = m_vSliceCUDataLink[s][i]; |
---|
359 | uiAddr = pcCU->getAddr(); |
---|
360 | |
---|
361 | if(pcCU->getPic()==0) |
---|
362 | { |
---|
363 | continue; |
---|
364 | } |
---|
365 | Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr); |
---|
366 | Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false; |
---|
367 | |
---|
368 | if(m_bIndependentTileBoundaryForNDBFilter) |
---|
369 | { |
---|
370 | //left |
---|
371 | if( uiAddr % numLCUsInPicWidth != 0) |
---|
372 | { |
---|
373 | bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false; |
---|
374 | } |
---|
375 | //right |
---|
376 | if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) ) |
---|
377 | { |
---|
378 | bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false; |
---|
379 | } |
---|
380 | //top |
---|
381 | if( uiAddr >= numLCUsInPicWidth) |
---|
382 | { |
---|
383 | bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) != iTileID )?true:false; |
---|
384 | } |
---|
385 | //down |
---|
386 | if( uiAddr + numLCUsInPicWidth < numLCUInPic ) |
---|
387 | { |
---|
388 | bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false; |
---|
389 | } |
---|
390 | |
---|
391 | } |
---|
392 | |
---|
393 | pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight |
---|
394 | , *LFCrossSliceBoundary |
---|
395 | ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary |
---|
396 | ,m_bIndependentTileBoundaryForNDBFilter); |
---|
397 | |
---|
398 | } |
---|
399 | |
---|
400 | } |
---|
401 | |
---|
402 | if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter) |
---|
403 | { |
---|
404 | m_pNDBFilterYuvTmp = new TComPicYuv(); |
---|
405 | m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); |
---|
406 | } |
---|
407 | |
---|
408 | } |
---|
409 | |
---|
410 | /** Create non-deblocked filter information for LCU |
---|
411 | * \param tileID tile index |
---|
412 | * \param sliceID slice index |
---|
413 | * \param pcCU CU data pointer |
---|
414 | * \param startSU start SU index in LCU |
---|
415 | * \param endSU end SU index in LCU |
---|
416 | * \param sliceGranularyDepth slice granularity |
---|
417 | * \param picWidth picture width |
---|
418 | * \param picHeight picture height |
---|
419 | */ |
---|
420 | Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight) |
---|
421 | { |
---|
422 | UInt LCUX = pcCU->getCUPelX(); |
---|
423 | UInt LCUY = pcCU->getCUPelY(); |
---|
424 | Int* pCUSliceMap = pcCU->getSliceSUMap(); |
---|
425 | UInt maxNumSUInLCU = getNumPartInCU(); |
---|
426 | UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1); |
---|
427 | UInt maxNumSUInLCUWidth = getNumPartInWidth(); |
---|
428 | UInt LPelX, TPelY; |
---|
429 | UInt currSU; |
---|
430 | |
---|
431 | |
---|
432 | //get the number of valid NBFilterBLock |
---|
433 | currSU = startSU; |
---|
434 | while(currSU <= endSU) |
---|
435 | { |
---|
436 | LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; |
---|
437 | TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; |
---|
438 | |
---|
439 | while(!( LPelX < picWidth ) || !( TPelY < picHeight )) |
---|
440 | { |
---|
441 | currSU += maxNumSUInSGU; |
---|
442 | if(currSU >= maxNumSUInLCU || currSU > endSU) |
---|
443 | { |
---|
444 | break; |
---|
445 | } |
---|
446 | LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; |
---|
447 | TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; |
---|
448 | } |
---|
449 | |
---|
450 | if(currSU >= maxNumSUInLCU || currSU > endSU) |
---|
451 | { |
---|
452 | break; |
---|
453 | } |
---|
454 | |
---|
455 | NDBFBlockInfo NDBFBlock; |
---|
456 | |
---|
457 | NDBFBlock.tileID = tileID; |
---|
458 | NDBFBlock.sliceID = sliceID; |
---|
459 | NDBFBlock.posY = TPelY; |
---|
460 | NDBFBlock.posX = LPelX; |
---|
461 | NDBFBlock.startSU = currSU; |
---|
462 | |
---|
463 | UInt uiLastValidSU = currSU; |
---|
464 | UInt uiIdx, uiLPelX_su, uiTPelY_su; |
---|
465 | for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++) |
---|
466 | { |
---|
467 | if(uiIdx > endSU) |
---|
468 | { |
---|
469 | break; |
---|
470 | } |
---|
471 | uiLPelX_su = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ]; |
---|
472 | uiTPelY_su = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ]; |
---|
473 | if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight )) |
---|
474 | { |
---|
475 | continue; |
---|
476 | } |
---|
477 | pCUSliceMap[uiIdx] = sliceID; |
---|
478 | uiLastValidSU = uiIdx; |
---|
479 | } |
---|
480 | NDBFBlock.endSU = uiLastValidSU; |
---|
481 | |
---|
482 | UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ]; |
---|
483 | UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU ]; |
---|
484 | NDBFBlock.widthSU = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1; |
---|
485 | NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1; |
---|
486 | NDBFBlock.width = NDBFBlock.widthSU * getMinCUWidth(); |
---|
487 | NDBFBlock.height = NDBFBlock.heightSU * getMinCUHeight(); |
---|
488 | |
---|
489 | pcCU->getNDBFilterBlocks()->push_back(NDBFBlock); |
---|
490 | |
---|
491 | currSU += maxNumSUInSGU; |
---|
492 | } |
---|
493 | |
---|
494 | } |
---|
495 | |
---|
496 | /** destroy non-deblocked filter information for LCU |
---|
497 | */ |
---|
498 | Void TComPic::destroyNonDBFilterInfo() |
---|
499 | { |
---|
500 | if(m_pbValidSlice != NULL) |
---|
501 | { |
---|
502 | delete[] m_pbValidSlice; |
---|
503 | m_pbValidSlice = NULL; |
---|
504 | } |
---|
505 | |
---|
506 | if(m_pSliceSUMap != NULL) |
---|
507 | { |
---|
508 | delete[] m_pSliceSUMap; |
---|
509 | m_pSliceSUMap = NULL; |
---|
510 | } |
---|
511 | for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ ) |
---|
512 | { |
---|
513 | TComDataCU* pcCU = getCU( CUAddr ); |
---|
514 | pcCU->getNDBFilterBlocks()->clear(); |
---|
515 | } |
---|
516 | |
---|
517 | if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter) |
---|
518 | { |
---|
519 | m_pNDBFilterYuvTmp->destroy(); |
---|
520 | delete m_pNDBFilterYuvTmp; |
---|
521 | m_pNDBFilterYuvTmp = NULL; |
---|
522 | } |
---|
523 | |
---|
524 | } |
---|
525 | |
---|
526 | #if REF_IDX_FRAMEWORK |
---|
527 | Void copyOnetoOnePicture( // SVC_NONCOLL |
---|
528 | Pel *in, |
---|
529 | Pel *out, |
---|
530 | Int nCols, |
---|
531 | Int nRows, |
---|
532 | Int fullRowWidth) |
---|
533 | { |
---|
534 | Int rX; |
---|
535 | |
---|
536 | for (rX = 0; rX < nRows; rX++) |
---|
537 | { |
---|
538 | memcpy( out, in, sizeof(Pel) * nCols ); |
---|
539 | in = in + fullRowWidth; |
---|
540 | out = out + fullRowWidth; |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | Void TComPic::copyUpsampledPictureYuv(TComPicYuv* pcPicYuvIn, TComPicYuv* pcPicYuvOut) |
---|
545 | { |
---|
546 | Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); |
---|
547 | Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1); |
---|
548 | |
---|
549 | copyOnetoOnePicture( |
---|
550 | pcPicYuvIn->getLumaAddr(), |
---|
551 | pcPicYuvOut->getLumaAddr(), |
---|
552 | pcPicYuvOut->getWidth(), |
---|
553 | pcPicYuvOut->getHeight(), |
---|
554 | upsampledRowWidthLuma); |
---|
555 | copyOnetoOnePicture( |
---|
556 | pcPicYuvIn->getCrAddr(), |
---|
557 | pcPicYuvOut->getCrAddr(), |
---|
558 | pcPicYuvOut->getWidth()>>1, |
---|
559 | pcPicYuvOut->getHeight()>>1, |
---|
560 | upsampledRowWidthCroma); |
---|
561 | copyOnetoOnePicture( |
---|
562 | pcPicYuvIn->getCbAddr(), |
---|
563 | pcPicYuvOut->getCbAddr(), |
---|
564 | pcPicYuvOut->getWidth()>>1, |
---|
565 | pcPicYuvOut->getHeight()>>1, |
---|
566 | upsampledRowWidthCroma); |
---|
567 | } |
---|
568 | |
---|
569 | #if REF_IDX_MFM |
---|
570 | Void TComPic::copyUpsampledMvField(TComPic* pcPicBase) |
---|
571 | { |
---|
572 | UInt refLayerIdc = pcPicBase->getLayerId(); |
---|
573 | #if AVC_SYNTAX && !ILP_DECODED_PICTURE |
---|
574 | const Window &confBL = pcPicBase->getConformanceWindow(); |
---|
575 | const Window &confEL = getPicYuvRec()->getConformanceWindow(); |
---|
576 | |
---|
577 | Int widthBL = pcPicBase->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset(); |
---|
578 | Int heightBL = pcPicBase->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset(); |
---|
579 | |
---|
580 | Int widthEL = getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset(); |
---|
581 | Int heightEL = getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset(); |
---|
582 | #endif |
---|
583 | |
---|
584 | UInt numPartitions = 1<<(g_uiMaxCUDepth<<1); |
---|
585 | UInt widthMinPU = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth); |
---|
586 | UInt heightMinPU = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth); |
---|
587 | Int unitNum = max (1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); |
---|
588 | |
---|
589 | for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++) //each LCU |
---|
590 | { |
---|
591 | TComDataCU* pcCUDes = getCU(cuIdx); |
---|
592 | |
---|
593 | for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum ) //each 16x16 unit |
---|
594 | { |
---|
595 | //pixel position of each unit in up-sampled layer |
---|
596 | UInt pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
---|
597 | UInt pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
---|
598 | UInt baseCUAddr, baseAbsPartIdx; |
---|
599 | |
---|
600 | TComDataCU *pcColCU = 0; |
---|
601 | pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx); |
---|
602 | |
---|
603 | #if AVC_SYNTAX && !ILP_DECODED_PICTURE |
---|
604 | Int xBL = ( (pelX + 8) * widthBL + widthEL/2 ) / widthEL; |
---|
605 | Int yBL = ( (pelY + 8) * heightBL+ heightEL/2 ) / heightEL; |
---|
606 | |
---|
607 | if( ( xBL < widthBL && yBL < heightBL ) && pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) ) //base layer unit not skip and invalid mode |
---|
608 | #else |
---|
609 | if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) ) //base layer unit not skip and invalid mode |
---|
610 | #endif |
---|
611 | { |
---|
612 | for(UInt refPicList = 0; refPicList < 2; refPicList++) //for each reference list |
---|
613 | { |
---|
614 | TComMvField sMvFieldBase, sMvField; |
---|
615 | pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase); |
---|
616 | pcCUDes->scaleBaseMV( sMvField, sMvFieldBase ); |
---|
617 | |
---|
618 | pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx); |
---|
619 | pcCUDes->setPredictionMode(absPartIdx, MODE_INTER); |
---|
620 | } |
---|
621 | } |
---|
622 | else |
---|
623 | { |
---|
624 | TComMvField zeroMvField; //zero MV and invalid reference index |
---|
625 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx); |
---|
626 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx); |
---|
627 | pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA); |
---|
628 | } |
---|
629 | |
---|
630 | for(UInt i = 1; i < unitNum; i++ ) |
---|
631 | { |
---|
632 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx + i); |
---|
633 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx + i); |
---|
634 | pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx)); |
---|
635 | } |
---|
636 | } |
---|
637 | memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(Char)*numPartitions); |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | Void TComPic::initUpsampledMvField() |
---|
642 | { |
---|
643 | UInt uiNumPartitions = 1<<(g_uiMaxCUDepth<<1); |
---|
644 | |
---|
645 | for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++) //each LCU |
---|
646 | { |
---|
647 | TComDataCU* pcCUDes = getCU(cuIdx); |
---|
648 | TComMvField zeroMvField; |
---|
649 | for(UInt list = 0; list < 2; list++) //each reference list |
---|
650 | { |
---|
651 | for(UInt i = 0; i < uiNumPartitions; i++ ) |
---|
652 | { |
---|
653 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i); |
---|
654 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i); |
---|
655 | pcCUDes->setPredictionMode(i, MODE_INTRA); |
---|
656 | pcCUDes->setPartitionSize(i, SIZE_2Nx2N); |
---|
657 | } |
---|
658 | } |
---|
659 | } |
---|
660 | return; |
---|
661 | } |
---|
662 | #endif |
---|
663 | #endif |
---|
664 | |
---|
665 | #if AVC_SYNTAX |
---|
666 | Void TComPic::readBLSyntax( fstream* filestream, UInt numBytes ) |
---|
667 | { |
---|
668 | if( !filestream->good() ) |
---|
669 | { |
---|
670 | return; |
---|
671 | } |
---|
672 | |
---|
673 | #if ILP_DECODED_PICTURE |
---|
674 | UInt width = this->getPicYuvRec()->getWidth(); |
---|
675 | UInt height = this->getPicYuvRec()->getHeight(); |
---|
676 | #else |
---|
677 | const Window &conf = this->getPicYuvRec()->getConformanceWindow(); |
---|
678 | UInt width = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset(); |
---|
679 | UInt height = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset(); |
---|
680 | #endif |
---|
681 | UInt64 poc = (UInt64)this->getPOC(); |
---|
682 | UInt partWidth = width / 4; |
---|
683 | UInt partHeight = height / 4; |
---|
684 | |
---|
685 | UInt numPartInWidth = this->getNumPartInWidth(); |
---|
686 | UInt numPartInHeight = this->getNumPartInHeight(); |
---|
687 | UInt numPartLCUInWidth = this->getFrameWidthInCU(); |
---|
688 | |
---|
689 | UInt64 uiPos = (UInt64)poc * width * height * numBytes / 16; |
---|
690 | |
---|
691 | filestream->seekg( uiPos, ios_base::beg ); |
---|
692 | |
---|
693 | for( Int i = 0; i < partHeight; i++ ) |
---|
694 | { |
---|
695 | for( Int j = 0; j < partWidth; j++ ) |
---|
696 | { |
---|
697 | UInt x = ( j / numPartInWidth ); |
---|
698 | UInt y = ( i / numPartInHeight ); |
---|
699 | |
---|
700 | UInt addrLCU = y * numPartLCUInWidth + x; |
---|
701 | UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth ); |
---|
702 | partAddr = g_auiRasterToZscan[partAddr]; |
---|
703 | |
---|
704 | TComDataCU* pcCU = this->getCU( addrLCU ); |
---|
705 | |
---|
706 | TComMv mv; |
---|
707 | Short temp; |
---|
708 | |
---|
709 | // RefIdxL0 |
---|
710 | Char refIdxL0 = -1; |
---|
711 | filestream->read( &refIdxL0, 1 ); |
---|
712 | assert( refIdxL0 >= -1 ); |
---|
713 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setRefIdx( (Int)refIdxL0, partAddr ); |
---|
714 | |
---|
715 | // RefIdxL1 |
---|
716 | Char refIdxL1 = -1; |
---|
717 | filestream->read( &refIdxL1, 1 ); |
---|
718 | assert( refIdxL1 >= -1 ); |
---|
719 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setRefIdx( (Int)refIdxL1, partAddr ); |
---|
720 | |
---|
721 | // MV L0 |
---|
722 | temp = 0; |
---|
723 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
724 | mv.setHor( (Short)temp ); |
---|
725 | temp = 0; |
---|
726 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
727 | mv.setVer( (Short)temp ); |
---|
728 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv, partAddr ); |
---|
729 | |
---|
730 | // MV L1 |
---|
731 | temp = 0; |
---|
732 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
733 | mv.setHor( (Short)temp ); |
---|
734 | temp = 0; |
---|
735 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
736 | mv.setVer( (Short)temp ); |
---|
737 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv, partAddr ); |
---|
738 | |
---|
739 | // set dependent information |
---|
740 | pcCU->setPredictionMode( partAddr, ( refIdxL0 == NOT_VALID && refIdxL1 == NOT_VALID ) ? MODE_INTRA : MODE_INTER ); |
---|
741 | UInt interDir = ( refIdxL0 != NOT_VALID ) + ( refIdxL1 != NOT_VALID && this->getSlice(0)->isInterB() ) * 2; |
---|
742 | assert( interDir <= 3 ); |
---|
743 | pcCU->setInterDir( partAddr, interDir ); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | #endif |
---|
748 | |
---|
749 | #if SYNTAX_OUTPUT |
---|
750 | Void TComPic::wrireBLSyntax( fstream* filestream, UInt numBytes ) |
---|
751 | { |
---|
752 | if( !filestream->good() ) |
---|
753 | { |
---|
754 | return; |
---|
755 | } |
---|
756 | |
---|
757 | #if ILP_DECODED_PICTURE |
---|
758 | UInt width = this->getPicYuvRec()->getWidth(); |
---|
759 | UInt height = this->getPicYuvRec()->getHeight(); |
---|
760 | #else |
---|
761 | const Window &conf = this->getConformanceWindow(); |
---|
762 | UInt width = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset(); |
---|
763 | UInt height = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset(); |
---|
764 | #endif |
---|
765 | |
---|
766 | UInt64 poc = (UInt64)this->getPOC(); |
---|
767 | UInt partWidth = width / 4; |
---|
768 | UInt partHeight = height / 4; |
---|
769 | |
---|
770 | UInt numPartInWidth = this->getNumPartInWidth(); |
---|
771 | UInt numPartInHeight = this->getNumPartInHeight(); |
---|
772 | UInt numPartLCUInWidth = this->getFrameWidthInCU(); |
---|
773 | |
---|
774 | filestream->seekg( poc * width * height * numBytes / 16 ); |
---|
775 | |
---|
776 | for( Int i = 0; i < partHeight; i++ ) |
---|
777 | { |
---|
778 | for( Int j = 0; j < partWidth; j++ ) |
---|
779 | { |
---|
780 | UInt x = ( j / numPartInWidth ); |
---|
781 | UInt y = ( i / numPartInHeight ); |
---|
782 | |
---|
783 | UInt addrLCU = y * numPartLCUInWidth + x; |
---|
784 | UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth ); |
---|
785 | partAddr = g_auiRasterToZscan[partAddr]; |
---|
786 | |
---|
787 | TComDataCU* pcCU = this->getCU( addrLCU ); |
---|
788 | |
---|
789 | TComMv mv; |
---|
790 | Short temp; |
---|
791 | Char refIdxL0 = NOT_VALID, refIdxL1 = NOT_VALID; |
---|
792 | |
---|
793 | // RefIdx |
---|
794 | if( !pcCU->isIntra( partAddr ) ) |
---|
795 | { |
---|
796 | refIdxL0 = (Char)pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( partAddr ); |
---|
797 | refIdxL1 = (Char)pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( partAddr ); |
---|
798 | } |
---|
799 | assert( refIdxL0 >= - 1 && refIdxL1 >= - 1 ); |
---|
800 | filestream->put( refIdxL0 ); |
---|
801 | filestream->put( refIdxL1 ); |
---|
802 | |
---|
803 | // MV L0 |
---|
804 | mv.setZero(); |
---|
805 | if( refIdxL0 >= 0 ) |
---|
806 | { |
---|
807 | mv = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( partAddr ); |
---|
808 | } |
---|
809 | temp = (Short)mv.getHor(); |
---|
810 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
811 | temp = (Short)mv.getVer(); |
---|
812 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
813 | |
---|
814 | // MV L1 |
---|
815 | mv.setZero(); |
---|
816 | if( refIdxL1 >= 0 ) |
---|
817 | { |
---|
818 | mv = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( partAddr ); |
---|
819 | } |
---|
820 | temp = (Short)mv.getHor(); |
---|
821 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
822 | temp = (Short)mv.getVer(); |
---|
823 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
824 | } |
---|
825 | } |
---|
826 | } |
---|
827 | #endif |
---|
828 | |
---|
829 | |
---|
830 | //! \} |
---|