Put the switch statement outside of loop
The switch statement is inside of the loop but it always resolves to same case. Put it outside to optimize the code. When the case is of one specific color, the other colors is always zero and makes no changes to final result. So, remove the unnecessary code.