Fix glScalerCalculator not clearing background in FIT mode

In FIT mode, the image is scaled in an aspect ratio preserving way. That means, the calculator does not render a full-screen quad. The letterbox areas are not drawn. This can cause artifacts, e.g. when MediaPipe reuses the GPU buffer from some other operation. This CL always clears the render target in FIT mode.

PiperOrigin-RevId: 566562715
This commit is contained in:
MediaPipe Team 2023-09-19 02:16:15 -07:00 committed by Copybara-Service
parent 94cda40a83
commit 0ed199186b

View File

@ -292,6 +292,14 @@ absl::Status GlScalerCalculator::Process(CalculatorContext* cc) {
GetOutputFormat());
helper_.BindFramebuffer(dst);
if (scale_mode_ == FrameScaleMode::kFit) {
// In kFit scale mode, the rendered quad does not fill the whole
// framebuffer, so clear it beforehand.
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(src1.target(), src1.name());
if (src2.name()) {