diff options
author | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2021-05-10 17:00:57 +0530 |
---|---|---|
committer | Umang Jain <umang.jain@ideasonboard.com> | 2021-06-28 14:12:06 +0530 |
commit | 249b42db7cd39d7ec20094242cd7a8c41ea3b442 (patch) | |
tree | 57fbc62da85337a020e4cf75615b242a7e4fd639 | |
parent | f21b9306a7893017b9f7e6b95001da9abade30f7 (diff) |
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 <kieran.bingham@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
-rw-r--r-- | binary_data.cpp | 67 | ||||
-rw-r--r-- | binary_data.h | 37 | ||||
-rw-r--r-- | meson.build | 2 |
3 files changed, 106 insertions, 0 deletions
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 <libcamera/base/file.h> +#include <libcamera/base/log.h> + +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 */ diff --git a/binary_data.h b/binary_data.h new file mode 100644 index 0000000..6f7e55a --- /dev/null +++ b/binary_data.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright (C) 2021, Google Inc. + * + * binary_data.h - AIQ Binary Data Wrapper + */ + +#include <vector> + +#include <ia_imaging/ia_aiq.h> + +#include <libcamera/base/class.h> + +#ifndef __IPA_IPU3_BINARY_DATA__ +#define __IPA_IPU3_BINARY_DATA__ + +namespace libcamera::ipa::ipu3 { + +class BinaryData +{ +public: + BinaryData(); + + int load(const char *filename); + ia_binary_data *data() { return &iaBinaryData_; } + +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(BinaryData) + + ia_binary_data iaBinaryData_; + std::vector<uint8_t> data_; +}; + +} /* namespace libcamera::ipa::ipu3 */ + +#endif /* __IPA_IPU3_BINARY_DATA__ */ + diff --git a/meson.build b/meson.build index 683af0e..5be3a94 100644 --- a/meson.build +++ b/meson.build @@ -50,6 +50,7 @@ common_arguments = [ ipa_includes = [ include_directories('include'), include_directories('include/ia_imaging'), + include_directories('.'), ] c_arguments = [] @@ -80,6 +81,7 @@ add_project_arguments(c_arguments, language : 'c') add_project_arguments(cpp_arguments, language : 'cpp') ipu3_ipa_files = files([ + 'binary_data.cpp', 'ipu3.cpp', ]) |