RGB2HSV conversion using actionscript…

rgb2hsv conversion

Another simple conversion function. This time it converts RGB values to HSV (Hue, Sat, Val).

function rgb2hsv(r,g,b)
{    
 var x, val, d1, d2, hue, sat, val;    
 r/=255;    
 g/=255;    
 b/=255;    
 x = Math.min(Math.min(r, g), b);    
 val = Math.max(Math.max(r, g), b);    
 if (x==val)
 {        
  return(”h is undefined, s: “+0+”,v: “+ val*100); //err obj
 }    
 d1 = (r == x) ? g-b : ((g == x) ? b-r : r-g);    
 d2 = (r == x) ? 3 : ((g == x) ? 5 : 1);    
 hue = Math.floor((d2-d1/(val-x))*60)%360;    
 sat = Math.floor(((val-x)/val)*100);    
 val = Math.floor(val*100);    
 return(hue+”,”+sat+”,”+val);
};

Have fun,

FLAIM

RGB2CMYK conversion using actionscript…

rgb2 cmyk conversion example

Hello :)

A small and useful function for converting RGB values to CMYK color space…

function rgb2cmyk(r,g,b)
{
 C = 1 - ( r / 255 );
 M = 1 - ( g / 255 );
 Y = 1 - ( b / 255 );
var_K = 1

if ( C < var_K )   var_K = C
if ( M < var_K )   var_K = M
if ( Y < var_K )   var_K = Y
if ( var_K == 1 ) { //Black
   C = 0
   M = 0
   Y = 0
}
else {
   C = ( C - var_K ) / ( 1 - var_K ) *100
   M = ( M - var_K ) / ( 1 - var_K ) *100
   Y = ( Y - var_K ) / ( 1 - var_K ) *100
}
 K = var_K*100
 return(”C: “+Math.floor(C)+”/ M: “+Math.floor(M)+”/ Y: “+Math.floor(Y)+”/ K: “+Math.floor(K));
};

// rgb2cmyk(255,0,0); returns –> C: 0/ M: 100/ Y: 100/ K: 0

Have fun :)

FLAIM

RGB2PANTO…err … I mean PATAPONE(R) ;-)

 rgb 2 patapone converter

Imagine that you need to convert a RGB colour to the nearest colour in a palette (I won’t mention its name so let’s call it my way - Patapone(R) ) which has only a few thousand colours (in comparison to RGB’s 16mln.). So what you need to do is to make an algorithm which can do the conversion. That, of course would be simple …but human eye is a tricky thing and there is a difference between the nearest colour calculated and the nearest that one could find by himself (using printed colour matrices). This method does it better and takes under consideration the way people see and compare colours…

So what the application does:

  1. converts RGB 2 PATAPONE(R) and shows the results in RGB (for display),
  2. converts PATAPONE(R) numbers to RGB and does a simple conversion (inaccurate I suppose) to CMYK and HSV..

all conversion besides cmyk and hsv are server sided… The conversion to PATAPONE(R) was very heavy so it was done only once for all RGB’s and saved in a database which the application uses.

For all companies that patent colours and claim them their own - GO AWAY! :)

Have fun using it!

FLAIM