#include #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include #include "app.hh" #include "input.hh" namespace pg { namespace { class Exporter final : public App { public: static inline TypeInfo kType = TypeInfo::Create("Exporter"); Exporter() noexcept { } void Update() noexcept override { const auto id = " Exporter | "+ std::to_string(reinterpret_cast(this)); if (ImGui::Begin(id.c_str())) { ImGui::DragInt("src", &src_); ImGui::InputText("dir", &dir_); if (ImGui::Button("export")) { Export(); } } ImGui::End(); } private: int src_ = 0; std::string dir_; void Export() noexcept { const auto src = Input::instance().slots(static_cast(src_)); const auto n = src->frames(); for (size_t i = 0; i < n; ++i) { const auto f = src->Fetch(i); if (!f.rgba) break; const auto path = dir_+"/"+std::to_string(i)+".png"; stbi_write_png( path.c_str(), static_cast(f.w), static_cast(f.h), 4, f.rgba, static_cast(f.w*4)); } } }; } } // namespace pg