Skip to content

Commit

Permalink
Update git URL for stb (#117)
Browse files Browse the repository at this point in the history
* Update git URL for stb

* Upgrade stb_image_resize2.h

* Update image_io.cpp

STBIR_RGBA replaced with static_cast<stbir_pixel_layout>(depth)
  • Loading branch information
amirtronics committed Oct 31, 2023
1 parent a98e42d commit 2d4669c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set(CXXOPTS_ENABLE_INSTALL OFF CACHE BOOL "Generate the install target" FORCE)

FetchContent_MakeAvailable(extern_cxxopts)

foreach(STB_IMAGE_LIB "stb_image" "stb_image_write" "stb_image_resize")
foreach(STB_IMAGE_LIB "stb_image" "stb_image_write" "stb_image_resize2")
FetchContent_Declare(
extern_${STB_IMAGE_LIB}
URL https://github.com/raw/nothings/stb/master/${STB_IMAGE_LIB}.h
Expand Down
2 changes: 1 addition & 1 deletion utils/image_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target_sources(image-io PUBLIC src/image_io.cpp
)
target_include_directories(image-io PUBLIC include)

target_link_libraries(image-io ${TORCH_LIBRARIES} stb-image stb-image-write stb-image-resize)
target_link_libraries(image-io ${TORCH_LIBRARIES} stb-image stb-image-write stb-image-resize2)

set_target_properties(image-io PROPERTIES
CXX_STANDARD 14
Expand Down
6 changes: 3 additions & 3 deletions utils/image_io/src/image_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "stb_image_write.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"
#include "stb_image_resize2.h"

namespace image_io {
namespace {
Expand Down Expand Up @@ -165,8 +165,8 @@ torch::Tensor load_image(const std::string& file_path,

std::vector<unsigned char> image_resized_buffer(buffer_size);

stbir_resize_uint8(image_raw.get(), width, height, 0,
image_resized_buffer.data(), new_width, new_height, 0, depth);
stbir_resize_uint8_linear(image_raw.get(), width, height, 0,
image_resized_buffer.data(), new_width, new_height, 0, static_cast<stbir_pixel_layout>(depth));

return transform(torch::from_blob(image_resized_buffer.data(),
{new_height, new_width, depth}, torch::kUInt8).clone().to(torch::kFloat32).permute({2, 0, 1}).div_(255));
Expand Down

0 comments on commit 2d4669c

Please sign in to comment.