#include "HSV.h" Pixel Hue(int h) { unsigned int c=h&0xff; switch((h>>8)%6) { default: case 0: return UnclampedRGB(0xff,c,0); case 1: case -5: return UnclampedRGB(0xff-c,0xff,0); case 2: case -4: return UnclampedRGB(0,0xff,c); case 3: case -3: return UnclampedRGB(0,0xff-c,0xff); case 4: case -2: return UnclampedRGB(c,0,0xff); case 5: case -1: return UnclampedRGB(0xff,0,0xff-c); } } Pixel HSV(int h,int s,int v) { if(v<0) return Grey(0); if(v>255) v=255; if(s<0) return Grey(v); if(s>255) s=255; unsigned int f=h&0xff; unsigned int p=v*(255-s)/255; unsigned int q=v*(255-f*s/255)/255; unsigned int t=v*(255-s+f*s/255)/255; switch((h>>8)%6) { default: case 0: return UnclampedRGB(v,t,p); case 1: case -5: return UnclampedRGB(q,v,p); case 2: case -4: return UnclampedRGB(p,v,t); case 3: case -3: return UnclampedRGB(p,q,v); case 4: case -2: return UnclampedRGB(t,p,v); case 5: case -1: return UnclampedRGB(v,p,q); } } Pixel HSL(int h,int l,int s) { if(l<=0) return Grey(0); if(l>255) l=255; if(s<=0) return Grey(l); if(s>255) s=255; unsigned int tmp; if(l<=127) tmp=s*l/255; else tmp=s*(255-l)/255; return HSV(h,2*255*tmp/(l+tmp),l+tmp); }