'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 steps are necessary to perform a pixel transposition.

1. Creating the pixel transpose table which holds the information for each pixel that shall 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.

 

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 necessary to use the second parameter because by default the growsize is set to 128.

 

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 starts counting 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 of the pixel.

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 set free.

 

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 Ramp effect on Preview A and insert the following source code into the Main Output Macro. The difference will be easily visible.

Clockwise Rotation

This macro rotates the output 90° clockwise.

@scriptname="Output Rotation";

@author="jky";

@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

This macro rotates the output by 90° counter-clockwise.

@scriptname="Output Rotation";

@author="jky";

@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

Use a SCE Color Ramp from bottom left to top right for example to see the result.

@scriptname="Output Rotation";

@author="jky";

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

}