diff options
author | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-19 18:51:01 +0000 |
---|---|---|
committer | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-19 18:51:01 +0000 |
commit | 30591e06f6c96933813d700ae255b2182f6e15e5 (patch) | |
tree | 9721347c1de135304b0e2766f7c3a99e6c5fe4bd /media/base/video_util.cc | |
parent | c667115d4da70673aea8e6ff069872bd1197339c (diff) | |
download | chromium_src-30591e06f6c96933813d700ae255b2182f6e15e5.zip chromium_src-30591e06f6c96933813d700ae255b2182f6e15e5.tar.gz chromium_src-30591e06f6c96933813d700ae255b2182f6e15e5.tar.bz2 |
Add test for RotatePlaneByPixels.
This is a follow-up patch for https://codereview.chromium.org/11860002/
BUG=161417
Review URL: https://codereview.chromium.org/12207190
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183257 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/video_util.cc')
-rw-r--r-- | media/base/video_util.cc | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/media/base/video_util.cc b/media/base/video_util.cc index 487c595..d7498ad 100644 --- a/media/base/video_util.cc +++ b/media/base/video_util.cc @@ -85,4 +85,105 @@ void FillYUV(VideoFrame* frame, uint8 y, uint8 u, uint8 v) { } } +void RotatePlaneByPixels( + uint8* src, + uint8* dest, + int width, + int height, + int rotation, // Clockwise. + bool flip_vert, + bool flip_horiz) { + DCHECK((width > 0) && (height > 0) && + ((width & 1) == 0) && ((height & 1) == 0) && + (rotation >= 0) && (rotation < 360) && (rotation % 90 == 0)); + + // Consolidate cases. Only 0 and 90 are left. + if (rotation == 180 || rotation == 270) { + rotation -= 180; + flip_vert = !flip_vert; + flip_horiz = !flip_horiz; + } + + int num_rows = height; + int num_cols = width; + int src_stride = width; + // During pixel copying, the corresponding incremental of dest pointer + // when src pointer moves to next row. + int dest_row_step = width; + // During pixel copying, the corresponding incremental of dest pointer + // when src pointer moves to next column. + int dest_col_step = 1; + + if (rotation == 0) { + if (flip_horiz) { + // Use pixel copying. + dest_col_step = -1; + if (flip_vert) { + // Rotation 180. + dest_row_step = -width; + dest += height * width - 1; + } else { + dest += width - 1; + } + } else { + if (flip_vert) { + // Fast copy by rows. + dest += width * (height - 1); + for (int row = 0; row < height; ++row) { + memcpy(dest, src, width); + src += width; + dest -= width; + } + } else { + memcpy(dest, src, width * height); + } + return; + } + } else if (rotation == 90) { + int offset; + if (width > height) { + offset = (width - height) / 2; + src += offset; + num_rows = num_cols = height; + } else { + offset = (height - width) / 2; + src += width * offset; + num_rows = num_cols = width; + } + + dest_col_step = (flip_vert ? -width : width); + dest_row_step = (flip_horiz ? 1 : -1); + if (flip_horiz) { + if (flip_vert) { + dest += (width > height ? width * (height - 1) + offset : + width * (height - offset - 1)); + } else { + dest += (width > height ? offset : width * offset); + } + } else { + if (flip_vert) { + dest += (width > height ? width * height - offset - 1 : + width * (height - offset) - 1); + } else { + dest += (width > height ? width - offset - 1 : + width * (offset + 1) - 1); + } + } + } else { + NOTREACHED(); + } + + // Copy pixels. + for (int row = 0; row < num_rows; ++row) { + uint8* src_ptr = src; + uint8* dest_ptr = dest; + for (int col = 0; col < num_cols; ++col) { + *dest_ptr = *src_ptr++; + dest_ptr += dest_col_step; + } + src += src_stride; + dest += dest_row_step; + } +} + } // namespace media |