1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4 
5    This file is part of the SANE package.
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 
20    As a special exception, the authors of SANE give permission for
21    additional uses of the libraries contained in this release of SANE.
22 
23    The exception is that, if you link a SANE library with other files
24    to produce an executable, this does not by itself cause the
25    resulting executable to be covered by the GNU General Public
26    License.  Your use of that executable is in no way restricted on
27    account of linking the SANE library code into it.
28 
29    This exception does not, however, invalidate any other reasons why
30    the executable file might be covered by the GNU General Public
31    License.
32 
33    If you submit changes to SANE to the maintainers to be included in
34    a subsequent release, you agree by submitting the changes that
35    those changes may be distributed with this exception intact.
36 
37    If you write modifications of your own for SANE, it is your choice
38    whether to permit this exception to apply to your modifications.
39    If you do not wish that, delete this exception notice.
40 */
41 
42 #define DEBUG_DECLARE_ONLY
43 
44 #include "sensor.h"
45 #include "utilities.h"
46 #include <iomanip>
47 
48 namespace genesys {
49 
operator <<(std::ostream & out,const StaggerConfig & config)50 std::ostream& operator<<(std::ostream& out, const StaggerConfig& config)
51 {
52     if (config.shifts().empty()) {
53         out << "StaggerConfig{}";
54         return out;
55     }
56 
57     out << "StaggerConfig{ " << config.shifts().front();
58     for (auto it = std::next(config.shifts().begin()); it != config.shifts().end(); ++it) {
59         out << ", " << *it;
60     }
61     out << " }";
62     return out;
63 }
64 
operator <<(std::ostream & out,const FrontendType & type)65 std::ostream& operator<<(std::ostream& out, const FrontendType& type)
66 {
67     switch (type) {
68         case FrontendType::UNKNOWN: out << "UNKNOWN"; break;
69         case FrontendType::WOLFSON: out << "WOLFSON"; break;
70         case FrontendType::ANALOG_DEVICES: out << "ANALOG_DEVICES"; break;
71         case FrontendType::CANON_LIDE_80: out << "CANON_LIDE_80"; break;
72         case FrontendType::WOLFSON_GL841: out << "WOLFSON_GL841"; break;
73         case FrontendType::WOLFSON_GL846: out << "WOLFSON_GL846"; break;
74         case FrontendType::ANALOG_DEVICES_GL847: out << "ANALOG_DEVICES_GL847"; break;
75         case FrontendType::WOLFSON_GL124: out << "WOLFSON_GL124"; break;
76         default: out << "(unknown value)";
77     }
78     return out;
79 }
80 
operator <<(std::ostream & out,const GenesysFrontendLayout & layout)81 std::ostream& operator<<(std::ostream& out, const GenesysFrontendLayout& layout)
82 {
83     StreamStateSaver state_saver{out};
84 
85     out << "GenesysFrontendLayout{\n"
86         << "    type: " << layout.type << '\n'
87         << std::hex
88         << "    offset_addr[0]: " << layout.offset_addr[0] << '\n'
89         << "    offset_addr[1]: " << layout.offset_addr[1] << '\n'
90         << "    offset_addr[2]: " << layout.offset_addr[2] << '\n'
91         << "    gain_addr[0]: " << layout.gain_addr[0] << '\n'
92         << "    gain_addr[1]: " << layout.gain_addr[1] << '\n'
93         << "    gain_addr[2]: " << layout.gain_addr[2] << '\n'
94         << '}';
95     return out;
96 }
97 
operator <<(std::ostream & out,const Genesys_Frontend & frontend)98 std::ostream& operator<<(std::ostream& out, const Genesys_Frontend& frontend)
99 {
100     StreamStateSaver state_saver{out};
101 
102     out << "Genesys_Frontend{\n"
103         << "    id: " << frontend.id << '\n'
104         << "    regs: " << format_indent_braced_list(4, frontend.regs) << '\n'
105         << std::hex
106         << "    reg2[0]: " << frontend.reg2[0] << '\n'
107         << "    reg2[1]: " << frontend.reg2[1] << '\n'
108         << "    reg2[2]: " << frontend.reg2[2] << '\n'
109         << "    layout: " << format_indent_braced_list(4, frontend.layout) << '\n'
110         << '}';
111     return out;
112 }
113 
operator <<(std::ostream & out,const SensorExposure & exposure)114 std::ostream& operator<<(std::ostream& out, const SensorExposure& exposure)
115 {
116     out << "SensorExposure{\n"
117         << "    red: " << exposure.red << '\n'
118         << "    green: " << exposure.green << '\n'
119         << "    blue: " << exposure.blue << '\n'
120         << '}';
121     return out;
122 }
123 
operator <<(std::ostream & out,const Genesys_Sensor & sensor)124 std::ostream& operator<<(std::ostream& out, const Genesys_Sensor& sensor)
125 {
126     out << "Genesys_Sensor{\n"
127         << "    sensor_id: " << static_cast<unsigned>(sensor.sensor_id) << '\n'
128         << "    full_resolution: " << sensor.full_resolution << '\n'
129         << "    optical_resolution: " << sensor.get_optical_resolution() << '\n'
130         << "    resolutions: " << format_indent_braced_list(4, sensor.resolutions) << '\n'
131         << "    channels: " << format_vector_unsigned(4, sensor.channels) << '\n'
132         << "    method: " << sensor.method << '\n'
133         << "    register_dpihw: " << sensor.register_dpihw << '\n'
134         << "    register_dpiset: " << sensor.register_dpiset << '\n'
135         << "    shading_factor: " << sensor.shading_factor << '\n'
136         << "    shading_pixel_offset: " << sensor.shading_pixel_offset << '\n'
137         << "    pixel_count_ratio: " << sensor.pixel_count_ratio << '\n'
138         << "    output_pixel_offset: " << sensor.output_pixel_offset << '\n'
139         << "    black_pixels: " << sensor.black_pixels << '\n'
140         << "    dummy_pixel: " << sensor.dummy_pixel << '\n'
141         << "    fau_gain_white_ref: " << sensor.fau_gain_white_ref << '\n'
142         << "    gain_white_ref: " << sensor.gain_white_ref << '\n'
143         << "    exposure: " << format_indent_braced_list(4, sensor.exposure) << '\n'
144         << "    exposure_lperiod: " << sensor.exposure_lperiod << '\n'
145         << "    segment_size: " << sensor.segment_size << '\n'
146         << "    segment_order: "
147         << format_indent_braced_list(4, format_vector_unsigned(4, sensor.segment_order)) << '\n'
148         << "    stagger_x: " << sensor.stagger_x << '\n'
149         << "    stagger_y: " << sensor.stagger_y << '\n'
150         << "    use_host_side_calib: " << sensor.use_host_side_calib << '\n'
151         << "    custom_regs: " << format_indent_braced_list(4, sensor.custom_regs) << '\n'
152         << "    custom_fe_regs: " << format_indent_braced_list(4, sensor.custom_fe_regs) << '\n'
153         << "    gamma.red: " << sensor.gamma[0] << '\n'
154         << "    gamma.green: " << sensor.gamma[1] << '\n'
155         << "    gamma.blue: " << sensor.gamma[2] << '\n'
156         << "}";
157     return out;
158 }
159 
160 } // namespace genesys
161