OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/base/util.h" | 5 #include "remoting/base/util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
14 #include "third_party/skia/include/core/SkRegion.h" | 14 #include "third_party/skia/include/core/SkRegion.h" |
15 | 15 |
16 using media::VideoFrame; | 16 using media::VideoFrame; |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
| 20 enum { kBytesPerPixelRGB32 = 4 }; |
| 21 |
20 // Do not write LOG messages in this routine since it is called from within | 22 // Do not write LOG messages in this routine since it is called from within |
21 // our LOG message handler. Bad things will happen. | 23 // our LOG message handler. Bad things will happen. |
22 std::string GetTimestampString() { | 24 std::string GetTimestampString() { |
23 base::Time t = base::Time::NowFromSystemTime(); | 25 base::Time t = base::Time::NowFromSystemTime(); |
24 base::Time::Exploded tex; | 26 base::Time::Exploded tex; |
25 t.LocalExplode(&tex); | 27 t.LocalExplode(&tex); |
26 return StringPrintf("%02d%02d/%02d%02d%02d:", | 28 return StringPrintf("%02d%02d/%02d%02d%02d:", |
27 tex.month, tex.day_of_month, | 29 tex.month, tex.day_of_month, |
28 tex.hour, tex.minute, tex.second); | 30 tex.hour, tex.minute, tex.second); |
29 } | 31 } |
30 | 32 |
31 int GetBytesPerPixel(VideoFrame::Format format) { | |
32 // Note: The order is important here for performance. This is sorted from the | |
33 // most common to the less common (PIXEL_FORMAT_ASCII is mostly used | |
34 // just for testing). | |
35 switch (format) { | |
36 case VideoFrame::RGB24: return 3; | |
37 case VideoFrame::RGB565: return 2; | |
38 case VideoFrame::RGB32: return 4; | |
39 case VideoFrame::ASCII: return 1; | |
40 default: | |
41 NOTREACHED() << "Pixel format not supported"; | |
42 return 0; | |
43 } | |
44 } | |
45 | |
46 // Helper methods to calculate plane offset given the coordinates. | 33 // Helper methods to calculate plane offset given the coordinates. |
47 static int CalculateRGBOffset(int x, int y, int stride) { | 34 static int CalculateRGBOffset(int x, int y, int stride) { |
48 return stride * y + GetBytesPerPixel(media::VideoFrame::RGB32) * x; | 35 return stride * y + kBytesPerPixelRGB32 * x; |
49 } | 36 } |
50 | 37 |
51 static int CalculateYOffset(int x, int y, int stride) { | 38 static int CalculateYOffset(int x, int y, int stride) { |
52 DCHECK(((x & 1) == 0) && ((y & 1) == 0)); | 39 DCHECK(((x & 1) == 0) && ((y & 1) == 0)); |
53 return stride * y + x; | 40 return stride * y + x; |
54 } | 41 } |
55 | 42 |
56 static int CalculateUVOffset(int x, int y, int stride) { | 43 static int CalculateUVOffset(int x, int y, int stride) { |
57 DCHECK(((x & 1) == 0) && ((y & 1) == 0)); | 44 DCHECK(((x & 1) == 0) && ((y & 1) == 0)); |
58 return stride * y / 2 + x / 2; | 45 return stride * y / 2 + x / 2; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 source_stride); | 254 source_stride); |
268 int dest_offset = CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(), | 255 int dest_offset = CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(), |
269 dest_rect.y() - dest_buffer_rect.y(), | 256 dest_rect.y() - dest_buffer_rect.y(), |
270 source_stride); | 257 source_stride); |
271 | 258 |
272 // Copy bits. | 259 // Copy bits. |
273 CopyRect(source_buffer + source_offset, | 260 CopyRect(source_buffer + source_offset, |
274 source_stride, | 261 source_stride, |
275 dest_buffer + dest_offset, | 262 dest_buffer + dest_offset, |
276 dest_stride, | 263 dest_stride, |
277 GetBytesPerPixel(media::VideoFrame::RGB32), | 264 kBytesPerPixelRGB32, |
278 SkIRect::MakeWH(dest_rect.width(), dest_rect.height())); | 265 SkIRect::MakeWH(dest_rect.width(), dest_rect.height())); |
279 } | 266 } |
280 | 267 |
281 } // namespace remoting | 268 } // namespace remoting |
OLD | NEW |