Changeset 916 in SHVCSoftware for branches/SHM-upgrade/source/Lib/TLibCommon/TComPicYuvMD5.cpp
- Timestamp:
- 12 Nov 2014, 08:09:17 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-upgrade/source/Lib/TLibCommon/TComPicYuvMD5.cpp
r595 r916 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) … … 84 84 } 85 85 86 static void compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, UChar digest[16]) 86 87 UInt compCRC(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComDigest &digest) 87 88 { 88 89 UInt crcMsb; … … 119 120 } 120 121 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]) 122 digest.hash.push_back((crcVal>>8) & 0xff); 123 digest.hash.push_back( crcVal & 0xff); 124 return 2; 125 } 126 127 UInt calcCRC(const TComPicYuv& pic, TComDigest &digest) 128 { 129 UInt digestLen=0; 130 digest.hash.clear(); 131 for(Int chan=0; chan<pic.getNumberValidComponents(); chan++) 132 { 133 const ComponentID compID=ComponentID(chan); 134 digestLen=compCRC(g_bitDepth[toChannelType(compID)], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID), digest); 135 } 136 return digestLen; 137 } 138 139 UInt compChecksum(Int bitdepth, const Pel* plane, UInt width, UInt height, UInt stride, TComDigest &digest) 142 140 { 143 141 UInt checksum = 0; … … 158 156 } 159 157 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]); 158 digest.hash.push_back((checksum>>24) & 0xff); 159 digest.hash.push_back((checksum>>16) & 0xff); 160 digest.hash.push_back((checksum>>8) & 0xff); 161 digest.hash.push_back( checksum & 0xff); 162 return 4; 163 } 164 165 UInt calcChecksum(const TComPicYuv& pic, TComDigest &digest) 166 { 167 UInt digestLen=0; 168 digest.hash.clear(); 169 for(Int chan=0; chan<pic.getNumberValidComponents(); chan++) 170 { 171 const ComponentID compID=ComponentID(chan); 172 digestLen=compChecksum(g_bitDepth[toChannelType(compID)], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID), digest); 173 } 174 return digestLen; 180 175 } 181 176 /** … … 186 181 * uses little-endian two byte words; 8bit data uses single byte words. 187 182 */ 188 void calcMD5(TComPicYuv& pic, UChar digest[3][16])183 UInt calcMD5(const TComPicYuv& pic, TComDigest &digest) 189 184 { 190 185 /* choose an md5_plane packing function based on the system bitdepth */ 191 typedef void (*MD5PlaneFunc)(MD5&, const Pel*, UInt, UInt, UInt);186 typedef Void (*MD5PlaneFunc)(MD5&, const Pel*, UInt, UInt, UInt); 192 187 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 } 188 189 MD5 md5[MAX_NUM_COMPONENT]; 190 191 digest.hash.clear(); 192 for(Int chan=0; chan<pic.getNumberValidComponents(); chan++) 193 { 194 const ComponentID compID=ComponentID(chan); 195 md5_plane_func = g_bitDepth[toChannelType(compID)] <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>; 196 UChar tmp_digest[MD5_DIGEST_STRING_LENGTH]; 197 md5_plane_func(md5[compID], pic.getAddr(compID), pic.getWidth(compID), pic.getHeight(compID), pic.getStride(compID)); 198 md5[compID].finalize(tmp_digest); 199 for(UInt i=0; i<MD5_DIGEST_STRING_LENGTH; i++) 200 { 201 digest.hash.push_back(tmp_digest[i]); 202 } 203 } 204 return 16; 205 } 206 207 std::string digestToString(const TComDigest &digest, Int numChar) 208 { 209 static const Char* hex = "0123456789abcdef"; 210 std::string result; 211 212 for(Int pos=0; pos<Int(digest.hash.size()); pos++) 213 { 214 if ((pos % numChar) == 0 && pos!=0 ) result += ','; 215 result += hex[digest.hash[pos] >> 4]; 216 result += hex[digest.hash[pos] & 0xf]; 217 } 218 219 return result; 220 } 221 214 222 //! \}
Note: See TracChangeset for help on using the changeset viewer.