Okay, a lookup table is where you get one value, and find out the next value based on that value.
var new_value = lookup_table[old_value];
Give sphere three or four arrays (lookup tables) and it can perform this operation on an image:
pixel.red = red_lookup[pixel.red];
pixel.green = red_lookup[pixel.green];
pixel.blue = red_lookup[pixel.blue];
pixel.alpha = red_lookup[pixel.alpha];
EvaluateSystemScript("time.js");
function Clamp(value, min, max)
{
return Math.max(min, Math.min(value, max));
}
/**
* This lookup does nothing, null, nada.
* It's useful for color channels that you don't want to change.
*/
function NullLookup()
{
var null_lookup = new Array(256);
for (var i = 0; i < 256; i++) {
null_lookup[i] = i;
}
return null_lookup;
}
/**
* This lookup adds 'value' to each color value
* it clamps the color within the range: 0 <-> 255
*/
function BrightenLookup(value)
{
var brighten_lookup = new Array(256);
for (var i = 0; i < 256; i++) {
brighten_lookup[i] = Clamp(i + value, 0, 255);
}
return brighten_lookup;
}
function ApplyLookupTest()
{
var original_surface = GrabSurface(0, 0, GetScreenWidth(), GetScreenHeight());
var surfare = original_surface.clone();
surfare.applyLookup(0, 0, surfare.width, surfare.height, BrightenLookup(5), BrightenLookup(5), BrightenLookup(5), NullLookup());
surfare.blit(0,0);
FlipScreen();
Delay(1000);
}
Thus, the screen just got slightly brighter for a second.
Now since the only line in the code for ApplyLookupTest that changes is:
surfare.applyLookup(0, 0, surfare.width, surfare.height, BrightenLookup(5), BrightenLookup(5), BrightenLookup(5), NullLookup());
That's the only line I'll mention from now on.
/**
* Invert lookup, i.e. new_color = 255 - old_color;
*/
function ReverseLookup() {
var reverse_lookup = new Array(256);
for (var i = 0; i < 256; i++) {
reverse_lookup[i] = 255 - i;
}
return reverse_lookup;
}
surfare.applyLookup(0, 0, surfare.width, surfare.height, ReverseLookup(), ReverseLookup(), ReverseLookup(), NullLookup());
Will invert the red, green and blue channels.
The resulting image will look very weird.
This is called Filter->Negative Image->RGB in the editor.
That's it folks, enjoy.
|