Skip to content

Commit 88dcec6

Browse files
committed
add new version stb
1 parent f20b17a commit 88dcec6

5 files changed

Lines changed: 23 additions & 27 deletions

File tree

modules/core/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ 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)
33-
target_link_libraries(${exec_func_tests} PUBLIC stb_image)
34-
3531
target_link_libraries(${exec_func_tests} PUBLIC ${exec_func_lib})
3632

3733
enable_testing()

modules/core/util/include/util.hpp

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

54
namespace ppc::util {
65

76
std::string GetAbsolutePath(const std::string &relative_path);
87
int GetPPCNumThreads();
9-
bool GetImageData(const std::string &abs_path, std::vector<uint8_t> &image, int &width, int &height, int &channels);
108

119
} // namespace ppc::util

modules/core/util/src/util.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
#include <memory>
88
#endif
99

10-
#define STB_IMAGE_IMPLEMENTATION
11-
#include <stb/stb_image.h>
12-
1310
#include <filesystem>
14-
#include <iostream>
1511
#include <string>
1612

1713
std::string ppc::util::GetAbsolutePath(const std::string &relative_path) {
@@ -34,18 +30,3 @@ int ppc::util::GetPPCNumThreads() {
3430
#endif
3531
return num_threads;
3632
}
37-
38-
bool ppc::util::GetImageData(const std::string &abs_path, std::vector<uint8_t> &image, int &width, int &height,
39-
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/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ endif ()
3838

3939
add_compile_definitions(PATH_TO_PPC_PROJECT="${CMAKE_SOURCE_DIR}")
4040

41+
add_library(stb_image INTERFACE)
42+
4143
foreach(TASK_TYPE ${LIST_OF_TASKS})
4244
set(PATH_TO_TASK "${CMAKE_CURRENT_SOURCE_DIR}/${TASK_TYPE}")
4345
get_filename_component(MODULE_NAME ${PATH_TO_TASK} NAME)
@@ -130,6 +132,9 @@ foreach(TASK_TYPE ${LIST_OF_TASKS})
130132
endif()
131133
endif ()
132134

135+
target_include_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
136+
target_link_libraries(${exec_func_tests} PUBLIC stb_image)
137+
133138
add_dependencies(${EXEC_FUNC} ppc_googletest)
134139
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")
135140
target_link_libraries(${EXEC_FUNC} PUBLIC gtest gtest_main)

tasks/all/example/func_tests/func_all.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#include "core/task/include/task.hpp"
1010
#include "core/util/include/util.hpp"
1111

12+
#include <iostream>
13+
#define STB_IMAGE_IMPLEMENTATION
14+
#include <stb/stb_image.h>
15+
#include <string>
16+
1217
TEST(nesterov_a_test_task_all, test_matmul_50) {
1318
constexpr size_t kCount = 50;
1419

@@ -41,9 +46,20 @@ TEST(nesterov_a_test_task_all, test_matmul_from_pic) {
4146
int height = -1;
4247
int channels = -1;
4348
std::vector<uint8_t> img;
49+
std::string abs_path = ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg");
50+
51+
auto get_image_data = [&]() -> bool {
52+
unsigned char *data = stbi_load(abs_path.c_str(), &width, &height, &channels, 0);
53+
if (data == nullptr) {
54+
std::cerr << "Failed to load image: " << stbi_failure_reason() << '\n';
55+
return false;
56+
}
57+
img = std::vector<uint8_t>(data, data + (width * height * channels));
58+
stbi_image_free(data);
59+
return true;
60+
};
61+
EXPECT_TRUE(get_image_data());
4462

45-
EXPECT_TRUE(ppc::util::GetImageData(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"), img, width, height,
46-
channels));
4763
EXPECT_EQ(width, height);
4864
const int count = (width + height) / 10;
4965

0 commit comments

Comments
 (0)