Skip to content

Commit

Permalink
Handle orientation conversion first if the input format is not RGB or…
Browse files Browse the repository at this point in the history
… RGBA to improve the color space conversion + rotation performance.

PiperOrigin-RevId: 368262094
  • Loading branch information
tensorflower-gardener authored and tflite-support-robot committed Apr 13, 2021
1 parent 0fa445a commit d1123e3
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions tensorflow_lite_support/cc/task/vision/utils/frame_buffer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,16 +593,32 @@ absl::Status FrameBufferUtils::Preprocess(
CropResizeOperation(0, 0, buffer.dimension(), pre_orient_dimension));
}

// Handle color space conversion.
if (output_buffer->format() != buffer.format()) {
frame_buffer_operations.push_back(
ConvertOperation(output_buffer->format()));
}

// Handle orientation conversion.
if (output_buffer->orientation() != buffer.orientation()) {
frame_buffer_operations.push_back(
OrientOperation(output_buffer->orientation()));
// Handle color space conversion first if the input format is RGB or RGBA,
// because the rotation performance for RGB and RGBA formats are not optimzed
// in libyuv.
if (buffer.format() == FrameBuffer::Format::kRGB ||
buffer.format() == FrameBuffer::Format::kRGBA) {
if (output_buffer->format() != buffer.format()) {
frame_buffer_operations.push_back(
ConvertOperation(output_buffer->format()));
}
// Handle orientation conversion
if (output_buffer->orientation() != buffer.orientation()) {
frame_buffer_operations.push_back(
OrientOperation(output_buffer->orientation()));
}
} else {
// Handle orientation conversion first if the input format is not RGB or
// RGBA.
if (output_buffer->orientation() != buffer.orientation()) {
frame_buffer_operations.push_back(
OrientOperation(output_buffer->orientation()));
}
// Handle color space conversion
if (output_buffer->format() != buffer.format()) {
frame_buffer_operations.push_back(
ConvertOperation(output_buffer->format()));
}
}

// Execute the processing pipeline.
Expand Down

0 comments on commit d1123e3

Please sign in to comment.