source: 3DVCSoftware/branches/0.1-poznan-univ/source/Lib/TLibCommon/TComPicYuvMD5.cpp @ 4

Last change on this file since 4 was 2, checked in by hhi, 13 years ago

inital import

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1
2
3#include "TComPicYuv.h"
4#include "../libmd5/MD5.h"
5
6/**
7 * Update @md5 using @n samples from @plane, each sample is adjusted to
8 * @OUTBIT_BITDEPTH_DIV8.
9 */
10template<unsigned OUTPUT_BITDEPTH_DIV8>
11static void md5_block(MD5& md5, const Pel* plane, unsigned n)
12{
13  /* create a 64 byte buffer for packing Pel's into */
14  unsigned char buf[64/OUTPUT_BITDEPTH_DIV8][OUTPUT_BITDEPTH_DIV8];
15  for (unsigned i = 0; i < n; i++)
16  {
17    Pel pel = plane[i];
18    /* perform bitdepth and endian conversion */
19    for (unsigned d = 0; d < OUTPUT_BITDEPTH_DIV8; d++)
20    {
21      buf[i][d] = pel >> (d*8);
22    }
23  }
24  md5.update((unsigned char*)buf, n * OUTPUT_BITDEPTH_DIV8);
25}
26
27/**
28 * Update @md5 with all samples in @plane in raster order, each sample
29 * is adjusted to @OUTBIT_BITDEPTH_DIV8.
30 */
31template<unsigned OUTPUT_BITDEPTH_DIV8>
32static void md5_plane(MD5& md5, const Pel* plane, unsigned width, unsigned height, unsigned stride)
33{
34  /* N is the number of samples to process per md5 update.
35   * All N samples must fit in buf */
36  unsigned N = 32;
37  unsigned width_modN = width % N;
38  unsigned width_less_modN = width - width_modN;
39
40  for (unsigned y = 0; y < height; y++)
41  {
42    /* convert pel's into unsigned chars in little endian byte order.
43     * NB, for 8bit data, data is truncated to 8bits. */
44    for (unsigned x = 0; x < width_less_modN; x += N)
45      md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + x], N);
46
47    /* mop up any of the remaining line */
48    md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + width_less_modN], width_modN);
49  }
50}
51
52/**
53 * Calculate the MD5sum of @pic, storing the result in @digest.
54 * MD5 calculation is performed on Y' then Cb, then Cr; each in raster order.
55 * Pel data is inserted into the MD5 function in little-endian byte order,
56 * using sufficient bytes to represent the picture bitdepth.  Eg, 10bit data
57 * uses little-endian two byte words; 8bit data uses single byte words.
58 */
59void calcMD5(TComPicYuv& pic, unsigned char digest[16])
60{
61  unsigned bitdepth = g_uiBitDepth + g_uiBitIncrement;
62  /* choose an md5_plane packing function based on the system bitdepth */
63  typedef void (*MD5PlaneFunc)(MD5&, const Pel*, unsigned, unsigned, unsigned);
64  MD5PlaneFunc md5_plane_func;
65  md5_plane_func = bitdepth <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
66
67  MD5 md5;
68  unsigned width = pic.getWidth();
69  unsigned height = pic.getHeight();
70  unsigned stride = pic.getStride();
71
72  md5_plane_func(md5, pic.getLumaAddr(), width, height, stride);
73
74  width >>= 1;
75  height >>= 1;
76  stride >>= 1;
77
78  md5_plane_func(md5, pic.getCbAddr(), width, height, stride);
79  md5_plane_func(md5, pic.getCrAddr(), width, height, stride);
80
81  md5.finalize(digest);
82}
Note: See TracBrowser for help on using the repository browser.