From 9e2a9bb4be88f2b9a5f886209ff254d743c5aeee Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 20 Oct 2022 12:32:07 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 482565462 --- .../tensor/image_to_tensor_converter_gl_buffer.cc | 13 +++++++------ .../tensor/image_to_tensor_converter_gl_texture.cc | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mediapipe/calculators/tensor/image_to_tensor_converter_gl_buffer.cc b/mediapipe/calculators/tensor/image_to_tensor_converter_gl_buffer.cc index 5671d7b4..14de410f 100644 --- a/mediapipe/calculators/tensor/image_to_tensor_converter_gl_buffer.cc +++ b/mediapipe/calculators/tensor/image_to_tensor_converter_gl_buffer.cc @@ -270,10 +270,10 @@ class GlProcessor : public ImageToTensorConverter { Tensor& output_tensor) override { if (input.format() != mediapipe::GpuBufferFormat::kBGRA32 && input.format() != mediapipe::GpuBufferFormat::kRGBAHalf64 && - input.format() != mediapipe::GpuBufferFormat::kRGBAFloat128) { + input.format() != mediapipe::GpuBufferFormat::kRGBAFloat128 && + input.format() != mediapipe::GpuBufferFormat::kRGB24) { return InvalidArgumentError(absl::StrCat( - "Only 4-channel texture input formats are supported, passed format: ", - static_cast(input.format()))); + "Unsupported format: ", static_cast(input.format()))); } const auto& output_shape = output_tensor.shape(); MP_RETURN_IF_ERROR(ValidateTensorShape(output_shape)); @@ -281,12 +281,13 @@ class GlProcessor : public ImageToTensorConverter { MP_RETURN_IF_ERROR(gl_helper_.RunInGlContext( [this, &output_tensor, &input, &roi, &output_shape, range_min, range_max, tensor_buffer_offset]() -> absl::Status { - constexpr int kRgbaNumChannels = 4; + const int input_num_channels = input.channels(); auto source_texture = gl_helper_.CreateSourceTexture(input); tflite::gpu::gl::GlTexture input_texture( - GL_TEXTURE_2D, source_texture.name(), GL_RGBA, + GL_TEXTURE_2D, source_texture.name(), + input_num_channels == 4 ? GL_RGB : GL_RGBA, source_texture.width() * source_texture.height() * - kRgbaNumChannels * sizeof(uint8_t), + input_num_channels * sizeof(uint8_t), /*layer=*/0, /*owned=*/false); diff --git a/mediapipe/calculators/tensor/image_to_tensor_converter_gl_texture.cc b/mediapipe/calculators/tensor/image_to_tensor_converter_gl_texture.cc index 06dfd578..5efd3404 100644 --- a/mediapipe/calculators/tensor/image_to_tensor_converter_gl_texture.cc +++ b/mediapipe/calculators/tensor/image_to_tensor_converter_gl_texture.cc @@ -174,10 +174,10 @@ class GlProcessor : public ImageToTensorConverter { Tensor& output_tensor) override { if (input.format() != mediapipe::GpuBufferFormat::kBGRA32 && input.format() != mediapipe::GpuBufferFormat::kRGBAHalf64 && - input.format() != mediapipe::GpuBufferFormat::kRGBAFloat128) { + input.format() != mediapipe::GpuBufferFormat::kRGBAFloat128 && + input.format() != mediapipe::GpuBufferFormat::kRGB24) { return InvalidArgumentError(absl::StrCat( - "Only 4-channel texture input formats are supported, passed format: ", - static_cast(input.format()))); + "Unsupported format: ", static_cast(input.format()))); } // TODO: support tensor_buffer_offset > 0 scenario. RET_CHECK_EQ(tensor_buffer_offset, 0)