Switching to a general align function.

Review URL: https://webrtc-codereview.appspot.com/851005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2847 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mikhal@webrtc.org
2012-09-28 16:07:10 +00:00
parent d1e7a9a90c
commit c7ecc11571
3 changed files with 12 additions and 15 deletions

View File

@ -57,11 +57,12 @@ enum VideoRotationMode {
kRotate270 = 270, kRotate270 = 270,
}; };
// Align value to 64 bits. // Align integer values.
// Input: // Input:
// - value : Input value to be aligned. // - value : Input value to be aligned.
// Return value: An aligned to 64 bit form of the input value. // - alignment : Alignment basis (power of 2).
int AlignTo64Bit(int value); // Return value: An aligned form of the input value.
int AlignInt(int value, int alignment);
// Calculate the required buffer size. // Calculate the required buffer size.
// Input: // Input:

View File

@ -332,15 +332,10 @@ TEST_F(TestLibYuv, DISABLED_MirrorTest) {
} }
TEST_F(TestLibYuv, alignment) { TEST_F(TestLibYuv, alignment) {
int value = 640; int value = 0x3FF; // 1023
int aligned_value = (value + 63) & ~63; EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero.
EXPECT_EQ(AlignTo64Bit(value), aligned_value); EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero.
value = 600; EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero.
aligned_value = (value + 63) & ~63;
EXPECT_EQ(AlignTo64Bit(value), aligned_value);
value = 0;
aligned_value = (value + 63) & ~63;
EXPECT_EQ(AlignTo64Bit(value), aligned_value);
} }
} // namespace } // namespace

View File

@ -52,8 +52,9 @@ VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) {
return kUnknown; return kUnknown;
} }
int AlignTo64Bit(int value) { int AlignInt(int value, int alignment) {
return ((value + 63) & ~63); assert(!((alignment - 1) & alignment));
return ((value + alignment - 1) & ~ (alignment - 1));
} }
int CalcBufferSize(VideoType type, int width, int height) { int CalcBufferSize(VideoType type, int width, int height) {