From 3e5d6c2f8deb66c1ef1744bf756c424bac720619 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 11 May 2016 22:55:37 -0500 Subject: [PATCH] Do better job of converting to grayscale --- src/test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test.c b/src/test.c index 390aad7..ff6be18 100644 --- a/src/test.c +++ b/src/test.c @@ -108,8 +108,12 @@ static void image_copy(cammy_sram_frame *frame, uint8_t *buf) { g = buf[4*CAMMY_SRAM_PHOTO_WIDTH*y+4*x+1], b = buf[4*CAMMY_SRAM_PHOTO_WIDTH*y+4*x+2]; - uint8_t avg = (uint8_t)(((float)r + (float)g + (float)b) / 3); - uint32_t slot = bayer_matrix[avg]; + uint8_t gray = (uint8_t) + ((0.2126 * (float)r) + + (0.7152 * (float)g) + + (0.0722 * (float)b)); + + uint32_t slot = bayer_matrix[gray]; uint32_t from = (slot & 0x03000000) >> 24; uint32_t to = (slot & 0x00030000) >> 16; uint8_t value;