mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
ConvertToARGB: Allows rotation on ARGB input
BUG=libyuv:668 TEST=run unit tests R=fbarchard@google.com Review-Url: https://codereview.chromium.org/2620183002 .
This commit is contained in:
parent
000d2fa91a
commit
cb11559408
@ -50,8 +50,8 @@ int ConvertToARGB(const uint8* sample,
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
// One pass rotation is available for some formats. For the rest, convert
|
// One pass rotation is available for some formats. For the rest, convert
|
||||||
// to I420 (with optional vertical flipping) into a temporary I420 buffer,
|
// to ARGB (with optional vertical flipping) into a temporary ARGB buffer,
|
||||||
// and then rotate the I420 to the final destination buffer.
|
// and then rotate the ARGB to the final destination buffer.
|
||||||
// For in-place conversion, if destination crop_argb is same as source sample,
|
// For in-place conversion, if destination crop_argb is same as source sample,
|
||||||
// also enable temporary buffer.
|
// also enable temporary buffer.
|
||||||
LIBYUV_BOOL need_buf =
|
LIBYUV_BOOL need_buf =
|
||||||
@ -102,9 +102,11 @@ int ConvertToARGB(const uint8* sample,
|
|||||||
inv_crop_height);
|
inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_ARGB:
|
case FOURCC_ARGB:
|
||||||
|
if (!need_buf && !rotation) {
|
||||||
src = sample + (src_width * crop_y + crop_x) * 4;
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
||||||
r = ARGBToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width,
|
r = ARGBToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width,
|
||||||
inv_crop_height);
|
inv_crop_height);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case FOURCC_BGRA:
|
case FOURCC_BGRA:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 4;
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
||||||
@ -253,6 +255,11 @@ int ConvertToARGB(const uint8* sample,
|
|||||||
crop_width, abs_crop_height, rotation);
|
crop_width, abs_crop_height, rotation);
|
||||||
}
|
}
|
||||||
free(rotate_buffer);
|
free(rotate_buffer);
|
||||||
|
} else if (rotation) {
|
||||||
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
||||||
|
r = ARGBRotate(src, src_width * 4,
|
||||||
|
crop_argb, argb_stride,
|
||||||
|
crop_width, inv_crop_height, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@ -1910,4 +1910,40 @@ TESTPLANARTOE(I422, 2, 1, UYVY, 2, 4, ARGB, 4)
|
|||||||
TESTQPLANARTOE(I420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4)
|
TESTQPLANARTOE(I420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4)
|
||||||
TESTQPLANARTOE(I420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4)
|
TESTQPLANARTOE(I420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4)
|
||||||
|
|
||||||
|
TEST_F(LibYUVConvertTest, RotateWithARGBSource) {
|
||||||
|
// 2x2 frames
|
||||||
|
uint32_t src[4];
|
||||||
|
uint32_t dst[4];
|
||||||
|
// some random input
|
||||||
|
src[0] = 0x11000000;
|
||||||
|
src[1] = 0x00450000;
|
||||||
|
src[2] = 0x00009f00;
|
||||||
|
src[3] = 0x000000ff;
|
||||||
|
// zeros on destination
|
||||||
|
dst[0] = 0x00000000;
|
||||||
|
dst[1] = 0x00000000;
|
||||||
|
dst[2] = 0x00000000;
|
||||||
|
dst[3] = 0x00000000;
|
||||||
|
|
||||||
|
int r = ConvertToARGB(
|
||||||
|
reinterpret_cast<uint8_t*>(src),
|
||||||
|
16, // input size
|
||||||
|
reinterpret_cast<uint8_t*>(dst),
|
||||||
|
8, // destination stride
|
||||||
|
0, // crop_x
|
||||||
|
0, // crop_y
|
||||||
|
2, // width
|
||||||
|
2, // height
|
||||||
|
2, // crop width
|
||||||
|
2, // crop height
|
||||||
|
kRotate90, FOURCC_ARGB);
|
||||||
|
|
||||||
|
EXPECT_EQ(r, 0);
|
||||||
|
// 90 degrees rotation, no conversion
|
||||||
|
EXPECT_EQ(dst[0], src[2]);
|
||||||
|
EXPECT_EQ(dst[1], src[0]);
|
||||||
|
EXPECT_EQ(dst[2], src[3]);
|
||||||
|
EXPECT_EQ(dst[3], src[1]);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace libyuv
|
} // namespace libyuv
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user