From ad213d71c134cb4e7fb4339e5c059f3980e7b1a3 Mon Sep 17 00:00:00 2001 From: Aang23 Date: Sun, 19 Jan 2025 18:55:12 +0100 Subject: [PATCH] WIP --- .../dataset/dataset_product_handler_lua.cpp | 34 +-------- .../viewer2/handler/dataset/lua/geodetic.cpp | 25 +++++++ .../viewer2/handler/dataset/lua/image.cpp | 75 +++++++++++++++++++ .../viewer2/handler/dataset/lua/logger.cpp | 24 ++++++ .../viewer2/handler/dataset/lua/lua_bind.h | 19 +++++ .../viewer2/handler/dataset/lua/product.cpp | 26 +++++++ .../handler/dataset/lua/projection.cpp | 17 +++++ .../viewer2/handler/dataset/lua_processor.cpp | 2 + .../handler/product/image_product_handler.cpp | 18 ++--- 9 files changed, 201 insertions(+), 39 deletions(-) create mode 100644 src-interface/viewer2/handler/dataset/lua/geodetic.cpp create mode 100644 src-interface/viewer2/handler/dataset/lua/image.cpp create mode 100644 src-interface/viewer2/handler/dataset/lua/logger.cpp create mode 100644 src-interface/viewer2/handler/dataset/lua/lua_bind.h create mode 100644 src-interface/viewer2/handler/dataset/lua/product.cpp create mode 100644 src-interface/viewer2/handler/dataset/lua/projection.cpp diff --git a/src-interface/viewer2/handler/dataset/dataset_product_handler_lua.cpp b/src-interface/viewer2/handler/dataset/dataset_product_handler_lua.cpp index 65f77ba56..b01983418 100644 --- a/src-interface/viewer2/handler/dataset/dataset_product_handler_lua.cpp +++ b/src-interface/viewer2/handler/dataset/dataset_product_handler_lua.cpp @@ -43,20 +43,10 @@ namespace satdump lua.open_libraries(sol::lib::string); lua.open_libraries(sol::lib::math); - // Product - auto product_type = lua.new_usertype("Product", sol::constructors()); - product_type["instrument_name"] = &products::Product::instrument_name; - product_type["type"] = &products::Product::type; - product_type["set_product_timestamp"] = &products::Product::set_product_timestamp; - product_type["has_product_timestamp"] = &products::Product::has_product_timestamp; - product_type["get_product_timestamp"] = &products::Product::get_product_timestamp; - product_type["set_product_source"] = &products::Product::set_product_source; - product_type["has_product_source"] = &products::Product::has_product_source; - product_type["save"] = &products::Product::save; - product_type["load"] = &products::Product::load; - - lua["loadProduct"] = &products::loadProduct; + lua.open_libraries(sol::lib::table); + lua.open_libraries(sol::lib::io); + // ImageProduct auto image_product_type = lua.new_usertype("ImageProduct", sol::constructors(), sol::base_classes, sol::bases()); @@ -75,23 +65,7 @@ namespace satdump [](products::ImageProduct *p, std::string c, double a, double b, std::string u) { return products::generate_calibrated_product_channel(p, c, a, b, u); }); - // Image - sol::usertype image_type = lua.new_usertype("Image", sol::constructors()); - - image_type["depth"] = &image::Image::depth; - image_type["width"] = &image::Image::width; - image_type["height"] = &image::Image::height; - image_type["channels"] = &image::Image::channels; - image_type["size"] = &image::Image::size; - - image_type["draw_image"] = &image::Image::draw_image; - image_type["draw_image_alpha"] = &image::Image::draw_image_alpha; - image_type["to_rgba"] = &image::Image::to_rgba; - lua["img_equalize"] = &image::equalize; - - lua["image_load_img"] = (void (*)(image::Image &, std::string))(&image::load_img); - lua["image_save_img"] = (void (*)(image::Image &, std::string))(&image::save_img); - + // ImageHandler sol::usertype image_handler_type = lua.new_usertype("ImageHandler", // sol::constructors(), std::shared_ptr(image::Image)>(), diff --git a/src-interface/viewer2/handler/dataset/lua/geodetic.cpp b/src-interface/viewer2/handler/dataset/lua/geodetic.cpp new file mode 100644 index 000000000..e1ec3f6ba --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/geodetic.cpp @@ -0,0 +1,25 @@ +#include "lua_bind.h" +#include "common/geodetic/geodetic_coordinates.h" + +namespace satdump +{ + namespace lua + { + void bind_geodetic(sol::state &lua) + { + sol::usertype type = lua.new_usertype("geodetic_coords_t", + sol::constructors< + geodetic::geodetic_coords_t(), + geodetic::geodetic_coords_t(double, double, double), + geodetic::geodetic_coords_t(double, double, double, bool)>()); + + type["toDegs"] = &geodetic::geodetic_coords_t::toDegs; + type["toRads"] = &geodetic::geodetic_coords_t::toRads; + type["lat"] = &geodetic::geodetic_coords_t::lat; + type["lon"] = &geodetic::geodetic_coords_t::lon; + type["alt"] = &geodetic::geodetic_coords_t::alt; + + // TODOREWORK VINCENTYS + } + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua/image.cpp b/src-interface/viewer2/handler/dataset/lua/image.cpp new file mode 100644 index 000000000..770199d96 --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/image.cpp @@ -0,0 +1,75 @@ +#include "lua_bind.h" +#include "common/image/image.h" +#include "common/image/processing.h" +#include "common/image/io.h" +#include "common/image/meta.h" +#include "projection/projection.h" + +namespace satdump +{ + namespace lua + { + void bind_image(sol::state &lua) + { + sol::usertype image_type = lua.new_usertype("Image", sol::constructors()); + + image_type["clear"] = &image::Image::clear; + + image_type["get"] = [](image::Image &img, size_t i) -> int + { + if (i < img.size()) + return img.get(i); + else + return 0; + }; + image_type["set"] = [](image::Image &img, size_t i, int x) + { + if (i < img.size()) + img.set(i, img.clamp(x)); + }; + + image_type["depth"] = &image::Image::depth; + image_type["width"] = &image::Image::width; + image_type["height"] = &image::Image::height; + image_type["channels"] = &image::Image::channels; + image_type["size"] = &image::Image::size; + + image_type["to_rgb"] = &image::Image::to_rgb; + image_type["to_rgba"] = &image::Image::to_rgba; + + image_type["fill_color"] = &image::Image::fill_color; + image_type["fill"] = &image::Image::fill; + image_type["mirror"] = &image::Image::mirror; + lua["image_equalize"] = &image::equalize; + lua["image_white_balance"] = &image::white_balance; + + image_type["resize"] = &image::Image::resize; + image_type["resize_to"] = &image::Image::resize_to; + image_type["resize_bilinear"] = &image::Image::resize_bilinear; + + image_type["draw_pixel"] = &image::Image::draw_pixel; + image_type["draw_line"] = &image::Image::draw_line; + image_type["draw_circle"] = &image::Image::draw_circle; + image_type["draw_image"] = &image::Image::draw_image; + image_type["draw_image_alpha"] = &image::Image::draw_image_alpha; + + lua["image_linear_invert"] = &image::linear_invert; + lua["image_equalize"] = &image::equalize; + lua["image_simple_despeckle"] = &image::simple_despeckle; + lua["image_median_blur"] = &image::median_blur; + lua["image_despeckle"] = &image::kuwahara_filter; + + lua["image_load_img"] = (void (*)(image::Image &, std::string))(&image::load_img); + lua["image_save_img"] = (void (*)(image::Image &, std::string))(&image::save_img); + + lua["image_get_metadata_proj_cfg"] = [](image::Image &img) + { + return (proj::Projection)image::get_metadata_proj_cfg(img); + }; + lua["image_set_metadata_proj_cfg"] = [](image::Image &img, proj::Projection p) + { + image::set_metadata_proj_cfg(img, p); + }; + } + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua/logger.cpp b/src-interface/viewer2/handler/dataset/lua/logger.cpp new file mode 100644 index 000000000..5a0793cc0 --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/logger.cpp @@ -0,0 +1,24 @@ +#include "lua_bind.h" +#include "logger.h" + +namespace satdump +{ + namespace lua + { + void bind_logger(sol::state &lua) + { + lua["ltrace"] = [](std::string log) + { logger->trace(log); }; + lua["ldebug"] = [](std::string log) + { logger->debug(log); }; + lua["linfo"] = [](std::string log) + { logger->info(log); }; + lua["lwarn"] = [](std::string log) + { logger->warn(log); }; + lua["lerror"] = [](std::string log) + { logger->error(log); }; + lua["lcritical"] = [](std::string log) + { logger->critical(log); }; + } + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua/lua_bind.h b/src-interface/viewer2/handler/dataset/lua/lua_bind.h new file mode 100644 index 000000000..ab252fa7b --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/lua_bind.h @@ -0,0 +1,19 @@ +#pragma once + +#include "libs/sol2/sol.hpp" + +namespace satdump +{ + namespace lua + { + void bind_logger(sol::state &lua); + + void bind_image(sol::state &lua); + + void bind_product(sol::state &lua); + + void bind_geodetic(sol::state &lua); + + void bind_projection(sol::state &lua); + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua/product.cpp b/src-interface/viewer2/handler/dataset/lua/product.cpp new file mode 100644 index 000000000..72b9ac299 --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/product.cpp @@ -0,0 +1,26 @@ +#include "lua_bind.h" +#include "products2/product.h" + +namespace satdump +{ + namespace lua + { + void bind_product(sol::state &lua) + { + auto product_type = lua.new_usertype("Product", sol::constructors()); + + product_type["instrument_name"] = &products::Product::instrument_name; + product_type["type"] = &products::Product::type; + product_type["set_product_timestamp"] = &products::Product::set_product_timestamp; + product_type["has_product_timestamp"] = &products::Product::has_product_timestamp; + product_type["get_product_timestamp"] = &products::Product::get_product_timestamp; + product_type["set_product_source"] = &products::Product::set_product_source; + product_type["has_product_source"] = &products::Product::has_product_source; + product_type["get_product_source"] = &products::Product::get_product_source; + product_type["save"] = &products::Product::save; + product_type["load"] = &products::Product::load; + + lua["loadProduct"] = &products::loadProduct; + } + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua/projection.cpp b/src-interface/viewer2/handler/dataset/lua/projection.cpp new file mode 100644 index 000000000..fbd486cfc --- /dev/null +++ b/src-interface/viewer2/handler/dataset/lua/projection.cpp @@ -0,0 +1,17 @@ +#include "lua_bind.h" +#include "projection/projection.h" + +namespace satdump +{ + namespace lua + { + void bind_projection(sol::state &lua) + { + auto product_type = lua.new_usertype("Projection", sol::constructors()); + + product_type["init"] = &proj::Projection::init; + // TODOREWORK product_type["forward"] = &proj::Projection::forward; + // TODOREWORK product_type["inverse"] = &proj::Projection::inverse; + } + } +} \ No newline at end of file diff --git a/src-interface/viewer2/handler/dataset/lua_processor.cpp b/src-interface/viewer2/handler/dataset/lua_processor.cpp index 472211697..34492ae58 100644 --- a/src-interface/viewer2/handler/dataset/lua_processor.cpp +++ b/src-interface/viewer2/handler/dataset/lua_processor.cpp @@ -21,6 +21,8 @@ namespace satdump lua.open_libraries(sol::lib::base); lua.open_libraries(sol::lib::string); lua.open_libraries(sol::lib::math); + lua.open_libraries(sol::lib::table); + lua.open_libraries(sol::lib::io); // Experimental lua["add_handler_to_products"] = [this](std::shared_ptr p) // TODO, find why THIS specifically crashes... diff --git a/src-interface/viewer2/handler/product/image_product_handler.cpp b/src-interface/viewer2/handler/product/image_product_handler.cpp index d8a53affe..5a4c5dbd7 100644 --- a/src-interface/viewer2/handler/product/image_product_handler.cpp +++ b/src-interface/viewer2/handler/product/image_product_handler.cpp @@ -143,6 +143,15 @@ namespace satdump ImGui::ProgressBar(progress); } + /// TODOREWORK UPDATE + if (needs_to_update) + { + asyncProcess(); + needs_to_update = false; + } + + img_handler.drawMenu(); + if (ImGui::CollapsingHeader("ImageProduct Advanced")) { if (ImGui::BeginTabBar("###imageproducttuning", ImGuiTabBarFlags_FittingPolicyScroll)) @@ -165,15 +174,6 @@ namespace satdump ImGui::EndTabBar(); } } - - /// TODOREWORK UPDATE - if (needs_to_update) - { - asyncProcess(); - needs_to_update = false; - } - - img_handler.drawMenu(); } void ImageProductHandler::setConfig(nlohmann::json p)