Skip to content

Commit c8cd3d6

Browse files
committed
Moved frame buffer null check to utils
1 parent 84ca38b commit c8cd3d6

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

tensorflow_lite_support/c/task/vision/image_classifier.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,8 @@ TfLiteClassificationResult* TfLiteImageClassifierClassifyWithRoi(
183183
return nullptr;
184184
}
185185

186-
if (frame_buffer == nullptr) {
187-
::tflite::support::CreateTfLiteSupportError(
188-
kInvalidArgumentError, "Expected non null frame buffer.", error);
189-
return nullptr;
190-
}
191-
192186
StatusOr<std::unique_ptr<FrameBufferCpp>> cpp_frame_buffer_status =
193-
::tflite::task::vision::CreateCppFrameBuffer(*frame_buffer);
187+
::tflite::task::vision::CreateCppFrameBuffer(frame_buffer);
194188
if (!cpp_frame_buffer_status.ok()) {
195189
tflite::support::CreateTfLiteSupportErrorWithStatus(
196190
cpp_frame_buffer_status.status(), error);

tensorflow_lite_support/c/task/vision/utils/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ cc_library(
1616
deps = [
1717
"//tensorflow_lite_support/c/task/vision/core:frame_buffer",
1818
"//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils",
19+
"//tensorflow_lite_support/cc:common",
1920
],
2021
)

tensorflow_lite_support/c/task/vision/utils/frame_buffer_cpp_c_utils.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,33 @@ limitations under the License.
1515

1616
#include "tensorflow_lite_support/c/task/vision/utils/frame_buffer_cpp_c_utils.h"
1717

18+
#include "external/com_google_absl/absl/strings/str_format.h"
19+
#include "tensorflow_lite_support/cc/common.h"
20+
1821
namespace tflite {
1922
namespace task {
2023
namespace vision {
2124

2225
namespace {
2326
using FrameBufferCpp = ::tflite::task::vision::FrameBuffer;
2427
using ::tflite::support::StatusOr;
28+
using ::tflite::support::TfLiteSupportStatus;
2529
} // namespace
2630

2731
StatusOr<std::unique_ptr<FrameBufferCpp>> CreateCppFrameBuffer(
28-
const TfLiteFrameBuffer& frame_buffer) {
32+
const TfLiteFrameBuffer* frame_buffer) {
33+
if (frame_buffer == nullptr)
34+
return CreateStatusWithPayload(
35+
absl::StatusCode::kInvalidArgument,
36+
absl::StrFormat("Expected non null frame buffer."),
37+
TfLiteSupportStatus::kInvalidArgumentError);
38+
2939
FrameBufferCpp::Format frame_buffer_format =
30-
FrameBufferCpp::Format(frame_buffer.format);
40+
FrameBufferCpp::Format(frame_buffer->format);
3141

3242
return CreateFromRawBuffer(
33-
frame_buffer.buffer,
34-
{frame_buffer.dimension.width, frame_buffer.dimension.height},
43+
frame_buffer->buffer,
44+
{frame_buffer->dimension.width, frame_buffer->dimension.height},
3545
frame_buffer_format);
3646
}
3747

tensorflow_lite_support/c/task/vision/utils/frame_buffer_cpp_c_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace task {
2828
namespace vision {
2929

3030
tflite::support::StatusOr<std::unique_ptr<tflite::task::vision::FrameBuffer>>
31-
CreateCppFrameBuffer(const TfLiteFrameBuffer& frame_buffer);
31+
CreateCppFrameBuffer(const TfLiteFrameBuffer* frame_buffer);
3232

3333
} // namespace vision
3434
} // namespace task

0 commit comments

Comments
 (0)