| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
| 10 #include "remoting/base/util.h" | 10 #include "remoting/base/util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 static int CalculateUVOffset(int x, int y, int stride) { | 49 static int CalculateUVOffset(int x, int y, int stride) { |
| 50 return stride * y / 2 + x / 2; | 50 return stride * y / 2 + x / 2; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ConvertYUVToRGB32WithRect(const uint8* y_plane, | 53 void ConvertYUVToRGB32WithRect(const uint8* y_plane, |
| 54 const uint8* u_plane, | 54 const uint8* u_plane, |
| 55 const uint8* v_plane, | 55 const uint8* v_plane, |
| 56 uint8* rgb_plane, | 56 uint8* rgb_plane, |
| 57 const gfx::Rect& rect, | 57 const SkIRect& rect, |
| 58 int y_stride, | 58 int y_stride, |
| 59 int uv_stride, | 59 int uv_stride, |
| 60 int rgb_stride) { | 60 int rgb_stride) { |
| 61 int rgb_offset = CalculateRGBOffset(rect.x(), rect.y(), rgb_stride); | 61 int rgb_offset = CalculateRGBOffset(rect.fLeft, rect.fTop, rgb_stride); |
| 62 int y_offset = CalculateYOffset(rect.x(), rect.y(), y_stride); | 62 int y_offset = CalculateYOffset(rect.fLeft, rect.fTop, y_stride); |
| 63 int uv_offset = CalculateUVOffset(rect.x(), rect.y(), uv_stride); | 63 int uv_offset = CalculateUVOffset(rect.fLeft, rect.fTop, uv_stride); |
| 64 | 64 |
| 65 media::ConvertYUVToRGB32(y_plane + y_offset, | 65 media::ConvertYUVToRGB32(y_plane + y_offset, |
| 66 u_plane + uv_offset, | 66 u_plane + uv_offset, |
| 67 v_plane + uv_offset, | 67 v_plane + uv_offset, |
| 68 rgb_plane + rgb_offset, | 68 rgb_plane + rgb_offset, |
| 69 rect.width(), | 69 rect.width(), |
| 70 rect.height(), | 70 rect.height(), |
| 71 y_stride, | 71 y_stride, |
| 72 uv_stride, | 72 uv_stride, |
| 73 rgb_stride, | 73 rgb_stride, |
| 74 media::YV12); | 74 media::YV12); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void ScaleYUVToRGB32WithRect(const uint8* y_plane, | 77 void ScaleYUVToRGB32WithRect(const uint8* y_plane, |
| 78 const uint8* u_plane, | 78 const uint8* u_plane, |
| 79 const uint8* v_plane, | 79 const uint8* v_plane, |
| 80 uint8* rgb_plane, | 80 uint8* rgb_plane, |
| 81 const gfx::Rect& source_rect, | 81 const SkIRect& source_rect, |
| 82 const gfx::Rect& dest_rect, | 82 const SkIRect& dest_rect, |
| 83 int y_stride, | 83 int y_stride, |
| 84 int uv_stride, | 84 int uv_stride, |
| 85 int rgb_stride) { | 85 int rgb_stride) { |
| 86 int rgb_offset = CalculateRGBOffset(dest_rect.x(), dest_rect.y(), rgb_stride); | 86 int rgb_offset = CalculateRGBOffset(dest_rect.fLeft, |
| 87 int y_offset = CalculateYOffset(source_rect.x(), source_rect.y(), y_stride); | 87 dest_rect.fTop, |
| 88 int uv_offset = CalculateUVOffset(source_rect.x(), | 88 rgb_stride); |
| 89 source_rect.y(), uv_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); |
| 90 | 95 |
| 91 media::ScaleYUVToRGB32(y_plane + y_offset, | 96 media::ScaleYUVToRGB32(y_plane + y_offset, |
| 92 u_plane + uv_offset, | 97 u_plane + uv_offset, |
| 93 v_plane + uv_offset, | 98 v_plane + uv_offset, |
| 94 rgb_plane + rgb_offset, | 99 rgb_plane + rgb_offset, |
| 95 source_rect.width(), | 100 source_rect.width(), |
| 96 source_rect.height(), | 101 source_rect.height(), |
| 97 dest_rect.width(), | 102 dest_rect.width(), |
| 98 dest_rect.height(), | 103 dest_rect.height(), |
| 99 y_stride, | 104 y_stride, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 127 height, | 132 height, |
| 128 rgb_stride, | 133 rgb_stride, |
| 129 y_stride, | 134 y_stride, |
| 130 uv_stride); | 135 uv_stride); |
| 131 } | 136 } |
| 132 | 137 |
| 133 int RoundToTwosMultiple(int x) { | 138 int RoundToTwosMultiple(int x) { |
| 134 return x & (~1); | 139 return x & (~1); |
| 135 } | 140 } |
| 136 | 141 |
| 137 gfx::Rect AlignRect(const gfx::Rect& rect) { | 142 SkIRect AlignRect(const SkIRect& rect) { |
| 138 int x = RoundToTwosMultiple(rect.x()); | 143 int x = RoundToTwosMultiple(rect.fLeft); |
| 139 int y = RoundToTwosMultiple(rect.y()); | 144 int y = RoundToTwosMultiple(rect.fTop); |
| 140 int right = RoundToTwosMultiple(rect.right() + 1); | 145 int right = RoundToTwosMultiple(rect.fRight + 1); |
| 141 int bottom = RoundToTwosMultiple(rect.bottom() + 1); | 146 int bottom = RoundToTwosMultiple(rect.fBottom + 1); |
| 142 return gfx::Rect(x, y, right - x, bottom - y); | 147 return SkIRect::MakeXYWH(x, y, right - x, bottom - y); |
| 143 } | 148 } |
| 144 | 149 |
| 145 gfx::Rect ScaleRect(const gfx::Rect& rect, | 150 SkIRect ScaleRect(const SkIRect& rect, |
| 146 double horizontal_ratio, | 151 double horizontal_ratio, |
| 147 double vertical_ratio) { | 152 double vertical_ratio) { |
| 148 gfx::Rect scaled_rect(rect.x() * horizontal_ratio, | 153 int x = rect.fLeft * horizontal_ratio; |
| 149 rect.y() * vertical_ratio, | 154 int y = rect.fTop * vertical_ratio; |
| 150 0, | 155 int w = rect.fRight * horizontal_ratio - x; |
| 151 0); | 156 int h = rect.fBottom * vertical_ratio - y; |
| 152 scaled_rect.set_width( | 157 |
| 153 rect.right() * horizontal_ratio - scaled_rect.x()); | 158 return SkIRect::MakeXYWH(x, y, w, h); |
| 154 scaled_rect.set_height( | |
| 155 rect.bottom() * vertical_ratio - scaled_rect.y()); | |
| 156 return scaled_rect; | |
| 157 } | 159 } |
| 158 | 160 |
| 159 void CopyRect(const uint8* src_plane, | 161 void CopyRect(const uint8* src_plane, |
| 160 int src_plane_stride, | 162 int src_plane_stride, |
| 161 uint8* dest_plane, | 163 uint8* dest_plane, |
| 162 int dest_plane_stride, | 164 int dest_plane_stride, |
| 163 int bytes_per_pixel, | 165 int bytes_per_pixel, |
| 164 const SkIRect& rect) { | 166 const SkIRect& rect) { |
| 165 // Get the address of the starting point. | 167 // Get the address of the starting point. |
| 166 const int src_y_offset = src_plane_stride * rect.fTop; | 168 const int src_y_offset = src_plane_stride * rect.fTop; |
| 167 const int dest_y_offset = dest_plane_stride * rect.fTop; | 169 const int dest_y_offset = dest_plane_stride * rect.fTop; |
| 168 const int x_offset = bytes_per_pixel * rect.fLeft; | 170 const int x_offset = bytes_per_pixel * rect.fLeft; |
| 169 src_plane += src_y_offset + x_offset; | 171 src_plane += src_y_offset + x_offset; |
| 170 dest_plane += dest_y_offset + x_offset; | 172 dest_plane += dest_y_offset + x_offset; |
| 171 | 173 |
| 172 // Copy pixels in the rectangle line by line. | 174 // Copy pixels in the rectangle line by line. |
| 173 const int bytes_per_line = bytes_per_pixel * rect.width(); | 175 const int bytes_per_line = bytes_per_pixel * rect.width(); |
| 174 const int height = rect.height(); | 176 const int height = rect.height(); |
| 175 for (int i = 0 ; i < height; ++i) { | 177 for (int i = 0 ; i < height; ++i) { |
| 176 memcpy(dest_plane, src_plane, bytes_per_line); | 178 memcpy(dest_plane, src_plane, bytes_per_line); |
| 177 src_plane += src_plane_stride; | 179 src_plane += src_plane_stride; |
| 178 dest_plane += dest_plane_stride; | 180 dest_plane += dest_plane_stride; |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 | 183 |
| 182 } // namespace remoting | 184 } // namespace remoting |
| OLD | NEW |