Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp


Ignore:
Timestamp:
16 Apr 2013, 06:39:31 (12 years ago)
Author:
seregin
Message:

copy from HM-10.0-dev-SHM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp

    r2 r125  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4242 * OUTBIT_BITDEPTH_DIV8.
    4343 */
    44 template<unsigned OUTPUT_BITDEPTH_DIV8>
    45 static void md5_block(MD5& md5, const Pel* plane, unsigned n)
     44template<UInt OUTPUT_BITDEPTH_DIV8>
     45static void md5_block(MD5& md5, const Pel* plane, UInt n)
    4646{
    4747  /* create a 64 byte buffer for packing Pel's into */
    48   unsigned char buf[64/OUTPUT_BITDEPTH_DIV8][OUTPUT_BITDEPTH_DIV8];
    49   for (unsigned i = 0; i < n; i++)
     48  UChar buf[64/OUTPUT_BITDEPTH_DIV8][OUTPUT_BITDEPTH_DIV8];
     49  for (UInt i = 0; i < n; i++)
    5050  {
    5151    Pel pel = plane[i];
    5252    /* perform bitdepth and endian conversion */
    53     for (unsigned d = 0; d < OUTPUT_BITDEPTH_DIV8; d++)
     53    for (UInt d = 0; d < OUTPUT_BITDEPTH_DIV8; d++)
    5454    {
    5555      buf[i][d] = pel >> (d*8);
    5656    }
    5757  }
    58   md5.update((unsigned char*)buf, n * OUTPUT_BITDEPTH_DIV8);
     58  md5.update((UChar*)buf, n * OUTPUT_BITDEPTH_DIV8);
    5959}
    6060
     
    6363 * is adjusted to OUTBIT_BITDEPTH_DIV8.
    6464 */
    65 template<unsigned OUTPUT_BITDEPTH_DIV8>
    66 static void md5_plane(MD5& md5, const Pel* plane, unsigned width, unsigned height, unsigned stride)
     65template<UInt OUTPUT_BITDEPTH_DIV8>
     66static void md5_plane(MD5& md5, const Pel* plane, UInt width, UInt height, UInt stride)
    6767{
    6868  /* N is the number of samples to process per md5 update.
    6969   * All N samples must fit in buf */
    70   unsigned N = 32;
    71   unsigned width_modN = width % N;
    72   unsigned width_less_modN = width - width_modN;
    73 
    74   for (unsigned y = 0; y < height; y++)
    75   {
    76     /* convert pel's into unsigned chars in little endian byte order.
     70  UInt N = 32;
     71  UInt width_modN = width % N;
     72  UInt width_less_modN = width - width_modN;
     73
     74  for (UInt y = 0; y < height; y++)
     75  {
     76    /* convert pel's into UInt chars in little endian byte order.
    7777     * NB, for 8bit data, data is truncated to 8bits. */
    78     for (unsigned x = 0; x < width_less_modN; x += N)
     78    for (UInt x = 0; x < width_less_modN; x += N)
    7979      md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + x], N);
    8080
     
    8484}
    8585
    86 void compCRC(const Pel* plane, unsigned int width, unsigned int height, unsigned int stride, unsigned char digest[16])
    87 {
    88   unsigned int bitdepth = g_uiBitDepth + g_uiBitIncrement;
    89   unsigned int dataMsbIdx = bitdepth - 1;
    90   unsigned int crcMsb;
    91   unsigned int bitVal;
    92   unsigned int crcVal = 0xffff;
    93   unsigned int bitIdx;
    94   for (unsigned y = 0; y < height; y++)
    95   {
    96     for (unsigned x = 0; x < width; x++)
    97     {     
    98       for(bitIdx=0; bitIdx<bitdepth; bitIdx++)
     86static void compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16])
     87{
     88  UInt crcMsb;
     89  UInt bitVal;
     90  UInt crcVal = 0xffff;
     91  UInt bitIdx;
     92  for (UInt y = 0; y < height; y++)
     93  {
     94    for (UInt x = 0; x < width; x++)
     95    {
     96      // take CRC of first pictureData byte
     97      for(bitIdx=0; bitIdx<8; bitIdx++)
    9998      {
    10099        crcMsb = (crcVal >> 15) & 1;
    101         bitVal = (plane[y*stride+x]>> (dataMsbIdx - (bitIdx&dataMsbIdx))) & 1;
     100        bitVal = (plane[y*stride+x] >> (7 - bitIdx)) & 1;
    102101        crcVal = (((crcVal << 1) + bitVal) & 0xffff) ^ (crcMsb * 0x1021);
    103102      }
     103      // take CRC of second pictureData byte if bit depth is greater than 8-bits
     104      if(bitdepth > 8)
     105      {
     106        for(bitIdx=0; bitIdx<8; bitIdx++)
     107        {
     108          crcMsb = (crcVal >> 15) & 1;
     109          bitVal = (plane[y*stride+x] >> (15 - bitIdx)) & 1;
     110          crcVal = (((crcVal << 1) + bitVal) & 0xffff) ^ (crcMsb * 0x1021);
     111        }
     112      }
    104113    }
    105114  }
     
    114123}
    115124
    116 void calcCRC(TComPicYuv& pic, unsigned char digest[3][16])
    117 {
    118   unsigned width = pic.getWidth();
    119   unsigned height = pic.getHeight();
    120   unsigned stride = pic.getStride();
    121 
    122   compCRC(pic.getLumaAddr(), width, height, stride, digest[0]);
     125void calcCRC(TComPicYuv& pic, UChar digest[3][16])
     126{
     127  UInt width = pic.getWidth();
     128  UInt height = pic.getHeight();
     129  UInt stride = pic.getStride();
     130
     131  compCRC(g_bitDepthY, pic.getLumaAddr(), width, height, stride, digest[0]);
    123132
    124133  width >>= 1;
     
    126135  stride >>= 1;
    127136
    128   compCRC(pic.getCbAddr(), width, height, stride, digest[1]);
    129   compCRC(pic.getCrAddr(), width, height, stride, digest[2]);
    130 }
    131 
    132 void compChecksum(const Pel* plane, unsigned int width, unsigned int height, unsigned int stride, unsigned char digest[16])
    133 {
    134   unsigned int bitdepth = g_uiBitDepth + g_uiBitIncrement;
    135 
    136   unsigned int checksum = 0;
    137   unsigned char xor_mask;
    138 
    139   for (unsigned y = 0; y < height; y++)
    140   {
    141     for (unsigned x = 0; x < width; x++)
     137  compCRC(g_bitDepthC, pic.getCbAddr(), width, height, stride, digest[1]);
     138  compCRC(g_bitDepthC, pic.getCrAddr(), width, height, stride, digest[2]);
     139}
     140
     141static void compChecksum(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16])
     142{
     143  UInt checksum = 0;
     144  UChar xor_mask;
     145
     146  for (UInt y = 0; y < height; y++)
     147  {
     148    for (UInt x = 0; x < width; x++)
    142149    {
    143150      xor_mask = (x & 0xff) ^ (y & 0xff) ^ (x >> 8) ^ (y >> 8);
     
    157164}
    158165
    159 void calcChecksum(TComPicYuv& pic, unsigned char digest[3][16])
    160 {
    161   unsigned width = pic.getWidth();
    162   unsigned height = pic.getHeight();
    163   unsigned stride = pic.getStride();
    164 
    165   compChecksum(pic.getLumaAddr(), width, height, stride, digest[0]);
     166void calcChecksum(TComPicYuv& pic, UChar digest[3][16])
     167{
     168  UInt width = pic.getWidth();
     169  UInt height = pic.getHeight();
     170  UInt stride = pic.getStride();
     171
     172  compChecksum(g_bitDepthY, pic.getLumaAddr(), width, height, stride, digest[0]);
    166173
    167174  width >>= 1;
     
    169176  stride >>= 1;
    170177
    171   compChecksum(pic.getCbAddr(), width, height, stride, digest[1]);
    172   compChecksum(pic.getCrAddr(), width, height, stride, digest[2]);
     178  compChecksum(g_bitDepthC, pic.getCbAddr(), width, height, stride, digest[1]);
     179  compChecksum(g_bitDepthC, pic.getCrAddr(), width, height, stride, digest[2]);
    173180}
    174181/**
     
    179186 * uses little-endian two byte words; 8bit data uses single byte words.
    180187 */
    181 void calcMD5(TComPicYuv& pic, unsigned char digest[3][16])
    182 {
    183   unsigned bitdepth = g_uiBitDepth + g_uiBitIncrement;
     188void calcMD5(TComPicYuv& pic, UChar digest[3][16])
     189{
    184190  /* choose an md5_plane packing function based on the system bitdepth */
    185   typedef void (*MD5PlaneFunc)(MD5&, const Pel*, unsigned, unsigned, unsigned);
     191  typedef void (*MD5PlaneFunc)(MD5&, const Pel*, UInt, UInt, UInt);
    186192  MD5PlaneFunc md5_plane_func;
    187   md5_plane_func = bitdepth <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
     193  md5_plane_func = g_bitDepthY <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
    188194
    189195  MD5 md5Y, md5U, md5V;
    190   unsigned width = pic.getWidth();
    191   unsigned height = pic.getHeight();
    192   unsigned stride = pic.getStride();
     196  UInt width = pic.getWidth();
     197  UInt height = pic.getHeight();
     198  UInt stride = pic.getStride();
    193199
    194200  md5_plane_func(md5Y, pic.getLumaAddr(), width, height, stride);
    195201  md5Y.finalize(digest[0]);
    196202
     203  md5_plane_func = g_bitDepthC <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
    197204  width >>= 1;
    198205  height >>= 1;
Note: See TracChangeset for help on using the changeset viewer.