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

Unified Diff: remoting/base/util.cc

Issue 9331003: Improving the decoder pipeline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: remoting/base/util.cc
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index 486b6a3510e6f42efa1680d449d7363628aa4b14..3b86a88190d0bb61d044e1c2003ada0d888be8ba 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -55,31 +55,6 @@ static int CalculateUVOffset(int x, int y, int stride) {
return stride * y / 2 + x / 2;
}
-void ConvertYUVToRGB32WithRect(const uint8* y_plane,
- const uint8* u_plane,
- const uint8* v_plane,
- uint8* rgb_plane,
- const SkIRect& rect,
- int y_stride,
- int uv_stride,
- int rgb_stride) {
- DCHECK((rect.x() & 1) == 0 && (rect.y() & 1) == 0);
- int rgb_offset = CalculateRGBOffset(rect.left(), rect.top(), rgb_stride);
- int y_offset = CalculateYOffset(rect.left(), rect.top(), y_stride);
- int uv_offset = CalculateUVOffset(rect.left(), rect.top(), uv_stride);
-
- media::ConvertYUVToRGB32(y_plane + y_offset,
- u_plane + uv_offset,
- v_plane + uv_offset,
- rgb_plane + rgb_offset,
- rect.width(),
- rect.height(),
- y_stride,
- uv_stride,
- rgb_stride,
- media::YV12);
-}
-
void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane,
uint8* y_plane,
uint8* u_plane,
@@ -106,6 +81,74 @@ void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane,
uv_stride);
}
+void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane,
+ const uint8* source_uplane,
+ const uint8* source_vplane,
+ int source_ystride,
+ int source_uvstride,
+ const SkISize& source_size,
+ const SkIRect& source_clip,
+ uint8* dest_buffer,
+ int dest_stride,
+ const SkISize& dest_size,
+ const SkIRect& dest_clip,
+ const SkIRect& dest_rect) {
+ // N.B. It is caller's responsibility to check if strides are large enough. We
+ // cannot do it here anyway.
+ DCHECK(SkIRect::MakeSize(source_size).contains(source_clip));
+ DCHECK(SkIRect::MakeSize(dest_size).contains(dest_clip));
+ DCHECK(dest_clip.contains(dest_rect));
+ DCHECK(source_clip.contains(ScaleRect(dest_rect, dest_size, source_size)));
+
+ // If the source and/or destination buffers don't start at (0, 0)
+ // offset the pointers to pretend we have complete buffers.
+ int y_offset = - CalculateYOffset(source_clip.x(), source_clip.y(),
+ source_ystride);
+ int uv_offset = - CalculateUVOffset(source_clip.x(), source_clip.y(),
+ source_uvstride);
+ int rgb_offset = - CalculateRGBOffset(dest_clip.x(), dest_clip.y(),
+ dest_stride);
+
+ // See if scaling is needed.
+ if (source_size == dest_size) {
+ DCHECK((dest_rect.x() & 1) == 0 && (dest_rect.y() & 1) == 0);
+
+ y_offset += CalculateYOffset(dest_rect.left(), dest_rect.top(),
+ source_ystride);
+ uv_offset += CalculateUVOffset(dest_rect.left(), dest_rect.top(),
+ source_uvstride);
+ rgb_offset += CalculateRGBOffset(dest_rect.left(), dest_rect.top(),
+ dest_stride);
+
+ media::ConvertYUVToRGB32(source_yplane + y_offset,
+ source_uplane + uv_offset,
+ source_vplane + uv_offset,
+ dest_buffer + rgb_offset,
+ dest_rect.width(),
+ dest_rect.height(),
+ source_ystride,
+ source_uvstride,
+ dest_stride,
+ media::YV12);
+ } else {
+ media::ScaleYUVToRGB32WithRect(source_yplane + y_offset,
+ source_uplane + uv_offset,
+ source_vplane + uv_offset,
+ dest_buffer + rgb_offset,
+ source_size.width(),
+ source_size.height(),
+ dest_size.width(),
+ dest_size.height(),
+ dest_rect.left(),
+ dest_rect.top(),
+ dest_rect.right(),
+ dest_rect.bottom(),
+ source_ystride,
+ source_uvstride,
+ dest_stride);
+ }
+}
+
int RoundToTwosMultiple(int x) {
return x & (~1);
}
@@ -121,12 +164,13 @@ SkIRect AlignRect(const SkIRect& rect) {
SkIRect ScaleRect(const SkIRect& rect,
const SkISize& in_size,
const SkISize& out_size) {
- int left = (rect.left() * out_size.width()) / in_size.width();
- int top = (rect.top() * out_size.height()) / in_size.height();
- int right = (rect.right() * out_size.width() + out_size.width() - 1) /
- in_size.width();
- int bottom = (rect.bottom() * out_size.height() + out_size.height() - 1) /
- in_size.height();
+ SkScalar scale_x = SkScalarDiv(out_size.width(), in_size.width());
+ SkScalar scale_y = SkScalarDiv(out_size.height(), in_size.height());
+
+ int left = SkScalarFloorToInt(scale_x * rect.left());
+ int top = SkScalarFloorToInt(scale_y * rect.top());
+ int right = SkScalarCeilToInt(scale_x * rect.right());
+ int bottom = SkScalarCeilToInt(scale_y * rect.bottom());
return SkIRect::MakeLTRB(left, top, right, bottom);
}
@@ -153,4 +197,31 @@ void CopyRect(const uint8* src_plane,
}
}
+void CopyRGB32Rect(const uint8* source_buffer,
+ int source_stride,
+ const SkIRect& source_clip,
+ uint8* dest_buffer,
+ int dest_stride,
+ const SkIRect& dest_clip,
+ const SkIRect& dest_rect) {
+ DCHECK(dest_clip.contains(dest_rect));
+ DCHECK(source_clip.contains(dest_rect));
+
+ // Get the address of the starting point.
+ int source_offset = CalculateRGBOffset(dest_rect.x() - source_clip.x(),
+ dest_rect.y() - source_clip.y(),
+ source_stride);
+ int dest_offset = CalculateRGBOffset(dest_rect.x() - dest_clip.x(),
+ dest_rect.y() - dest_clip.y(),
+ source_stride);
+
+ // Copy bits.
+ CopyRect(source_buffer + source_offset,
+ source_stride,
+ dest_buffer + dest_offset,
+ dest_stride,
+ GetBytesPerPixel(media::VideoFrame::RGB32),
+ SkIRect::MakeWH(dest_rect.width(), dest_rect.height()));
+}
+
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698