Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: webrtc/modules/video_processing/brightness_detection.cc

Issue 1508793002: Clang format of video_processing folder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC 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 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 prop_high += stats.hist[i]; 57 prop_high += stats.hist[i];
58 } 58 }
59 prop_high /= stats.num_pixels; 59 prop_high /= stats.num_pixels;
60 60
61 if (prop_high < 0.4) { 61 if (prop_high < 0.4) {
62 if (stats.mean < 90 || stats.mean > 170) { 62 if (stats.mean < 90 || stats.mean > 170) {
63 // Standard deviation of Y 63 // Standard deviation of Y
64 const uint8_t* buffer = frame.buffer(kYPlane); 64 const uint8_t* buffer = frame.buffer(kYPlane);
65 float std_y = 0; 65 float std_y = 0;
66 for (int h = 0; h < height; h += (1 << stats.sub_sampling_factor)) { 66 for (int h = 0; h < height; h += (1 << stats.sub_sampling_factor)) {
67 int row = h*width; 67 int row = h * width;
68 for (int w = 0; w < width; w += (1 << stats.sub_sampling_factor)) { 68 for (int w = 0; w < width; w += (1 << stats.sub_sampling_factor)) {
69 std_y += (buffer[w + row] - stats.mean) * (buffer[w + row] - 69 std_y +=
70 stats.mean); 70 (buffer[w + row] - stats.mean) * (buffer[w + row] - stats.mean);
71 } 71 }
72 } 72 }
73 std_y = sqrt(std_y / stats.num_pixels); 73 std_y = sqrt(std_y / stats.num_pixels);
74 74
75 // Get percentiles. 75 // Get percentiles.
76 uint32_t sum = 0; 76 uint32_t sum = 0;
77 uint32_t median_y = 140; 77 uint32_t median_y = 140;
78 uint32_t perc05 = 0; 78 uint32_t perc05 = 0;
79 uint32_t perc95 = 255; 79 uint32_t perc95 = 255;
80 float pos_perc05 = stats.num_pixels * 0.05f; 80 float pos_perc05 = stats.num_pixels * 0.05f;
81 float pos_median = stats.num_pixels * 0.5f; 81 float pos_median = stats.num_pixels * 0.5f;
82 float posPerc95 = stats.num_pixels * 0.95f; 82 float posPerc95 = stats.num_pixels * 0.95f;
83 for (uint32_t i = 0; i < 256; i++) { 83 for (uint32_t i = 0; i < 256; i++) {
84 sum += stats.hist[i]; 84 sum += stats.hist[i];
85 if (sum < pos_perc05) perc05 = i; // 5th perc. 85 if (sum < pos_perc05)
86 if (sum < pos_median) median_y = i; // 50th perc. 86 perc05 = i; // 5th perc.
87 if (sum < pos_median)
88 median_y = i; // 50th perc.
87 if (sum < posPerc95) 89 if (sum < posPerc95)
88 perc95 = i; // 95th perc. 90 perc95 = i; // 95th perc.
89 else 91 else
90 break; 92 break;
91 } 93 }
92 94
93 // Check if image is too dark 95 // Check if image is too dark
94 if ((std_y < 55) && (perc05 < 50)) { 96 if ((std_y < 55) && (perc05 < 50)) {
95 if (median_y < 60 || stats.mean < 80 || perc95 < 130 || 97 if (median_y < 60 || stats.mean < 80 || perc95 < 130 ||
96 prop_low > 0.20) { 98 prop_low > 0.20) {
97 frame_cnt_dark_++; 99 frame_cnt_dark_++;
98 } else {
99 frame_cnt_dark_ = 0;
100 }
101 } else { 100 } else {
102 frame_cnt_dark_ = 0; 101 frame_cnt_dark_ = 0;
103 } 102 }
103 } else {
104 frame_cnt_dark_ = 0;
105 }
104 106
105 // Check if image is too bright 107 // Check if image is too bright
106 if ((std_y < 52) && (perc95 > 200) && (median_y > 160)) { 108 if ((std_y < 52) && (perc95 > 200) && (median_y > 160)) {
107 if (median_y > 185 || stats.mean > 185 || perc05 > 140 || 109 if (median_y > 185 || stats.mean > 185 || perc05 > 140 ||
108 prop_high > 0.25) { 110 prop_high > 0.25) {
109 frame_cnt_bright_++; 111 frame_cnt_bright_++;
110 } else {
111 frame_cnt_bright_ = 0;
112 }
113 } else { 112 } else {
114 frame_cnt_bright_ = 0; 113 frame_cnt_bright_ = 0;
115 } 114 }
115 } else {
116 frame_cnt_bright_ = 0;
117 }
116 } else { 118 } else {
117 frame_cnt_dark_ = 0; 119 frame_cnt_dark_ = 0;
118 frame_cnt_bright_ = 0; 120 frame_cnt_bright_ = 0;
119 } 121 }
120 } else { 122 } else {
121 frame_cnt_bright_++; 123 frame_cnt_bright_++;
122 frame_cnt_dark_ = 0; 124 frame_cnt_dark_ = 0;
123 } 125 }
124 126
125 if (frame_cnt_dark_ > frame_cnt_alarm) { 127 if (frame_cnt_dark_ > frame_cnt_alarm) {
126 return VideoProcessing::kDarkWarning; 128 return VideoProcessing::kDarkWarning;
127 } else if (frame_cnt_bright_ > frame_cnt_alarm) { 129 } else if (frame_cnt_bright_ > frame_cnt_alarm) {
128 return VideoProcessing::kBrightWarning; 130 return VideoProcessing::kBrightWarning;
129 } else { 131 } else {
130 return VideoProcessing::kNoWarning; 132 return VideoProcessing::kNoWarning;
131 } 133 }
132 } 134 }
133 135
134 } // namespace webrtc 136 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/video_processing/content_analysis.h » ('j') | webrtc/modules/video_processing/deflickering.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698