Talkback #2 written by Zip on 2004-06-12.
int GetMaskByColour(int gmbc_col, int gmbc_image)
// Creates a mask of an image, magenta background, black where specified colour is
// Pass: the colour to create mask from; image handle
// Return: the handle to the mask created
// Assumes: you have global: int x, y; Rename and declare locally if you like
{
int gmbc_h = ImageHeight(gmbc_image); // Height of passed image
int gmbc_w = ImageWidth(gmbc_image); // Width of passed image
// Gets pointer to new image of same dimensions
int gmbc_handle = NewImage(gmbc_w, gmbc_h);
for (y = 0; y < gmbc_h; y++) // Scan through all y pixels
{
for (x = 0; x < gmbc_w; x++) // Scan through all x pixels
{
// If this pixel matches the set colour
if (GetPixel(x, y, gmbc_image) == gmbc_col)
{
// Put a black pixel in the mask
SetPixel(x, y, 0, gmbc_handle);
}
else // Otherwise put a magenta pixel in the mask
{
SetPixel(x, y, 16711935, gmbc_handle);
}
}
}
return gmbc_handle; // Return the pointer to the mask
}
int x, y;
void autoexec()
{
int r,g,b; // To store colour values
int vimg = LoadImage("v3.gif"); // Loads image of v3 logo
// Creates mask of white values
int vmask = GetMaskByColour(RGB(255,255,255), vimg);
while (!b3) // If espace is not pressed
{
r += 1; // Cycle through red values...
g += 2; // ...and green...
b += 4; // ...and blue
Blit(0, 0, vimg, screen); // Puts the image in the screen buffer
// Blits coloured mask over the top
Silhouette(0, 0, RGB(r,g,b), vmask, screen);
ShowPage(); // Displays the buffer on the screen
Wait(5); // Wait 5 timer ticks
}
FreeImage(vimg); // Remove image from memory
FreeImage(vmask); // Ditto
exit("Bye!");
}
Talkback #1 written by Zip on 2004-06-12.
void SwapColours(int sc_col_out, int sc_col_in, int sc_image)
// Changes all of one colour value in an image to another colour
// Pass: the colour to replace; the colour to insert; image handle
// Assumes: you have global: int x, y; Rename and declare locally if you like
{
int sc_h = ImageHeight(sc_image); // Height of passed image
int sc_w = ImageWidth(sc_image); // Width of passed image
for (y = 0; y < sc_h; y++) // Scan through all y pixels
{
for (x = 0; x < sc_w; x++) // Scan through all x pixels
{
// If this pixel matches the old colour
if (GetPixel(x, y, sc_image) == sc_col_out)
// Set the pixel to the new colour
SetPixel(x, y, sc_col_in, sc_image);
}
}
}
int x, y;
void autoexec()
{
int test = LoadImage("v3.gif"); // Loads image of v3 logo
Blit(0, 0, test, screen); // Puts the image in the screen buffer
SwapColours(RGB(255,255,255), RGB(0,255,0), test); // Change white to green
Blit(100, 0, test, screen); // Puts image on screen with all white now green
ShowPage(); // Displays the buffer on the screen
FreeImage(test); // Remove image from memory
while (!b3) // If espace is not pressed
{
UpdateControls(); // Check inputs
}
exit("Bye!");
}
Doc Nav |
Your docs |