Loading media/codec2/components/apv/C2SoftApvEnc.cpp +26 −12 Original line number Diff line number Diff line Loading @@ -973,23 +973,37 @@ c2_status_t C2SoftApvEnc::setEncodeArgs(oapv_frms_t* inputFrames, const C2Graphi inputFrames->frm[mReceivedFrames].pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME; switch (layout.type) { case C2PlanarLayout::TYPE_RGB: ALOGE("Not supported RGB color format"); return C2_BAD_VALUE; case C2PlanarLayout::TYPE_RGB: { uint16_t *dstY = (uint16_t*)inputFrames->frm[0].imgb->a[0]; uint16_t *dstUV = (uint16_t*)inputFrames->frm[0].imgb->a[1]; size_t dstYStride = inputFrames->frm[0].imgb->s[0] / 2; size_t dstUVStride = inputFrames->frm[0].imgb->s[1] / 2; convertRGBToP210(dstY, dstUV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, dstYStride, dstUVStride, width, height, mColorAspects->matrix, mColorAspects->range); break; } case C2PlanarLayout::TYPE_RGBA: { [[fallthrough]]; } case C2PlanarLayout::TYPE_YUVA: { ALOGV("Convert from ABGR2101010 to P210"); uint16_t *dstY, *dstU, *dstV; if (mColorFormat == OAPV_CF_PLANAR2) { uint16_t *dstY, *dstUV; dstY = (uint16_t*)inputFrames->frm[0].imgb->a[0]; dstU = (uint16_t*)inputFrames->frm[0].imgb->a[1]; dstV = (uint16_t*)inputFrames->frm[0].imgb->a[2]; convertRGBA1010102ToYUV420Planar16(dstY, dstU, dstV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, width, height, mColorAspects->matrix, mColorAspects->range); dstUV = (uint16_t*)inputFrames->frm[0].imgb->a[1]; size_t dstYStride = inputFrames->frm[0].imgb->s[0] / 2; size_t dstUVStride = inputFrames->frm[0].imgb->s[1] / 2; convertRGBA1010102ToP210(dstY, dstUV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, dstYStride, dstUVStride, width, height, mColorAspects->matrix, mColorAspects->range); break; } else { ALOGE("Not supported color format. %d", mColorFormat); return C2_BAD_VALUE; } } case C2PlanarLayout::TYPE_YUV: { if (IsP010(*input)) { Loading media/codec2/components/base/SimpleC2Component.cpp +60 −3 Original line number Diff line number Diff line Loading @@ -534,8 +534,9 @@ void convertRGBA1010102ToYUV420Planar16(uint16_t* dstY, uint16_t* dstU, uint16_t } void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { uint16_t r, g, b; int32_t i32Y, i32U, i32V; uint16_t zeroLvl = colorRange == C2Color::RANGE_FULL ? 0 : 64; Loading Loading @@ -568,7 +569,63 @@ void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* s } } srcRGBA += srcRGBStride; dstY += width; dstY += dstYStride; dstUV += dstUVStride; } } // Matrix coefficient to convert RGB to Planar YUV data. // Each sub-array represents the 3X3 coeff used with R, G and B static const int16_t bt601Matrix[2][3][3] = { { { 77, 150, 29 }, { -43, -85, 128 }, { 128, -107, -21 } }, /* RANGE_FULL */ { { 66, 129, 25 }, { -38, -74, 112 }, { 112, -94, -18 } }, /* RANGE_LIMITED */ }; static const int16_t bt709Matrix[2][3][3] = { // TRICKY: 18 is adjusted to 19 so that sum of row 1 is 256 { { 54, 183, 19 }, { -29, -99, 128 }, { 128, -116, -12 } }, /* RANGE_FULL */ // TRICKY: -87 is adjusted to -86 so that sum of row 2 is 0 { { 47, 157, 16 }, { -26, -86, 112 }, { 112, -102, -10 } }, /* RANGE_LIMITED */ }; void convertRGBToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { uint8_t r, g, b; uint8_t i8Y, i8U, i8V; int32_t i32Y, i32U, i32V; uint8_t zeroLvl = colorRange == C2Color::RANGE_FULL ? 0 : 16; uint8_t maxLvlLuma = colorRange == C2Color::RANGE_FULL ? 255 : 235; uint8_t maxLvlChroma = colorRange == C2Color::RANGE_FULL ? 255 : 240; // set default range as limited if (colorRange != C2Color::RANGE_FULL && colorRange != C2Color::RANGE_LIMITED) { colorRange = C2Color::RANGE_LIMITED; } const int16_t (*weights)[3] = (colorMatrix == C2Color::MATRIX_BT709) ? bt709Matrix[colorRange - 1] : bt601Matrix[colorRange - 1]; for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { b = (srcRGBA[x] >> 16) & 0xFF; g = (srcRGBA[x] >> 8) & 0xFF; r = srcRGBA[x] & 0xFF; i32Y = ((r * weights[0][0] + g * weights[0][1] + b * weights[0][2]) >> 8) + zeroLvl; i8Y = CLIP3(zeroLvl, i32Y, maxLvlLuma); dstY[x] = ((uint16_t)((double)i8Y * 1023 / 255 + 0.5) << 6) & 0xFFC0; if (x % 2 == 0) { i32U = ((r * weights[1][0] + g * weights[1][1] + b * weights[1][2]) >> 8) + 128; i32V = ((r * weights[2][0] + g * weights[2][1] + b * weights[2][2]) >> 8) + 128; i8U = CLIP3(zeroLvl, i32U, maxLvlChroma); i8V = CLIP3(zeroLvl, i32V, maxLvlChroma); dstUV[x] = ((uint16_t)((double)i8U * 1023 / 255 + 0.5) << 6) & 0xFFC0; dstUV[x + 1] = ((uint16_t)((double)i8V * 1023 / 255 + 0.5) << 6) & 0xFFC0; } } srcRGBA += srcRGBStride; dstY += dstYStride; dstUV += dstUVStride; } } Loading media/codec2/components/base/include/SimpleC2Component.h +7 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,13 @@ void convertRGBA1010102ToYUV420Planar16(uint16_t* dstY, uint16_t* dstU, uint16_t C2Color::range_t colorRange); void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t width, size_t height, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange); void convertRGBToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange); void convertPlanar16ToY410OrRGBA1010102(uint8_t* dst, const uint16_t* srcY, const uint16_t* srcU, Loading Loading
media/codec2/components/apv/C2SoftApvEnc.cpp +26 −12 Original line number Diff line number Diff line Loading @@ -973,23 +973,37 @@ c2_status_t C2SoftApvEnc::setEncodeArgs(oapv_frms_t* inputFrames, const C2Graphi inputFrames->frm[mReceivedFrames].pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME; switch (layout.type) { case C2PlanarLayout::TYPE_RGB: ALOGE("Not supported RGB color format"); return C2_BAD_VALUE; case C2PlanarLayout::TYPE_RGB: { uint16_t *dstY = (uint16_t*)inputFrames->frm[0].imgb->a[0]; uint16_t *dstUV = (uint16_t*)inputFrames->frm[0].imgb->a[1]; size_t dstYStride = inputFrames->frm[0].imgb->s[0] / 2; size_t dstUVStride = inputFrames->frm[0].imgb->s[1] / 2; convertRGBToP210(dstY, dstUV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, dstYStride, dstUVStride, width, height, mColorAspects->matrix, mColorAspects->range); break; } case C2PlanarLayout::TYPE_RGBA: { [[fallthrough]]; } case C2PlanarLayout::TYPE_YUVA: { ALOGV("Convert from ABGR2101010 to P210"); uint16_t *dstY, *dstU, *dstV; if (mColorFormat == OAPV_CF_PLANAR2) { uint16_t *dstY, *dstUV; dstY = (uint16_t*)inputFrames->frm[0].imgb->a[0]; dstU = (uint16_t*)inputFrames->frm[0].imgb->a[1]; dstV = (uint16_t*)inputFrames->frm[0].imgb->a[2]; convertRGBA1010102ToYUV420Planar16(dstY, dstU, dstV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, width, height, mColorAspects->matrix, mColorAspects->range); dstUV = (uint16_t*)inputFrames->frm[0].imgb->a[1]; size_t dstYStride = inputFrames->frm[0].imgb->s[0] / 2; size_t dstUVStride = inputFrames->frm[0].imgb->s[1] / 2; convertRGBA1010102ToP210(dstY, dstUV, (uint32_t*)(input->data()[0]), layout.planes[layout.PLANE_Y].rowInc / 4, dstYStride, dstUVStride, width, height, mColorAspects->matrix, mColorAspects->range); break; } else { ALOGE("Not supported color format. %d", mColorFormat); return C2_BAD_VALUE; } } case C2PlanarLayout::TYPE_YUV: { if (IsP010(*input)) { Loading
media/codec2/components/base/SimpleC2Component.cpp +60 −3 Original line number Diff line number Diff line Loading @@ -534,8 +534,9 @@ void convertRGBA1010102ToYUV420Planar16(uint16_t* dstY, uint16_t* dstU, uint16_t } void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { uint16_t r, g, b; int32_t i32Y, i32U, i32V; uint16_t zeroLvl = colorRange == C2Color::RANGE_FULL ? 0 : 64; Loading Loading @@ -568,7 +569,63 @@ void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* s } } srcRGBA += srcRGBStride; dstY += width; dstY += dstYStride; dstUV += dstUVStride; } } // Matrix coefficient to convert RGB to Planar YUV data. // Each sub-array represents the 3X3 coeff used with R, G and B static const int16_t bt601Matrix[2][3][3] = { { { 77, 150, 29 }, { -43, -85, 128 }, { 128, -107, -21 } }, /* RANGE_FULL */ { { 66, 129, 25 }, { -38, -74, 112 }, { 112, -94, -18 } }, /* RANGE_LIMITED */ }; static const int16_t bt709Matrix[2][3][3] = { // TRICKY: 18 is adjusted to 19 so that sum of row 1 is 256 { { 54, 183, 19 }, { -29, -99, 128 }, { 128, -116, -12 } }, /* RANGE_FULL */ // TRICKY: -87 is adjusted to -86 so that sum of row 2 is 0 { { 47, 157, 16 }, { -26, -86, 112 }, { 112, -102, -10 } }, /* RANGE_LIMITED */ }; void convertRGBToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange) { uint8_t r, g, b; uint8_t i8Y, i8U, i8V; int32_t i32Y, i32U, i32V; uint8_t zeroLvl = colorRange == C2Color::RANGE_FULL ? 0 : 16; uint8_t maxLvlLuma = colorRange == C2Color::RANGE_FULL ? 255 : 235; uint8_t maxLvlChroma = colorRange == C2Color::RANGE_FULL ? 255 : 240; // set default range as limited if (colorRange != C2Color::RANGE_FULL && colorRange != C2Color::RANGE_LIMITED) { colorRange = C2Color::RANGE_LIMITED; } const int16_t (*weights)[3] = (colorMatrix == C2Color::MATRIX_BT709) ? bt709Matrix[colorRange - 1] : bt601Matrix[colorRange - 1]; for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { b = (srcRGBA[x] >> 16) & 0xFF; g = (srcRGBA[x] >> 8) & 0xFF; r = srcRGBA[x] & 0xFF; i32Y = ((r * weights[0][0] + g * weights[0][1] + b * weights[0][2]) >> 8) + zeroLvl; i8Y = CLIP3(zeroLvl, i32Y, maxLvlLuma); dstY[x] = ((uint16_t)((double)i8Y * 1023 / 255 + 0.5) << 6) & 0xFFC0; if (x % 2 == 0) { i32U = ((r * weights[1][0] + g * weights[1][1] + b * weights[1][2]) >> 8) + 128; i32V = ((r * weights[2][0] + g * weights[2][1] + b * weights[2][2]) >> 8) + 128; i8U = CLIP3(zeroLvl, i32U, maxLvlChroma); i8V = CLIP3(zeroLvl, i32V, maxLvlChroma); dstUV[x] = ((uint16_t)((double)i8U * 1023 / 255 + 0.5) << 6) & 0xFFC0; dstUV[x + 1] = ((uint16_t)((double)i8V * 1023 / 255 + 0.5) << 6) & 0xFFC0; } } srcRGBA += srcRGBStride; dstY += dstYStride; dstUV += dstUVStride; } } Loading
media/codec2/components/base/include/SimpleC2Component.h +7 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,13 @@ void convertRGBA1010102ToYUV420Planar16(uint16_t* dstY, uint16_t* dstU, uint16_t C2Color::range_t colorRange); void convertRGBA1010102ToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t width, size_t height, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange); void convertRGBToP210(uint16_t* dstY, uint16_t* dstUV, const uint32_t* srcRGBA, size_t srcRGBStride, size_t dstYStride, size_t dstUVStride, size_t width, size_t height, C2Color::matrix_t colorMatrix, C2Color::range_t colorRange); void convertPlanar16ToY410OrRGBA1010102(uint8_t* dst, const uint16_t* srcY, const uint16_t* srcU, Loading