Is there an easier way to do all of this?

 switch(chan) 
181. { 
182. case 0: 
183. r = 0;
184. g = r++; 
185. b = g++; 
186. break; 
187. case 1: 
188. r = 3; 
189. g = r++; 
190. b = g++; 
191. break;

etc..

This should be simple arithmetic, or a table, not a switch/case.

I'm not even sure your arithmetic is correct.