kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Simplify shading computation by using enum for color order
rodzic
3a1163480a
commit
503797c248
|
@ -65,6 +65,7 @@
|
||||||
#include "../include/sane/sanei_config.h"
|
#include "../include/sane/sanei_config.h"
|
||||||
#include "../include/sane/sanei_magic.h"
|
#include "../include/sane/sanei_magic.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -2199,6 +2200,16 @@ compute_averaged_planar (Genesys_Device * dev, const Genesys_Sensor& sensor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::array<unsigned, 3> color_order_to_cmat(ColorOrder color_order)
|
||||||
|
{
|
||||||
|
switch (color_order) {
|
||||||
|
case ColorOrder::RGB: return {0, 1, 2};
|
||||||
|
case ColorOrder::GBR: return {2, 0, 1};
|
||||||
|
default:
|
||||||
|
throw std::logic_error("Unknown color order");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes shading coefficient using formula in data sheet. 16bit data values
|
* Computes shading coefficient using formula in data sheet. 16bit data values
|
||||||
* manipulated here are little endian. For now we assume deletion scanning type
|
* manipulated here are little endian. For now we assume deletion scanning type
|
||||||
|
@ -2212,12 +2223,11 @@ compute_averaged_planar (Genesys_Device * dev, const Genesys_Sensor& sensor,
|
||||||
* @param coeff 4000h or 2000h depending on fast scan mode or not
|
* @param coeff 4000h or 2000h depending on fast scan mode or not
|
||||||
* @param target value of the target code
|
* @param target value of the target code
|
||||||
*/
|
*/
|
||||||
static void
|
static void compute_coefficients(Genesys_Device * dev,
|
||||||
compute_coefficients (Genesys_Device * dev,
|
|
||||||
uint8_t * shading_data,
|
uint8_t * shading_data,
|
||||||
unsigned int pixels_per_line,
|
unsigned int pixels_per_line,
|
||||||
unsigned int channels,
|
unsigned int channels,
|
||||||
unsigned int cmat[3],
|
ColorOrder color_order,
|
||||||
int offset,
|
int offset,
|
||||||
unsigned int coeff,
|
unsigned int coeff,
|
||||||
unsigned int target)
|
unsigned int target)
|
||||||
|
@ -2229,6 +2239,8 @@ compute_coefficients (Genesys_Device * dev,
|
||||||
|
|
||||||
DBG(DBG_io, "%s: pixels_per_line=%d, coeff=0x%04x\n", __func__, pixels_per_line, coeff);
|
DBG(DBG_io, "%s: pixels_per_line=%d, coeff=0x%04x\n", __func__, pixels_per_line, coeff);
|
||||||
|
|
||||||
|
auto cmat = color_order_to_cmat(color_order);
|
||||||
|
|
||||||
/* compute start & end values depending of the offset */
|
/* compute start & end values depending of the offset */
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
{
|
{
|
||||||
|
@ -2283,14 +2295,13 @@ compute_coefficients (Genesys_Device * dev,
|
||||||
* @param coeff 4000h or 2000h depending on fast scan mode or not
|
* @param coeff 4000h or 2000h depending on fast scan mode or not
|
||||||
* @param target white target value
|
* @param target white target value
|
||||||
*/
|
*/
|
||||||
static void
|
static void compute_planar_coefficients(Genesys_Device * dev,
|
||||||
compute_planar_coefficients (Genesys_Device * dev,
|
|
||||||
uint8_t * shading_data,
|
uint8_t * shading_data,
|
||||||
unsigned int factor,
|
unsigned int factor,
|
||||||
unsigned int pixels_per_line,
|
unsigned int pixels_per_line,
|
||||||
unsigned int words_per_color,
|
unsigned int words_per_color,
|
||||||
unsigned int channels,
|
unsigned int channels,
|
||||||
unsigned int cmat[3],
|
ColorOrder color_order,
|
||||||
unsigned int offset,
|
unsigned int offset,
|
||||||
unsigned int coeff,
|
unsigned int coeff,
|
||||||
unsigned int target)
|
unsigned int target)
|
||||||
|
@ -2299,6 +2310,8 @@ compute_planar_coefficients (Genesys_Device * dev,
|
||||||
uint32_t x, c, i;
|
uint32_t x, c, i;
|
||||||
uint32_t val, dk, br;
|
uint32_t val, dk, br;
|
||||||
|
|
||||||
|
auto cmat = color_order_to_cmat(color_order);
|
||||||
|
|
||||||
DBG(DBG_io, "%s: factor=%d, pixels_per_line=%d, words=0x%X, coeff=0x%04x\n", __func__, factor,
|
DBG(DBG_io, "%s: factor=%d, pixels_per_line=%d, words=0x%X, coeff=0x%04x\n", __func__, factor,
|
||||||
pixels_per_line, words_per_color, coeff);
|
pixels_per_line, words_per_color, coeff);
|
||||||
for (c = 0; c < channels; c++)
|
for (c = 0; c < channels; c++)
|
||||||
|
@ -2353,7 +2366,7 @@ compute_shifted_coefficients (Genesys_Device * dev,
|
||||||
uint8_t * shading_data,
|
uint8_t * shading_data,
|
||||||
unsigned int pixels_per_line,
|
unsigned int pixels_per_line,
|
||||||
unsigned int channels,
|
unsigned int channels,
|
||||||
unsigned int cmat[3],
|
ColorOrder color_order,
|
||||||
int offset,
|
int offset,
|
||||||
unsigned int coeff,
|
unsigned int coeff,
|
||||||
unsigned int target_dark,
|
unsigned int target_dark,
|
||||||
|
@ -2365,6 +2378,8 @@ compute_shifted_coefficients (Genesys_Device * dev,
|
||||||
uint8_t *ptr = shading_data + offset * 3 * 4; /* contain 16bit words in little endian */
|
uint8_t *ptr = shading_data + offset * 3 * 4; /* contain 16bit words in little endian */
|
||||||
unsigned int patch_cnt = offset * 3; /* at start, offset of first patch */
|
unsigned int patch_cnt = offset * 3; /* at start, offset of first patch */
|
||||||
|
|
||||||
|
auto cmat = color_order_to_cmat(color_order);
|
||||||
|
|
||||||
x = dev->settings.xres;
|
x = dev->settings.xres;
|
||||||
if (sensor.get_ccd_size_divisor_for_dpi(dev->settings.xres) > 1)
|
if (sensor.get_ccd_size_divisor_for_dpi(dev->settings.xres) > 1)
|
||||||
x *= 2; /* scanner is using half-ccd mode */
|
x *= 2; /* scanner is using half-ccd mode */
|
||||||
|
@ -2445,7 +2460,6 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
int o;
|
int o;
|
||||||
unsigned int length; /**> number of shading calibration data words */
|
unsigned int length; /**> number of shading calibration data words */
|
||||||
unsigned int factor;
|
unsigned int factor;
|
||||||
unsigned int cmat[3]; /**> matrix of color channels */
|
|
||||||
unsigned int coeff, target_code, words_per_color = 0;
|
unsigned int coeff, target_code, words_per_color = 0;
|
||||||
|
|
||||||
pixels_per_line = dev->calib_pixels + dev->calib_pixels_offset;
|
pixels_per_line = dev->calib_pixels + dev->calib_pixels_offset;
|
||||||
|
@ -2519,9 +2533,6 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
|
|
||||||
/* TODO setup a struct in genesys_devices that
|
/* TODO setup a struct in genesys_devices that
|
||||||
* will handle these settings instead of having this switch growing up */
|
* will handle these settings instead of having this switch growing up */
|
||||||
cmat[0] = 0;
|
|
||||||
cmat[1] = 1;
|
|
||||||
cmat[2] = 2;
|
|
||||||
switch (dev->model->ccd_type)
|
switch (dev->model->ccd_type)
|
||||||
{
|
{
|
||||||
case CCD_XP300:
|
case CCD_XP300:
|
||||||
|
@ -2537,7 +2548,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
words_per_color,
|
words_per_color,
|
||||||
channels,
|
channels,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2545,16 +2556,13 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
case CIS_XP200:
|
case CIS_XP200:
|
||||||
target_code = 0xdc00;
|
target_code = 0xdc00;
|
||||||
o = 2;
|
o = 2;
|
||||||
cmat[0] = 2; /* red is last */
|
|
||||||
cmat[1] = 0; /* green is first */
|
|
||||||
cmat[2] = 1; /* blue is second */
|
|
||||||
compute_planar_coefficients (dev,
|
compute_planar_coefficients (dev,
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
1,
|
1,
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
words_per_color,
|
words_per_color,
|
||||||
channels,
|
channels,
|
||||||
cmat,
|
ColorOrder::GBR,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2570,7 +2578,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
3,
|
3,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2586,7 +2594,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
3,
|
3,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2613,7 +2621,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
3,
|
3,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2630,7 +2638,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
3,
|
3,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
o,
|
o,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2668,7 +2676,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
words_per_color,
|
words_per_color,
|
||||||
channels,
|
channels,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
0,
|
0,
|
||||||
coeff,
|
coeff,
|
||||||
target_code);
|
target_code);
|
||||||
|
@ -2700,7 +2708,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
||||||
shading_data.data(),
|
shading_data.data(),
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
channels,
|
channels,
|
||||||
cmat,
|
ColorOrder::RGB,
|
||||||
12, /* offset */
|
12, /* offset */
|
||||||
coeff,
|
coeff,
|
||||||
0x0001, /* target_dark */
|
0x0001, /* target_dark */
|
||||||
|
|
|
@ -116,6 +116,12 @@ enum Genesys_Color_Order
|
||||||
COLOR_ORDER_BGR
|
COLOR_ORDER_BGR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ColorOrder
|
||||||
|
{
|
||||||
|
RGB,
|
||||||
|
GBR,
|
||||||
|
};
|
||||||
|
|
||||||
enum Genesys_Model_Type
|
enum Genesys_Model_Type
|
||||||
{
|
{
|
||||||
MODEL_UMAX_ASTRA_4500 = 0,
|
MODEL_UMAX_ASTRA_4500 = 0,
|
||||||
|
|
Ładowanie…
Reference in New Issue