From 0ed199186be46b18679bb4d93f8f6f1f403354f3 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Tue, 19 Sep 2023 02:16:15 -0700 Subject: [PATCH] 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 --- mediapipe/gpu/gl_scaler_calculator.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mediapipe/gpu/gl_scaler_calculator.cc b/mediapipe/gpu/gl_scaler_calculator.cc index 14540b52..a181287f 100644 --- a/mediapipe/gpu/gl_scaler_calculator.cc +++ b/mediapipe/gpu/gl_scaler_calculator.cc @@ -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()) {