summaryrefslogtreecommitdiff
path: root/binary_data.cpp
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2021-05-10 17:00:57 +0530
committerUmang Jain <umang.jain@ideasonboard.com>2021-06-28 14:12:06 +0530
commit249b42db7cd39d7ec20094242cd7a8c41ea3b442 (patch)
tree57fbc62da85337a020e4cf75615b242a7e4fd639 /binary_data.cpp
parentf21b9306a7893017b9f7e6b95001da9abade30f7 (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>
Diffstat (limited to 'binary_data.cpp')
-rw-r--r--binary_data.cpp67
1 files changed, 67 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 */