kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Enable image data logging as a separate environment variable
rodzic
5d441bdd3e
commit
6092e2d682
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include "error.h"
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace genesys {
|
||||
|
||||
|
@ -212,4 +213,32 @@ void DebugMessageHelper::vlog(unsigned level, const char* format, ...)
|
|||
DBG(level, "%s: %s\n", func_, msg.c_str());
|
||||
}
|
||||
|
||||
enum class LogImageDataStatus
|
||||
{
|
||||
NOT_SET,
|
||||
ENABLED,
|
||||
DISABLED
|
||||
};
|
||||
|
||||
static LogImageDataStatus s_log_image_data_setting = LogImageDataStatus::NOT_SET;
|
||||
|
||||
LogImageDataStatus dbg_read_log_image_data_setting()
|
||||
{
|
||||
auto* setting = std::getenv("SANE_DEBUG_GENESYS_IMAGE");
|
||||
if (!setting)
|
||||
return LogImageDataStatus::DISABLED;
|
||||
auto setting_int = std::strtol(setting, nullptr, 10);
|
||||
if (setting_int == 0)
|
||||
return LogImageDataStatus::DISABLED;
|
||||
return LogImageDataStatus::ENABLED;
|
||||
}
|
||||
|
||||
bool dbg_log_image_data()
|
||||
{
|
||||
if (s_log_image_data_setting == LogImageDataStatus::NOT_SET) {
|
||||
s_log_image_data_setting = dbg_read_log_image_data_setting();
|
||||
}
|
||||
return s_log_image_data_setting == LogImageDataStatus::ENABLED;
|
||||
}
|
||||
|
||||
} // namespace genesys
|
||||
|
|
|
@ -137,7 +137,6 @@ private:
|
|||
unsigned num_exceptions_on_enter_ = 0;
|
||||
};
|
||||
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define GENESYS_CURRENT_FUNCTION __PRETTY_FUNCTION__
|
||||
#elif defined(__FUNCSIG__)
|
||||
|
@ -149,6 +148,8 @@ private:
|
|||
#define DBG_HELPER(var) DebugMessageHelper var(GENESYS_CURRENT_FUNCTION)
|
||||
#define DBG_HELPER_ARGS(var, ...) DebugMessageHelper var(GENESYS_CURRENT_FUNCTION, __VA_ARGS__)
|
||||
|
||||
bool dbg_log_image_data();
|
||||
|
||||
template<class F>
|
||||
SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
|
||||
{
|
||||
|
|
|
@ -1218,7 +1218,7 @@ void scanner_search_strip(Genesys_Device& dev, bool forward, bool black)
|
|||
scanner_stop_action(dev);
|
||||
|
||||
unsigned pass = 0;
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char title[80];
|
||||
std::sprintf(title, "gl_search_strip_%s_%s%02d.pnm",
|
||||
black ? "black" : "white", forward ? "fwd" : "bwd", pass);
|
||||
|
@ -1240,7 +1240,7 @@ void scanner_search_strip(Genesys_Device& dev, bool forward, bool black)
|
|||
|
||||
scanner_stop_action(dev);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char title[80];
|
||||
std::sprintf(title, "gl_search_strip_%s_%s%02d.pnm",
|
||||
black ? "black" : "white",
|
||||
|
@ -1529,7 +1529,7 @@ void scanner_offset_calibration(Genesys_Device& dev, const Genesys_Sensor& senso
|
|||
first_line = read_unshuffled_image_from_scanner(&dev, session, session.output_total_bytes);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[40];
|
||||
std::snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.pnm",
|
||||
bottom[0], bottom[1], bottom[2]);
|
||||
|
@ -1605,7 +1605,7 @@ void scanner_offset_calibration(Genesys_Device& dev, const Genesys_Sensor& senso
|
|||
second_line = read_unshuffled_image_from_scanner(&dev, session, session.output_total_bytes);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char title[100];
|
||||
std::snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n",
|
||||
lines, output_pixels,
|
||||
|
@ -1637,7 +1637,7 @@ void scanner_offset_calibration(Genesys_Device& dev, const Genesys_Sensor& senso
|
|||
}
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_file("gl_offset_all_desc.txt",
|
||||
reinterpret_cast<const std::uint8_t*>(debug_image_info.data()),
|
||||
debug_image_info.size());
|
||||
|
@ -1828,7 +1828,7 @@ void scanner_coarse_gain_calibration(Genesys_Device& dev, const Genesys_Sensor&
|
|||
scanner_stop_action_no_move(dev, regs);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file("gl_coarse_gain.pnm", image);
|
||||
}
|
||||
|
||||
|
@ -2085,7 +2085,7 @@ SensorExposure scanner_led_calibration(Genesys_Device& dev, const Genesys_Sensor
|
|||
|
||||
scanner_stop_action(dev);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[30];
|
||||
std::snprintf(fn, 30, "gl_led_%02d.pnm", i_test);
|
||||
sanei_genesys_write_pnm_file(fn, image);
|
||||
|
@ -2382,7 +2382,7 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_
|
|||
dev->calib_session.params.lines, pixels_per_line * channels,
|
||||
0.5f);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file16((log_filename_prefix + "_shading.pnm").c_str(),
|
||||
calibration_data.data(),
|
||||
channels, pixels_per_line, dev->calib_session.params.lines);
|
||||
|
@ -2595,19 +2595,15 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
|
|||
|
||||
dev->cmd_set->end_scan(dev, &local_reg, true);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data)
|
||||
{
|
||||
if (dev->model->is_cis)
|
||||
{
|
||||
sanei_genesys_write_pnm_file("gl_black_white_shading.pnm", calibration_data.data(),
|
||||
16, 1, pixels_per_line*channels,
|
||||
dev->calib_session.params.lines);
|
||||
}
|
||||
else
|
||||
{
|
||||
sanei_genesys_write_pnm_file("gl_black_white_shading.pnm", calibration_data.data(),
|
||||
16, channels, pixels_per_line,
|
||||
dev->calib_session.params.lines);
|
||||
if (dbg_log_image_data()) {
|
||||
if (dev->model->is_cis) {
|
||||
sanei_genesys_write_pnm_file("gl_black_white_shading.pnm", calibration_data.data(),
|
||||
16, 1, pixels_per_line*channels,
|
||||
dev->calib_session.params.lines);
|
||||
} else {
|
||||
sanei_genesys_write_pnm_file("gl_black_white_shading.pnm", calibration_data.data(),
|
||||
16, channels, pixels_per_line,
|
||||
dev->calib_session.params.lines);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2678,7 +2674,7 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
|
|||
*average_white++ = white_sum;
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file16("gl_white_average.pnm", dev->white_average_data.data(),
|
||||
channels, out_pixels_per_line, 1);
|
||||
sanei_genesys_write_pnm_file16("gl_dark_average.pnm", dev->dark_average_data.data(),
|
||||
|
@ -3854,7 +3850,7 @@ static void genesys_warmup_lamp(Genesys_Device* dev)
|
|||
first_average /= total_pixels;
|
||||
second_average /= total_pixels;
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file("gl_warmup1.pnm", first_line.data(),
|
||||
dev->session.params.depth, channels,
|
||||
total_size / (lines * channels), lines);
|
||||
|
@ -5461,9 +5457,9 @@ static void genesys_buffer_image(Genesys_Scanner *s)
|
|||
dev->total_bytes_read = 0;
|
||||
|
||||
/* update params */
|
||||
s->params.lines = total / s->params.bytes_per_line;
|
||||
if (DBG_LEVEL >= DBG_io2)
|
||||
{
|
||||
s->params.lines = total / s->params.bytes_per_line;
|
||||
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file("gl_unprocessed.pnm", dev->img_buffer.data(), s->params.depth,
|
||||
s->params.format==SANE_FRAME_RGB ? 3 : 1,
|
||||
s->params.pixels_per_line, s->params.lines);
|
||||
|
|
|
@ -1252,7 +1252,7 @@ void move_to_calibration_area(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
|||
// stop scanning
|
||||
scanner_stop_action(*dev);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
sanei_genesys_write_pnm_file("gl124_movetocalarea.pnm", image);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2058,12 +2058,11 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes
|
|||
return calib_sensor.exposure;
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data)
|
||||
{
|
||||
char fn[30];
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[30];
|
||||
std::snprintf(fn, 30, "gl646_led_%02d.pnm", turn);
|
||||
sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, pixels, 1);
|
||||
}
|
||||
sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, pixels, 1);
|
||||
}
|
||||
|
||||
acceptable = true;
|
||||
|
||||
|
@ -2227,9 +2226,9 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
|
|||
return;
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
char title[30];
|
||||
std::snprintf(title, 30, "gl646_offset%03d.pnm", static_cast<int>(bottom));
|
||||
if (dbg_log_image_data()) {
|
||||
char title[30];
|
||||
std::snprintf(title, 30, "gl646_offset%03d.pnm", static_cast<int>(bottom));
|
||||
sanei_genesys_write_pnm_file (title, line.data(), 8, channels, pixels, lines);
|
||||
}
|
||||
|
||||
|
@ -2337,8 +2336,8 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
dev->cmd_set->init_regs_for_scan_session(dev, sensor, &dev->reg, session);
|
||||
simple_scan(dev, calib_sensor, session, false, first_line, "offset_first_line");
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
char title[30];
|
||||
if (dbg_log_image_data()) {
|
||||
char title[30];
|
||||
std::snprintf(title, 30, "gl646_offset%03d.pnm", bottom);
|
||||
sanei_genesys_write_pnm_file(title, first_line.data(), 8, channels, pixels, lines);
|
||||
}
|
||||
|
@ -2353,8 +2352,8 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
dev->cmd_set->init_regs_for_scan_session(dev, calib_sensor, &dev->reg, session);
|
||||
simple_scan(dev, calib_sensor, session, false, second_line, "offset_second_line");
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
char title[30];
|
||||
if (dbg_log_image_data()) {
|
||||
char title[30];
|
||||
std::snprintf(title, 30, "gl646_offset%03d.pnm", top);
|
||||
sanei_genesys_write_pnm_file (title, second_line.data(), 8, channels, pixels, lines);
|
||||
}
|
||||
|
@ -2380,8 +2379,8 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
simple_scan(dev, calib_sensor, session, false, second_line,
|
||||
"offset_calibration_i");
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
char title[30];
|
||||
if (dbg_log_image_data()) {
|
||||
char title[30];
|
||||
std::snprintf(title, 30, "gl646_offset%03d.pnm", dev->frontend.get_offset(1));
|
||||
sanei_genesys_write_pnm_file(title, second_line.data(), 8, channels, pixels, lines);
|
||||
}
|
||||
|
@ -2493,7 +2492,7 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys
|
|||
dev->cmd_set->init_regs_for_scan_session(dev, calib_sensor, &dev->reg, session);
|
||||
simple_scan(dev, calib_sensor, session, false, line, "coarse_gain_calibration");
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
std::sprintf(title, "gl646_gain%02d.pnm", pass);
|
||||
sanei_genesys_write_pnm_file(title, line.data(), 8, channels, pixels, lines);
|
||||
}
|
||||
|
|
|
@ -1816,7 +1816,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
|
|||
|
||||
sanei_genesys_read_data_from_scanner(dev, line.data(), total_size);
|
||||
scanner_stop_action(*dev);
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[30];
|
||||
std::snprintf(fn, 30, "gl841_offset_%02d.pnm", turn);
|
||||
sanei_genesys_write_pnm_file(fn, line.data(), 8, 3, num_pixels, 1);
|
||||
|
@ -1959,7 +1959,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
first_line = read_unshuffled_image_from_scanner(dev, session, session.output_total_bytes);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[30];
|
||||
std::snprintf(fn, 30, "gl841_offset1_%02d.pnm", turn);
|
||||
sanei_genesys_write_pnm_file(fn, first_line);
|
||||
|
@ -2054,7 +2054,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
dev->cmd_set->begin_scan(dev, calib_sensor, ®s, true);
|
||||
second_line = read_unshuffled_image_from_scanner(dev, session, session.output_total_bytes);
|
||||
|
||||
if (DBG_LEVEL >= DBG_data) {
|
||||
if (dbg_log_image_data()) {
|
||||
char fn[30];
|
||||
std::snprintf(fn, 30, "gl841_offset2_%02d.pnm", turn);
|
||||
sanei_genesys_write_pnm_file(fn, second_line);
|
||||
|
|
|
@ -1174,7 +1174,7 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
|
|||
session.buffer_size_read, read_data_from_usb);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_io2) {
|
||||
if (dbg_log_image_data()) {
|
||||
dev->pipeline.push_node<ImagePipelineNodeDebug>("gl_pipeline_" +
|
||||
std::to_string(s_pipeline_index) +
|
||||
"_0_before_swap.pnm");
|
||||
|
@ -1190,7 +1190,7 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (DBG_LEVEL >= DBG_io2) {
|
||||
if (dbg_log_image_data()) {
|
||||
dev->pipeline.push_node<ImagePipelineNodeDebug>("gl_pipeline_" +
|
||||
std::to_string(s_pipeline_index) +
|
||||
"_1_after_swap.pnm");
|
||||
|
@ -1219,7 +1219,7 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
|
|||
session.color_shift_lines_b);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_io2) {
|
||||
if (dbg_log_image_data()) {
|
||||
dev->pipeline.push_node<ImagePipelineNodeDebug>("gl_pipeline_" +
|
||||
std::to_string(s_pipeline_index) +
|
||||
"_2_after_shift.pnm");
|
||||
|
@ -1230,7 +1230,7 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
|
|||
dev->pipeline.push_node<ImagePipelineNodePixelShiftLines>(shifts);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_io2) {
|
||||
if (dbg_log_image_data()) {
|
||||
dev->pipeline.push_node<ImagePipelineNodeDebug>("gl_pipeline_" +
|
||||
std::to_string(s_pipeline_index) +
|
||||
"_3_after_stagger.pnm");
|
||||
|
@ -1245,7 +1245,7 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
|
|||
session.params.startx *
|
||||
dev->calib_session.params.channels);
|
||||
|
||||
if (DBG_LEVEL >= DBG_io2) {
|
||||
if (dbg_log_image_data()) {
|
||||
dev->pipeline.push_node<ImagePipelineNodeDebug>("gl_pipeline_" +
|
||||
std::to_string(s_pipeline_index) +
|
||||
"_4_after_calibrate.pnm");
|
||||
|
|
Ładowanie…
Reference in New Issue