From 9cd1de5c5268a89b20c21e2777229bde08f8e3d6 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 13 Sep 2019 17:04:03 +0300 Subject: [PATCH] genesys: Add a way to debug image pipelines --- backend/genesys_image_pipeline.cc | 41 +++++++++++++++++++++++++++++++ backend/genesys_image_pipeline.h | 23 ++++++++++++++--- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/backend/genesys_image_pipeline.cc b/backend/genesys_image_pipeline.cc index e580a216f..e13870b9f 100644 --- a/backend/genesys_image_pipeline.cc +++ b/backend/genesys_image_pipeline.cc @@ -44,6 +44,7 @@ #define DEBUG_DECLARE_ONLY #include "genesys_image_pipeline.h" +#include "genesys_low.h" #include ImagePipelineNode::~ImagePipelineNode() {} @@ -560,6 +561,36 @@ void ImagePipelineNodeExtract::get_next_row_data(std::uint8_t* out_data) current_line_++; } +ImagePipelineNodeDebug::ImagePipelineNodeDebug(ImagePipelineNode& source, + const std::string& path) : + source_(source), + path_{path}, + buffer_{source_.get_row_bytes()} +{} + +ImagePipelineNodeDebug::~ImagePipelineNodeDebug() +{ + catch_all_exceptions(__func__, [&]() + { + if (buffer_.empty()) + return; + + auto format = get_format(); + buffer_.linearize(); + sanei_genesys_write_pnm_file(path_.c_str(), buffer_.get_front_row_ptr(), + get_pixel_format_depth(format), + get_pixel_channels(format), + get_width(), buffer_.height()); + }); +} + +void ImagePipelineNodeDebug::get_next_row_data(std::uint8_t* out_data) +{ + buffer_.push_back(); + source_.get_next_row_data(out_data); + std::memcpy(buffer_.get_back_row_ptr(), out_data, get_row_bytes()); +} + std::size_t ImagePipelineStack::get_input_width() const { ensure_node_exists(); @@ -615,6 +646,16 @@ void ImagePipelineStack::ensure_node_exists() const } } +void ImagePipelineStack::clear() +{ + // we need to destroy the nodes back to front, so that the destructors still have valid + // references to sources + for (auto it = nodes_.rbegin(); it != nodes_.rend(); ++it) { + it->reset(); + } + nodes_.clear(); +} + std::vector ImagePipelineStack::get_all_data() { auto row_bytes = get_output_row_bytes(); diff --git a/backend/genesys_image_pipeline.h b/backend/genesys_image_pipeline.h index 2a45914f0..73d5865d4 100644 --- a/backend/genesys_image_pipeline.h +++ b/backend/genesys_image_pipeline.h @@ -402,6 +402,24 @@ private: std::vector cached_line_; }; +class ImagePipelineNodeDebug : public ImagePipelineNode +{ +public: + ImagePipelineNodeDebug(ImagePipelineNode& source, const std::string& path); + ~ImagePipelineNodeDebug() override; + + std::size_t get_width() const override { return source_.get_width(); } + std::size_t get_height() const override { return source_.get_height(); } + PixelFormat get_format() const override { return source_.get_format(); } + + void get_next_row_data(std::uint8_t* out_data) override; + +private: + ImagePipelineNode& source_; + std::string path_; + RowBuffer buffer_; +}; + class ImagePipelineStack { public: @@ -417,10 +435,7 @@ public: PixelFormat get_output_format() const; std::size_t get_output_row_bytes() const; - void clear() - { - nodes_.clear(); - } + void clear(); template void push_first_node(Args&&... args)