'PixelTranspose'

   Print  Previous  Next

Introduction

PixelTranspose is a technic 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, int growsize)

 

The parameter size describes the amount of pixels in the table. The second parameter growsize describes the size that will be used to grow the table by using AddPixelTransposeEntry if the predefined size of PixelTransposeTable is reached. It is not necessarily required to use the second parameter because the growsize is set to 128 by default.

 

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 of the predefined table. This index count starts with zero 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 coordinate 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 3 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 Main Output Macro. The differences will be easily visible.

 

Clockwise Rotation

As an Main Output Macro, this macro rotates the output 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 Main Output Macro, this macro rotates the Main 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 an Main Output Macro, use a SCE Color Gradient from bottom left to top right for example to see the result.

@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(); 

}

 

MADRIX Version: 3.6g | Script Version: 2.21
[Ctrl & +/-] = Zoom In/Out | [Ctrl & 0] = 100%
Print   Previous   Next