From 25ab591a9fb21d24e09a5120c0a3080c4f560927 Mon Sep 17 00:00:00 2001 From: "jijoong.moon" Date: Mon, 21 Sep 2020 16:41:36 +0900 Subject: [PATCH] [ Application ] Make Util for Application Currently some of application use bitmap_helper and they have it independently. rather than do this way, It might be better to make static lib and link. **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: jijoong.moon --- Applications/KNN/jni/Android.mk | 25 +++-- Applications/KNN/jni/bitmap_helpers.cpp | 119 -------------------- Applications/KNN/jni/bitmap_helpers.h | 30 ----- Applications/KNN/jni/meson.build | 5 +- .../CIFAR_Classification/jni/Android.mk | 14 ++- .../CIFAR_Classification/jni/meson.build | 5 +- .../Draw_Classification/jni/Android.mk | 16 ++- .../Draw_Classification/jni/bitmap_helpers.cpp | 121 --------------------- .../Draw_Classification/jni/bitmap_helpers.h | 30 ----- .../Draw_Classification/jni/meson.build | 5 +- Applications/meson.build | 1 + Applications/utils/jni/Android.mk | 27 +++++ Applications/utils/jni/Application.mk | 3 + .../jni/bitmap_helpers.cpp | 4 + .../jni => utils/jni/includes}/bitmap_helpers.h | 0 Applications/utils/jni/meson.build | 24 ++++ 16 files changed, 105 insertions(+), 324 deletions(-) delete mode 100644 Applications/KNN/jni/bitmap_helpers.cpp delete mode 100644 Applications/KNN/jni/bitmap_helpers.h delete mode 100644 Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.cpp delete mode 100644 Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.h create mode 100644 Applications/utils/jni/Android.mk create mode 100644 Applications/utils/jni/Application.mk rename Applications/{TransferLearning/CIFAR_Classification => utils}/jni/bitmap_helpers.cpp (99%) rename Applications/{TransferLearning/CIFAR_Classification/jni => utils/jni/includes}/bitmap_helpers.h (100%) create mode 100644 Applications/utils/jni/meson.build diff --git a/Applications/KNN/jni/Android.mk b/Applications/KNN/jni/Android.mk index 36518ec..2171163 100644 --- a/Applications/KNN/jni/Android.mk +++ b/Applications/KNN/jni/Android.mk @@ -8,10 +8,10 @@ $(error ANDROID_NDK is not defined!) endif ifndef NNTRAINER_ROOT -NNTRAINER_ROOT := $(LOCAL_PATH)/../../../libs/arm64-v8a -NNTRAINER_INCLUDES := $(LOCAL_PATH)/../../../nntrainer/include \ - $(LOCAL_PATH)/../../../api \ - $(LOCAL_PATH)/../../../api/capi/include/platform +NNTRAINER_ROOT := $(LOCAL_PATH)/../../../ +NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer/include \ + $(NNTRAINER_ROOT)/api \ + $(NNTRAINER_ROOT)/api/capi/include/platform endif include $(CLEAR_VARS) @@ -39,7 +39,16 @@ include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := nntrainer -LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libnntrainer.so +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libs/$(TARGET_ARCH_ABI)/libnntrainer.so + +include $(PREBUILT_SHARED_LIBRARY) + + +include $(CLEAR_VARS) + +LOCAL_MODULE := app_utils +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/Applications/utils/libs/$(TARGET_ARCH_ABI)/libapp_utils.so +APP_UTILS_INCLUDES := $(NNTRAINER_ROOT)/Applications/utils/jni/includes include $(PREBUILT_SHARED_LIBRARY) @@ -56,12 +65,12 @@ LOCAL_ARM_MODE := arm LOCAL_MODULE := knn_sample LOCAL_LDLIBS := -llog -LOCAL_SRC_FILES := main_sample.cpp bitmap_helpers.cpp +LOCAL_SRC_FILES := main_sample.cpp -LOCAL_SHARED_LIBRARIES := nntrainer +LOCAL_SHARED_LIBRARIES := nntrainer app_utils LOCAL_STATIC_LIBRARIES := tensorflow-lite -LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) +LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) $(APP_UTILS_INCLUDES) include $(BUILD_EXECUTABLE) diff --git a/Applications/KNN/jni/bitmap_helpers.cpp b/Applications/KNN/jni/bitmap_helpers.cpp deleted file mode 100644 index a3e3d59..0000000 --- a/Applications/KNN/jni/bitmap_helpers.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -@file bitmat_helpers.cpp -@brief bitmap_helpers from tensorflow - -==============================================================================*/ - -#include -#include -#include -#include -#include - -#include // NOLINT(build/include_order) - -#include "bitmap_helpers.h" - -#define LOG(x) std::cerr - -namespace tflite { -namespace label_image { - -uint8_t *decode_bmp(const uint8_t *input, int row_size, uint8_t *const output, - int width, int height, int channels, bool top_down) { - for (int i = 0; i < height; i++) { - int src_pos; - int dst_pos; - - for (int j = 0; j < width; j++) { - if (!top_down) { - src_pos = ((height - 1 - i) * row_size) + j * channels; - } else { - src_pos = i * row_size + j * channels; - } - - dst_pos = (i * width + j) * channels; - - switch (channels) { - case 1: - output[dst_pos] = input[src_pos]; - break; - case 3: - // BGR -> RGB - output[dst_pos] = input[src_pos + 2]; - output[dst_pos + 1] = input[src_pos + 1]; - output[dst_pos + 2] = input[src_pos]; - break; - case 4: - // BGRA -> RGBA - output[dst_pos] = input[src_pos + 2]; - output[dst_pos + 1] = input[src_pos + 1]; - output[dst_pos + 2] = input[src_pos]; - output[dst_pos + 3] = input[src_pos + 3]; - break; - default: - LOG(FATAL) << "Unexpected number of channels: " << channels; - break; - } - } - } - - return output; -} - -uint8_t *read_bmp(const std::string &input_bmp_name, int *width, int *height, - int *channels) { - int begin, end; - - std::ifstream file(input_bmp_name, std::ios::in | std::ios::binary); - if (!file) { - LOG(FATAL) << "input file " << input_bmp_name << " not found\n"; - exit(-1); - } - - begin = file.tellg(); - file.seekg(0, std::ios::end); - end = file.tellg(); - size_t len = end - begin; - - const uint8_t *img_bytes = new uint8_t[len]; - file.seekg(0, std::ios::beg); - file.read((char *)img_bytes, len); - const int32_t header_size = - *(reinterpret_cast(img_bytes + 10)); - *width = *(reinterpret_cast(img_bytes + 18)); - *height = *(reinterpret_cast(img_bytes + 22)); - const int32_t bpp = *(reinterpret_cast(img_bytes + 28)); - *channels = bpp / 8; - - // there may be padding bytes when the width is not a multiple of 4 bytes - // 8 * channels == bits per pixel - const int row_size = (8 * *channels * *width + 31) / 32 * 4; - - // if height is negative, data layout is top down - // otherwise, it's bottom up - bool top_down = (*height < 0); - - // Decode image, allocating tensor once the image size is known - uint8_t *output = new uint8_t[abs(*height) * *width * *channels]; - const uint8_t *bmp_pixels = &img_bytes[header_size]; - decode_bmp(bmp_pixels, row_size, output, *width, abs(*height), *channels, - top_down); - delete[] img_bytes; - return output; -} - -} // namespace label_image -} // namespace tflite diff --git a/Applications/KNN/jni/bitmap_helpers.h b/Applications/KNN/jni/bitmap_helpers.h deleted file mode 100644 index 90511db..0000000 --- a/Applications/KNN/jni/bitmap_helpers.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -@file bitmat_helpers.h -@brief bitmap_helpers from tensorflow - -==============================================================================*/ - -#ifndef TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H_ -#define TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H_ -#include -#include -namespace tflite { -namespace label_image { -uint8_t *read_bmp(const std::string &input_bmp_name, int *width, int *height, - int *channels); -} // namespace label_image -} // namespace tflite - -#endif // TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H diff --git a/Applications/KNN/jni/meson.build b/Applications/KNN/jni/meson.build index 0c1b1c5..bdb3e6d 100644 --- a/Applications/KNN/jni/meson.build +++ b/Applications/KNN/jni/meson.build @@ -1,15 +1,14 @@ res_path = join_paths(meson.current_source_dir(), '..', 'res') knn_sources = [ - 'main_sample.cpp', - 'bitmap_helpers.cpp' + 'main_sample.cpp' ] knn_inc = include_directories('.') e = executable('knn_sample', knn_sources, - dependencies: [iniparser_dep, nntrainer_dep, tflite_dep], + dependencies: [app_utils_dep, iniparser_dep, nntrainer_dep, tflite_dep], install: get_option('install-app'), install_dir: application_install_dir ) diff --git a/Applications/TransferLearning/CIFAR_Classification/jni/Android.mk b/Applications/TransferLearning/CIFAR_Classification/jni/Android.mk index 9c5f684..1a24727 100644 --- a/Applications/TransferLearning/CIFAR_Classification/jni/Android.mk +++ b/Applications/TransferLearning/CIFAR_Classification/jni/Android.mk @@ -48,6 +48,14 @@ include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) +LOCAL_MODULE := app_utils +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/Applications/utils/libs/$(TARGET_ARCH_ABI)/libapp_utils.so +APP_UTILS_INCLUDES := $(NNTRAINER_ROOT)/Applications/utils/jni/includes + +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) + LOCAL_ARM_NEON := true LOCAL_CFLAGS += -std=c++14 -Ofast -mcpu=cortex-a53 -Ilz4-nougat/lib LOCAL_LDFLAGS += -Llz4-nougat/lib/obj/local/$(TARGET_ARCH_ABI)/ @@ -59,13 +67,13 @@ LOCAL_ARM_MODE := arm LOCAL_MODULE := nntrainer_classification LOCAL_LDLIBS := -llog -LOCAL_SRC_FILES := main.cpp bitmap_helpers.cpp +LOCAL_SRC_FILES := main.cpp -LOCAL_SHARED_LIBRARIES := nntrainer +LOCAL_SHARED_LIBRARIES := nntrainer app_utils LOCAL_STATIC_LIBRARIES := tensorflow-lite -LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) +LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) $(APP_UTILS_INCLUDES) include $(BUILD_EXECUTABLE) diff --git a/Applications/TransferLearning/CIFAR_Classification/jni/meson.build b/Applications/TransferLearning/CIFAR_Classification/jni/meson.build index f6f76ad..fcc6b7f 100644 --- a/Applications/TransferLearning/CIFAR_Classification/jni/meson.build +++ b/Applications/TransferLearning/CIFAR_Classification/jni/meson.build @@ -2,13 +2,12 @@ build_root = meson.build_root() res_path = join_paths(meson.current_source_dir(), '..', 'res') classification_sources = [ - 'main.cpp', - 'bitmap_helpers.cpp' + 'main.cpp' ] e = executable('nntrainer_classification', classification_sources, - dependencies: [iniparser_dep, nntrainer_dep, tflite_dep], + dependencies: [app_utils_dep, iniparser_dep, nntrainer_dep, tflite_dep], include_directories: include_directories('.'), install: get_option('install-app'), install_dir: application_install_dir diff --git a/Applications/TransferLearning/Draw_Classification/jni/Android.mk b/Applications/TransferLearning/Draw_Classification/jni/Android.mk index 603e5df..6baa938 100644 --- a/Applications/TransferLearning/Draw_Classification/jni/Android.mk +++ b/Applications/TransferLearning/Draw_Classification/jni/Android.mk @@ -8,7 +8,7 @@ $(error ANDROID_NDK is not defined!) endif ifndef NNTRAINER_ROOT -NNTRAINER_ROOT := $(LOCAL_PATH)/../../../.. +NNTRAINER_ROOT := $(LOCAL_PATH)/../../../../ endif NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer/include \ @@ -56,6 +56,14 @@ include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) +LOCAL_MODULE := app_utils +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/Applications/utils/libs/$(TARGET_ARCH_ABI)/libapp_utils.so +APP_UTILS_INCLUDES := $(NNTRAINER_ROOT)/Applications/utils/jni/includes + +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) + LOCAL_ARM_NEON := true LOCAL_CFLAGS += -std=c++14 -Ofast -mcpu=cortex-a53 -Ilz4-nougat/lib LOCAL_LDFLAGS += -Llz4-nougat/lib/obj/local/$(TARGET_ARCH_ABI)/ @@ -67,12 +75,12 @@ LOCAL_ARM_MODE := arm LOCAL_MODULE := nntrainer_training LOCAL_LDLIBS := -llog -LOCAL_SRC_FILES := main.cpp bitmap_helpers.cpp +LOCAL_SRC_FILES := main.cpp -LOCAL_SHARED_LIBRARIES := capi-nntrainer +LOCAL_SHARED_LIBRARIES := capi-nntrainer app_utils LOCAL_STATIC_LIBRARIES := tensorflow-lite -LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) +LOCAL_C_INCLUDES += $(TFLITE_INCLUDES) $(NNTRAINER_INCLUDES) $(APP_UTILS_INCLUDES) include $(BUILD_EXECUTABLE) diff --git a/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.cpp b/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.cpp deleted file mode 100644 index e3f2e8d..0000000 --- a/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -@file bitmat_helpers.cpp -@brief bitmap_helpers from tensorflow - -==============================================================================*/ - -#include -#include -#include - -#include // NOLINT(build/include_order) - -#include "bitmap_helpers.h" - -#define LOG(x) std::cerr - -namespace tflite { -namespace label_image { - -uint8_t *decode_bmp(const uint8_t *input, int row_size, uint8_t *const output, - int width, int height, int channels, bool top_down) { - for (int i = 0; i < height; i++) { - int src_pos; - int dst_pos; - - for (int j = 0; j < width; j++) { - if (!top_down) { - src_pos = ((height - 1 - i) * row_size) + j * channels; - } else { - src_pos = i * row_size + j * channels; - } - - dst_pos = (i * width + j) * channels; - - switch (channels) { - case 1: - output[dst_pos] = input[src_pos]; - break; - case 3: - // BGR -> RGB - output[dst_pos] = input[src_pos + 2]; - output[dst_pos + 1] = input[src_pos + 1]; - output[dst_pos + 2] = input[src_pos]; - break; - case 4: - // BGRA -> RGBA - output[dst_pos] = input[src_pos + 2]; - output[dst_pos + 1] = input[src_pos + 1]; - output[dst_pos + 2] = input[src_pos]; - output[dst_pos + 3] = input[src_pos + 3]; - break; - default: - LOG(FATAL) << "Unexpected number of channels: " << channels; - break; - } - } - } - - return output; -} - -uint8_t *read_bmp(const char *input_bmp_name, int *width, int *height, - int *channels) { - int begin, end; - - std::ifstream file(input_bmp_name, std::ios::in | std::ios::binary); - if (!file) { - LOG(FATAL) << "input file " << input_bmp_name << " not found\n"; - exit(-1); - } - - begin = file.tellg(); - file.seekg(0, std::ios::end); - end = file.tellg(); - size_t len = end - begin; - - const uint8_t *img_bytes = new uint8_t[len]; - file.seekg(0, std::ios::beg); - file.read((char *)img_bytes, len); - const int32_t header_size = - *(reinterpret_cast(img_bytes + 10)); - *width = *(reinterpret_cast(img_bytes + 18)); - *height = *(reinterpret_cast(img_bytes + 22)); - const int32_t bpp = *(reinterpret_cast(img_bytes + 28)); - *channels = bpp / 8; - - // there may be padding bytes when the width is not a multiple of 4 bytes - // 8 * channels == bits per pixel - const int row_size = (8 * *channels * *width + 31) / 32 * 4; - - // if height is negative, data layout is top down - // otherwise, it's bottom up - bool top_down = (*height < 0); - - // Decode image, allocating tensor once the image size is known - uint8_t *output = new uint8_t[abs(*height) * *width * *channels]; - - const uint8_t *bmp_pixels = &img_bytes[header_size]; - - decode_bmp(bmp_pixels, row_size, output, *width, abs(*height), *channels, - top_down); - - delete[] img_bytes; - - return output; -} - -} // namespace label_image -} // namespace tflite diff --git a/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.h b/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.h deleted file mode 100644 index 5d8ffcd..0000000 --- a/Applications/TransferLearning/Draw_Classification/jni/bitmap_helpers.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -@file bitmat_helpers.h -@brief bitmap_helpers from tensorflow - -==============================================================================*/ - -#ifndef TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H_ -#define TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H_ -#include -#include -namespace tflite { -namespace label_image { -uint8_t *read_bmp(const char *input_bmp_name, int *width, int *height, - int *channels); -} // namespace label_image -} // namespace tflite - -#endif // TENSORFLOW_CONTRIB_LITE_EXAMPLES_LABEL_IMAGE_BITMAP_HELPERS_H diff --git a/Applications/TransferLearning/Draw_Classification/jni/meson.build b/Applications/TransferLearning/Draw_Classification/jni/meson.build index 56cf3fb..9f790aa 100644 --- a/Applications/TransferLearning/Draw_Classification/jni/meson.build +++ b/Applications/TransferLearning/Draw_Classification/jni/meson.build @@ -10,13 +10,12 @@ if build_platform == 'tizen' endif training_sources = [ - 'main.cpp', - 'bitmap_helpers.cpp' + 'main.cpp' ] e = executable('nntrainer_training', training_sources, - dependencies: [iniparser_dep, nntrainer_capi_dep, nnstreamer_capi_dep, tflite_dep], + dependencies: [app_utils_dep, iniparser_dep, nntrainer_capi_dep, nnstreamer_capi_dep, tflite_dep], include_directories: include_directories('.'), install: get_option('install-app'), install_dir: application_install_dir diff --git a/Applications/meson.build b/Applications/meson.build index 831736d..d22709f 100644 --- a/Applications/meson.build +++ b/Applications/meson.build @@ -1,3 +1,4 @@ +subdir('utils/jni') subdir('KNN/jni') subdir('LogisticRegression/jni') subdir('MNIST/jni') diff --git a/Applications/utils/jni/Android.mk b/Applications/utils/jni/Android.mk new file mode 100644 index 0000000..91ed7b0 --- /dev/null +++ b/Applications/utils/jni/Android.mk @@ -0,0 +1,27 @@ +# ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk -j2 +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +ifndef NNTRAINER_ROOT +NNTRAINER_ROOT := $(LOCAL_PATH)/../../.. +endif + +NNTRAINER_APPLICATION := $(NNTRAINER_ROOT)/Applications + +UTILS_SRCS := $(NNTRAINER_APPLICATION)/utils/jni/bitmap_helpers.cpp + +UTILS_INCLUDES := $(NNTRAINER_APPLICATION)/utils/jni/includes + +LOCAL_ARM_NEON := true +LOCAL_CFLAGS += -pthread -fopenmp -fexceptions +LOCAL_CXXFLAGS += -std=c++14 -frtti -fexceptions +LOCAL_LDFLAGS += -fuse-ld=bfd -fopenmp +LOCAL_MODULE_TAGS := optional + +LOCAL_LDLIBS := -llog + +LOCAL_MODULE := app_utils +LOCAL_SRC_FILES := $(UTILS_SRCS) +LOCAL_C_INCLUDES += $(UTILS_INCLUDES) + +include $(BUILD_SHARED_LIBRARY) diff --git a/Applications/utils/jni/Application.mk b/Applications/utils/jni/Application.mk new file mode 100644 index 0000000..228f653 --- /dev/null +++ b/Applications/utils/jni/Application.mk @@ -0,0 +1,3 @@ +APP_ABI = arm64-v8a +APP_STL = c++_shared +APP_PLATFORM=android-24 diff --git a/Applications/TransferLearning/CIFAR_Classification/jni/bitmap_helpers.cpp b/Applications/utils/jni/bitmap_helpers.cpp similarity index 99% rename from Applications/TransferLearning/CIFAR_Classification/jni/bitmap_helpers.cpp rename to Applications/utils/jni/bitmap_helpers.cpp index fe29c30..b8f5648 100644 --- a/Applications/TransferLearning/CIFAR_Classification/jni/bitmap_helpers.cpp +++ b/Applications/utils/jni/bitmap_helpers.cpp @@ -106,10 +106,14 @@ uint8_t *read_bmp(const std::string &input_bmp_name, int *width, int *height, // Decode image, allocating tensor once the image size is known uint8_t *output = new uint8_t[abs(*height) * *width * *channels]; + const uint8_t *bmp_pixels = &img_bytes[header_size]; + decode_bmp(bmp_pixels, row_size, output, *width, abs(*height), *channels, top_down); + delete[] img_bytes; + return output; } diff --git a/Applications/TransferLearning/CIFAR_Classification/jni/bitmap_helpers.h b/Applications/utils/jni/includes/bitmap_helpers.h similarity index 100% rename from Applications/TransferLearning/CIFAR_Classification/jni/bitmap_helpers.h rename to Applications/utils/jni/includes/bitmap_helpers.h diff --git a/Applications/utils/jni/meson.build b/Applications/utils/jni/meson.build new file mode 100644 index 0000000..ff39574 --- /dev/null +++ b/Applications/utils/jni/meson.build @@ -0,0 +1,24 @@ +utils_inc = include_directories('./includes') + +app_utils_source = [ + 'bitmap_helpers.cpp' +] + +shared_library('app_utils', + app_utils_source, + include_directories: utils_inc, + install: get_option('install-app'), + install_dir: application_install_dir +) + +app_utils_lib = static_library('app_utils', + app_utils_source, + include_directories: utils_inc, + install: get_option('install-app'), + install_dir: application_install_dir +) + +app_utils_dep = declare_dependency( + link_with:app_utils_lib, + include_directories: utils_inc +) -- 2.7.4