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

Side by Side Diff: media/cast/sender/performance_metrics_overlay.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/sender/performance_metrics_overlay.h" 5 #include "media/cast/sender/performance_metrics_overlay.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 11 matching lines...) Expand all
22 const int kCharacterHeight = 5; // Logical pixel height of one character. 22 const int kCharacterHeight = 5; // Logical pixel height of one character.
23 const int kCharacterSpacing = 1; // Logical pixels between each character. 23 const int kCharacterSpacing = 1; // Logical pixels between each character.
24 const int kLineSpacing = 2; // Logical pixels between each line of characters. 24 const int kLineSpacing = 2; // Logical pixels between each line of characters.
25 const int kPlane = 0; // Y-plane in YUV formats. 25 const int kPlane = 0; // Y-plane in YUV formats.
26 26
27 // For each pixel in the |rect| (logical coordinates), either decrease the 27 // For each pixel in the |rect| (logical coordinates), either decrease the
28 // intensity or increase it so that the resulting pixel has a perceivably 28 // intensity or increase it so that the resulting pixel has a perceivably
29 // different value than it did before. |p_ul| is a pointer to the pixel at 29 // different value than it did before. |p_ul| is a pointer to the pixel at
30 // coordinate (0,0) in a single-channel 8bpp bitmap. |stride| is the number of 30 // coordinate (0,0) in a single-channel 8bpp bitmap. |stride| is the number of
31 // bytes per row in the output bitmap. 31 // bytes per row in the output bitmap.
32 void DivergePixels(const gfx::Rect& rect, uint8* p_ul, int stride) { 32 void DivergePixels(const gfx::Rect& rect, uint8_t* p_ul, int stride) {
33 DCHECK(p_ul); 33 DCHECK(p_ul);
34 DCHECK_GT(stride, 0); 34 DCHECK_GT(stride, 0);
35 35
36 // These constants and heuristics were chosen based on experimenting with a 36 // These constants and heuristics were chosen based on experimenting with a
37 // wide variety of content, and converging on a readable result. The amount 37 // wide variety of content, and converging on a readable result. The amount
38 // by which the darker pixels are changed is less because each unit of change 38 // by which the darker pixels are changed is less because each unit of change
39 // has a larger visual impact on the darker end of the spectrum. Each pixel's 39 // has a larger visual impact on the darker end of the spectrum. Each pixel's
40 // intensity value is changed as follows: 40 // intensity value is changed as follows:
41 // 41 //
42 // [16,31] --> [32,63] (always a difference of +16) 42 // [16,31] --> [32,63] (always a difference of +16)
43 // [32,64] --> 16 (a difference between -16 and -48) 43 // [32,64] --> 16 (a difference between -16 and -48)
44 // [65,235] --> [17,187] (always a difference of -48) 44 // [65,235] --> [17,187] (always a difference of -48)
45 const int kDivergeDownThreshold = 32; 45 const int kDivergeDownThreshold = 32;
46 const int kDivergeDownAmount = 48; 46 const int kDivergeDownAmount = 48;
47 const int kDivergeUpAmount = 32; 47 const int kDivergeUpAmount = 32;
48 const int kMinIntensity = 16; 48 const int kMinIntensity = 16;
49 49
50 const int top = rect.y() * kScale; 50 const int top = rect.y() * kScale;
51 const int bottom = rect.bottom() * kScale; 51 const int bottom = rect.bottom() * kScale;
52 const int left = rect.x() * kScale; 52 const int left = rect.x() * kScale;
53 const int right = rect.right() * kScale; 53 const int right = rect.right() * kScale;
54 for (int y = top; y < bottom; ++y) { 54 for (int y = top; y < bottom; ++y) {
55 uint8* const p_l = p_ul + y * stride; 55 uint8_t* const p_l = p_ul + y * stride;
56 for (int x = left; x < right; ++x) { 56 for (int x = left; x < right; ++x) {
57 int intensity = p_l[x]; 57 int intensity = p_l[x];
58 if (intensity >= kDivergeDownThreshold) 58 if (intensity >= kDivergeDownThreshold)
59 intensity = std::max(kMinIntensity, intensity - kDivergeDownAmount); 59 intensity = std::max(kMinIntensity, intensity - kDivergeDownAmount);
60 else 60 else
61 intensity += kDivergeUpAmount; 61 intensity += kDivergeUpAmount;
62 p_l[x] = static_cast<uint8>(intensity); 62 p_l[x] = static_cast<uint8_t>(intensity);
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 // Render |line| into |frame| at physical pixel row |top| and aligned to the 67 // Render |line| into |frame| at physical pixel row |top| and aligned to the
68 // right edge. Only number digits and a smattering of punctuation characters 68 // right edge. Only number digits and a smattering of punctuation characters
69 // will be rendered. 69 // will be rendered.
70 void RenderLineOfText(const std::string& line, int top, VideoFrame* frame) { 70 void RenderLineOfText(const std::string& line, int top, VideoFrame* frame) {
71 // Compute number of physical pixels wide the rendered |line| would be, 71 // Compute number of physical pixels wide the rendered |line| would be,
72 // including padding. 72 // including padding.
73 const int line_width = 73 const int line_width =
74 (((kCharacterWidth + kCharacterSpacing) * static_cast<int>(line.size())) + 74 (((kCharacterWidth + kCharacterSpacing) * static_cast<int>(line.size())) +
75 kCharacterSpacing) * kScale; 75 kCharacterSpacing) * kScale;
76 76
77 // Determine if any characters would render past the left edge of the frame, 77 // Determine if any characters would render past the left edge of the frame,
78 // and compute the index of the first character to be rendered. 78 // and compute the index of the first character to be rendered.
79 const int pixels_per_char = (kCharacterWidth + kCharacterSpacing) * kScale; 79 const int pixels_per_char = (kCharacterWidth + kCharacterSpacing) * kScale;
80 const size_t first_idx = (line_width < frame->visible_rect().width()) ? 0u : 80 const size_t first_idx = (line_width < frame->visible_rect().width()) ? 0u :
81 static_cast<size_t>( 81 static_cast<size_t>(
82 ((line_width - frame->visible_rect().width()) / pixels_per_char) + 1); 82 ((line_width - frame->visible_rect().width()) / pixels_per_char) + 1);
83 83
84 // Compute the pointer to the pixel at the upper-left corner of the first 84 // Compute the pointer to the pixel at the upper-left corner of the first
85 // character to be rendered. 85 // character to be rendered.
86 const int stride = frame->stride(kPlane); 86 const int stride = frame->stride(kPlane);
87 uint8* p_ul = 87 uint8_t* p_ul =
88 // Start at the first pixel in the first row... 88 // Start at the first pixel in the first row...
89 frame->visible_data(kPlane) + (stride * top) 89 frame->visible_data(kPlane) + (stride * top)
90 // ...now move to the right edge of the visible part of the frame... 90 // ...now move to the right edge of the visible part of the frame...
91 + frame->visible_rect().width() 91 + frame->visible_rect().width()
92 // ...now move left to where line[0] would be rendered... 92 // ...now move left to where line[0] would be rendered...
93 - line_width 93 - line_width
94 // ...now move right to where line[first_idx] would be rendered. 94 // ...now move right to where line[first_idx] would be rendered.
95 + first_idx * pixels_per_char; 95 + first_idx * pixels_per_char;
96 96
97 // Render each character. 97 // Render each character.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 RenderLineOfText(base::StringPrintf("%d %3.1d%% %3.1d%%", 303 RenderLineOfText(base::StringPrintf("%d %3.1d%% %3.1d%%",
304 frames_ago, 304 frames_ago,
305 deadline_pct, 305 deadline_pct,
306 lossy_pct), 306 lossy_pct),
307 top, 307 top,
308 frame); 308 frame);
309 } 309 }
310 310
311 } // namespace cast 311 } // namespace cast
312 } // namespace media 312 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698