genesys: Represent pixel count ratio as a class

fix-build-obselete-jpeg
Povilas Kanapickas 2020-03-20 23:29:01 +02:00
rodzic b2b569a743
commit 75d227f9c4
8 zmienionych plików z 107 dodań i 57 usunięć

Wyświetl plik

@ -1997,7 +1997,7 @@ void CommandSetGl843::send_shading_data(Genesys_Device* dev, const Genesys_Senso
// FIXME: the following is likely incorrect
// start coordinate in optical dpi coordinates
startx = (sensor.dummy_pixel / sensor.ccd_pixels_per_system_pixel()) / dev->session.hwdpi_divisor;
startx *= dev->session.pixel_count_multiplier;
startx = dev->session.pixel_count_ratio.apply(startx);
/* current scan coordinates */
strpixel = dev->session.pixel_startx;

Wyświetl plik

@ -940,13 +940,10 @@ void compute_session_pixel_offsets(const Genesys_Device* dev, ScanSession& s,
}
}
s.pixel_count_multiplier = sensor.pixel_count_multiplier;
s.pixel_count_divisor = sensor.pixel_count_divisor;
s.pixel_count_ratio = sensor.pixel_count_ratio;
s.pixel_startx *= sensor.pixel_count_multiplier;
s.pixel_endx *= sensor.pixel_count_multiplier;
s.pixel_startx /= sensor.pixel_count_divisor;
s.pixel_endx /= sensor.pixel_count_divisor;
s.pixel_startx = sensor.pixel_count_ratio.apply(s.pixel_startx);
s.pixel_endx = sensor.pixel_count_ratio.apply(s.pixel_endx);
}
void compute_session(const Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor)

Wyświetl plik

@ -129,8 +129,7 @@ std::ostream& operator<<(std::ostream& out, const Genesys_Sensor& sensor)
<< " logical_dpihw_override: " << sensor.logical_dpihw_override << '\n'
<< " dpiset_override: " << sensor.dpiset_override << '\n'
<< " ccd_size_divisor: " << sensor.ccd_size_divisor << '\n'
<< " pixel_count_multiplier: " << sensor.pixel_count_multiplier << '\n'
<< " pixel_count_divisor: " << sensor.pixel_count_divisor << '\n'
<< " pixel_count_ratio: " << sensor.pixel_count_ratio << '\n'
<< " black_pixels: " << sensor.black_pixels << '\n'
<< " dummy_pixel: " << sensor.dummy_pixel << '\n'
<< " ccd_start_xoffset: " << sensor.ccd_start_xoffset << '\n'

Wyświetl plik

@ -286,8 +286,7 @@ struct Genesys_Sensor {
// This defines the ratio between logical pixel coordinates and the pixel coordinates sent to
// the scanner.
int pixel_count_multiplier = 1;
int pixel_count_divisor = 1;
Ratio pixel_count_ratio = Ratio{1, 1};
int black_pixels = 0;
// value of the dummy register
@ -368,6 +367,7 @@ struct Genesys_Sensor {
resolutions == other.resolutions &&
method == other.method &&
ccd_size_divisor == other.ccd_size_divisor &&
pixel_count_ratio == other.pixel_count_ratio &&
black_pixels == other.black_pixels &&
dummy_pixel == other.dummy_pixel &&
ccd_start_xoffset == other.ccd_start_xoffset &&
@ -394,6 +394,7 @@ void serialize(Stream& str, Genesys_Sensor& x)
serialize(str, x.resolutions);
serialize(str, x.method);
serialize(str, x.ccd_size_divisor);
serialize(str, x.pixel_count_ratio);
serialize(str, x.black_pixels);
serialize(str, x.dummy_pixel);
serialize(str, x.ccd_start_xoffset);

Wyświetl plik

@ -120,8 +120,7 @@ bool ScanSession::operator==(const ScanSession& other) const
segment_count == other.segment_count &&
pixel_startx == other.pixel_startx &&
pixel_endx == other.pixel_endx &&
pixel_count_multiplier == other.pixel_count_multiplier &&
pixel_count_divisor == other.pixel_count_divisor &&
pixel_count_ratio == other.pixel_count_ratio &&
conseq_pixel_dist == other.conseq_pixel_dist &&
output_segment_pixel_group_count == other.output_segment_pixel_group_count &&
output_segment_start_offset == other.output_segment_start_offset &&

Wyświetl plik

@ -46,6 +46,7 @@
#include "enums.h"
#include "serialize.h"
#include "utilities.h"
namespace genesys {
@ -294,8 +295,7 @@ struct ScanSession {
- The scanner will automatically average the pixels that come from the sensor using a
certain ratio.
*/
unsigned pixel_count_multiplier = 1;
unsigned pixel_count_divisor = 1;
Ratio pixel_count_ratio = Ratio{1, 1};
// Distance in pixels between consecutive pixels, e.g. between odd and even pixels. Note that
// the number of segments can be large.
@ -366,8 +366,7 @@ void serialize(Stream& str, ScanSession& x)
serialize(str, x.segment_count);
serialize(str, x.pixel_startx);
serialize(str, x.pixel_endx);
serialize(str, x.pixel_count_multiplier);
serialize(str, x.pixel_count_divisor);
serialize(str, x.pixel_count_ratio);
serialize(str, x.conseq_pixel_dist);
serialize(str, x.output_segment_pixel_group_count);
serialize(str, x.output_segment_start_offset);

Wyświetl plik

@ -1661,7 +1661,7 @@ void genesys_init_sensor_tables()
struct CustomSensorSettings {
ValueFilterAny<unsigned> resolutions;
unsigned dpiset_override;
unsigned pixel_count_multiplier;
Ratio pixel_count_ratio;
int exposure_lperiod;
std::vector<ScanMethod> methods;
GenesysRegisterSettingSet extra_custom_regs;
@ -1669,7 +1669,7 @@ void genesys_init_sensor_tables()
};
CustomSensorSettings custom_settings[] = {
{ { 400 }, 2400, 1, 7200, { ScanMethod::FLATBED }, {
{ { 400 }, 2400, Ratio{1, 1}, 7200, { ScanMethod::FLATBED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x13 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x0d }, { 0x53, 0x10 }, { 0x54, 0x01 }, { 0x55, 0x04 },
@ -1681,7 +1681,7 @@ void genesys_init_sensor_tables()
{ 0x80, 0x2a },
}, {}
},
{ { 800 }, 4800, 1, 7200, { ScanMethod::FLATBED }, {
{ { 800 }, 4800, Ratio{1, 1}, 7200, { ScanMethod::FLATBED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x13 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x0d }, { 0x53, 0x10 }, { 0x54, 0x01 }, { 0x55, 0x04 },
@ -1693,7 +1693,7 @@ void genesys_init_sensor_tables()
{ 0x80, 0x20 },
}, {}
},
{ { 1600 }, 4800, 1, 14400, { ScanMethod::FLATBED }, {
{ { 1600 }, 4800, Ratio{1, 1}, 14400, { ScanMethod::FLATBED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x11 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa1 },
{ 0x52, 0x0b }, { 0x53, 0x0e }, { 0x54, 0x11 }, { 0x55, 0x02 },
@ -1707,7 +1707,7 @@ void genesys_init_sensor_tables()
{ 0x03, 0x1f },
}
},
{ { 3200 }, 4800, 1, 28800, { ScanMethod::FLATBED }, {
{ { 3200 }, 4800, Ratio{1, 1}, 28800, { ScanMethod::FLATBED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x10 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x20 }, { 0x1d, 0x84 }, { 0x1e, 0xa1 },
{ 0x52, 0x02 }, { 0x53, 0x05 }, { 0x54, 0x08 }, { 0x55, 0x0b },
@ -1721,8 +1721,8 @@ void genesys_init_sensor_tables()
{ 0x03, 0x1f },
},
},
{ { 400 }, 2400, 1, 14400, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ { 400 }, 2400, Ratio{1, 1}, 14400, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x13 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x0d }, { 0x53, 0x10 }, { 0x54, 0x01 }, { 0x55, 0x04 },
@ -1734,8 +1734,8 @@ void genesys_init_sensor_tables()
{ 0x80, 0x20 },
}, {}
},
{ { 800 }, 4800, 1, 14400, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ { 800 }, 4800, Ratio{1, 1}, 14400, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x13 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x0d }, { 0x53, 0x10 }, { 0x54, 0x01 }, { 0x55, 0x04 },
@ -1747,8 +1747,8 @@ void genesys_init_sensor_tables()
{ 0x80, 0x20 },
}, {}
},
{ { 1600 }, 4800, 1, 28800, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ { 1600 }, 4800, Ratio{1, 1}, 28800, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x11 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x0b }, { 0x53, 0x0e }, { 0x54, 0x11 }, { 0x55, 0x02 },
@ -1762,8 +1762,8 @@ void genesys_init_sensor_tables()
{ 0x03, 0x1f },
},
},
{ { 3200 }, 4800, 1, 28800, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ { 3200 }, 4800, Ratio{1, 1}, 28800, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED }, {
{ 0x16, 0x33 }, { 0x17, 0x0c }, { 0x18, 0x10 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x20 }, { 0x1d, 0x84 }, { 0x1e, 0xa0 },
{ 0x52, 0x02 }, { 0x53, 0x05 }, { 0x54, 0x08 }, { 0x55, 0x0b },
@ -1784,7 +1784,7 @@ void genesys_init_sensor_tables()
for (auto method : setting.methods) {
sensor.resolutions = setting.resolutions;
sensor.dpiset_override = setting.dpiset_override;
sensor.pixel_count_multiplier = setting.pixel_count_multiplier;
sensor.pixel_count_ratio = setting.pixel_count_ratio;
sensor.exposure_lperiod = setting.exposure_lperiod;
sensor.method = method;
sensor.custom_regs = setting.extra_custom_regs;
@ -2479,26 +2479,26 @@ void genesys_init_sensor_tables()
ScanMethod method;
unsigned ccd_size_divisor;
unsigned logical_dpihw_override;
unsigned pixel_count_multiplier;
Ratio pixel_count_ratio;
unsigned exposure_lperiod;
unsigned dpiset_override;
GenesysRegisterSettingSet custom_fe_regs;
};
CustomSensorSettings custom_settings[] = {
{ { 900 }, ScanMethod::TRANSPARENCY, 1, 900, 8, 0x2538, 150, {} },
{ { 1800 }, ScanMethod::TRANSPARENCY, 1, 1800, 4, 0x2538, 300, {} },
{ { 3600 }, ScanMethod::TRANSPARENCY, 1, 3600, 2, 0x2538, 600, {} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1, 7200, 1, 0x19c8, 1200, {
{ { 900 }, ScanMethod::TRANSPARENCY, 1, 900, Ratio{8, 1}, 0x2538, 150, {} },
{ { 1800 }, ScanMethod::TRANSPARENCY, 1, 1800, Ratio{4, 1}, 0x2538, 300, {} },
{ { 3600 }, ScanMethod::TRANSPARENCY, 1, 3600, Ratio{2, 1}, 0x2538, 600, {} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1, 7200, Ratio{1, 1}, 0x19c8, 1200, {
{ 0x02, 0x1b },
{ 0x03, 0x14 },
{ 0x04, 0x20 },
}
},
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 900, 8, 0x1f54, 150, {} },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 1800, 4, 0x1f54, 300, {} },
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 3600, 2, 0x1f54, 600, {} },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 7200, 1, 0x1f54, 1200, {} },
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 900, Ratio{8, 1}, 0x1f54, 150, {} },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 1800, Ratio{4, 1}, 0x1f54, 300, {} },
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 3600, Ratio{2, 1}, 0x1f54, 600, {} },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 7200, Ratio{1, 1}, 0x1f54, 1200, {} },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -2506,7 +2506,7 @@ void genesys_init_sensor_tables()
sensor.method = setting.method;
sensor.ccd_size_divisor = setting.ccd_size_divisor;
sensor.logical_dpihw_override = setting.logical_dpihw_override;
sensor.pixel_count_multiplier = setting.pixel_count_multiplier;
sensor.pixel_count_ratio = setting.pixel_count_ratio;
sensor.exposure_lperiod = setting.exposure_lperiod;
sensor.dpiset_override = setting.dpiset_override;
sensor.custom_fe_regs = setting.custom_fe_regs;
@ -2568,22 +2568,22 @@ void genesys_init_sensor_tables()
ValueFilterAny<unsigned> resolutions;
unsigned ccd_size_divisor;
unsigned logical_dpihw_override;
unsigned pixel_count_multiplier;
Ratio pixel_count_ratio;
unsigned dpiset_override;
};
CustomSensorSettings custom_settings[] = {
{ { 900 }, 1, 900, 8, 150 },
{ { 1800 }, 1, 1800, 4, 300 },
{ { 3600 }, 1, 3600, 2, 600 },
{ { 7200 }, 1, 7200, 1, 1200 },
{ { 900 }, 1, 900, Ratio{8, 1}, 150 },
{ { 1800 }, 1, 1800, Ratio{4, 1}, 300 },
{ { 3600 }, 1, 3600, Ratio{2, 1}, 600 },
{ { 7200 }, 1, 7200, Ratio{1, 1}, 1200 },
};
for (const CustomSensorSettings& setting : custom_settings) {
sensor.resolutions = setting.resolutions;
sensor.ccd_size_divisor = setting.ccd_size_divisor;
sensor.logical_dpihw_override = setting.logical_dpihw_override;
sensor.pixel_count_multiplier = setting.pixel_count_multiplier;
sensor.pixel_count_ratio = setting.pixel_count_ratio;
sensor.dpiset_override = setting.dpiset_override;
s_sensors->push_back(sensor);
}
@ -2642,20 +2642,20 @@ void genesys_init_sensor_tables()
ScanMethod method;
unsigned ccd_size_divisor;
unsigned logical_dpihw_override;
unsigned pixel_count_multiplier;
Ratio pixel_count_ratio;
unsigned exposure_lperiod;
unsigned dpiset_override;
};
CustomSensorSettings custom_settings[] = {
{ { 900 }, ScanMethod::TRANSPARENCY, 1, 900, 8, 0x2f44, 150 },
{ { 1800 }, ScanMethod::TRANSPARENCY, 1, 1800, 4, 0x2f44, 300 },
{ { 3600 }, ScanMethod::TRANSPARENCY, 1, 3600, 2, 0x2f44, 600 },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1, 7200, 1, 0x2f44, 1200 },
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 900, 8, 0x2af8, 150 },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 1800, 4, 0x2af8, 300 },
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 3600, 2, 0x2af8, 600 },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 7200, 1, 0x2af8, 1200 },
{ { 900 }, ScanMethod::TRANSPARENCY, 1, 900, Ratio{8, 1}, 0x2f44, 150 },
{ { 1800 }, ScanMethod::TRANSPARENCY, 1, 1800, Ratio{4, 1}, 0x2f44, 300 },
{ { 3600 }, ScanMethod::TRANSPARENCY, 1, 3600, Ratio{2, 1}, 0x2f44, 600 },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1, 7200, Ratio{1, 1}, 0x2f44, 1200 },
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 900, Ratio{8, 1}, 0x2af8, 150 },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 1800, Ratio{4, 1}, 0x2af8, 300 },
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 3600, Ratio{2, 1}, 0x2af8, 600 },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1, 7200, Ratio{1, 1}, 0x2af8, 1200 },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -2663,7 +2663,7 @@ void genesys_init_sensor_tables()
sensor.method = setting.method;
sensor.ccd_size_divisor = setting.ccd_size_divisor;
sensor.logical_dpihw_override = setting.logical_dpihw_override;
sensor.pixel_count_multiplier = setting.pixel_count_multiplier;
sensor.pixel_count_ratio = setting.pixel_count_ratio;
sensor.exposure_lperiod = setting.exposure_lperiod;
sensor.dpiset_override = setting.dpiset_override;
s_sensors->push_back(sensor);

Wyświetl plik

@ -46,6 +46,7 @@
#include "error.h"
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <vector>
@ -108,6 +109,60 @@ void compute_array_percentile_approx(T* result, const T* data,
}
}
class Ratio
{
public:
Ratio() : multiplier_{1}, divisor_{1}
{
}
Ratio(unsigned multiplier, unsigned divisor) : multiplier_{multiplier}, divisor_{divisor}
{
}
unsigned multiplier() const { return multiplier_; }
unsigned divisor() const { return divisor_; }
unsigned apply(unsigned arg) const
{
return static_cast<std::uint64_t>(arg) * multiplier_ / divisor_;
}
int apply(int arg) const
{
return static_cast<std::int64_t>(arg) * multiplier_ / divisor_;
}
float apply(float arg) const
{
return arg * multiplier_ / divisor_;
}
bool operator==(const Ratio& other) const
{
return multiplier_ == other.multiplier_ && divisor_ == other.divisor_;
}
private:
unsigned multiplier_;
unsigned divisor_;
template<class Stream>
friend void serialize(Stream& str, Ratio& x);
};
template<class Stream>
void serialize(Stream& str, Ratio& x)
{
serialize(str, x.multiplier_);
serialize(str, x.divisor_);
}
inline std::ostream& operator<<(std::ostream& out, const Ratio& ratio)
{
out << ratio.multiplier() << "/" << ratio.divisor();
return out;
}
template<class Char, class Traits>
class BasicStreamStateSaver
{