| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include <stdlib.h> |
| 10 | 11 |
| 11 #include "./vp9_rtcd.h" | |
| 12 #include "./vpx_config.h" | |
| 13 #include "./vpx_dsp_rtcd.h" | |
| 14 #include "vp9/common/vp9_common.h" | |
| 15 #include "vp9/common/vp9_filter.h" | |
| 16 #include "vpx/vpx_integer.h" | 12 #include "vpx/vpx_integer.h" |
| 17 #include "vpx_dsp/vpx_convolve.h" | 13 #include "vpx_ports/system_state.h" |
| 18 #include "vpx_dsp/vpx_filter.h" | |
| 19 #include "vpx_ports/mem.h" | |
| 20 | 14 |
| 21 static int horizontal_filter(const uint8_t *s) { | 15 static int horizontal_filter(const uint8_t *s) { |
| 22 return (s[1] - s[-2]) * 2 + (s[-1] - s[0]) * 6; | 16 return (s[1] - s[-2]) * 2 + (s[-1] - s[0]) * 6; |
| 23 } | 17 } |
| 24 | 18 |
| 25 static int vertical_filter(const uint8_t *s, int p) { | 19 static int vertical_filter(const uint8_t *s, int p) { |
| 26 return (s[p] - s[-2 * p]) * 2 + (s[-p] - s[0]) * 6; | 20 return (s[p] - s[-2 * p]) * 2 + (s[-p] - s[0]) * 6; |
| 27 } | 21 } |
| 28 | 22 |
| 29 static int variance(int sum, int sum_squared, int size) { | 23 static int variance(int sum, int sum_squared, int size) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 47 // blockiness from source buffer,0) | 41 // blockiness from source buffer,0) |
| 48 // | 42 // |
| 49 // I make the assumption that flat blocks are much more visible than high | 43 // I make the assumption that flat blocks are much more visible than high |
| 50 // contrast blocks. As such, I scale the result of the blockiness calc | 44 // contrast blocks. As such, I scale the result of the blockiness calc |
| 51 // by dividing the blockiness by the variance of the pixels on either side | 45 // by dividing the blockiness by the variance of the pixels on either side |
| 52 // of the edge as follows: | 46 // of the edge as follows: |
| 53 // var_0 = (q0^2+q1^2+q2^2+q3^2) - ((q0 + q1 + q2 + q3) / 4 )^2 | 47 // var_0 = (q0^2+q1^2+q2^2+q3^2) - ((q0 + q1 + q2 + q3) / 4 )^2 |
| 54 // var_1 = (r0^2+r1^2+r2^2+r3^2) - ((r0 + r1 + r2 + r3) / 4 )^2 | 48 // var_1 = (r0^2+r1^2+r2^2+r3^2) - ((r0 + r1 + r2 + r3) / 4 )^2 |
| 55 // The returned blockiness is the scaled value | 49 // The returned blockiness is the scaled value |
| 56 // Reconstructed blockiness / ( 1 + var_0 + var_1 ) ; | 50 // Reconstructed blockiness / ( 1 + var_0 + var_1 ) ; |
| 57 int blockiness_vertical(const uint8_t *s, int sp, const uint8_t *r, int rp, | 51 static int blockiness_vertical(const uint8_t *s, int sp, const uint8_t *r, |
| 58 int size) { | 52 int rp, int size) { |
| 59 int s_blockiness = 0; | 53 int s_blockiness = 0; |
| 60 int r_blockiness = 0; | 54 int r_blockiness = 0; |
| 61 int sum_0 = 0; | 55 int sum_0 = 0; |
| 62 int sum_sq_0 = 0; | 56 int sum_sq_0 = 0; |
| 63 int sum_1 = 0; | 57 int sum_1 = 0; |
| 64 int sum_sq_1 = 0; | 58 int sum_sq_1 = 0; |
| 65 int i; | 59 int i; |
| 66 int var_0; | 60 int var_0; |
| 67 int var_1; | 61 int var_1; |
| 68 for (i = 0; i < size; ++i, s += sp, r += rp) { | 62 for (i = 0; i < size; ++i, s += sp, r += rp) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 s_blockiness = abs(s_blockiness); | 73 s_blockiness = abs(s_blockiness); |
| 80 | 74 |
| 81 if (r_blockiness > s_blockiness) | 75 if (r_blockiness > s_blockiness) |
| 82 return (r_blockiness - s_blockiness) / (1 + var_0 + var_1); | 76 return (r_blockiness - s_blockiness) / (1 + var_0 + var_1); |
| 83 else | 77 else |
| 84 return 0; | 78 return 0; |
| 85 } | 79 } |
| 86 | 80 |
| 87 // Calculate a blockiness level for a horizontal block edge | 81 // Calculate a blockiness level for a horizontal block edge |
| 88 // same as above. | 82 // same as above. |
| 89 int blockiness_horizontal(const uint8_t *s, int sp, const uint8_t *r, int rp, | 83 static int blockiness_horizontal(const uint8_t *s, int sp, const uint8_t *r, |
| 90 int size) { | 84 int rp, int size) { |
| 91 int s_blockiness = 0; | 85 int s_blockiness = 0; |
| 92 int r_blockiness = 0; | 86 int r_blockiness = 0; |
| 93 int sum_0 = 0; | 87 int sum_0 = 0; |
| 94 int sum_sq_0 = 0; | 88 int sum_sq_0 = 0; |
| 95 int sum_1 = 0; | 89 int sum_1 = 0; |
| 96 int sum_sq_1 = 0; | 90 int sum_sq_1 = 0; |
| 97 int i; | 91 int i; |
| 98 int var_0; | 92 int var_0; |
| 99 int var_1; | 93 int var_1; |
| 100 for (i = 0; i < size; ++i, ++s, ++r) { | 94 for (i = 0; i < size; ++i, ++s, ++r) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 s_blockiness = abs(s_blockiness); | 105 s_blockiness = abs(s_blockiness); |
| 112 | 106 |
| 113 if (r_blockiness > s_blockiness) | 107 if (r_blockiness > s_blockiness) |
| 114 return (r_blockiness - s_blockiness) / (1 + var_0 + var_1); | 108 return (r_blockiness - s_blockiness) / (1 + var_0 + var_1); |
| 115 else | 109 else |
| 116 return 0; | 110 return 0; |
| 117 } | 111 } |
| 118 | 112 |
| 119 // This function returns the blockiness for the entire frame currently by | 113 // This function returns the blockiness for the entire frame currently by |
| 120 // looking at all borders in steps of 4. | 114 // looking at all borders in steps of 4. |
| 121 double vp9_get_blockiness(const unsigned char *img1, int img1_pitch, | 115 double vp9_get_blockiness(const uint8_t *img1, int img1_pitch, |
| 122 const unsigned char *img2, int img2_pitch, | 116 const uint8_t *img2, int img2_pitch, |
| 123 int width, int height ) { | 117 int width, int height) { |
| 124 double blockiness = 0; | 118 double blockiness = 0; |
| 125 int i, j; | 119 int i, j; |
| 126 vp9_clear_system_state(); | 120 vpx_clear_system_state(); |
| 127 for (i = 0; i < height; i += 4, img1 += img1_pitch * 4, | 121 for (i = 0; i < height; i += 4, img1 += img1_pitch * 4, |
| 128 img2 += img2_pitch * 4) { | 122 img2 += img2_pitch * 4) { |
| 129 for (j = 0; j < width; j += 4) { | 123 for (j = 0; j < width; j += 4) { |
| 130 if (i > 0 && i < height && j > 0 && j < width) { | 124 if (i > 0 && i < height && j > 0 && j < width) { |
| 131 blockiness += blockiness_vertical(img1 + j, img1_pitch, | 125 blockiness += blockiness_vertical(img1 + j, img1_pitch, |
| 132 img2 + j, img2_pitch, 4); | 126 img2 + j, img2_pitch, 4); |
| 133 blockiness += blockiness_horizontal(img1 + j, img1_pitch, | 127 blockiness += blockiness_horizontal(img1 + j, img1_pitch, |
| 134 img2 + j, img2_pitch, 4); | 128 img2 + j, img2_pitch, 4); |
| 135 } | 129 } |
| 136 } | 130 } |
| 137 } | 131 } |
| 138 blockiness /= width * height / 16; | 132 blockiness /= width * height / 16; |
| 139 return blockiness; | 133 return blockiness; |
| 140 } | 134 } |
| OLD | NEW |