Skip to content

Commit 33153ce

Browse files
committed
add stb
1 parent 2914e47 commit 33153ce

8 files changed

Lines changed: 8023 additions & 9 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44
[submodule "3rdparty/onetbb"]
55
path = 3rdparty/onetbb
66
url = https://github.com/uxlfoundation/oneTBB
7-
[submodule "3rdparty/opencv"]
8-
path = 3rdparty/opencv
9-
url = https://github.com/opencv/opencv

3rdparty/opencv

Lines changed: 0 additions & 1 deletion
This file was deleted.

3rdparty/stb/stb_image.h

Lines changed: 7988 additions & 0 deletions
Large diffs are not rendered by default.

cmake/configure.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if( UNIX )
5252
-Wold-style-definition \
5353
-Wmissing-prototypes")
5454

55-
if (${ENABLE_ADDRESS_SANITIZER} OR ${ENABLE_UB_SANITIZER})
55+
if ("${ENABLE_ADDRESS_SANITIZER}" OR "${ENABLE_UB_SANITIZER}")
5656
set (COMMON_COMPILER_FLAGS "${COMMON_COMPILER_FLAGS} -Wno-cast-align")
5757
endif()
5858

modules/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ add_dependencies(${exec_func_tests} ppc_googletest)
2828
target_link_directories(${exec_func_tests} PUBLIC ${CMAKE_BINARY_DIR}/ppc_googletest/install/lib)
2929
target_link_libraries(${exec_func_tests} PUBLIC gtest gtest_main)
3030

31+
add_library(stb_image INTERFACE)
32+
target_include_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb/stb_image.h)
33+
target_link_libraries(${exec_func_tests} PUBLIC stb_image)
34+
3135
target_link_libraries(${exec_func_tests} PUBLIC ${exec_func_lib})
3236

3337
enable_testing()

modules/core/util/include/util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22
#include <string>
3+
#include <vector>
34

45
namespace ppc::util {
56

67
std::string GetAbsolutePath(const std::string &relative_path);
78
int GetPPCNumThreads();
9+
bool GetImageData(const std::string &abs_path, std::vector<uint8_t> &image, int &width, int &height, int &channels);
810

911
} // namespace ppc::util

modules/core/util/src/util.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
#include <cstdint>
66
#include <iostream>
77
#include <memory>
8-
#include <vector>
98
#endif
109

10+
#define STB_IMAGE_IMPLEMENTATION
11+
#include <stb/stb_image.h>
12+
1113
#include <filesystem>
14+
#include <iostream>
1215
#include <string>
1316

1417
std::string ppc::util::GetAbsolutePath(const std::string &relative_path) {
@@ -31,3 +34,18 @@ int ppc::util::GetPPCNumThreads() {
3134
#endif
3235
return num_threads;
3336
}
37+
38+
bool ppc::util::GetImageData(const std::string &abs_path,
39+
std::vector<uint8_t> &image, int &width, int &height, int &channels) {
40+
width = -1;
41+
height = -1;
42+
channels = -1;
43+
unsigned char *data = stbi_load(abs_path.c_str(), &width, &height, &channels, 0);
44+
if (data == nullptr) {
45+
std::cerr << "Failed to load image: " << stbi_failure_reason() << '\n';
46+
return false;
47+
}
48+
image = std::vector<uint8_t>(data, data + (width * height * channels));
49+
stbi_image_free(data);
50+
return true;
51+
}

tasks/all/example/func_tests/func_all.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ TEST(nesterov_a_test_task_all, test_matmul_50) {
3838
}
3939

4040
TEST(nesterov_a_test_task_all, test_matmul_from_pic) {
41-
cv::Mat img = cv::imread(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"));
42-
EXPECT_EQ(img.rows, img.cols);
43-
const int count = (img.rows + img.cols) / 10;
41+
int width = -1;
42+
int height = -1;
43+
int channels = -1;
44+
std::vector<uint8_t> img;
45+
46+
EXPECT_TRUE(ppc::util::GetImageData(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"),
47+
img, width, height, channels));
48+
EXPECT_EQ(width, height);
49+
const int count = (width + height) / 10;
4450

4551
// Create data
4652
std::vector<int> in(count * count, 0);

0 commit comments

Comments
 (0)