kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'genesys-desegmentation-refactor' into 'master'
genesys: Simplify desegmentation state (part 6) See merge request sane-project/backends!172merge-requests/173/merge
commit
17dc1aee81
|
@ -3452,79 +3452,92 @@ static void genesys_fill_line_interp_buffer(Genesys_Device* dev, uint8_t* work_b
|
|||
* back to back and must be interleaved to get usable by the other stages
|
||||
* of the backend
|
||||
*/
|
||||
static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buffer_dst,
|
||||
size_t size)
|
||||
void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buffer_dst, size_t size)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
size_t count;
|
||||
int depth, i, k;
|
||||
|
||||
depth = dev->settings.depth;
|
||||
if (dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart==SANE_FALSE)
|
||||
depth = 1;
|
||||
unsigned depth = dev->settings.depth;
|
||||
if (dev->settings.scan_mode == ScanColorMode::LINEART &&
|
||||
dev->settings.dynamic_lineart == false)
|
||||
{
|
||||
depth = 1;
|
||||
}
|
||||
|
||||
/* fill buffer if needed */
|
||||
if (dev->oe_buffer.avail() == 0)
|
||||
// fill buffer if needed
|
||||
if (dev->oe_buffer.avail() == 0)
|
||||
{
|
||||
accurate_line_read(dev, dev->oe_buffer);
|
||||
}
|
||||
|
||||
/* copy size bytes of data, copying from a subwindow of each line
|
||||
* when last line of buffer is exhausted, read another one */
|
||||
count = 0;
|
||||
while (count < size)
|
||||
{
|
||||
if (depth==1) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count && count < size) {
|
||||
auto read_desegmented = [&](size_t curr_byte, size_t curr_segment) -> uint8_t
|
||||
{
|
||||
curr_byte += dev->session.output_segment_start_offset;
|
||||
curr_byte += dev->session.conseq_pixel_dist_bytes * dev->segment_order[curr_segment];
|
||||
return dev->oe_buffer.get_read_pos()[curr_byte];
|
||||
};
|
||||
|
||||
// copy size bytes of data, copying from a subwindow of each line
|
||||
// when last line of buffer is exhausted, read another one
|
||||
size_t count = 0;
|
||||
while (count < size) {
|
||||
if (depth == 1) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count &&
|
||||
count < size)
|
||||
{
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count + n] = 0;
|
||||
}
|
||||
/* interleaving is at bit level */
|
||||
for (unsigned i = 0; i < 8; i++) {
|
||||
unsigned k = count + (i * dev->session.segment_count) / 8;
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count+n] = 0;
|
||||
}
|
||||
/* interleaving is at bit level */
|
||||
for (i=0;i<8;i++) {
|
||||
k = count + (i * dev->session.segment_count) / 8;
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[k] = work_buffer_dst[k] << 1;
|
||||
if ((dev->oe_buffer.get_read_pos()[dev->deseg_curr_byte + dev->session.output_segment_start_offset + dev->session.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) {
|
||||
work_buffer_dst[k] |= 1;
|
||||
}
|
||||
work_buffer_dst[k] = work_buffer_dst[k] << 1;
|
||||
if (read_desegmented(dev->deseg_curr_byte, n) & (0x80 >> i)) {
|
||||
work_buffer_dst[k] |= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count;
|
||||
dev->deseg_curr_byte++;
|
||||
}
|
||||
}
|
||||
if (depth==8) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count && count < size) {
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->deseg_curr_byte + dev->session.output_segment_start_offset + dev->session.conseq_pixel_dist_bytes *dev->segment_order[n]];
|
||||
}
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count;
|
||||
dev->deseg_curr_byte++;
|
||||
}
|
||||
}
|
||||
if (depth==16) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count && count < size) {
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->deseg_curr_byte + dev->session.output_segment_start_offset + dev->session.conseq_pixel_dist_bytes * dev->segment_order[n]];
|
||||
work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->deseg_curr_byte + dev->session.output_segment_start_offset + dev->session.conseq_pixel_dist_bytes * dev->segment_order[n] + 1];
|
||||
}
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count * 2;
|
||||
dev->deseg_curr_byte += 2;
|
||||
}
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count;
|
||||
dev->deseg_curr_byte++;
|
||||
}
|
||||
}
|
||||
|
||||
/* go to next line if needed */
|
||||
if (depth == 8) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count &&
|
||||
count < size)
|
||||
{
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count + n] = read_desegmented(dev->deseg_curr_byte, n);
|
||||
}
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count;
|
||||
dev->deseg_curr_byte++;
|
||||
}
|
||||
}
|
||||
|
||||
if (depth == 16) {
|
||||
while (dev->deseg_curr_byte < dev->session.output_segment_pixel_group_count &&
|
||||
count < size) {
|
||||
for (unsigned n = 0; n < dev->session.segment_count; n++) {
|
||||
work_buffer_dst[count + n * 2] = read_desegmented(dev->deseg_curr_byte, n);
|
||||
work_buffer_dst[count + n * 2 + 1] = read_desegmented(dev->deseg_curr_byte + 1, n);
|
||||
}
|
||||
/* update counter and pointer */
|
||||
count += dev->session.segment_count * 2;
|
||||
dev->deseg_curr_byte += 2;
|
||||
}
|
||||
}
|
||||
|
||||
// go to next line if needed
|
||||
if (dev->deseg_curr_byte == dev->session.output_segment_pixel_group_count) {
|
||||
dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->session.output_line_bytes_raw);
|
||||
dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->session.output_line_bytes_raw);
|
||||
dev->deseg_curr_byte = 0;
|
||||
}
|
||||
|
||||
/* read a new buffer if needed */
|
||||
if (dev->oe_buffer.pos() >= dev->oe_buffer.avail())
|
||||
// read a new buffer if needed
|
||||
if (dev->oe_buffer.pos() >= dev->oe_buffer.avail())
|
||||
{
|
||||
accurate_line_read(dev, dev->oe_buffer);
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ struct Genesys_Device
|
|||
// total bytes read to be sent to frontend
|
||||
size_t total_bytes_to_read = 0;
|
||||
|
||||
// The current byte during desegmentation process
|
||||
// The current byte in line during desegmentation process
|
||||
size_t deseg_curr_byte = 0;
|
||||
|
||||
// contains the real used values
|
||||
|
|
|
@ -636,6 +636,8 @@ extern void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev,
|
|||
|
||||
void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor);
|
||||
|
||||
void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buffer_dst, size_t size);
|
||||
|
||||
const SensorProfile& get_sensor_profile(AsicType asic_type, const Genesys_Sensor& sensor,
|
||||
unsigned dpi, unsigned ccd_size_divisor);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ AM_CPPFLAGS += -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
|
|||
-DBACKEND_NAME=genesys
|
||||
|
||||
genesys_tests_SOURCES = tests.cc tests.h minigtest.cc minigtest.h \
|
||||
tests_calibration.cc
|
||||
tests_calibration.cc \
|
||||
tests_sensor.cc
|
||||
|
||||
genesys_tests_LDADD = $(TEST_LDADD)
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
int main()
|
||||
{
|
||||
test_calibration_parsing();
|
||||
test_sensor();
|
||||
return finish_tests();
|
||||
}
|
||||
|
|
|
@ -24,5 +24,6 @@
|
|||
#define SANE_TESTSUITE_BACKEND_GENESYS_GENESYS_UNIT_TEST_H
|
||||
|
||||
void test_calibration_parsing();
|
||||
void test_sensor();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/* sane - Scanner Access Now Easy.
|
||||
|
||||
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
|
||||
|
||||
This file is part of the SANE package.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
|
||||
#include "tests.h"
|
||||
#include "minigtest.h"
|
||||
|
||||
#include "../../../backend/genesys_low.h"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
template<class T>
|
||||
std::ostream& operator<<(std::ostream& str, const std::vector<T>& arg)
|
||||
{
|
||||
str << "{ ";
|
||||
for (const auto& el : arg) {
|
||||
str << (unsigned) el << ", ";
|
||||
}
|
||||
str << "}\n";
|
||||
return str;
|
||||
}
|
||||
|
||||
void test_fill_segmented_buffer_depth8()
|
||||
{
|
||||
Genesys_Device dev;
|
||||
dev.settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
||||
dev.settings.dynamic_lineart = false;
|
||||
dev.settings.depth = 8;
|
||||
|
||||
// 2 lines, 4 segments, 5 bytes each
|
||||
dev.deseg_curr_byte = 0;
|
||||
dev.session.output_segment_start_offset = 0;
|
||||
dev.session.output_segment_pixel_group_count = 5;
|
||||
dev.session.segment_count = 4;
|
||||
dev.session.conseq_pixel_dist_bytes = 5;
|
||||
dev.session.output_line_bytes_raw = 20;
|
||||
dev.segment_order = { 0, 2, 1, 3 };
|
||||
|
||||
dev.oe_buffer.alloc(1024);
|
||||
uint8_t* data = dev.oe_buffer.get_write_pos(40);
|
||||
std::array<uint8_t, 41> input_data = { {
|
||||
1, 5, 9, 13, 17,
|
||||
3, 7, 11, 15, 19,
|
||||
2, 6, 10, 14, 18,
|
||||
4, 8, 12, 16, 20,
|
||||
21, 25, 29, 33, 37,
|
||||
23, 27, 31, 35, 39,
|
||||
22, 26, 30, 34, 38,
|
||||
24, 28, 32, 36, 40,
|
||||
0 // one extra byte so that we don't attempt to refill the buffer
|
||||
} };
|
||||
std::copy(input_data.begin(), input_data.end(), data);
|
||||
dev.oe_buffer.produce(41);
|
||||
|
||||
std::vector<uint8_t> out_data;
|
||||
out_data.resize(40, 0);
|
||||
|
||||
genesys_fill_segmented_buffer(&dev, out_data.data(), 16);
|
||||
ASSERT_EQ(dev.deseg_curr_byte, 4u);
|
||||
genesys_fill_segmented_buffer(&dev, out_data.data() + 16, 4);
|
||||
ASSERT_EQ(dev.deseg_curr_byte, 0u);
|
||||
genesys_fill_segmented_buffer(&dev, out_data.data() + 20, 20);
|
||||
ASSERT_EQ(dev.deseg_curr_byte, 0u);
|
||||
|
||||
std::vector<uint8_t> expected;
|
||||
expected.resize(40, 0);
|
||||
std::iota(expected.begin(), expected.end(), 1); // will fill with 1, 2, 3, ..., 40
|
||||
|
||||
ASSERT_EQ(out_data, expected);
|
||||
}
|
||||
|
||||
void test_sensor()
|
||||
{
|
||||
test_fill_segmented_buffer_depth8();
|
||||
}
|
Ładowanie…
Reference in New Issue