newtx/imgproc/imgprc_mgr.h

80 lines
2.2 KiB
C++

#pragma once
// image processor
//
// created on 2023-11-07
//
// ver: 1.0
//
// NOTE: the interface is for all algorithms are in ONE module
#include <imgprc/img_processor.h>
#include <base/utils.h> // for refer
#include <base/data.h>
#include <vector>
typedef std::shared_ptr<std::vector<char>> dcptr;
class device_option;
class rebuild;
class imgproc_mgr : public sane_opt_provider
{
typedef struct _raw_img
{
PACKIMAGE info;
dyn_mem_ptr data;
bool img;
}RAWIMG;
refer_guard<rebuild> rebuild_;
image_processor* stretcher_ = nullptr;
bool do_rebuild_ = true;
volatile bool run_ = true;
bool dump_img_ = false;
uint32_t scan_id_ = 0;
uint32_t sent_ind_ = 0;
uint32_t session_id_ = 0;
MUTEX working_cnt_lock_;
uint32_t working_cnt_ = 0;
std::vector<image_processor*> processors_;
device_option* opts_;
safe_thread workers_;
safe_fifo<RAWIMG> prc_que_;
std::function<void(data_source_ptr)> img_sender_;
static bool sort_processor_by_pos(image_processor* l, image_processor* r);
static bool sort_image_packet(image_packet_ptr l, image_packet_ptr r);
static data_source_ptr scan_finished_packet(uint32_t scanid, uint32_t err = 0);
static image_packet_ptr image_sent_packet(LPPACKIMAGE head, dyn_mem_ptr img, uint32_t scanid, void* info = nullptr, size_t info_l = 0);
uint32_t add_busy_worker(int inc = 1);
void thread_worker(void);
void process(RAWIMG* img);
void process(image_processor* prc, std::vector<PROCIMGINFO>* in, std::vector<PROCIMGINFO>* out);
void send_image(LPPACKIMAGE head, uint8_t* data, size_t size, void* info = nullptr, size_t info_l = 0);
void send_image(std::vector<PROCIMGINFO>& imgs, bool clear_after_send);
public:
imgproc_mgr(std::function<void(data_source_ptr)> sender, device_option* devopts);
protected:
virtual ~imgproc_mgr();
public:
virtual int set_value(const char* name, void* val) override;
// process
public:
int load_processor(const char* path); // outer-modules path
int clear(void);
int process(LPPACKIMAGE info, dyn_mem_ptr data, bool img);
// life
public:
void stop(void);
bool is_busy(void);
void start_new_turn(uint32_t scanid, uint32_t sessionid);
};