From 2417ae97acaaf05ae13a6822005b6a710aafd9c4 Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 5 Jun 2019 00:56:04 +0200 Subject: [PATCH] improve colormix --- wagon.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wagon.cpp b/wagon.cpp index 677b382..2830113 100644 --- a/wagon.cpp +++ b/wagon.cpp @@ -295,7 +295,17 @@ void Wagon::updateGraphics() uint16_t _tmpr=_pxr+_r; //add colors uint16_t _tmpg=_pxg+_g; uint16_t _tmpb=_pxb+_b; - if (_tmpr>255){ //clamp + + double _brightnesscorrection = 0; + if ( (_tmpr+_tmpg+_tmpb) > 0){ + _brightnesscorrection = max((double)_pxr+(double)_pxg+(double)_pxb, (double)_r+(double)_g+(double)_b)/(_tmpr+_tmpg+_tmpb); + } + + + _tmpr=(uint16_t)(min(255,_tmpr*_brightnesscorrection)); + _tmpg=(uint16_t)(min(255,_tmpg*_brightnesscorrection)); + _tmpb=(uint16_t)(min(255,_tmpb*_brightnesscorrection)); + /*if (_tmpr>255){ //clamp _tmpr=255; } if (_tmpg>255){ @@ -303,7 +313,7 @@ void Wagon::updateGraphics() } if (_tmpb>255){ _tmpb=255; - } + }*/ _strip->setPixelColor(iCorrected,_tmpr,_tmpg,_tmpb); //draw pixel } }