kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Don't use std types from global namespace
rodzic
1423db6618
commit
c8f2a815c0
|
@ -45,7 +45,7 @@
|
|||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
void Genesys_Buffer::alloc(size_t size)
|
||||
void Genesys_Buffer::alloc(std::size_t size)
|
||||
{
|
||||
buffer_.resize(size);
|
||||
avail_ = 0;
|
||||
|
@ -65,7 +65,7 @@ void Genesys_Buffer::reset()
|
|||
pos_ = 0;
|
||||
}
|
||||
|
||||
uint8_t* Genesys_Buffer::get_write_pos(size_t size)
|
||||
std::uint8_t* Genesys_Buffer::get_write_pos(std::size_t size)
|
||||
{
|
||||
if (avail_ + size > buffer_.size())
|
||||
return nullptr;
|
||||
|
@ -77,19 +77,19 @@ uint8_t* Genesys_Buffer::get_write_pos(size_t size)
|
|||
return buffer_.data() + pos_ + avail_;
|
||||
}
|
||||
|
||||
uint8_t* Genesys_Buffer::get_read_pos()
|
||||
std::uint8_t* Genesys_Buffer::get_read_pos()
|
||||
{
|
||||
return buffer_.data() + pos_;
|
||||
}
|
||||
|
||||
void Genesys_Buffer::produce(size_t size)
|
||||
void Genesys_Buffer::produce(std::size_t size)
|
||||
{
|
||||
if (size > buffer_.size() - avail_)
|
||||
throw std::runtime_error("buffer size exceeded");
|
||||
avail_ += size;
|
||||
}
|
||||
|
||||
void Genesys_Buffer::consume(size_t size)
|
||||
void Genesys_Buffer::consume(std::size_t size)
|
||||
{
|
||||
if (size > avail_)
|
||||
throw std::runtime_error("no more data in buffer");
|
||||
|
|
|
@ -56,30 +56,30 @@ struct Genesys_Buffer
|
|||
{
|
||||
Genesys_Buffer() = default;
|
||||
|
||||
size_t size() const { return buffer_.size(); }
|
||||
size_t avail() const { return avail_; }
|
||||
size_t pos() const { return pos_; }
|
||||
std::size_t size() const { return buffer_.size(); }
|
||||
std::size_t avail() const { return avail_; }
|
||||
std::size_t pos() const { return pos_; }
|
||||
|
||||
// TODO: refactor code that uses this function to no longer use it
|
||||
void set_pos(size_t pos) { pos_ = pos; }
|
||||
void set_pos(std::size_t pos) { pos_ = pos; }
|
||||
|
||||
void alloc(size_t size);
|
||||
void alloc(std::size_t size);
|
||||
void clear();
|
||||
|
||||
void reset();
|
||||
|
||||
uint8_t* get_write_pos(size_t size);
|
||||
uint8_t* get_read_pos(); // TODO: mark as const
|
||||
std::uint8_t* get_write_pos(std::size_t size);
|
||||
std::uint8_t* get_read_pos(); // TODO: mark as const
|
||||
|
||||
void produce(size_t size);
|
||||
void consume(size_t size);
|
||||
void produce(std::size_t size);
|
||||
void consume(std::size_t size);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> buffer_;
|
||||
std::vector<std::uint8_t> buffer_;
|
||||
// current position in read buffer
|
||||
size_t pos_ = 0;
|
||||
std::size_t pos_ = 0;
|
||||
// data bytes currently in buffer
|
||||
size_t avail_ = 0;
|
||||
std::size_t avail_ = 0;
|
||||
};
|
||||
|
||||
#endif // BACKEND_GENESYS_BUFFER_H
|
||||
|
|
|
@ -56,7 +56,7 @@ struct Genesys_Calibration_Cache
|
|||
// used to check if entry is compatible
|
||||
Genesys_Current_Setup used_setup;
|
||||
SetupParams params;
|
||||
time_t last_calibration = 0;
|
||||
std::time_t last_calibration = 0;
|
||||
|
||||
Genesys_Frontend frontend;
|
||||
Genesys_Sensor sensor;
|
||||
|
@ -64,8 +64,8 @@ struct Genesys_Calibration_Cache
|
|||
size_t calib_pixels = 0;
|
||||
size_t calib_channels = 0;
|
||||
size_t average_size = 0;
|
||||
std::vector<uint16_t> white_average_data;
|
||||
std::vector<uint16_t> dark_average_data;
|
||||
std::vector<std::uint16_t> white_average_data;
|
||||
std::vector<std::uint16_t> dark_average_data;
|
||||
|
||||
bool operator==(const Genesys_Calibration_Cache& other) const
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
|
||||
virtual bool test_buffer_empty_bit(std::uint8_t val) const = 0;
|
||||
|
||||
virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const = 0;
|
||||
virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const = 0;
|
||||
virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0;
|
||||
virtual void save_power(Genesys_Device* dev, bool enable) const = 0;
|
||||
|
||||
|
@ -107,9 +107,9 @@ public:
|
|||
|
||||
virtual bool has_rewind() const { return true; }
|
||||
|
||||
virtual void bulk_write_data(Genesys_Device* dev, uint8_t addr, uint8_t* data,
|
||||
virtual void bulk_write_data(Genesys_Device* dev, std::uint8_t addr, std::uint8_t* data,
|
||||
size_t len) const = 0;
|
||||
virtual void bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
virtual void bulk_read_data(Genesys_Device * dev, std::uint8_t addr, std::uint8_t* data,
|
||||
size_t len) const = 0;
|
||||
|
||||
// Updates hardware sensor information in Genesys_Scanner.val[].
|
||||
|
@ -142,7 +142,7 @@ public:
|
|||
|
||||
/// write shading data calibration to ASIC
|
||||
virtual void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||
uint8_t* data, int size) const = 0;
|
||||
std::uint8_t* data, int size) const = 0;
|
||||
|
||||
virtual bool has_send_shading_data() const
|
||||
{
|
||||
|
|
|
@ -267,7 +267,7 @@ struct Genesys_Device
|
|||
|
||||
Genesys_Gpo gpo;
|
||||
Genesys_Motor motor;
|
||||
uint8_t control[6] = {};
|
||||
std::uint8_t control[6] = {};
|
||||
|
||||
size_t average_size = 0;
|
||||
// number of pixels used during shading calibration
|
||||
|
@ -289,10 +289,10 @@ struct Genesys_Device
|
|||
|
||||
// gamma overrides. If a respective array is not empty then it means that the gamma for that
|
||||
// color is overridden.
|
||||
std::vector<uint16_t> gamma_override_tables[3];
|
||||
std::vector<std::uint16_t> gamma_override_tables[3];
|
||||
|
||||
std::vector<uint16_t> white_average_data;
|
||||
std::vector<uint16_t> dark_average_data;
|
||||
std::vector<std::uint16_t> white_average_data;
|
||||
std::vector<std::uint16_t> dark_average_data;
|
||||
|
||||
bool already_initialized = false;
|
||||
SANE_Int scanhead_position_in_steps = 0;
|
||||
|
@ -354,10 +354,10 @@ struct Genesys_Device
|
|||
bool buffer_image = false;
|
||||
|
||||
// image buffer where the scanned picture is stored
|
||||
std::vector<uint8_t> img_buffer;
|
||||
std::vector<std::uint8_t> img_buffer;
|
||||
|
||||
// binary logger file
|
||||
FILE *binary = nullptr;
|
||||
std::FILE *binary = nullptr;
|
||||
|
||||
// A snapshot of the last known physical state of the device registers. This variable is updated
|
||||
// whenever a register is written or read to the scanner.
|
||||
|
@ -365,12 +365,12 @@ struct Genesys_Device
|
|||
|
||||
ImagePipelineNodeBytesSource& get_pipeline_source();
|
||||
|
||||
uint8_t read_register(uint16_t address);
|
||||
void write_register(uint16_t address, uint8_t value);
|
||||
std::uint8_t read_register(std::uint16_t address);
|
||||
void write_register(std::uint16_t address, std::uint8_t value);
|
||||
void write_registers(Genesys_Register_Set& regs);
|
||||
|
||||
private:
|
||||
void update_register_state(uint16_t address, uint8_t value);
|
||||
void update_register_state(std::uint16_t address, std::uint8_t value);
|
||||
};
|
||||
|
||||
void apply_reg_settings_to_device(Genesys_Device& dev, const GenesysRegisterSettingSet& regs);
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#include <cstdio>
|
||||
|
||||
extern "C" void sanei_debug_msg(int level, int max_level, const char *be, const char *fmt,
|
||||
va_list ap);
|
||||
std::va_list ap);
|
||||
|
||||
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
|
||||
extern "C" char* __cxa_get_globals();
|
||||
|
|
|
@ -1771,7 +1771,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso
|
|||
/* binary data logging */
|
||||
if(DBG_LEVEL>=DBG_data)
|
||||
{
|
||||
dev->binary=fopen("binary.pnm","wb");
|
||||
dev->binary = std::fopen("binary.pnm","wb");
|
||||
lines = dev->reg.get24(REG_LINCNT);
|
||||
channels = dev->session.params.channels;
|
||||
if (dev->binary != nullptr) {
|
||||
|
|
|
@ -85,7 +85,7 @@ void sanei_genesys_init_cmd_set(Genesys_Device* dev)
|
|||
/* General IO and debugging functions */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length)
|
||||
void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
FILE *out;
|
||||
|
@ -105,10 +105,9 @@ void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data
|
|||
{
|
||||
DBG_HELPER_ARGS(dbg, "depth=%d, channels=%d, ppl=%d, lines=%d", depth, channels,
|
||||
pixels_per_line, lines);
|
||||
FILE *out;
|
||||
int count;
|
||||
|
||||
out = fopen (filename, "w");
|
||||
std::FILE* out = std::fopen(filename, "w");
|
||||
if (!out)
|
||||
{
|
||||
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
||||
|
@ -158,7 +157,7 @@ void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data
|
|||
}
|
||||
}
|
||||
}
|
||||
fclose (out);
|
||||
std::fclose(out);
|
||||
}
|
||||
|
||||
void sanei_genesys_write_pnm_file16(const char* filename, const uint16_t* data, unsigned channels,
|
||||
|
@ -167,7 +166,7 @@ void sanei_genesys_write_pnm_file16(const char* filename, const uint16_t* data,
|
|||
DBG_HELPER_ARGS(dbg, "channels=%d, ppl=%d, lines=%d", channels,
|
||||
pixels_per_line, lines);
|
||||
|
||||
FILE* out = std::fopen(filename, "w");
|
||||
std::FILE* out = std::fopen(filename, "w");
|
||||
if (!out) {
|
||||
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
||||
}
|
||||
|
|
|
@ -404,7 +404,8 @@ extern void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Se
|
|||
const uint8_t* src_data, int start_pixel, int dpi,
|
||||
int width, int height);
|
||||
|
||||
extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length);
|
||||
extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data,
|
||||
std::size_t length);
|
||||
|
||||
extern void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data, int depth,
|
||||
int channels, int pixels_per_line, int lines);
|
||||
|
|
|
@ -53,8 +53,8 @@
|
|||
|
||||
struct GenesysRegister
|
||||
{
|
||||
uint16_t address = 0;
|
||||
uint8_t value = 0;
|
||||
std::uint16_t address = 0;
|
||||
std::uint8_t value = 0;
|
||||
};
|
||||
|
||||
inline bool operator<(const GenesysRegister& lhs, const GenesysRegister& rhs)
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void init_reg(uint16_t address, uint8_t default_value)
|
||||
void init_reg(std::uint16_t address, std::uint8_t default_value)
|
||||
{
|
||||
if (find_reg_index(address) >= 0) {
|
||||
set8(address, default_value);
|
||||
|
@ -112,12 +112,12 @@ public:
|
|||
std::sort(registers_.begin(), registers_.end());
|
||||
}
|
||||
|
||||
bool has_reg(uint16_t address) const
|
||||
bool has_reg(std::uint16_t address) const
|
||||
{
|
||||
return find_reg_index(address) >= 0;
|
||||
}
|
||||
|
||||
void remove_reg(uint16_t address)
|
||||
void remove_reg(std::uint16_t address)
|
||||
{
|
||||
int i = find_reg_index(address);
|
||||
if (i < 0) {
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
registers_.erase(registers_.begin() + i);
|
||||
}
|
||||
|
||||
GenesysRegister& find_reg(uint16_t address)
|
||||
GenesysRegister& find_reg(std::uint16_t address)
|
||||
{
|
||||
int i = find_reg_index(address);
|
||||
if (i < 0) {
|
||||
|
@ -135,7 +135,7 @@ public:
|
|||
return registers_[i];
|
||||
}
|
||||
|
||||
const GenesysRegister& find_reg(uint16_t address) const
|
||||
const GenesysRegister& find_reg(std::uint16_t address) const
|
||||
{
|
||||
int i = find_reg_index(address);
|
||||
if (i < 0) {
|
||||
|
@ -144,51 +144,51 @@ public:
|
|||
return registers_[i];
|
||||
}
|
||||
|
||||
GenesysRegister* find_reg_address(uint16_t address)
|
||||
GenesysRegister* find_reg_address(std::uint16_t address)
|
||||
{
|
||||
return &find_reg(address);
|
||||
}
|
||||
|
||||
const GenesysRegister* find_reg_address(uint16_t address) const
|
||||
const GenesysRegister* find_reg_address(std::uint16_t address) const
|
||||
{
|
||||
return &find_reg(address);
|
||||
}
|
||||
|
||||
void set8(uint16_t address, uint8_t value)
|
||||
void set8(std::uint16_t address, std::uint8_t value)
|
||||
{
|
||||
find_reg(address).value = value;
|
||||
}
|
||||
|
||||
void set8_mask(uint16_t address, uint8_t value, uint8_t mask)
|
||||
void set8_mask(std::uint16_t address, std::uint8_t value, std::uint8_t mask)
|
||||
{
|
||||
auto& reg = find_reg(address);
|
||||
reg.value = (reg.value & ~mask) | value;
|
||||
}
|
||||
|
||||
void set16(uint16_t address, uint16_t value)
|
||||
void set16(std::uint16_t address, std::uint16_t value)
|
||||
{
|
||||
find_reg(address).value = (value >> 8) & 0xff;
|
||||
find_reg(address + 1).value = value & 0xff;
|
||||
}
|
||||
|
||||
void set24(uint16_t address, uint32_t value)
|
||||
void set24(std::uint16_t address, std::uint32_t value)
|
||||
{
|
||||
find_reg(address).value = (value >> 16) & 0xff;
|
||||
find_reg(address + 1).value = (value >> 8) & 0xff;
|
||||
find_reg(address + 2).value = value & 0xff;
|
||||
}
|
||||
|
||||
uint8_t get8(uint16_t address) const
|
||||
std::uint8_t get8(std::uint16_t address) const
|
||||
{
|
||||
return find_reg(address).value;
|
||||
}
|
||||
|
||||
uint16_t get16(uint16_t address) const
|
||||
std::uint16_t get16(std::uint16_t address) const
|
||||
{
|
||||
return (find_reg(address).value << 8) | find_reg(address + 1).value;
|
||||
}
|
||||
|
||||
uint32_t get24(uint16_t address) const
|
||||
std::uint32_t get24(std::uint16_t address) const
|
||||
{
|
||||
return (find_reg(address).value << 16) |
|
||||
(find_reg(address + 1).value << 8) |
|
||||
|
@ -196,7 +196,7 @@ public:
|
|||
}
|
||||
|
||||
void clear() { registers_.clear(); }
|
||||
size_t size() const { return registers_.size(); }
|
||||
std::size_t size() const { return registers_.size(); }
|
||||
|
||||
iterator begin() { return registers_.begin(); }
|
||||
const_iterator begin() const { return registers_.begin(); }
|
||||
|
@ -205,10 +205,10 @@ public:
|
|||
const_iterator end() const { return registers_.end(); }
|
||||
|
||||
private:
|
||||
int find_reg_index(uint16_t address) const
|
||||
int find_reg_index(std::uint16_t address) const
|
||||
{
|
||||
if (!sorted_) {
|
||||
for (size_t i = 0; i < registers_.size(); i++) {
|
||||
for (std::size_t i = 0; i < registers_.size(); i++) {
|
||||
if (registers_[i].address == address) {
|
||||
return i;
|
||||
}
|
||||
|
@ -290,10 +290,10 @@ public:
|
|||
iterator end() { return registers_.end(); }
|
||||
const_iterator end() const { return registers_.end(); }
|
||||
|
||||
SettingType& operator[](size_t i) { return registers_[i]; }
|
||||
const SettingType& operator[](size_t i) const { return registers_[i]; }
|
||||
SettingType& operator[](std::size_t i) { return registers_[i]; }
|
||||
const SettingType& operator[](std::size_t i) const { return registers_[i]; }
|
||||
|
||||
size_t size() const { return registers_.size(); }
|
||||
std::size_t size() const { return registers_.size(); }
|
||||
bool empty() const { return registers_.empty(); }
|
||||
void clear() { registers_.clear(); }
|
||||
|
||||
|
@ -357,7 +357,7 @@ private:
|
|||
|
||||
int find_reg_index(AddressType address) const
|
||||
{
|
||||
for (size_t i = 0; i < registers_.size(); i++) {
|
||||
for (std::size_t i = 0; i < registers_.size(); i++) {
|
||||
if (registers_[i].address == address) {
|
||||
return i;
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ inline void serialize(std::istream& str, RegisterSettingSet<Value>& reg)
|
|||
using AddressType = typename RegisterSetting<Value>::AddressType;
|
||||
|
||||
reg.clear();
|
||||
const size_t max_register_address = 1 << (sizeof(AddressType) * CHAR_BIT);
|
||||
const std::size_t max_register_address = 1 << (sizeof(AddressType) * CHAR_BIT);
|
||||
serialize(str, reg.registers_, max_register_address);
|
||||
}
|
||||
|
||||
|
@ -389,9 +389,9 @@ inline void serialize(std::ostream& str, RegisterSettingSet<Value>& reg)
|
|||
|
||||
template<class F, class Value>
|
||||
void apply_registers_ordered(const RegisterSettingSet<Value>& set,
|
||||
std::initializer_list<uint16_t> order, F f)
|
||||
std::initializer_list<std::uint16_t> order, F f)
|
||||
{
|
||||
for (uint16_t addr : order) {
|
||||
for (std::uint16_t addr : order) {
|
||||
f(set.find_reg(addr));
|
||||
}
|
||||
for (const auto& reg : set) {
|
||||
|
|
|
@ -104,21 +104,22 @@ void UsbDevice::get_vendor_product(int& vendor, int& product)
|
|||
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
||||
}
|
||||
|
||||
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data)
|
||||
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length,
|
||||
std::uint8_t* data)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
assert_is_open();
|
||||
TIE(sanei_usb_control_msg(device_num_, rtype, reg, value, index, length, data));
|
||||
}
|
||||
|
||||
void UsbDevice::bulk_read(uint8_t* buffer, size_t* size)
|
||||
void UsbDevice::bulk_read(std::uint8_t* buffer, std::size_t* size)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
assert_is_open();
|
||||
TIE(sanei_usb_read_bulk(device_num_, buffer, size));
|
||||
}
|
||||
|
||||
void UsbDevice::bulk_write(const uint8_t* buffer, size_t* size)
|
||||
void UsbDevice::bulk_write(const std::uint8_t* buffer, std::size_t* size)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
assert_is_open();
|
||||
|
|
|
@ -80,9 +80,9 @@ public:
|
|||
|
||||
void get_vendor_product(int& vendor, int& product);
|
||||
|
||||
void control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data);
|
||||
void bulk_read(uint8_t* buffer, size_t* size);
|
||||
void bulk_write(const uint8_t* buffer, size_t* size);
|
||||
void control_msg(int rtype, int reg, int value, int index, int length, std::uint8_t* data);
|
||||
void bulk_read(std::uint8_t* buffer, std::size_t* size);
|
||||
void bulk_write(const std::uint8_t* buffer, std::size_t* size);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ enum class FrontendType : unsigned
|
|||
struct GenesysFrontendLayout
|
||||
{
|
||||
FrontendType type = FrontendType::UNKNOWN;
|
||||
std::array<uint16_t, 3> offset_addr = {};
|
||||
std::array<uint16_t, 3> gain_addr = {};
|
||||
std::array<std::uint16_t, 3> offset_addr = {};
|
||||
std::array<std::uint16_t, 3> gain_addr = {};
|
||||
|
||||
bool operator==(const GenesysFrontendLayout& other) const
|
||||
{
|
||||
|
@ -149,9 +149,9 @@ void serialize(Stream& str, Genesys_Frontend& x)
|
|||
}
|
||||
|
||||
struct SensorExposure {
|
||||
uint16_t red = 0;
|
||||
uint16_t green = 0;
|
||||
uint16_t blue = 0;
|
||||
std::uint16_t red = 0;
|
||||
std::uint16_t green = 0;
|
||||
std::uint16_t blue = 0;
|
||||
|
||||
SensorExposure() = default;
|
||||
SensorExposure(std::uint16_t r, std::uint16_t g, std::uint16_t b) :
|
||||
|
|
Ładowanie…
Reference in New Issue