Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function JsTicker_24bit_from_color(rgb){ // Returns The Unsigned 24bit Integer Representing The Given HTML-Compliant Hexidecimal Color Code
- var i=0;
- var ret=0;
- var bpc=0; //depth as bits per channel
- switch(rgb.length){
- case 0:
- bpc=0;
- break;
- case 1:
- case 2:
- case 3:
- bpc=4;
- break;
- case 4:
- case 5:
- case 6:
- bpc=8;
- break;
- default:
- bpc=-1;
- }
- switch(bpc){
- case 4:
- for(i=2;i>=0;i--)
- ret=ret<<8+parseInt('0x'+('0'.repeat(3)+rgb).slice(-3).substr(2-i,1).repeat(2));
- break;
- case 8:
- for(i=2;i>=0;i--)
- ret=ret<<8+parseInt('0x'+('0'.repeat(6)+rgb).slice(-6).subtr((2-i)<<1,2));
- break;
- default:
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement