2024-01-16 09:51:34 +00:00
|
|
|
|
#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>
|
|
|
|
|
|
2024-03-05 09:07:44 +00:00
|
|
|
|
#define DUMP_PROTO union _page_thrd_data_4k* obj, std::vector<PROCIMGINFO>* arr, LPPACKIMAGE info, cv::Mat* mat, char* infoex, size_t infexl, bool last, void* param
|
2024-01-16 09:51:34 +00:00
|
|
|
|
|
|
|
|
|
class device_option;
|
2024-02-27 04:03:51 +00:00
|
|
|
|
class img_encoder;
|
2024-03-05 09:07:44 +00:00
|
|
|
|
class rebuild;
|
|
|
|
|
|
2024-01-23 07:07:17 +00:00
|
|
|
|
|
2024-01-16 09:51:34 +00:00
|
|
|
|
class imgproc_mgr : public sane_opt_provider
|
|
|
|
|
{
|
|
|
|
|
typedef struct _raw_img
|
|
|
|
|
{
|
2024-03-07 08:00:48 +00:00
|
|
|
|
#ifdef REBUILD_IN_CIS_THREAD
|
|
|
|
|
std::vector<PROCIMGINFO> imgs;
|
|
|
|
|
#else
|
2024-01-16 09:51:34 +00:00
|
|
|
|
PACKIMAGE info;
|
2024-03-05 09:07:44 +00:00
|
|
|
|
dyn_mem_ptr data; // nullptr and img is 'true' to exit worker
|
2024-03-07 08:00:48 +00:00
|
|
|
|
#endif
|
2024-01-16 09:51:34 +00:00
|
|
|
|
bool img;
|
|
|
|
|
}RAWIMG;
|
|
|
|
|
|
2024-03-05 09:07:44 +00:00
|
|
|
|
// allocate a page to store the vars for every worker thread
|
|
|
|
|
typedef union _page_thrd_data_4k
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
bool run;
|
|
|
|
|
bool dumpi;
|
|
|
|
|
int ind;
|
|
|
|
|
int session;
|
|
|
|
|
int scan_id;
|
|
|
|
|
rebuild* rebld;
|
|
|
|
|
img_encoder* encoder;
|
|
|
|
|
safe_fifo<RAWIMG> *que;
|
|
|
|
|
image_processor* processors[20];
|
|
|
|
|
bool(*res)(RES_CHK_PROTO);
|
|
|
|
|
void *res_param;
|
|
|
|
|
void(*dump)(DUMP_PROTO);
|
|
|
|
|
void *dump_param;
|
|
|
|
|
void(*sender)(SENDER_PROTO);
|
|
|
|
|
void *sender_param;
|
|
|
|
|
}mean;
|
|
|
|
|
uint8_t page[SIZE_KB(4)];
|
|
|
|
|
|
|
|
|
|
_page_thrd_data_4k()
|
|
|
|
|
{
|
|
|
|
|
mean.rebld = nullptr;
|
|
|
|
|
mean.encoder = nullptr;
|
|
|
|
|
mean.que = nullptr;
|
|
|
|
|
memset(mean.processors, 0, sizeof(mean.processors));
|
|
|
|
|
|
|
|
|
|
mean.res = nullptr;
|
|
|
|
|
mean.dump = nullptr;
|
|
|
|
|
mean.sender = nullptr;
|
|
|
|
|
mean.res_param = mean.dump_param = mean.sender_param = nullptr;
|
|
|
|
|
}
|
|
|
|
|
~_page_thrd_data_4k()
|
|
|
|
|
{
|
|
|
|
|
this->free();
|
|
|
|
|
}
|
|
|
|
|
void free(void);
|
|
|
|
|
}PAGEDPARAM, *LPPAGEDPARAM;
|
|
|
|
|
std::vector<LPPAGEDPARAM> params_;
|
|
|
|
|
|
2024-02-27 04:03:51 +00:00
|
|
|
|
refer_guard<rebuild> first_;
|
|
|
|
|
refer_guard<img_encoder> last_;
|
2024-01-30 03:43:06 +00:00
|
|
|
|
bool do_rebuild_ = true;
|
2024-01-16 09:51:34 +00:00
|
|
|
|
volatile bool run_ = true;
|
2024-03-01 09:16:12 +00:00
|
|
|
|
volatile uint32_t sent_ind_ = 1;
|
2024-01-16 09:51:34 +00:00
|
|
|
|
bool dump_img_ = false;
|
|
|
|
|
uint32_t scan_id_ = 0;
|
|
|
|
|
uint32_t session_id_ = 0;
|
|
|
|
|
MUTEX working_cnt_lock_;
|
|
|
|
|
uint32_t working_cnt_ = 0;
|
2024-03-05 09:07:44 +00:00
|
|
|
|
uint32_t put_ind_ = 0;
|
2024-01-16 09:51:34 +00:00
|
|
|
|
std::vector<image_processor*> processors_;
|
|
|
|
|
device_option* opts_;
|
|
|
|
|
safe_thread workers_;
|
2024-02-25 05:51:52 +00:00
|
|
|
|
|
2024-03-05 09:07:44 +00:00
|
|
|
|
bool(*res_)(RES_CHK_PROTO) = nullptr;
|
|
|
|
|
void* res_param_ = nullptr;
|
|
|
|
|
|
|
|
|
|
void(*img_sender_)(SENDER_PROTO) = nullptr;
|
|
|
|
|
void* sender_param_ = nullptr;
|
2024-01-16 09:51:34 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2024-03-05 09:07:44 +00:00
|
|
|
|
static void process(image_processor* prc, std::vector<PROCIMGINFO>* in, std::vector<PROCIMGINFO>* out);
|
|
|
|
|
static void send_image(LPPAGEDPARAM obj, LPPACKIMAGE head, cv::Mat& mat, void* info = nullptr, size_t info_l = 0, bool last = true);
|
|
|
|
|
static void real_dump_image(DUMP_PROTO);
|
|
|
|
|
static void empty_dump_image(DUMP_PROTO);
|
2024-01-16 09:51:34 +00:00
|
|
|
|
|
2024-03-05 09:07:44 +00:00
|
|
|
|
void start_workers(int cnt);
|
2024-01-16 09:51:34 +00:00
|
|
|
|
uint32_t add_busy_worker(int inc = 1);
|
2024-03-05 09:07:44 +00:00
|
|
|
|
void thread_worker(void* param);
|
|
|
|
|
void process(RAWIMG* img, LPPAGEDPARAM param);
|
|
|
|
|
void send_image(LPPAGEDPARAM obj, std::vector<PROCIMGINFO>& imgs, bool last);
|
2024-01-16 09:51:34 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2024-03-05 09:07:44 +00:00
|
|
|
|
imgproc_mgr(device_option* devopts, void(*sender)(SENDER_PROTO), void* sp,
|
|
|
|
|
bool(*res)(RES_CHK_PROTO) = nullptr, void* rp = nullptr);
|
2024-01-16 09:51:34 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|