[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RGB <-> IUV



Greetings,

as far as you remember, Adobe FAQ on FF covers only RGB->IUV conversion. I
feel like the ability to convert both ways is important so I though - what
the heck... it uses somewhat different formulas pulled somewhere from the
net, but anyway it works. So now you can go to brightness-separated colour
space (IUV), do something and go back. I'm sending this short code as
FM-compartible but I'm sure everybody interested will easily convert it to
whatever needed. It's _not_ optimal FM-code (I'd use "ForEveryPixel" then)
but more of a useful (supposed to be <g>) code snippet. The filter does
pretty simple thing - something like "cycling" Wern was taking about a while
ago, but now in IUV. So you can pervert brightness without touching chroma
and the like. You can do many really useful things instead <g> if you place
your code between colour space conversion code fragments.

Here it go. Var names are quite self-explanatory:

%ffp

Category: "Toadies"
Title: "IUV cycler"
Author: "Ilyich the Toad"

Dialog:color=silver

ctl[0]:"i",range=(0,256),val=0,pagesize=5,linesize=1, pos=(266, 20),
size=(90,9), fontcolor=black
ctl[1]:"u",range=(0,256),val=0,pagesize=5,linesize=1, pos=(266, 31),
size=(90,9), fontcolor=black
ctl[2]:"v",range=(0,256),val=0,pagesize=5,linesize=1, pos=(266, 42),
size=(90,9), fontcolor=black

ForEveryTile:
{

int i, u, v;
int i2, u2, v2;

setCtlRange(0,0,256);
setCtlRange(1,0,256);
setCtlRange(2,0,256);

for (y=0; y < Y; y++) {
 if(updateProgress(y,Y)) break;
  for (x=0; x < X; x++) {

    i = (77*src(x,y,0)+ 150*src(x,y,1)+29*src(x,y,2))/256;
    u = ((-38)*src(x,y,0)-74*src(x,y,1)+112*src(x,y,2))/256;
    v = (157*src(x,y,0)-132*src(x,y,1)-26*src(x,y,2))/256;

    i2=(i+ctl(0))%256;

    u2=scl(u,-112,112,0,255);
    u2=(u2+ctl(1))%256;
    u2=scl(u2,0,255,-112,112);

    v2=scl(v,-156,156,0,255);
    v2=(v2+ctl(2))%256;
    v2=scl(v2,0,255,-156,156);

    pset(x,y,0, (256*i2 + 292*v2)/256);
    pset(x,y,1, (256*i2 - 101*u2 - 149*v2)/256);
    pset(x,y,2, (256*i2 + 519*u2)/256);

  } file://for x
} file://for y



updateProgress(0, 100);
return (true);
}