Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

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

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4343 */
    4444template<UInt OUTPUT_BITDEPTH_DIV8>
    45 static void md5_block(MD5& md5, const Pel* plane, UInt n)
     45static Void md5_block(MD5& md5, const Pel* plane, UInt n)
    4646{
    4747  /* create a 64 byte buffer for packing Pel's into */
     
    6464 */
    6565template<UInt OUTPUT_BITDEPTH_DIV8>
    66 static void md5_plane(MD5& md5, const Pel* plane, UInt width, UInt height, UInt stride)
     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.
     
    7474  for (UInt y = 0; y < height; y++)
    7575  {
    76     /* convert pel's into UInt chars in little endian byte order.
     76    /* convert pels into unsigned chars in little endian byte order.
    7777     * NB, for 8bit data, data is truncated to 8bits. */
    7878    for (UInt x = 0; x < width_less_modN; x += N)
     79    {
    7980      md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + x], N);
     81    }
    8082
    8183    /* mop up any of the remaining line */
     
    8486}
    8587
    86 static void compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16])
     88
     89UInt compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComPictureHash &digest)
    8790{
    8891  UInt crcMsb;
     
    119122  }
    120123
    121   digest[0] = (crcVal>>8)  & 0xff;
    122   digest[1] =  crcVal      & 0xff;
    123 }
    124 
    125 void 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]);
    132 
    133   width >>= 1;
    134   height >>= 1;
    135   stride >>= 1;
    136 
    137   compCRC(g_bitDepthC, pic.getCbAddr(), width, height, stride, digest[1]);
    138   compCRC(g_bitDepthC, pic.getCrAddr(), width, height, stride, digest[2]);
    139 }
    140 
    141 static void compChecksum(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16])
     124  digest.hash.push_back((crcVal>>8)  & 0xff);
     125  digest.hash.push_back( crcVal      & 0xff);
     126  return 2;
     127}
     128
     129UInt calcCRC(const TComPicYuv& pic, TComPictureHash &digest, const BitDepths &bitDepths)
     130{
     131  UInt digestLen=0;
     132  digest.hash.clear();
     133  for(Int chan=0; chan<pic.getNumberValidComponents(); chan++)
     134  {
     135    const ComponentID compID=ComponentID(chan);
     136    digestLen=compCRC(bitDepths.recon[toChannelType(compID)], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID), digest);
     137  }
     138  return digestLen;
     139}
     140
     141UInt compChecksum(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComPictureHash &digest, const BitDepths &/*bitDepths*/)
    142142{
    143143  UInt checksum = 0;
     
    158158  }
    159159
    160   digest[0] = (checksum>>24) & 0xff;
    161   digest[1] = (checksum>>16) & 0xff;
    162   digest[2] = (checksum>>8)  & 0xff;
    163   digest[3] =  checksum      & 0xff;
    164 }
    165 
    166 void 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]);
    173 
    174   width >>= 1;
    175   height >>= 1;
    176   stride >>= 1;
    177 
    178   compChecksum(g_bitDepthC, pic.getCbAddr(), width, height, stride, digest[1]);
    179   compChecksum(g_bitDepthC, pic.getCrAddr(), width, height, stride, digest[2]);
     160  digest.hash.push_back((checksum>>24) & 0xff);
     161  digest.hash.push_back((checksum>>16) & 0xff);
     162  digest.hash.push_back((checksum>>8)  & 0xff);
     163  digest.hash.push_back( checksum      & 0xff);
     164  return 4;
     165}
     166
     167UInt calcChecksum(const TComPicYuv& pic, TComPictureHash &digest, const BitDepths &bitDepths)
     168{
     169  UInt digestLen=0;
     170  digest.hash.clear();
     171  for(Int chan=0; chan<pic.getNumberValidComponents(); chan++)
     172  {
     173    const ComponentID compID=ComponentID(chan);
     174    digestLen=compChecksum(bitDepths.recon[toChannelType(compID)], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID), digest, bitDepths);
     175  }
     176  return digestLen;
    180177}
    181178/**
     
    186183 * uses little-endian two byte words; 8bit data uses single byte words.
    187184 */
    188 void calcMD5(TComPicYuv& pic, UChar digest[3][16])
     185UInt calcMD5(const TComPicYuv& pic, TComPictureHash &digest, const BitDepths &bitDepths)
    189186{
    190187  /* choose an md5_plane packing function based on the system bitdepth */
    191   typedef void (*MD5PlaneFunc)(MD5&, const Pel*, UInt, UInt, UInt);
     188  typedef Void (*MD5PlaneFunc)(MD5&, const Pel*, UInt, UInt, UInt);
    192189  MD5PlaneFunc md5_plane_func;
    193   md5_plane_func = g_bitDepthY <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
    194 
    195   MD5 md5Y, md5U, md5V;
    196   UInt width = pic.getWidth();
    197   UInt height = pic.getHeight();
    198   UInt stride = pic.getStride();
    199 
    200   md5_plane_func(md5Y, pic.getLumaAddr(), width, height, stride);
    201   md5Y.finalize(digest[0]);
    202 
    203   md5_plane_func = g_bitDepthC <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
    204   width >>= 1;
    205   height >>= 1;
    206   stride >>= 1;
    207 
    208   md5_plane_func(md5U, pic.getCbAddr(), width, height, stride);
    209   md5U.finalize(digest[1]);
    210 
    211   md5_plane_func(md5V, pic.getCrAddr(), width, height, stride);
    212   md5V.finalize(digest[2]);
    213 }
     190
     191  MD5 md5[MAX_NUM_COMPONENT];
     192
     193  digest.hash.clear();
     194  for(Int chan=0; chan<pic.getNumberValidComponents(); chan++)
     195  {
     196    const ComponentID compID=ComponentID(chan);
     197    md5_plane_func = bitDepths.recon[toChannelType(compID)] <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
     198    UChar tmp_digest[MD5_DIGEST_STRING_LENGTH];
     199    md5_plane_func(md5[compID], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID));
     200    md5[compID].finalize(tmp_digest);
     201    for(UInt i=0; i<MD5_DIGEST_STRING_LENGTH; i++)
     202    {
     203      digest.hash.push_back(tmp_digest[i]);
     204    }
     205  }
     206  return 16;
     207}
     208
     209std::string hashToString(const TComPictureHash &digest, Int numChar)
     210{
     211  static const Char* hex = "0123456789abcdef";
     212  std::string result;
     213
     214  for(Int pos=0; pos<Int(digest.hash.size()); pos++)
     215  {
     216    if ((pos % numChar) == 0 && pos!=0 )
     217    {
     218      result += ',';
     219    }
     220    result += hex[digest.hash[pos] >> 4];
     221    result += hex[digest.hash[pos] & 0xf];
     222  }
     223
     224  return result;
     225}
     226
    214227//! \}
Note: See TracChangeset for help on using the changeset viewer.