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

Side by Side Diff: remoting/base/util.cc

Issue 8954003: Revised sub-rectangle scaling for use in Chromoting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace bounds-check on loop with a DCHECK. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
6
7 #include <math.h>
8
5 #include "base/logging.h" 9 #include "base/logging.h"
6 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
7 #include "base/time.h" 11 #include "base/time.h"
8 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
9 #include "media/base/yuv_convert.h" 13 #include "media/base/yuv_convert.h"
10 #include "remoting/base/util.h"
11 14
12 using media::VideoFrame; 15 using media::VideoFrame;
13 16
14 namespace remoting { 17 namespace remoting {
15 18
16 std::string GetTimestampString() { 19 std::string GetTimestampString() {
17 base::Time t = base::Time::NowFromSystemTime(); 20 base::Time t = base::Time::NowFromSystemTime();
18 base::Time::Exploded tex; 21 base::Time::Exploded tex;
19 t.LocalExplode(&tex); 22 t.LocalExplode(&tex);
20 return StringPrintf("%02d%02d/%02d%02d%02d:", 23 return StringPrintf("%02d%02d/%02d%02d%02d:",
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 v_plane + uv_offset, 70 v_plane + uv_offset,
68 rgb_plane + rgb_offset, 71 rgb_plane + rgb_offset,
69 rect.width(), 72 rect.width(),
70 rect.height(), 73 rect.height(),
71 y_stride, 74 y_stride,
72 uv_stride, 75 uv_stride,
73 rgb_stride, 76 rgb_stride,
74 media::YV12); 77 media::YV12);
75 } 78 }
76 79
77 void ScaleYUVToRGB32WithRect(const uint8* y_plane,
78 const uint8* u_plane,
79 const uint8* v_plane,
80 uint8* rgb_plane,
81 const SkIRect& source_rect,
82 const SkIRect& dest_rect,
83 int y_stride,
84 int uv_stride,
85 int rgb_stride) {
86 int rgb_offset = CalculateRGBOffset(dest_rect.fLeft,
87 dest_rect.fTop,
88 rgb_stride);
89 int y_offset = CalculateYOffset(source_rect.fLeft,
90 source_rect.fTop,
91 y_stride);
92 int uv_offset = CalculateUVOffset(source_rect.fLeft,
93 source_rect.fTop,
94 uv_stride);
95
96 media::ScaleYUVToRGB32(y_plane + y_offset,
97 u_plane + uv_offset,
98 v_plane + uv_offset,
99 rgb_plane + rgb_offset,
100 source_rect.width(),
101 source_rect.height(),
102 dest_rect.width(),
103 dest_rect.height(),
104 y_stride,
105 uv_stride,
106 rgb_stride,
107 media::YV12,
108 media::ROTATE_0,
109 media::FILTER_NONE);
110 }
111
112 void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, 80 void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane,
113 uint8* y_plane, 81 uint8* y_plane,
114 uint8* u_plane, 82 uint8* u_plane,
115 uint8* v_plane, 83 uint8* v_plane,
116 int x, 84 int x,
117 int y, 85 int y,
118 int width, 86 int width,
119 int height, 87 int height,
120 int rgb_stride, 88 int rgb_stride,
121 int y_stride, 89 int y_stride,
(...skipping 21 matching lines...) Expand all
143 int x = RoundToTwosMultiple(rect.fLeft); 111 int x = RoundToTwosMultiple(rect.fLeft);
144 int y = RoundToTwosMultiple(rect.fTop); 112 int y = RoundToTwosMultiple(rect.fTop);
145 int right = RoundToTwosMultiple(rect.fRight + 1); 113 int right = RoundToTwosMultiple(rect.fRight + 1);
146 int bottom = RoundToTwosMultiple(rect.fBottom + 1); 114 int bottom = RoundToTwosMultiple(rect.fBottom + 1);
147 return SkIRect::MakeXYWH(x, y, right - x, bottom - y); 115 return SkIRect::MakeXYWH(x, y, right - x, bottom - y);
148 } 116 }
149 117
150 SkIRect ScaleRect(const SkIRect& rect, 118 SkIRect ScaleRect(const SkIRect& rect,
151 double horizontal_ratio, 119 double horizontal_ratio,
152 double vertical_ratio) { 120 double vertical_ratio) {
153 int x = rect.fLeft * horizontal_ratio; 121 int left = floor(rect.left() * horizontal_ratio);
154 int y = rect.fTop * vertical_ratio; 122 int top = floor(rect.top() * vertical_ratio);
155 int w = rect.fRight * horizontal_ratio - x; 123 int right = ceil(rect.right() * horizontal_ratio);
156 int h = rect.fBottom * vertical_ratio - y; 124 int bottom = ceil(rect.bottom() * vertical_ratio);
157 125 return SkIRect::MakeLTRB(left, top, right, bottom);
158 return SkIRect::MakeXYWH(x, y, w, h);
159 } 126 }
160 127
161 void CopyRect(const uint8* src_plane, 128 void CopyRect(const uint8* src_plane,
162 int src_plane_stride, 129 int src_plane_stride,
163 uint8* dest_plane, 130 uint8* dest_plane,
164 int dest_plane_stride, 131 int dest_plane_stride,
165 int bytes_per_pixel, 132 int bytes_per_pixel,
166 const SkIRect& rect) { 133 const SkIRect& rect) {
167 // Get the address of the starting point. 134 // Get the address of the starting point.
168 const int src_y_offset = src_plane_stride * rect.fTop; 135 const int src_y_offset = src_plane_stride * rect.fTop;
169 const int dest_y_offset = dest_plane_stride * rect.fTop; 136 const int dest_y_offset = dest_plane_stride * rect.fTop;
170 const int x_offset = bytes_per_pixel * rect.fLeft; 137 const int x_offset = bytes_per_pixel * rect.fLeft;
171 src_plane += src_y_offset + x_offset; 138 src_plane += src_y_offset + x_offset;
172 dest_plane += dest_y_offset + x_offset; 139 dest_plane += dest_y_offset + x_offset;
173 140
174 // Copy pixels in the rectangle line by line. 141 // Copy pixels in the rectangle line by line.
175 const int bytes_per_line = bytes_per_pixel * rect.width(); 142 const int bytes_per_line = bytes_per_pixel * rect.width();
176 const int height = rect.height(); 143 const int height = rect.height();
177 for (int i = 0 ; i < height; ++i) { 144 for (int i = 0 ; i < height; ++i) {
178 memcpy(dest_plane, src_plane, bytes_per_line); 145 memcpy(dest_plane, src_plane, bytes_per_line);
179 src_plane += src_plane_stride; 146 src_plane += src_plane_stride;
180 dest_plane += dest_plane_stride; 147 dest_plane += dest_plane_stride;
181 } 148 }
182 } 149 }
183 150
184 } // namespace remoting 151 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698