pixma: for grayscale conversion use BT.709 luma

Before we used linear grayscale conversion. This is not state of the art.
reorg-descriptions
Rolf Bensch 2020-03-24 12:37:24 +01:00
rodzic 199b9eeef6
commit 6e52b3f01a
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -335,7 +335,7 @@ pixma_r_to_ir (uint8_t * gptr, uint8_t * sptr, unsigned w, unsigned c)
/* convert 24/48 bit RGB to 8/16 bit grayscale
*
* Formular: g = (R + G + B) / 3
* Formular: Y' = 0,2126 R' + 0,7152 G' + 0,0722 B'
*
* sptr: source color scale buffer
* gptr: destination gray scale buffer
@ -345,19 +345,28 @@ pixma_r_to_ir (uint8_t * gptr, uint8_t * sptr, unsigned w, unsigned c)
uint8_t *
pixma_rgb_to_gray (uint8_t * gptr, uint8_t * sptr, unsigned w, unsigned c)
{
unsigned i, j, g;
unsigned i, g;
/* PDBG (pixma_dbg (4, "*pixma_rgb_to_gray*****\n")); */
for (i = 0; i < w; i++)
{
for (j = 0, g = 0; j < 3; j++)
{
g += *sptr++;
if (c == 6) g += (*sptr++ << 8); /* 48 bit RGB: high byte */
}
if (c == 6)
{ /* 48 bit RGB */
unsigned r = sptr[0] + (sptr[1] << 8);
unsigned y = sptr[2] + (sptr[3] << 8);
unsigned b = sptr[4] + (sptr[5] << 8);
g = (r * 2126) + (y * 7152) + (b * 722);
sptr += 6;
}
else
{ /* 24 bit RGB */
g = (sptr[0] * 2126) + (sptr[1] * 7152) + (sptr[2] * 722);
sptr += 3;
}
g /= 10000; /* 8 and 16 bit gray */
g /= 3; /* 8 or 16 bit gray */
*gptr++ = g;
if (c == 6) *gptr++ = (g >> 8); /* 16 bit gray: high byte */
}