Introduction
PixelTranspose is a technique to transpose (move) pixels from their origin/source (srcX and srcY coordinate) to a new destination. Three (or four) steps are necessary to perform a pixel transposition.
1. Creating the pixel transpose table which holds the information for each pixel that should be moved.
2. Setting or adding the information (source and destination coordinates) for each of those pixels to the table.
3. Executing the pixel transposition.
4. Releasing the pixel transpose table.
1. Creating The Pixel Transpose Table
void CreatePixelTransposeTable(int size)
The parameter size describes the amount of pixels in the table.
(If the predefined size has been reached, the software will grow the table automatically. The second parameter growsize has been deprecated with MADRIX 5.7 and now has a default value of 0.)
2. Setting Or Adding Information
void SetPixelTransposeEntry(int idx, int srcX, int srcY, int destX, int destY)
Using SetPixelTransposeEntry requires 5 parameters. The first parameter idx defines the index in the predefined table. This index count starts with 0 and has to be lower than the size value of CreatePixelTransposeTable(int size, int growsize). The second and third parameter, srcX and srcY, describe the source coordinates and the fourth and fifth parameter, destX and destY, set the destination coordinates.
void AddPixelTransposeEntry(int srcX, int srcY, int destX, int destY)
Using AddPixelTransposeEntry requires only 4 parameters, i.e. the source and destination coordinates. The function validates if an entry already exists. If this is not the case, the function adds the entry to the end of the pixel transpose table. If the predefined size in CreatePixelTransposeTable(int size, int growsize) is then exceeded, the table automatically grows by the size defined with growsize.
The execution of SetPixelTransposeEntry is performed much faster than that of AddPixelTransposeEntry.
3. Executing The Pixel Transposition
void ExecutePixelTranspose(int clear)
Using this function executes all pixel transpositions that are defined in the pixel transpose table. The clear parameter defines how the part of the matrix is handled which is not defined as destination. If the clear parameter is set to CLEAR, the part will be erased using black. Otherwise, if this parameter is set to NOCLEAR, the color values will be left like they were before.
4. Releasing The Pixel Transpose Table
void ReleasePixelTransposeTable()
Using this function releases the created transpose table. That means, that the reserved memory is made available again.
Examples
The following three examples will rotate the Main Output using the pixel transpose technique. Please note that this only works on quadratic matrices. Just use the SCE Color Gradient effect and insert the following source code into the Global Macro. The differences will be easily visible.
Clockwise Rotation
As a Global Macro, this macro rotates the output by 90° clockwise.
@scriptname="Output Rotation";
@author="inoage";
@version="2.9";
@description="Rotates the main output";
int Init=0;
void InitEffect()
{
int w = GetMatrixWidth();
int h = GetMatrixHeight();
Init=0;
if(w==h) //this example runs only on quadratic matrices
{
int idx = 0;
CreatePixelTransposeTable(w*h); //make a table with w*h entities
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
SetPixelTransposeEntry(idx,x,y,h-y-1,x); //rotate clockwise
idx++;
}
}
Init=1; //init ready, can use ExecutePixelTranspose()
}
else
{
WriteText("This script runs only on quadratic matrices,");
WriteText("but your matrix is "+(string)w+"x"+(string)h);
}
}
void PreRenderEffect()
{
}
void PostRenderEffect()
{
if(Init==1)
ExecutePixelTranspose(CLEAR); //execute to transpose all pixels
//and to clear all non-transposed pixels
}
void MatrixSizeChanged()
{
ReleasePixelTransposeTable(); //release the old transpose table if existent
InitEffect();
}
Counter-Clockwise Rotation
As a Global Macro, this macro rotates the output by 90° counter-clockwise.
@scriptname="Output Rotation";
@author="inoage";
@version="2.9";
@description="Rotates the main output";
int Init=0;
void InitEffect()
{
int w = GetMatrixWidth();
int h = GetMatrixHeight();
Init=0;
if(w==h) //this example runs only on quadratic matrices
{
int idx = 0;
CreatePixelTransposeTable(w*h); //make a table with w*h entities
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
SetPixelTransposeEntry(idx,x,y,y,w-x-1); //rotate counter-clockwise
idx++;
}
}
Init=1; //init ready, can use ExecutePixelTranspose()
}
else
{
WriteText("This script runs only on quadratic matrices,");
WriteText("but your matrix is "+(string)w+"x"+(string)h);
}
}
void PreRenderEffect()
{
}
void PostRenderEffect()
{
if(Init==1)
ExecutePixelTranspose(CLEAR); //execute to transpose all pixels
//and to clear all non-transposed pixels
}
void MatrixSizeChanged()
{
ReleasePixelTransposeTable(); //release the old transpose table if existent
InitEffect();
}
Mirror Diagonally
As a Global Macro, this macro mirrors the output at the diagonal axis.
@scriptname="Output Rotation";
@author="inoage";
@version="2.9";
@description="Rotates the main output";
int Init=0;
void InitEffect()
{
int w = GetMatrixWidth();
int h = GetMatrixHeight();
Init=0;
if(w==h) //this example runs only on quadratic matrices
{
int idx = 0;
CreatePixelTransposeTable(w*h); //make a table with w*h entities
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
SetPixelTransposeEntry(idx,x,y,y,x); //mirror diagonally
idx++;
}
}
Init=1; //init ready, can use ExecutePixelTranspose()
}
else
{
WriteText("This script runs only on quadratic matrices,");
WriteText("but your matrix is "+(string)w+"x"+(string)h);
}
}
void PreRenderEffect()
{
}
void PostRenderEffect()
{
if(Init==1)
ExecutePixelTranspose(CLEAR); //execute to transpose all pixels
//and to clear all non-transposed pixels
}
void MatrixSizeChanged()
{
ReleasePixelTransposeTable(); //release the old transpose table if existent
InitEffect();
}
|