| OLD | NEW |
| 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" | 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ConvertYUVToRGB32WithRect(const uint8* y_plane, | 56 void ConvertYUVToRGB32WithRect(const uint8* y_plane, |
| 57 const uint8* u_plane, | 57 const uint8* u_plane, |
| 58 const uint8* v_plane, | 58 const uint8* v_plane, |
| 59 uint8* rgb_plane, | 59 uint8* rgb_plane, |
| 60 const SkIRect& rect, | 60 const SkIRect& rect, |
| 61 int y_stride, | 61 int y_stride, |
| 62 int uv_stride, | 62 int uv_stride, |
| 63 int rgb_stride) { | 63 int rgb_stride) { |
| 64 int rgb_offset = CalculateRGBOffset(rect.fLeft, rect.fTop, rgb_stride); | 64 int rgb_offset = CalculateRGBOffset(rect.left(), rect.top(), rgb_stride); |
| 65 int y_offset = CalculateYOffset(rect.fLeft, rect.fTop, y_stride); | 65 int y_offset = CalculateYOffset(rect.left(), rect.top(), y_stride); |
| 66 int uv_offset = CalculateUVOffset(rect.fLeft, rect.fTop, uv_stride); | 66 int uv_offset = CalculateUVOffset(rect.left(), rect.top(), uv_stride); |
| 67 | 67 |
| 68 media::ConvertYUVToRGB32(y_plane + y_offset, | 68 media::ConvertYUVToRGB32(y_plane + y_offset, |
| 69 u_plane + uv_offset, | 69 u_plane + uv_offset, |
| 70 v_plane + uv_offset, | 70 v_plane + uv_offset, |
| 71 rgb_plane + rgb_offset, | 71 rgb_plane + rgb_offset, |
| 72 rect.width(), | 72 rect.width(), |
| 73 rect.height(), | 73 rect.height(), |
| 74 y_stride, | 74 y_stride, |
| 75 uv_stride, | 75 uv_stride, |
| 76 rgb_stride, | 76 rgb_stride, |
| 77 media::YV12); | 77 media::YV12); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void ScaleYUVToRGB32WithRect(const uint8* y_plane, | 80 void ScaleYUVToRGB32WithRect(const uint8* y_plane, |
| 81 const uint8* u_plane, | 81 const uint8* u_plane, |
| 82 const uint8* v_plane, | 82 const uint8* v_plane, |
| 83 uint8* rgb_plane, | 83 uint8* rgb_plane, |
| 84 const SkIRect& source_rect, | 84 const SkIRect& source_rect, |
| 85 const SkIRect& dest_rect, | 85 const SkIRect& dest_rect, |
| 86 int y_stride, | 86 int y_stride, |
| 87 int uv_stride, | 87 int uv_stride, |
| 88 int rgb_stride) { | 88 int rgb_stride) { |
| 89 int rgb_offset = CalculateRGBOffset(dest_rect.fLeft, | 89 int rgb_offset = CalculateRGBOffset(dest_rect.left(), |
| 90 dest_rect.fTop, | 90 dest_rect.top(), |
| 91 rgb_stride); | 91 rgb_stride); |
| 92 int y_offset = CalculateYOffset(source_rect.fLeft, | 92 int y_offset = CalculateYOffset(source_rect.left(), |
| 93 source_rect.fTop, | 93 source_rect.top(), |
| 94 y_stride); | 94 y_stride); |
| 95 int uv_offset = CalculateUVOffset(source_rect.fLeft, | 95 int uv_offset = CalculateUVOffset(source_rect.left(), |
| 96 source_rect.fTop, | 96 source_rect.top(), |
| 97 uv_stride); | 97 uv_stride); |
| 98 | 98 |
| 99 media::ScaleYUVToRGB32(y_plane + y_offset, | 99 media::ScaleYUVToRGB32(y_plane + y_offset, |
| 100 u_plane + uv_offset, | 100 u_plane + uv_offset, |
| 101 v_plane + uv_offset, | 101 v_plane + uv_offset, |
| 102 rgb_plane + rgb_offset, | 102 rgb_plane + rgb_offset, |
| 103 source_rect.width(), | 103 source_rect.width(), |
| 104 source_rect.height(), | 104 source_rect.height(), |
| 105 dest_rect.width(), | 105 dest_rect.width(), |
| 106 dest_rect.height(), | 106 dest_rect.height(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 136 rgb_stride, | 136 rgb_stride, |
| 137 y_stride, | 137 y_stride, |
| 138 uv_stride); | 138 uv_stride); |
| 139 } | 139 } |
| 140 | 140 |
| 141 int RoundToTwosMultiple(int x) { | 141 int RoundToTwosMultiple(int x) { |
| 142 return x & (~1); | 142 return x & (~1); |
| 143 } | 143 } |
| 144 | 144 |
| 145 SkIRect AlignRect(const SkIRect& rect) { | 145 SkIRect AlignRect(const SkIRect& rect) { |
| 146 int x = RoundToTwosMultiple(rect.fLeft); | 146 int x = RoundToTwosMultiple(rect.left()); |
| 147 int y = RoundToTwosMultiple(rect.fTop); | 147 int y = RoundToTwosMultiple(rect.top()); |
| 148 int right = RoundToTwosMultiple(rect.fRight + 1); | 148 int right = RoundToTwosMultiple(rect.right() + 1); |
| 149 int bottom = RoundToTwosMultiple(rect.fBottom + 1); | 149 int bottom = RoundToTwosMultiple(rect.bottom() + 1); |
| 150 return SkIRect::MakeXYWH(x, y, right - x, bottom - y); | 150 return SkIRect::MakeLTRB(x, y, right, bottom); |
| 151 } | 151 } |
| 152 | 152 |
| 153 SkIRect ScaleRect(const SkIRect& rect, | 153 SkIRect ScaleRect(const SkIRect& rect, |
| 154 double horizontal_ratio, | 154 const SkISize& in_size, |
| 155 double vertical_ratio) { | 155 const SkISize& out_size) { |
| 156 int left = floor(rect.left() * horizontal_ratio); | 156 int left = (rect.left() * out_size.width()) / in_size.width(); |
| 157 int top = floor(rect.top() * vertical_ratio); | 157 int top = (rect.top() * out_size.height()) / in_size.height(); |
| 158 int right = ceil(rect.right() * horizontal_ratio); | 158 int right = (rect.right() * out_size.width() + out_size.width() - 1) / |
| 159 int bottom = ceil(rect.bottom() * vertical_ratio); | 159 in_size.width(); |
| 160 int bottom = (rect.bottom() * out_size.height() + out_size.height() - 1) / |
| 161 in_size.height(); |
| 160 return SkIRect::MakeLTRB(left, top, right, bottom); | 162 return SkIRect::MakeLTRB(left, top, right, bottom); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void CopyRect(const uint8* src_plane, | 165 void CopyRect(const uint8* src_plane, |
| 164 int src_plane_stride, | 166 int src_plane_stride, |
| 165 uint8* dest_plane, | 167 uint8* dest_plane, |
| 166 int dest_plane_stride, | 168 int dest_plane_stride, |
| 167 int bytes_per_pixel, | 169 int bytes_per_pixel, |
| 168 const SkIRect& rect) { | 170 const SkIRect& rect) { |
| 169 // Get the address of the starting point. | 171 // Get the address of the starting point. |
| 170 const int src_y_offset = src_plane_stride * rect.fTop; | 172 const int src_y_offset = src_plane_stride * rect.top(); |
| 171 const int dest_y_offset = dest_plane_stride * rect.fTop; | 173 const int dest_y_offset = dest_plane_stride * rect.top(); |
| 172 const int x_offset = bytes_per_pixel * rect.fLeft; | 174 const int x_offset = bytes_per_pixel * rect.left(); |
| 173 src_plane += src_y_offset + x_offset; | 175 src_plane += src_y_offset + x_offset; |
| 174 dest_plane += dest_y_offset + x_offset; | 176 dest_plane += dest_y_offset + x_offset; |
| 175 | 177 |
| 176 // Copy pixels in the rectangle line by line. | 178 // Copy pixels in the rectangle line by line. |
| 177 const int bytes_per_line = bytes_per_pixel * rect.width(); | 179 const int bytes_per_line = bytes_per_pixel * rect.width(); |
| 178 const int height = rect.height(); | 180 const int height = rect.height(); |
| 179 for (int i = 0 ; i < height; ++i) { | 181 for (int i = 0 ; i < height; ++i) { |
| 180 memcpy(dest_plane, src_plane, bytes_per_line); | 182 memcpy(dest_plane, src_plane, bytes_per_line); |
| 181 src_plane += src_plane_stride; | 183 src_plane += src_plane_stride; |
| 182 dest_plane += dest_plane_stride; | 184 dest_plane += dest_plane_stride; |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 | 187 |
| 186 } // namespace remoting | 188 } // namespace remoting |
| OLD | NEW |