AV1 Encoder: Fix 10bit encoding
This CL adds proper handling of 10bit input data. For now the only
10-bit input supported is P010.
Fixes: 256115786,255277757,253491266,249143037
Bug: 252836071
Test: atest CodecEncoderSurfaceTest
Change-Id: Id74efbc47bd0cc81895ce6d40a939efc19ec9794
diff --git a/media/codec2/components/base/SimpleC2Component.cpp b/media/codec2/components/base/SimpleC2Component.cpp
index 199875d..d549c3b 100644
--- a/media/codec2/components/base/SimpleC2Component.cpp
+++ b/media/codec2/components/base/SimpleC2Component.cpp
@@ -414,6 +414,44 @@
dstUV += dstUVStride;
}
}
+
+void convertP010ToYUV420Planar16(uint16_t *dstY, uint16_t *dstU, uint16_t *dstV,
+ const uint16_t *srcY, const uint16_t *srcUV,
+ size_t srcYStride, size_t srcUVStride, size_t dstYStride,
+ size_t dstUStride, size_t dstVStride, size_t width,
+ size_t height, bool isMonochrome) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
+ dstY[x] = srcY[x] >> 6;
+ }
+ srcY += srcYStride;
+ dstY += dstYStride;
+ }
+
+ if (isMonochrome) {
+ // Fill with neutral U/V values.
+ for (size_t y = 0; y < (height + 1) / 2; ++y) {
+ for (size_t x = 0; x < (width + 1) / 2; ++x) {
+ dstU[x] = kNeutralUVBitDepth10;
+ dstV[x] = kNeutralUVBitDepth10;
+ }
+ dstU += dstUStride;
+ dstV += dstVStride;
+ }
+ return;
+ }
+
+ for (size_t y = 0; y < (height + 1) / 2; ++y) {
+ for (size_t x = 0; x < (width + 1) / 2; ++x) {
+ dstU[x] = srcUV[2 * x] >> 6;
+ dstV[x] = srcUV[2 * x + 1] >> 6;
+ }
+ dstU += dstUStride;
+ dstV += dstVStride;
+ srcUV += srcUVStride;
+ }
+}
+
std::unique_ptr<C2Work> SimpleC2Component::WorkQueue::pop_front() {
std::unique_ptr<C2Work> work = std::move(mQueue.front().work);
mQueue.pop_front();