Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp
r1179 r1313 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 43 43 */ 44 44 template<UInt OUTPUT_BITDEPTH_DIV8> 45 static void md5_block(MD5& md5, const Pel* plane, UInt n)45 static Void md5_block(MD5& md5, const Pel* plane, UInt n) 46 46 { 47 47 /* create a 64 byte buffer for packing Pel's into */ … … 64 64 */ 65 65 template<UInt OUTPUT_BITDEPTH_DIV8> 66 static void md5_plane(MD5& md5, const Pel* plane, UInt width, UInt height, UInt stride)66 static Void md5_plane(MD5& md5, const Pel* plane, UInt width, UInt height, UInt stride) 67 67 { 68 68 /* N is the number of samples to process per md5 update. … … 74 74 for (UInt y = 0; y < height; y++) 75 75 { 76 /* convert pel 's into UIntchars in little endian byte order.76 /* convert pels into unsigned chars in little endian byte order. 77 77 * NB, for 8bit data, data is truncated to 8bits. */ 78 78 for (UInt x = 0; x < width_less_modN; x += N) 79 { 79 80 md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + x], N); 81 } 80 82 81 83 /* mop up any of the remaining line */ … … 84 86 } 85 87 86 static void compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16]) 88 89 UInt compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComPictureHash &digest) 87 90 { 88 91 UInt crcMsb; … … 119 122 } 120 123 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 129 UInt 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 141 UInt compChecksum(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComPictureHash &digest, const BitDepths &/*bitDepths*/) 142 142 { 143 143 UInt checksum = 0; … … 158 158 } 159 159 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 167 UInt 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; 180 177 } 181 178 /** … … 186 183 * uses little-endian two byte words; 8bit data uses single byte words. 187 184 */ 188 void calcMD5(TComPicYuv& pic, UChar digest[3][16])185 UInt calcMD5(const TComPicYuv& pic, TComPictureHash &digest, const BitDepths &bitDepths) 189 186 { 190 187 /* 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); 192 189 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 209 std::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 214 227 //! \}
Note: See TracChangeset for help on using the changeset viewer.