source: 3DVCSoftware/branches/0.3-nokia/source/Lib/TLibCommon/TComPicYuvMD5.cpp

Last change on this file was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2011, ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36#include "TComPicYuv.h"
37#include "../libmd5/MD5.h"
38
39/**
40 * Update @md5 using @n samples from @plane, each sample is adjusted to
41 * @OUTBIT_BITDEPTH_DIV8.
42 */
43template<unsigned OUTPUT_BITDEPTH_DIV8>
44static void md5_block(MD5& md5, const Pel* plane, unsigned n)
45{
46  /* create a 64 byte buffer for packing Pel's into */
47  unsigned char buf[64/OUTPUT_BITDEPTH_DIV8][OUTPUT_BITDEPTH_DIV8];
48  for (unsigned i = 0; i < n; i++)
49  {
50    Pel pel = plane[i];
51    /* perform bitdepth and endian conversion */
52    for (unsigned d = 0; d < OUTPUT_BITDEPTH_DIV8; d++)
53    {
54      buf[i][d] = pel >> (d*8);
55    }
56  }
57  md5.update((unsigned char*)buf, n * OUTPUT_BITDEPTH_DIV8);
58}
59
60/**
61 * Update @md5 with all samples in @plane in raster order, each sample
62 * is adjusted to @OUTBIT_BITDEPTH_DIV8.
63 */
64template<unsigned OUTPUT_BITDEPTH_DIV8>
65static void md5_plane(MD5& md5, const Pel* plane, unsigned width, unsigned height, unsigned stride)
66{
67  /* N is the number of samples to process per md5 update.
68   * All N samples must fit in buf */
69  unsigned N = 32;
70  unsigned width_modN = width % N;
71  unsigned width_less_modN = width - width_modN;
72
73  for (unsigned y = 0; y < height; y++)
74  {
75    /* convert pel's into unsigned chars in little endian byte order.
76     * NB, for 8bit data, data is truncated to 8bits. */
77    for (unsigned x = 0; x < width_less_modN; x += N)
78      md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + x], N);
79
80    /* mop up any of the remaining line */
81    md5_block<OUTPUT_BITDEPTH_DIV8>(md5, &plane[y*stride + width_less_modN], width_modN);
82  }
83}
84
85/**
86 * Calculate the MD5sum of @pic, storing the result in @digest.
87 * MD5 calculation is performed on Y' then Cb, then Cr; each in raster order.
88 * Pel data is inserted into the MD5 function in little-endian byte order,
89 * using sufficient bytes to represent the picture bitdepth.  Eg, 10bit data
90 * uses little-endian two byte words; 8bit data uses single byte words.
91 */
92void calcMD5(TComPicYuv& pic, unsigned char digest[16])
93{
94  unsigned bitdepth = g_uiBitDepth + g_uiBitIncrement;
95  /* choose an md5_plane packing function based on the system bitdepth */
96  typedef void (*MD5PlaneFunc)(MD5&, const Pel*, unsigned, unsigned, unsigned);
97  MD5PlaneFunc md5_plane_func;
98  md5_plane_func = bitdepth <= 8 ? (MD5PlaneFunc)md5_plane<1> : (MD5PlaneFunc)md5_plane<2>;
99
100  MD5 md5;
101  unsigned width = pic.getWidth();
102  unsigned height = pic.getHeight();
103  unsigned stride = pic.getStride();
104
105  md5_plane_func(md5, pic.getLumaAddr(), width, height, stride);
106
107  width >>= 1;
108  height >>= 1;
109  stride >>= 1;
110
111  md5_plane_func(md5, pic.getCbAddr(), width, height, stride);
112  md5_plane_func(md5, pic.getCrAddr(), width, height, stride);
113
114  md5.finalize(digest);
115}
Note: See TracBrowser for help on using the repository browser.