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" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const SkISize& out_size) { | 207 const SkISize& out_size) { |
208 int left = (rect.left() * out_size.width()) / in_size.width(); | 208 int left = (rect.left() * out_size.width()) / in_size.width(); |
209 int top = (rect.top() * out_size.height()) / in_size.height(); | 209 int top = (rect.top() * out_size.height()) / in_size.height(); |
210 int right = (rect.right() * out_size.width() + in_size.width() - 1) / | 210 int right = (rect.right() * out_size.width() + in_size.width() - 1) / |
211 in_size.width(); | 211 in_size.width(); |
212 int bottom = (rect.bottom() * out_size.height() + in_size.height() - 1) / | 212 int bottom = (rect.bottom() * out_size.height() + in_size.height() - 1) / |
213 in_size.height(); | 213 in_size.height(); |
214 return SkIRect::MakeLTRB(left, top, right, bottom); | 214 return SkIRect::MakeLTRB(left, top, right, bottom); |
215 } | 215 } |
216 | 216 |
217 void CopyRect(const uint8* src_plane, | |
218 int src_plane_stride, | |
219 uint8* dest_plane, | |
220 int dest_plane_stride, | |
221 int bytes_per_pixel, | |
222 const SkIRect& rect) { | |
223 // Get the address of the starting point. | |
224 const int src_y_offset = src_plane_stride * rect.top(); | |
225 const int dest_y_offset = dest_plane_stride * rect.top(); | |
226 const int x_offset = bytes_per_pixel * rect.left(); | |
227 src_plane += src_y_offset + x_offset; | |
228 dest_plane += dest_y_offset + x_offset; | |
229 | |
230 // Copy pixels in the rectangle line by line. | |
231 const int bytes_per_line = bytes_per_pixel * rect.width(); | |
232 const int height = rect.height(); | |
233 for (int i = 0 ; i < height; ++i) { | |
234 memcpy(dest_plane, src_plane, bytes_per_line); | |
235 src_plane += src_plane_stride; | |
236 dest_plane += dest_plane_stride; | |
237 } | |
238 } | |
239 | |
240 void CopyRGB32Rect(const uint8* source_buffer, | 217 void CopyRGB32Rect(const uint8* source_buffer, |
241 int source_stride, | 218 int source_stride, |
242 const SkIRect& source_buffer_rect, | 219 const SkIRect& source_buffer_rect, |
243 uint8* dest_buffer, | 220 uint8* dest_buffer, |
244 int dest_stride, | 221 int dest_stride, |
245 const SkIRect& dest_buffer_rect, | 222 const SkIRect& dest_buffer_rect, |
246 const SkIRect& dest_rect) { | 223 const SkIRect& dest_rect) { |
247 DCHECK(dest_buffer_rect.contains(dest_rect)); | 224 DCHECK(dest_buffer_rect.contains(dest_rect)); |
248 DCHECK(source_buffer_rect.contains(dest_rect)); | 225 DCHECK(source_buffer_rect.contains(dest_rect)); |
249 | 226 |
250 // Get the address of the starting point. | 227 // Get the address of the starting point. |
251 int source_offset = CalculateRGBOffset(dest_rect.x() - source_buffer_rect.x(), | 228 source_buffer += CalculateRGBOffset(dest_rect.x() - source_buffer_rect.x(), |
252 dest_rect.y() - source_buffer_rect.y(), | 229 dest_rect.y() - source_buffer_rect.y(), |
253 source_stride); | 230 source_stride); |
254 int dest_offset = CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(), | 231 dest_buffer += CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(), |
255 dest_rect.y() - dest_buffer_rect.y(), | 232 dest_rect.y() - dest_buffer_rect.y(), |
256 source_stride); | 233 source_stride); |
257 | 234 |
258 // Copy bits. | 235 // Copy pixels in the rectangle line by line. |
259 CopyRect(source_buffer + source_offset, | 236 const int bytes_per_line = kBytesPerPixelRGB32 * dest_rect.width(); |
260 source_stride, | 237 for (int i = 0 ; i < dest_rect.height(); ++i) { |
261 dest_buffer + dest_offset, | 238 memcpy(dest_buffer, source_buffer, bytes_per_line); |
262 dest_stride, | 239 source_buffer += source_stride; |
263 kBytesPerPixelRGB32, | 240 dest_buffer += dest_stride; |
264 SkIRect::MakeWH(dest_rect.width(), dest_rect.height())); | 241 } |
265 } | 242 } |
266 | 243 |
267 std::string ReplaceLfByCrLf(const std::string& in) { | 244 std::string ReplaceLfByCrLf(const std::string& in) { |
268 std::string out; | 245 std::string out; |
269 out.resize(2 * in.size()); | 246 out.resize(2 * in.size()); |
270 char* out_p_begin = &out[0]; | 247 char* out_p_begin = &out[0]; |
271 char* out_p = out_p_begin; | 248 char* out_p = out_p_begin; |
272 const char* in_p_begin = &in[0]; | 249 const char* in_p_begin = &in[0]; |
273 const char* in_p_end = &in[in.size()]; | 250 const char* in_p_end = &in[in.size()]; |
274 for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { | 251 for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 305 } |
329 | 306 |
330 ++ptr; | 307 ++ptr; |
331 } | 308 } |
332 } | 309 } |
333 | 310 |
334 return true; | 311 return true; |
335 } | 312 } |
336 | 313 |
337 } // namespace remoting | 314 } // namespace remoting |
OLD | NEW |