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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 int x = RoundToTwosMultiple(rect.left()); | 212 int x = RoundToTwosMultiple(rect.left()); |
213 int y = RoundToTwosMultiple(rect.top()); | 213 int y = RoundToTwosMultiple(rect.top()); |
214 int right = RoundToTwosMultiple(rect.right() + 1); | 214 int right = RoundToTwosMultiple(rect.right() + 1); |
215 int bottom = RoundToTwosMultiple(rect.bottom() + 1); | 215 int bottom = RoundToTwosMultiple(rect.bottom() + 1); |
216 return SkIRect::MakeLTRB(x, y, right, bottom); | 216 return SkIRect::MakeLTRB(x, y, right, bottom); |
217 } | 217 } |
218 | 218 |
219 SkIRect ScaleRect(const SkIRect& rect, | 219 SkIRect ScaleRect(const SkIRect& rect, |
220 const SkISize& in_size, | 220 const SkISize& in_size, |
221 const SkISize& out_size) { | 221 const SkISize& out_size) { |
222 int left = (rect.left() * out_size.width()) / in_size.width(); | 222 // Use floating point to up/down scale more accurately. |
Wez
2012/02/17 23:42:17
Given that the results are still integer, how is t
alexeypa (please no reviews)
2012/02/21 23:00:44
Up-scaling didn't work properly in all cases with
Wez
2012/02/23 00:11:09
Do remember in what way it was broken? I'd prefer
alexeypa (please no reviews)
2012/02/23 17:10:33
Sorry, I don't remember. I do remember that I hit
Wez
2012/02/23 22:59:26
OK; there's no intrinsic reason why doing the inte
alexeypa (please no reviews)
2012/02/23 23:59:14
OK, here is the bug I was talking about. Say in_si
Wez
2012/02/24 00:12:30
Correct. :)
alexeypa (please no reviews)
2012/02/24 16:46:56
I don't think anything can be called a performance
Wez
2012/02/24 18:02:04
Sorry, I should have pointed out that my comments
| |
223 int top = (rect.top() * out_size.height()) / in_size.height(); | 223 float scale_x = static_cast<float>(out_size.width()) / in_size.width(); |
224 int right = (rect.right() * out_size.width() + out_size.width() - 1) / | 224 float scale_y = static_cast<float>(out_size.height()) / in_size.height(); |
225 in_size.width(); | 225 |
226 int bottom = (rect.bottom() * out_size.height() + out_size.height() - 1) / | 226 int left = static_cast<int>(floor(scale_x * rect.left())); |
227 in_size.height(); | 227 int top = static_cast<int>(floor(scale_y * rect.top())); |
228 int right = static_cast<int>(ceil(scale_x * rect.right())); | |
229 int bottom = static_cast<int>(ceil(scale_y * rect.bottom())); | |
228 return SkIRect::MakeLTRB(left, top, right, bottom); | 230 return SkIRect::MakeLTRB(left, top, right, bottom); |
229 } | 231 } |
230 | 232 |
231 void CopyRect(const uint8* src_plane, | 233 void CopyRect(const uint8* src_plane, |
232 int src_plane_stride, | 234 int src_plane_stride, |
233 uint8* dest_plane, | 235 uint8* dest_plane, |
234 int dest_plane_stride, | 236 int dest_plane_stride, |
235 int bytes_per_pixel, | 237 int bytes_per_pixel, |
236 const SkIRect& rect) { | 238 const SkIRect& rect) { |
237 // Get the address of the starting point. | 239 // Get the address of the starting point. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 // Copy bits. | 274 // Copy bits. |
273 CopyRect(source_buffer + source_offset, | 275 CopyRect(source_buffer + source_offset, |
274 source_stride, | 276 source_stride, |
275 dest_buffer + dest_offset, | 277 dest_buffer + dest_offset, |
276 dest_stride, | 278 dest_stride, |
277 GetBytesPerPixel(media::VideoFrame::RGB32), | 279 GetBytesPerPixel(media::VideoFrame::RGB32), |
278 SkIRect::MakeWH(dest_rect.width(), dest_rect.height())); | 280 SkIRect::MakeWH(dest_rect.width(), dest_rect.height())); |
279 } | 281 } |
280 | 282 |
281 } // namespace remoting | 283 } // namespace remoting |
OLD | NEW |