~ubuntu-branches/ubuntu/wily/libde265/wily

« back to all changes in this revision

Viewing changes to libde265/quality.cc

  • Committer: Package Import Robot
  • Author(s): Joachim Bauch
  • Date: 2015-07-16 11:07:46 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150716110746-76vsv24j3yux7tnu
Tags: 1.0.2-1
* Imported Upstream version 1.0.2
* Added new files to copyright information.
* Only export decoder API and update symbols for new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * H.265 video codec.
 
3
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
 
4
 *
 
5
 * This file is part of libde265.
 
6
 *
 
7
 * libde265 is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Lesser General Public License as
 
9
 * published by the Free Software Foundation, either version 3 of
 
10
 * the License, or (at your option) any later version.
 
11
 *
 
12
 * libde265 is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include "quality.h"
 
22
#include <math.h>
 
23
 
 
24
 
 
25
uint32_t SSD(const uint8_t* img, int imgStride,
 
26
             const uint8_t* ref, int refStride,
 
27
             int width, int height)
 
28
{
 
29
  uint32_t sum=0;
 
30
 
 
31
  const uint8_t* iPtr = img;
 
32
  const uint8_t* rPtr = ref;
 
33
 
 
34
  for (int y=0;y<height;y++) {
 
35
    for (int x=0;x<width;x++) {
 
36
      int diff = iPtr[x] - rPtr[x];
 
37
      sum += diff*diff;
 
38
    }
 
39
 
 
40
    iPtr += imgStride;
 
41
    rPtr += refStride;
 
42
  }
 
43
 
 
44
  return sum;
 
45
}
 
46
 
 
47
 
 
48
uint32_t SAD(const uint8_t* img, int imgStride,
 
49
             const uint8_t* ref, int refStride,
 
50
             int width, int height)
 
51
{
 
52
  uint32_t sum=0;
 
53
 
 
54
  const uint8_t* iPtr = img;
 
55
  const uint8_t* rPtr = ref;
 
56
 
 
57
  for (int y=0;y<height;y++) {
 
58
    for (int x=0;x<width;x++) {
 
59
      int diff = iPtr[x] - rPtr[x];
 
60
      sum += abs_value(diff);
 
61
    }
 
62
 
 
63
    iPtr += imgStride;
 
64
    rPtr += refStride;
 
65
  }
 
66
 
 
67
  return sum;
 
68
}
 
69
 
 
70
 
 
71
double MSE(const uint8_t* img, int imgStride,
 
72
           const uint8_t* ref, int refStride,
 
73
           int width, int height)
 
74
{
 
75
  double sum=0.0;
 
76
 
 
77
  const uint8_t* iPtr = img;
 
78
  const uint8_t* rPtr = ref;
 
79
 
 
80
  for (int y=0;y<height;y++) {
 
81
    uint32_t lineSum=0;
 
82
 
 
83
    for (int x=0;x<width;x++) {
 
84
      int diff = iPtr[x] - rPtr[x];
 
85
      lineSum += diff*diff;
 
86
    }
 
87
 
 
88
    sum += ((double)lineSum)/width;
 
89
 
 
90
    iPtr += imgStride;
 
91
    rPtr += refStride;
 
92
  }
 
93
 
 
94
  return sum/height;
 
95
}
 
96
 
 
97
 
 
98
double PSNR(double mse)
 
99
{
 
100
  if (mse==0) { return 99.99999; }
 
101
 
 
102
  return 10*log10(255.0*255.0/mse);
 
103
}
 
104
 
 
105
uint32_t compute_distortion_ssd(const de265_image* img1, const de265_image* img2,
 
106
                                int x0, int y0, int log2size, int cIdx)
 
107
{
 
108
  return SSD(img1->get_image_plane_at_pos(cIdx,x0,y0), img1->get_image_stride(cIdx),
 
109
             img2->get_image_plane_at_pos(cIdx,x0,y0), img2->get_image_stride(cIdx),
 
110
             1<<log2size, 1<<log2size);
 
111
}
 
112