Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2019, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file TEncHash.cpp
\brief hash encoder class
*/
#include "CommonLib/dtrace_codingstruct.h"
#include "CommonLib/Picture.h"
#include "CommonLib/UnitTools.h"
#include "Hash.h"
// ====================================================================================================================
// Constructor / destructor / create / destroy
// ====================================================================================================================
int TComHash::m_blockSizeToIndex[65][65];
TCRCCalculatorLight TComHash::m_crcCalculator1(24, 0x5D6DCB);
TCRCCalculatorLight TComHash::m_crcCalculator2(24, 0x864CFB);
TCRCCalculatorLight::TCRCCalculatorLight(uint32_t bits, uint32_t truncPoly)
{
m_remainder = 0;
m_bits = bits;
m_truncPoly = truncPoly;
m_finalResultMask = (1 << bits) - 1;
xInitTable();
}
TCRCCalculatorLight::~TCRCCalculatorLight()
{
}
void TCRCCalculatorLight::xInitTable()
{
const uint32_t highBit = 1 << (m_bits - 1);
const uint32_t byteHighBit = 1 << (8 - 1);
for (uint32_t value = 0; value < 256; value++)
for (unsigned char mask = byteHighBit; mask != 0; mask >>= 1)
{
if (value & mask)
{
remainder ^= highBit;
}
if (remainder & highBit)
{
remainder <<= 1;
remainder ^= m_truncPoly;
}
else
{
remainder <<= 1;
}
}
m_table[value] = remainder;
}
}
void TCRCCalculatorLight::processData(unsigned char* curData, uint32_t dataLength)
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
unsigned char index = (m_remainder >> (m_bits - 8)) ^ curData[i];
m_remainder <<= 8;
m_remainder ^= m_table[index];
}
}
TComHash::TComHash()
{
m_lookupTable = NULL;
tableHasContent = false;
}
TComHash::~TComHash()
{
clearAll();
if (m_lookupTable != NULL)
{
delete[] m_lookupTable;
m_lookupTable = NULL;
}
}
void TComHash::create()
{
if (m_lookupTable != NULL)
{
clearAll();
return;
}
int maxAddr = 1 << (m_CRCBits + m_blockSizeBits);
m_lookupTable = new std::vector<BlockHash>*[maxAddr];
memset(m_lookupTable, 0, sizeof(std::vector<BlockHash>*) * maxAddr);
tableHasContent = false;
}
void TComHash::clearAll()
{
tableHasContent = false;
if (m_lookupTable == NULL)
{
return;
}
int maxAddr = 1 << (m_CRCBits + m_blockSizeBits);
for (int i = 0; i < maxAddr; i++)
{
if (m_lookupTable[i] != NULL)
{
delete m_lookupTable[i];
m_lookupTable[i] = NULL;
}
}
}
void TComHash::addToTable(uint32_t hashValue, const BlockHash& blockHash)
{
if (m_lookupTable[hashValue] == NULL)
{
m_lookupTable[hashValue] = new std::vector<BlockHash>;
m_lookupTable[hashValue]->push_back(blockHash);
}
else
{
m_lookupTable[hashValue]->push_back(blockHash);
}
}
{
if (m_lookupTable[hashValue] == NULL)
{
return 0;
}
else
{
return static_cast<int>(m_lookupTable[hashValue]->size());
}
}
int TComHash::count(uint32_t hashValue) const
{
if (m_lookupTable[hashValue] == NULL)
{
return 0;
}
else
{
return static_cast<int>(m_lookupTable[hashValue]->size());
}
}
MapIterator TComHash::getFirstIterator(uint32_t hashValue)
{
return m_lookupTable[hashValue]->begin();
}
const MapIterator TComHash::getFirstIterator(uint32_t hashValue) const
{
return m_lookupTable[hashValue]->begin();
}
bool TComHash::hasExactMatch(uint32_t hashValue1, uint32_t hashValue2)
{
if (m_lookupTable[hashValue1] == NULL)
{
return false;
}
std::vector<BlockHash>::iterator it;
for (it = m_lookupTable[hashValue1]->begin(); it != m_lookupTable[hashValue1]->end(); it++)
{
if ((*it).hashValue2 == hashValue2)
{
return true;
}
}
return false;
}
void TComHash::generateBlock2x2HashValue(const PelUnitBuf &curPicBuf, int picWidth, int picHeight, const BitDepths bitDepths, uint32_t* picBlockHash[2], bool* picBlockSameInfo[3])
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{
const int width = 2;
const int height = 2;
int xEnd = picWidth - width + 1;
int yEnd = picHeight - height + 1;
int length = width * 2;
bool includeChroma = false;
if ((curPicBuf).chromaFormat == CHROMA_444)
{
length *= 3;
includeChroma = true;
}
unsigned char* p = new unsigned char[length];
int pos = 0;
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
TComHash::getPixelsIn1DCharArrayByBlock2x2(curPicBuf, p, xPos, yPos, bitDepths, includeChroma);
picBlockSameInfo[0][pos] = isBlock2x2RowSameValue(p, includeChroma);
picBlockSameInfo[1][pos] = isBlock2x2ColSameValue(p, includeChroma);
picBlockHash[0][pos] = TComHash::getCRCValue1(p, length * sizeof(unsigned char));
picBlockHash[1][pos] = TComHash::getCRCValue2(p, length * sizeof(unsigned char));
pos++;
}
pos += width - 1;
}
delete[] p;
}
void TComHash::generateRectangleHashValue(int picWidth, int picHeight, int width, int height, uint32_t* srcPicBlockHash[2], uint32_t* dstPicBlockHash[2], bool* srcPicBlockSameInfo[3], bool* dstPicBlockSameInfo[3])
{
//at present, only support 1:2(2:1) retangle hash value
CHECK(width != (height << 1) && (width << 1) != height, "Wrong")
bool isHorizontal = width == (height << 1) ? true : false;
int xEnd = picWidth - width + 1;
int yEnd = picHeight - height + 1;
int srcWidth = width >> 1;
int quadWidth = width >> 2;
int srcHeight = height >> 1;
int quadHeight = height >> 2;
int length = 2 * sizeof(uint32_t);
uint32_t* p = new uint32_t[2];
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
int pos = 0;
if (isHorizontal)
{
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
p[0] = srcPicBlockHash[0][pos];
p[1] = srcPicBlockHash[0][pos + srcWidth];
dstPicBlockHash[0][pos] = TComHash::getCRCValue1((unsigned char*)p, length);
p[0] = srcPicBlockHash[1][pos];
p[1] = srcPicBlockHash[1][pos + srcWidth];
dstPicBlockHash[1][pos] = TComHash::getCRCValue2((unsigned char*)p, length);
dstPicBlockSameInfo[0][pos] = srcPicBlockSameInfo[0][pos] && srcPicBlockSameInfo[0][pos + quadWidth] && srcPicBlockSameInfo[0][pos + srcWidth];
dstPicBlockSameInfo[1][pos] = srcPicBlockSameInfo[1][pos] && srcPicBlockSameInfo[1][pos + srcWidth];
pos++;
}
pos += width - 1;
}
}
else
{
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
p[0] = srcPicBlockHash[0][pos];
p[1] = srcPicBlockHash[0][pos + srcHeight * picWidth];
dstPicBlockHash[0][pos] = TComHash::getCRCValue1((unsigned char*)p, length);
p[0] = srcPicBlockHash[1][pos];
p[1] = srcPicBlockHash[1][pos + srcHeight * picWidth];
dstPicBlockHash[1][pos] = TComHash::getCRCValue2((unsigned char*)p, length);
dstPicBlockSameInfo[0][pos] = srcPicBlockSameInfo[0][pos] && srcPicBlockSameInfo[0][pos + srcHeight * picWidth];
dstPicBlockSameInfo[1][pos] = srcPicBlockSameInfo[1][pos] && srcPicBlockSameInfo[1][pos + quadHeight * picWidth] && srcPicBlockSameInfo[1][pos + srcHeight * picWidth];
pos++;
}
pos += width - 1;
}
}
int widthMinus1 = width - 1;
int heightMinus1 = height - 1;
pos = 0;
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
dstPicBlockSameInfo[2][pos] = (!dstPicBlockSameInfo[0][pos] && !dstPicBlockSameInfo[1][pos]) || (((xPos & widthMinus1) == 0) && ((yPos & heightMinus1) == 0));
pos++;
}
pos += width - 1;
}
delete[] p;
}
void TComHash::generateBlockHashValue(int picWidth, int picHeight, int width, int height, uint32_t* srcPicBlockHash[2], uint32_t* dstPicBlockHash[2], bool* srcPicBlockSameInfo[3], bool* dstPicBlockSameInfo[3])
{
int xEnd = picWidth - width + 1;
int yEnd = picHeight - height + 1;
int srcWidth = width >> 1;
int quadWidth = width >> 2;
int srcHeight = height >> 1;
int quadHeight = height >> 2;
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
int pos = 0;
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
p[0] = srcPicBlockHash[0][pos];
p[1] = srcPicBlockHash[0][pos + srcWidth];
p[2] = srcPicBlockHash[0][pos + srcHeight * picWidth];
p[3] = srcPicBlockHash[0][pos + srcHeight * picWidth + srcWidth];
dstPicBlockHash[0][pos] = TComHash::getCRCValue1((unsigned char*)p, length);
p[0] = srcPicBlockHash[1][pos];
p[1] = srcPicBlockHash[1][pos + srcWidth];
p[2] = srcPicBlockHash[1][pos + srcHeight * picWidth];
p[3] = srcPicBlockHash[1][pos + srcHeight * picWidth + srcWidth];
dstPicBlockHash[1][pos] = TComHash::getCRCValue2((unsigned char*)p, length);
dstPicBlockSameInfo[0][pos] = srcPicBlockSameInfo[0][pos] && srcPicBlockSameInfo[0][pos + quadWidth] && srcPicBlockSameInfo[0][pos + srcWidth]
&& srcPicBlockSameInfo[0][pos + srcHeight * picWidth] && srcPicBlockSameInfo[0][pos + srcHeight * picWidth + quadWidth] && srcPicBlockSameInfo[0][pos + srcHeight * picWidth + srcWidth];
dstPicBlockSameInfo[1][pos] = srcPicBlockSameInfo[1][pos] && srcPicBlockSameInfo[1][pos + srcWidth] && srcPicBlockSameInfo[1][pos + quadHeight * picWidth]
&& srcPicBlockSameInfo[1][pos + quadHeight * picWidth + srcWidth] && srcPicBlockSameInfo[1][pos + srcHeight * picWidth] && srcPicBlockSameInfo[1][pos + srcHeight * picWidth + srcWidth];
pos++;
}
pos += width - 1;
}
if (width >= 4)
{
int widthMinus1 = width - 1;
int heightMinus1 = height - 1;
pos = 0;
for (int yPos = 0; yPos < yEnd; yPos++)
{
for (int xPos = 0; xPos < xEnd; xPos++)
{
dstPicBlockSameInfo[2][pos] = (!dstPicBlockSameInfo[0][pos] && !dstPicBlockSameInfo[1][pos]) || (((xPos & widthMinus1) == 0) && ((yPos & heightMinus1) == 0));
pos++;
}
pos += width - 1;
}
}
delete[] p;
}
void TComHash::addToHashMapByRowWithPrecalData(uint32_t* picHash[2], bool* picIsSame, int picWidth, int picHeight, int width, int height)
{
int xEnd = picWidth - width + 1;
int yEnd = picHeight - height + 1;
bool* srcIsAdded = picIsSame;
uint32_t* srcHash[2] = { picHash[0], picHash[1] };
int addValue = m_blockSizeToIndex[width][height];
CHECK(addValue < 0, "Wrong")
int crcMask = 1 << m_CRCBits;
crcMask -= 1;
for (int xPos = 0; xPos < xEnd; xPos++)
{
for (int yPos = 0; yPos < yEnd; yPos++)
{
int pos = yPos * picWidth + xPos;
//valid data
if (srcIsAdded[pos])
{
BlockHash blockHash;
blockHash.x = xPos;
blockHash.y = yPos;
uint32_t hashValue1 = (srcHash[0][pos] & crcMask) + addValue;
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
blockHash.hashValue2 = srcHash[1][pos];
addToTable(hashValue1, blockHash);
}
}
}
}
void TComHash::getPixelsIn1DCharArrayByBlock2x2(const PelUnitBuf &curPicBuf, unsigned char* pixelsIn1D, int xStart, int yStart, const BitDepths& bitDepths, bool includeAllComponent)
{
ChromaFormat fmt = (curPicBuf).chromaFormat;
if (fmt != CHROMA_444)
{
includeAllComponent = false;
}
if (bitDepths.recon[CHANNEL_TYPE_LUMA] == 8 && bitDepths.recon[CHANNEL_TYPE_CHROMA] == 8)
{
Pel* curPel[3];
int stride[3];
for (int id = 0; id < 3; id++)
{
ComponentID compID = ComponentID(id);
stride[id] = (curPicBuf).get(compID).stride;
curPel[id] = (curPicBuf).get(compID).buf;
curPel[id] += (yStart >> getComponentScaleY(compID, fmt)) * stride[id] + (xStart >> getComponentScaleX(compID, fmt));
}
int index = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[0][j]);
if (includeAllComponent)
{
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[1][j]);
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[2][j]);
}
}
curPel[0] += stride[0];
if (includeAllComponent)
{
curPel[1] += stride[1];
curPel[2] += stride[2];
}
}
}
else
{
int shift = bitDepths.recon[CHANNEL_TYPE_LUMA] - 8;
int shiftc = bitDepths.recon[CHANNEL_TYPE_CHROMA] - 8;
Pel* curPel[3];
int stride[3];
for (int id = 0; id < 3; id++)
{
ComponentID compID = ComponentID(id);
stride[id] = (curPicBuf).get(compID).stride;
curPel[id] = (curPicBuf).get(compID).buf;
curPel[id] += (yStart >> getComponentScaleY(compID, fmt)) * stride[id] + (xStart >> getComponentScaleX(compID, fmt));
}
int index = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[0][j] >> shift);
if (includeAllComponent)
{
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[1][j] >> shiftc);
pixelsIn1D[index++] = static_cast<unsigned char>(curPel[2][j] >> shiftc);
}
}
curPel[0] += stride[0];
if (includeAllComponent)
{
curPel[1] += stride[1];
curPel[2] += stride[2];
}
}
}
}
bool TComHash::isBlock2x2RowSameValue(unsigned char* p, bool includeAllComponent)
{
if (includeAllComponent)
{
if (p[0] != p[3] || p[6] != p[9])
{
return false;
}
if (p[1] != p[4] || p[7] != p[10])
{
return false;
}
if (p[2] != p[5] || p[8] != p[11])
{
return false;
}
}
else
{
if (p[0] != p[1] || p[2] != p[3])
{
return false;
}
}
return true;
}
bool TComHash::isBlock2x2ColSameValue(unsigned char* p, bool includeAllComponent)
{
if (includeAllComponent)
{
if (p[0] != p[6] || p[3] != p[9])
{
return false;
}
if (p[1] != p[7] || p[4] != p[10])
{
return false;
}
if (p[2] != p[8] || p[5] != p[11])
{
return false;
}
}
else
{
if ((p[0] != p[2]) || (p[1] != p[3]))
{
return false;
}
}
return true;
}
bool TComHash::getBlockHashValue(const PelUnitBuf &curPicBuf, int width, int height, int xStart, int yStart, const BitDepths bitDepths, uint32_t& hashValue1, uint32_t& hashValue2)
{
int addValue = m_blockSizeToIndex[width][height];
CHECK(addValue < 0, "Wrong")
addValue <<= m_CRCBits;
int crcMask = 1 << m_CRCBits;
crcMask -= 1;
int length = 4;
bool includeChroma = false;
if ((curPicBuf).chromaFormat == CHROMA_444)
{
length *= 3;
includeChroma = true;
}
unsigned char* p = new unsigned char[length];
int block2x2Num = (width*height) >> 2;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
hashValueBuffer[i][j] = new uint32_t[block2x2Num];
}
}
//2x2 subblock hash values in current CU
int subBlockInWidth = (width >> 1);
int subBlockInHeight = (height >> 1);
for (int yPos = 0; yPos < height; yPos += 2)
{
for (int xPos = 0; xPos < width; xPos += 2)
{
int pos = (yPos >> 1)*subBlockInWidth + (xPos >> 1);
TComHash::getPixelsIn1DCharArrayByBlock2x2(curPicBuf, p, xStart + xPos, yStart + yPos, bitDepths, includeChroma);
hashValueBuffer[0][0][pos] = TComHash::getCRCValue1(p, length * sizeof(unsigned char));
hashValueBuffer[1][0][pos] = TComHash::getCRCValue2(p, length * sizeof(unsigned char));
}
}
int srcSubBlockInWidth = subBlockInWidth;
subBlockInWidth >>= 1;
subBlockInHeight >>= 1;
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
int srcIdx = 1;
int dstIdx = 0;
//4x4 subblock hash values to current block hash values
int minSize = std::min(height, width);
for (int subWidth = 4; subWidth <= minSize; subWidth *= 2)
{
srcIdx = 1 - srcIdx;
dstIdx = 1 - dstIdx;
int dstPos = 0;
for (int yPos = 0; yPos < subBlockInHeight; yPos++)
{
for (int xPos = 0; xPos < subBlockInWidth; xPos++)
{
int srcPos = (yPos << 1)*srcSubBlockInWidth + (xPos << 1);
toHash[0] = hashValueBuffer[0][srcIdx][srcPos];
toHash[1] = hashValueBuffer[0][srcIdx][srcPos + 1];
toHash[2] = hashValueBuffer[0][srcIdx][srcPos + srcSubBlockInWidth];
toHash[3] = hashValueBuffer[0][srcIdx][srcPos + srcSubBlockInWidth + 1];
hashValueBuffer[0][dstIdx][dstPos] = TComHash::getCRCValue1((unsigned char*)toHash, length);
toHash[0] = hashValueBuffer[1][srcIdx][srcPos];
toHash[1] = hashValueBuffer[1][srcIdx][srcPos + 1];
toHash[2] = hashValueBuffer[1][srcIdx][srcPos + srcSubBlockInWidth];
toHash[3] = hashValueBuffer[1][srcIdx][srcPos + srcSubBlockInWidth + 1];
hashValueBuffer[1][dstIdx][dstPos] = TComHash::getCRCValue2((unsigned char*)toHash, length);
dstPos++;
}
}
srcSubBlockInWidth = subBlockInWidth;
subBlockInWidth >>= 1;
subBlockInHeight >>= 1;
}
if (width != height)//currently support 1:2 or 2:1 block size
{
CHECK(width != (height << 1) && (width << 1) != height, "Wrong")
bool isHorizontal = width == (height << 1) ? true : false;
length = 2 * sizeof(uint32_t);
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
srcIdx = 1 - srcIdx;
dstIdx = 1 - dstIdx;
if (isHorizontal)
{
toHash[0] = hashValueBuffer[0][srcIdx][0];
toHash[1] = hashValueBuffer[0][srcIdx][1];
hashValueBuffer[0][dstIdx][0] = TComHash::getCRCValue1((unsigned char*)toHash, length);
toHash[0] = hashValueBuffer[1][srcIdx][0];
toHash[1] = hashValueBuffer[1][srcIdx][1];
hashValueBuffer[1][dstIdx][0] = TComHash::getCRCValue2((unsigned char*)toHash, length);
}
else
{
CHECK(srcSubBlockInWidth != 1, "Wrong")
toHash[0] = hashValueBuffer[0][srcIdx][0];
toHash[1] = hashValueBuffer[0][srcIdx][srcSubBlockInWidth];
hashValueBuffer[0][dstIdx][0] = TComHash::getCRCValue1((unsigned char*)toHash, length);
toHash[0] = hashValueBuffer[1][srcIdx][0];
toHash[1] = hashValueBuffer[1][srcIdx][srcSubBlockInWidth];
hashValueBuffer[1][dstIdx][0] = TComHash::getCRCValue2((unsigned char*)toHash, length);
}
}
hashValue1 = (hashValueBuffer[0][dstIdx][0] & crcMask) + addValue;
hashValue2 = hashValueBuffer[1][dstIdx][0];
delete[] toHash;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
delete[] hashValueBuffer[i][j];
}
}
delete[] p;
return true;
}
void TComHash::initBlockSizeToIndex()
{
for (int i = 0; i < 65; i++)
{
for (int j = 0; j < 65; j++)
{
m_blockSizeToIndex[i][j] = -1;
}
}
m_blockSizeToIndex[8][8] = 0;
m_blockSizeToIndex[16][16] = 1;
m_blockSizeToIndex[32][32] = 2;
m_blockSizeToIndex[64][64] = 3;
m_blockSizeToIndex[4][4] = 4;
m_blockSizeToIndex[4][8] = 5;
m_blockSizeToIndex[8][4] = 6;
}
uint32_t TComHash::getCRCValue1(unsigned char* p, int length)
{
m_crcCalculator1.reset();
m_crcCalculator1.processData(p, length);
return m_crcCalculator1.getCRC();
}
uint32_t TComHash::getCRCValue2(unsigned char* p, int length)