diff --git a/example/src/main.cpp b/example/src/main.cpp index df3cd07..17d8ccd 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -8,23 +8,11 @@ #include "widget/panel_widget/mbox.h" #include "pixel.h" #include "misc/mapped_file/mapped_file.h" -#include "mirage_stb_image.h" +#include "stb_image_loader.h" int main(int argc, char* argv[]) { mirage_app::get().init(); - // auto file = mapped_file::create(); - // file->map_file(L"Z:/Root/Local/NanakoDisk/涩图/可爱偷猴计划/东风谷早苗/57092520_p1.jpg"); - // - // mirage_stb_image image; - // image.init(file->get_data(), file->get_size()); - // - // auto heap = image.load(); - // auto pixel_format = heap->info.get_pixel_format(); - // - // auto accessor = pixel_factory::create_image_accessor(pixel_format, heap->data, heap->info.width, heap->info.height); - // pixel_factory::destroy_image_accessor(accessor); - const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); window->set_content( std::make_shared() diff --git a/src/mirage_render/CMakeLists.txt b/src/mirage_render/CMakeLists.txt index ae00892..1394169 100644 --- a/src/mirage_render/CMakeLists.txt +++ b/src/mirage_render/CMakeLists.txt @@ -7,10 +7,10 @@ add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(${PROJECT_NAME} PUBLIC mirage_core sokol) -option(MIRAGE_STB_IMAGE "Use stb_image" ON) +option(MIRAGE_STB_IMAGE_LOADER "Use stb load image" ON) -if (MIRAGE_STB_IMAGE) - target_link_libraries(${PROJECT_NAME} PUBLIC mirage_stb_image) +if (MIRAGE_STB_IMAGE_LOADER) + target_link_libraries(${PROJECT_NAME} PUBLIC mirage_stb_image_loader) endif () # 添加编译shader的自定义命令 diff --git a/src/mirage_stb_image/CMakeLists.txt b/src/mirage_stb_image/CMakeLists.txt index 3c64524..7eef283 100644 --- a/src/mirage_stb_image/CMakeLists.txt +++ b/src/mirage_stb_image/CMakeLists.txt @@ -1,4 +1,4 @@ -project(mirage_stb_image) +project(mirage_stb_image_loader) set(SRC_FILES) retrieve_files(${CMAKE_CURRENT_SOURCE_DIR} SRC_FILES) diff --git a/src/mirage_stb_image/mirage_stb_image.cpp b/src/mirage_stb_image/stb_image_loader.cpp similarity index 80% rename from src/mirage_stb_image/mirage_stb_image.cpp rename to src/mirage_stb_image/stb_image_loader.cpp index 17e03b7..069caac 100644 --- a/src/mirage_stb_image/mirage_stb_image.cpp +++ b/src/mirage_stb_image/stb_image_loader.cpp @@ -1,4 +1,4 @@ -#include "mirage_stb_image.h" +#include "stb_image_loader.h" #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" @@ -47,12 +47,12 @@ sg_pixel_format stb_image_info::get_pixel_format() const { } } -void mirage_stb_image::init(void* in_data, int32_t in_size) { +void stb_image_loader::init(void* in_data, int32_t in_size) { data_ = static_cast(in_data); size_ = in_size; } -stb_image_info mirage_stb_image::get_info() const { +stb_image_info stb_image_loader::get_info() const { stb_image_info info{}; stbi_info_from_memory(data_, size_, &info.width, &info.height, &info.channels); info.is_hdr = is_hdr(); @@ -60,30 +60,30 @@ stb_image_info mirage_stb_image::get_info() const { return info; } -bool mirage_stb_image::is_hdr() const { +bool stb_image_loader::is_hdr() const { return stbi_is_hdr_from_memory(data_, size_); } -bool mirage_stb_image::is_16_bit() const { +bool stb_image_loader::is_16_bit() const { return stbi_is_16_bit_from_memory(data_, size_); } -float* mirage_stb_image::load_hdr() const { +float* stb_image_loader::load_hdr() const { int width, height, channels; return stbi_loadf_from_memory(data_, size_, &width, &height, &channels, 4); } -uint16_t* mirage_stb_image::load_16_bit() const { +uint16_t* stb_image_loader::load_16_bit() const { int width, height, channels; return stbi_load_16_from_memory(data_, size_, &width, &height, &channels, 4); } -uint8_t* mirage_stb_image::load_8_bit() const { +uint8_t* stb_image_loader::load_8_bit() const { int width, height, channels; return stbi_load_from_memory(data_, size_, &width, &height, &channels, 4); } -std::shared_ptr mirage_stb_image::load() const { +std::shared_ptr stb_image_loader::load() const { auto heap = std::make_shared(); heap->info = get_info(); if (is_hdr()) diff --git a/src/mirage_stb_image/mirage_stb_image.h b/src/mirage_stb_image/stb_image_loader.h similarity index 97% rename from src/mirage_stb_image/mirage_stb_image.h rename to src/mirage_stb_image/stb_image_loader.h index 662d527..dbd3c4f 100644 --- a/src/mirage_stb_image/mirage_stb_image.h +++ b/src/mirage_stb_image/stb_image_loader.h @@ -25,7 +25,7 @@ struct stb_heap_image { } }; -class mirage_stb_image { +class stb_image_loader { public: void init(void* in_data, int32_t in_size); @@ -37,7 +37,6 @@ public: [[nodiscard]] uint16_t* load_16_bit() const; [[nodiscard]] uint8_t* load_8_bit() const; [[nodiscard]] std::shared_ptr load() const; - private: stbi_uc* data_{};