From 249b42db7cd39d7ec20094242cd7a8c41ea3b442 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Mon, 10 May 2021 17:00:57 +0530 Subject: aiq: Provide a BinaryData wrapper The AIQ class loads data as instances of ia_binary_data. The data for this structure should be loaded from files, and the lifetime of the data is managed by the lifetime of the class. Signed-off-by: Kieran Bingham Signed-off-by: Umang Jain --- binary_data.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 binary_data.cpp (limited to 'binary_data.cpp') diff --git a/binary_data.cpp b/binary_data.cpp new file mode 100644 index 0000000..aa65778 --- /dev/null +++ b/binary_data.cpp @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright (C) 2021, Google Inc. + * + * binary_data.cpp - AIQ Binary Data Wrapper + */ + +#include "binary_data.h" + +#include +#include + +namespace libcamera::ipa::ipu3 { + +LOG_DEFINE_CATEGORY(AIBD) + +/** + * \class BinaryData + * \brief Binary Data wrapper + * + * Loads data from a file, and returns it as an ia_binary_data type. + * Data is freed automatically when the object goes out of scope. + */ + +BinaryData::BinaryData() +{ + iaBinaryData_.data = nullptr; + iaBinaryData_.size = 0; +} + +int BinaryData::load(const char *filename) +{ + File binary(filename); + + if (!binary.exists()) { + LOG(AIBD, Error) << "Failed to find file: " << filename; + return -ENOENT; + } + + if (!binary.open(File::ReadOnly)) { + LOG(AIBD, Error) << "Failed to open: " << filename; + return -EINVAL; + } + + ssize_t fileSize = binary.size(); + if (fileSize < 0) { + LOG(AIBD, Error) << "Failed to determine fileSize: " << filename; + return -ENODATA; + } + + data_.resize(fileSize); + + int bytesRead = binary.read(data_); + if (bytesRead != fileSize) { + LOG(AIBD, Error) << "Failed to read file: " << filename; + return -EINVAL; + } + + iaBinaryData_.data = data_.data(); + iaBinaryData_.size = fileSize; + + LOG(AIBD, Info) << "Successfully loaded: " << filename; + + return 0; +} + +} /* namespace libcamera::ipa::ipu3 */ -- cgit v1.2.1