aboutsummaryrefslogtreecommitdiff
path: root/utils/Utils.cpp
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-07-03 12:06:23 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:10 +0000
commit12be7ab4876f77fecfab903df70791623219b3da (patch)
tree1cfa6852e60948bee9db0831a9f3abc97a2031c8 /utils/Utils.cpp
parente39334c15c7fd141bb8173d5017ea5ca157fca2c (diff)
downloadComputeLibrary-12be7ab4876f77fecfab903df70791623219b3da.tar.gz
COMPMID-1310: Create graph validation executables.
Change-Id: I9e0b57b1b83fe5a95777cdaeddba6ecef650bafc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/138697 Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'utils/Utils.cpp')
-rw-r--r--utils/Utils.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/utils/Utils.cpp b/utils/Utils.cpp
index a5c6a95a2a..133248e30c 100644
--- a/utils/Utils.cpp
+++ b/utils/Utils.cpp
@@ -74,7 +74,11 @@ int run_example(int argc, char **argv, std::unique_ptr<Example> example)
try
{
- example->do_setup(argc, argv);
+ bool status = example->do_setup(argc, argv);
+ if(!status)
+ {
+ return 1;
+ }
example->do_run();
example->do_teardown();
@@ -141,6 +145,41 @@ void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint
}
}
+ImageType get_image_type_from_file(const std::string &filename)
+{
+ ImageType type = ImageType::UNKNOWN;
+
+ try
+ {
+ // Open file
+ std::ifstream fs;
+ fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
+ fs.open(filename, std::ios::in | std::ios::binary);
+
+ // Identify type from magic number
+ std::array<unsigned char, 2> magic_number{ { 0 } };
+ fs >> magic_number[0] >> magic_number[1];
+
+ // PPM check
+ if(static_cast<char>(magic_number[0]) == 'P' && static_cast<char>(magic_number[1]) == '6')
+ {
+ type = ImageType::PPM;
+ }
+ else if(magic_number[0] == 0xFF && magic_number[1] == 0xD8)
+ {
+ type = ImageType::JPEG;
+ }
+
+ fs.close();
+ }
+ catch(std::runtime_error &e)
+ {
+ ARM_COMPUTE_ERROR("Accessing %s: %s", filename.c_str(), e.what());
+ }
+
+ return type;
+}
+
std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
{
// Check the PPM magic number is valid