kopia lustrzana https://gitlab.com/sane-project/backends
calculate 16-bit gamma table
Generation 1 scanners need a 8-bit gamma table, with 4096 bytes size. All other scanners need a 16-bit gamma table, with 1024 bytes size. For these scanners values of the generated gamma table are close by the values used from the manufacturers proprietary driver.merge-requests/244/head
rodzic
103c77ddee
commit
11126468ef
|
@ -1186,14 +1186,35 @@ pixma_get_config (pixma_t * s)
|
|||
void
|
||||
pixma_fill_gamma_table (double gamma, uint8_t * table, unsigned n)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
double r_gamma = 1.0 / gamma;
|
||||
double out_scale = 255.0;
|
||||
double in_scale = 1.0 / (n - 1);
|
||||
|
||||
for (i = 0; (unsigned) i != n; i++)
|
||||
/* 8-bits gamma table
|
||||
* for generation 1 scanners
|
||||
*/
|
||||
if (n == 4096)
|
||||
{
|
||||
table[i] = (int) (out_scale * pow (i * in_scale, r_gamma) + 0.5);
|
||||
double out_scale = 255.0;
|
||||
|
||||
for (i = 0; (unsigned) i != n; i++)
|
||||
{
|
||||
table[i] = (int) (out_scale * pow (i * in_scale, r_gamma) + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
/* 16-bits gamma table */
|
||||
else
|
||||
{
|
||||
double out_scale = 65535.0;
|
||||
uint16_t value;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
value = (uint16_t) (out_scale * pow (i * in_scale, r_gamma) + 0.5);
|
||||
table[2 * i] = (uint8_t) (value & 0xff);
|
||||
table[2 * i + 1] = (uint8_t) (value >> 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,6 @@
|
|||
4096 = size of gamma table. 24 = header + checksum */
|
||||
#define IMAGE_BLOCK_SIZE (512*1024)
|
||||
#define CMDBUF_SIZE (4096 + 24)
|
||||
#define DEFAULT_GAMMA 2.0 /***** Gamma different from 1.0 is potentially impacting color profile generation *****/
|
||||
#define UNKNOWN_PID 0xffff
|
||||
|
||||
|
||||
|
@ -573,36 +572,39 @@ send_gamma_table (pixma_t * s)
|
|||
data[0] = (s->param->channels == 3) ? 0x10 : 0x01;
|
||||
pixma_set_be16 (0x1004, data + 2);
|
||||
if (lut)
|
||||
memcpy (data + 4, lut, 4096);
|
||||
{
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Use 4096 bytes from LUT ***** \n"));
|
||||
/* PDBG (pixma_hexdump (4, lut, 4096)); */
|
||||
memcpy (data + 4, lut, 4096);
|
||||
}
|
||||
else
|
||||
pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 4096);
|
||||
{
|
||||
/* fallback: we should never see this */
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 4096 bytes Table with %f ***** \n",
|
||||
s->param->gamma));
|
||||
pixma_fill_gamma_table (s->param->gamma, data + 4, 4096);
|
||||
/* PDBG (pixma_hexdump (4, data + 4, 4096)); */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FIXME: Gamma table for 2nd generation: 1024 * uint16_le */
|
||||
data = pixma_newcmd (&mp->cb, cmd_gamma, 2048 + 8, 0);
|
||||
/* Gamma table for 2nd+ generation: 1024 * uint16_le */
|
||||
data = pixma_newcmd (&mp->cb, cmd_gamma, 1024 * 2 + 8, 0);
|
||||
data[0] = 0x10;
|
||||
pixma_set_be16 (0x0804, data + 2);
|
||||
if (lut)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
int j = (i << 2) + (i >> 8);
|
||||
data[4 + 2 * i + 0] = lut[j];
|
||||
data[4 + 2 * i + 1] = lut[j];
|
||||
}
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Use 1024 * 2 bytes from LUT ***** \n"));
|
||||
/* PDBG (pixma_hexdump (4, lut, 1024 * 2)); */
|
||||
memcpy (data + 4, lut, 1024 * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 2048);
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
int j = (i << 1) + (i >> 9);
|
||||
data[4 + 2 * i + 0] = data[4 + j];
|
||||
data[4 + 2 * i + 1] = data[4 + j];
|
||||
}
|
||||
/* fallback: we should never see this */
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 1024 * 2 Table with %f ***** \n",
|
||||
s->param->gamma));
|
||||
pixma_fill_gamma_table (s->param->gamma, data + 4, 1024);
|
||||
/* PDBG (pixma_hexdump (4, data + 4, 1024 * 2)); */
|
||||
}
|
||||
}
|
||||
return pixma_exec (s, &mp->cb);
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
4096 = size of gamma table. 24 = header + checksum */
|
||||
#define IMAGE_BLOCK_SIZE (512*1024)
|
||||
#define CMDBUF_SIZE (4096 + 24)
|
||||
#define DEFAULT_GAMMA 2.0 /***** Gamma different from 1.0 is potentially impacting color profile generation *****/
|
||||
#define UNKNOWN_PID 0xffff
|
||||
|
||||
#define CANON_VID 0x04a9
|
||||
|
@ -442,38 +441,41 @@ static int send_gamma_table (pixma_t * s)
|
|||
data[0] = (s->param->channels == 3) ? 0x10 : 0x01;
|
||||
pixma_set_be16 (0x1004, data + 2);
|
||||
if (lut)
|
||||
memcpy (data + 4, lut, 4096);
|
||||
{
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Use 4096 bytes from LUT ***** \n"));
|
||||
/* PDBG (pixma_hexdump (4, lut, 4096)); */
|
||||
memcpy (data + 4, lut, 4096);
|
||||
}
|
||||
else
|
||||
pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 4096);
|
||||
{
|
||||
/* fallback: we should never see this */
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 4096 bytes Table with %f ***** \n",
|
||||
s->param->gamma));
|
||||
pixma_fill_gamma_table (s->param->gamma, data + 4, 4096);
|
||||
/* PDBG (pixma_hexdump (4, data + 4, 4096)); */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FIXME: Gamma table for 2nd generation: 1024 * uint16_le */
|
||||
data = pixma_newcmd (&mp->cb, cmd_gamma, 2048 + 8, 0);
|
||||
data[0] = 0x10;
|
||||
pixma_set_be16 (0x0804, data + 2);
|
||||
if (lut)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
int j = (i << 2) + (i >> 8);
|
||||
data[4 + 2 * i + 0] = lut[j];
|
||||
data[4 + 2 * i + 1] = lut[j];
|
||||
}
|
||||
/* Gamma table for 2nd+ generation: 1024 * uint16_le */
|
||||
data = pixma_newcmd (&mp->cb, cmd_gamma, 1024 * 2 + 8, 0);
|
||||
data[0] = 0x10;
|
||||
pixma_set_be16 (0x0804, data + 2);
|
||||
if (lut)
|
||||
{
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Use 1024 * 2 bytes from LUT ***** \n"));
|
||||
/* PDBG (pixma_hexdump (4, lut, 1024 * 2)); */
|
||||
memcpy (data + 4, lut, 1024 * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* fallback: we should never see this */
|
||||
PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 1024 * 2 bytes Table with %f ***** \n",
|
||||
s->param->gamma));
|
||||
pixma_fill_gamma_table (s->param->gamma, data + 4, 1024);
|
||||
/* PDBG (pixma_hexdump (4, data + 4, 1024 * 2)); */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 2048);
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
int j = (i << 1) + (i >> 9);
|
||||
data[4 + 2 * i + 0] = data[4 + j];
|
||||
data[4 + 2 * i + 1] = data[4 + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return pixma_exec (s, &mp->cb);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue