QUARTZ_COMPOSER
JAVASCRIPT_KERNEL_TEMPLATES
JAVASCRIPT_TEMPLATES
=================2D_Array_2_Table_Limit=============================
Convert a 2D array into a multiline text table.
Separation default is by spaces and “\n”.
Limit output to the first values of the array
var OutArray = new Array();
function (
__number VertNumb,
__number HorzNumb,
__string outputstring)
main (
__structure InputArray,
__number lenArray,
__number lenStr,
__string SepLine,
__string SepStr)
{ var result = new Object();
var numbPt, numbPt2, i ,j;
var str = "";
var str1 = "";
if (!_testMode )
{ numbPt = Math.min( InputArray.length, lenArray);
result.VertNumb = numbPt;
for (j=0;j<numbPt ;j++)
{ OutArray = InputArray[j];
numbPt2 = OutArray.length;
result.HorzNumb = numbPt2;
for (i=0;i<numbPt2 ;i++)
{ str1 = OutArray[i].toString() ;
str = str +str1.substring(0,lenStr) + SepStr ;
}
str = str + SepLine +"\n";
}
} result.outputstring = str;
return result;
}
=================2D_Array_2_Table=============================
Convert a 2D array into a multiline text table.
Separation default is by spaces and “\n”.
var OutArray = new Array();
function (
__number VertNumb,
__number HorzNumb,
__string outputstring)
main (
__structure InputArray,
__number lenStr,
__string SepLine,
__string SepStr)
{ var result = new Object();
var numbPt, numbPt2, i ,j;
var str = "";
var str1 = "";
if (!_testMode )
{ numbPt = InputArray.length;
result.VertNumb = numbPt;
for (j=0;j<numbPt ;j++)
{ OutArray = InputArray[j];
numbPt2 = OutArray.length;
result.HorzNumb = numbPt2;
for (i=0;i<numbPt2 ;i++)
{ str1 = OutArray[i].toString() ;
str = str +str1.substring(0,lenStr) + SepStr ;
}
str = str + SepLine +"\n";
}
} result.outputstring = str;
return result;
}
=================table_2_2D_Array_limit============================
Convert a 2D array into a string length limited multiline text table.
var myarray2 = new Array();
function (
__number N,
__string S,
__structure ArrayOut)
main (
__string StrinIN,
__string LineSep,
__string StrSep,
__number rows,
__number cols)
{ var result = new Object();
var val = 0;
var Str = StrinIN;
Str = Str.replace(/(\r\n|\n|\r)/gm,"");
var Lsep = LineSep;
var Ssep = StrSep;
var Nrow = rows;
var Ncol = cols;
if (!_testMode)
{ myarray = Str.split(Lsep,Nrow);
N = myarray.length;
result.N = N;
result.S = myarray[0];
for (i=0;i<N;i++)
{ myarray2[i] = myarray[i].split(Ssep,Ncol);
}
} result.ArrayOut = myarray2;
return result;
}
=================table_2_2D_Array==========================
Reads a text table into a 2D array.
Separated default by “#” and “/” due to LF/CR confusion.
var myarray2 = new Array();
function (
__number N,
__string S,
__structure ArrayOut)
main (
__string StrinIN,
__string LineSep,
__string StrSep)
{ var result = new Object();
var val = 0;
var Str = StrinIN;
Str = Str.replace(/(\r\n|\n|\r)/gm,"");
var Lsep = LineSep;
var Ssep = StrSep;
if (!_testMode)
{ myarray = Str.split(Lsep);
N = myarray.length;
result.N = N;
result.S = myarray[0];
for (i=0;i<N;i++)
{ myarray2[i] = myarray[i].split(Ssep);
}
} result.ArrayOut = myarray2;
return result;
}
=================1D_Array_to_Multiline_Str=========================
Convert a 1D array into a length limited multiline text table.
function (
__number Numb,
__string outputstring)
main (
__structure ArrayOrList,
__number lenStr)
{ var result = new Object();
var str = "";
var str1 = "";
var number = 0 ;
if (!_testMode)
{ result.Numb = ArrayOrList.length;
number = ArrayOrList.length;
for (i=0;i< number;i++)
{ str1 = ArrayOrList[i].toString();
str = str + str1.substring(0, lenStr) + "\n" ;
}
result.outputstring = str;
} return result;
}
=================1D_Array_from_Col_of_2D_Array=========================
Convert a column of a 2D array into a 1D array
var OutArray = new Array();
function (
__number TotalNumb,
__structure OutputArray)
main (
__structure InputArray,
__number col)
{ var result = new Object();
var numbPt = 0;
if (!_testMode )
{ numbPt = InputArray.length;
result.TotalNumb = numbPt;
for (i=0;i<numbPt;i++)
{ OutArray[i] = InputArray[i][col];
}
}
result.OutputArray = OutArray;
return result;
}
=================1D_Array_from_Row_of_2D_Array=============
Convert a row of a 2D array into a 1D array
var OutArray = new Array();
function (
__number TotalNumb,
__structure OutputArray)
main (
__structure InputArray,
__number row)
{ var result = new Object();
var numbPt = 0;
if (!_testMode )
{ numbPt = InputArray.length;
result.TotalNumb = numbPt;
for (i=0;i<numbPt;i++)
{ OutArray[i] = InputArray[row][i];
}
}
result.OutputArray = OutArray;
return result;
}
================Append_String=======================
Appends a input string to a stored internal string.
var fullstring= "";
function (
__string OutStr)
main (
__string InStr,
__boolean append,
__boolean reset)
{ var result = new Object();
if ( append ) fullstring = fullstring + InStr;
if ( reset ) fullstring = "";
result.OutStr = fullstring;
return result;
}
===============String_2_Array==========================
Converts a “:” separated input string into a 1D array.
var myarray = new Array();
function (
__number N,
__string S,
__structure ArrayOut)
main (
__string StrIN)
{ var result = new Object();
if (!_testMode)
{ myarray = StrIN.split(":");
var Num = myarray.length;
}
result.S = String(Num);
result.N = Number(Num);
result.ArrayOut = myarray;
return result;
}
=================String_2_LIST======================
Converts a “:” separated input string into a X/Y/Z list.
var myarray = new Array();
function (
__number X,
__number Y,
__number W,
__structure ArrayOut)
main (
__string StrIN)
{ var result = new Object();
if (!_testMode)
{ myarray = StrIN.split(":");
}
result.X = Number(myarray[0]);
result.Y = Number(myarray[1]);
result.W = Number(myarray[2]);
result.ArrayOut = myarray;
return result;
}
=================MakeRand_Array====================
Creating a Random array of size Numb.
var myarray = new Array();
function (
__number NumbPt,
__structure ArrayOut)
main (
__number Numb )
{ var result = new Object();
for (i=0;i< Numb ;i++)
{ myarray[i] = Math.random()-.5;
} result.NumbPt = myarray.length;
result.ArrayOut = myarray;
return result;
}
================MakeSine_Array======================
Creating a Sinewave array of size NumbPt.
var myarray = new Array();
function (
__structure ArrayOut)
main (
__number NumbPt,
__number Mag,
__number Freq,
__number Phas )
{ var result = new Object();
for (i=0;i< NumbPt ;i++)
{ myarray[i] = Mag*Math.sin(2*Math.PI*i*Freq/(NumbPt-1)+Phas);
} result.ArrayOut = myarray;
return result;
}
=================Make_2D_Array===============
Construct a 2D array
var myarray = new Array();
function (
__number Numb,
__structure ArrayOut)
main ( )
{ var result = new Object();
myarray[0] = new Array(-.5 ,.6 , 0);
myarray[1] = new Array( .3 ,.4 ,.1);
result.Numb = myarray.length;
result.ArrayOut = myarray;
return result;
}
================View_2D_Array_Point===============
Read a 2D array
function (
__number Numb,
__number T,
__number X,
__number Y)
main (
__structure ArrayIN,
__number index)
{ var result = new Object();
var i = index;
if (!_testMode )
{ result.Numb = ArrayIN.length;
result.T = Number(ArrayIN[i][0]) ;
result.X = Number(ArrayIN[i][1]) ;
result.Y = Number(ArrayIN[i][2]) ;
} return result;
}
=================X_Y_InRange===============
X/Y InRange? JavaScript Patch
function (
__number YES)
main (
__number Xmouse ,
__number Ymouse ,
__number Xcenter ,
__number Ycenter ,
__number Range )
{ var result = new Object();
result.YES = 1;
if (Xmouse < Xcenter - Range) result.YES = 0;
if (Xmouse > Xcenter + Range) result.YES = 0;
if (Ymouse < Ycenter - Range) result.YES = 0;
if (Ymouse > Ycenter + Range) result.YES = 0;
return result;
}
=================InRange===============
function (
__number YES)
main (
__number IN ,
__number MAX,
__number MIN )
{ var result = new Object();
result.YES = 0;
if (IN < MAX && IN > MIN ) result.YES = 1;
return result;
}
================Make_Read_3D_Array========================================
What it take to get an array it to work in 3D. Structures in XYZ may be preferred.
var i = 0;
var A = new Array("");
var myarray = new Array([ [1,2,3,4],
[4,5,6,7],
[7,8,9,10] ],
[ [11,12,13,14],
[14,15,16,17],
[17,18,19,20] ]);
function (
__number A,
__number B)
main (
__number x,
__number y,
__number z)
{ var result = new Object();
var i = Math.floor(x);
var j = Math.floor(y);
var k = Math.floor(z);
result.A = myarray[0][0][0];
result.B = myarray[i][j][k];
return result;
}
======================MovingAverage===============
var signal = inputs[0] * 0.5;
var rate = inputs[1];
var avg = signal;
if (inputs[2] > 0.01) {avg = outputs[0];}
avg = (signal * rate) + (avg * (1 - rate));
outputs[0] = avg;
=======================Sample_Hold===========
Sample input every "Interval" seconds, placing it on the output
var interval = inputs[1];
var time = inputs[2];
if (Object.sampleTime == undefined)
{ Object.sampleTime = time + interval;
outputs[0] = inputs[0];
}
if (time > Object.sampleTime)
{ Object.sampleTime = time + interval;
outputs[0] = inputs[0];
}
VISUAL_TEMPLATES
====================DisplayValue========================================
Display text where the formating is done using one text string
====================DisplayVal_Limit========================================
Display text as above where the length of the string can be limited
APPLICATION_TEMPLATES
==================MultiLine_String_Macro.qtz=================
StringPrinter Creates text images/ option return to add lines
DisplayValue Two line macro to display a value
======================Read_1D_Array.qtz=================
random 1D_Array Creates array
Read_1D_Array Converts array to outputs
MultiLine_String Convert outputs to string
DisplayValue Displays string
random 1D_Array
=========================
var myarray = new Array();
function (
__structure ArrayOut)
main (
__number Numb )
{ var result = new Object();
for (i=0;i< Numb ;i++)
{ myarray[i] = Math.random();
} result.ArrayOut = myarray;
return result;
}
Read_1D_Array
=========================
function (
__number Numb,
__number X0,
__number X1,
__number X2,
__number X3)
main (
__structure ArrayOrList)
{ var result = new Object();
if (!_testMode)
{ result.Numb = ArrayOrList.length;
result.X0 = ArrayOrList[0];
result.X1 = ArrayOrList[1];
result.X2 = ArrayOrList[2];
result.X3 = ArrayOrList[3];
} return result;
}
======================Read_1D_Array_to_Mulitline.qtz=================
random 1D_Array
1D_Array_to_Multiline_Str
DisplayValue
random 1D_Array
=========================
var myarray = new Array();
function (
__structure ArrayOut)
main (
__number Numb )
{ var result = new Object();
for (i=0;i< Numb ;i++)
{ myarray[i] = Math.random();
} result.ArrayOut = myarray;
return result;
}
Read 1D array to multiline string (Javascript)
=====================
function (
__number Numb,
__string outputstring)
main (
__structure ArrayOrList,
__number lenStr)
{ var result = new Object();
var str = "";
var str1 = "";
var number = 0 ;
if (!_testMode)
{ result.Numb = ArrayOrList.length;
number = ArrayOrList.length;
for (i=0;i< number;i++)
{ str1 = ArrayOrList[i].toString();
str = str + str1.substring(0, lenStr) + "\n" ;
}
result.outputstring = str;
} return result;
}
===========================Plot_Arrays.qtz=================
random 1D_Array Create noise array
Sine_1D_Array Create sinewave array
1D_Array_to_Multiline_Str
Structure Count
Counter Counts up from 0 to 12
Structure Index Member Extract array values at the count value
MaxLength
ACPlotter Counts up from 0 to 12
DisplayVal
DisplayVal_Limit
Javascript Create Random Array
===================
var myarray = new Array();
function (
__structure ArrayOut)
main (
__number Numb )
{ var result = new Object();
for (i=0;i< Numb ;i++)
{ myarray[i] = Math.random();
} result.ArrayOut = myarray;
return result;
}
Javascript Create Sinwave Array
=============================
var myarray = new Array();
function (
__structure ArrayOut)
main (
__number NumbPt,
__number Mag,
__number Freq,
__number Phas )
{ var result = new Object();
for (i=0;i< NumbPt ;i++)
{ myarray[i] = Mag*Math.sin(2*Math.PI*i*Freq/(NumbPt-1)+Phas);
} result.ArrayOut = myarray;
return result;
}
1D array to Numb MulitLine Str
==================================
function (
__number Numb,
__string outputstring)
main (
__structure ArrayOrList,
__number len)
{ var result = new Object();
var str = "";
var str1 = "";
var number = 0 ;
if (!_testMode)
{ result.Numb = ArrayOrList.length;
number = ArrayOrList.length;
for (i=0;i< number;i++)
{ str1 = ArrayOrList[i].toString();
str = str +i+" " + str1.substring(0,len) + "\n" ;
}
result.outputstring = str;
} return result;
}
================================create_2D_Arrays.qtz=================
2D_X/Y array Code a 2D Array
1D_Array_from_Row_of_2D_Array Extract a row
1D_Array_from_Col_of_2D_Array Extract a Column
2D_Array_2_Table Convert to table
1D array to MulitLine Str
Structure Index Member
DisplayValue
2D_X/Y array
==========================================
var myarray = new Array();
function (
__number Numb,
__structure ArrayOut)
main ( )
{ var result = new Object();
myarray[0] = new Array(-.7 , -.3 );
myarray[1] = new Array(.2 , .4 );
myarray[2] = new Array(.7 ,-.1 );
myarray[3] = new Array(.8 , .5 );
myarray[4] = new Array(.9 , -.5 );
result.Numb = myarray.length;
result.ArrayOut = myarray;
return result;
}
1D_Array_from_Row_of_2D_Array
==========================================
var OutArray = new Array();
function (
__number TotalNumb,
__structure OutputArray)
main (
__structure InputArray,
__number row)
{ var result = new Object();
var numbPt = 0;
if (!_testMode )
{ numbPt = InputArray.length;
result.TotalNumb = numbPt;
for (i=0;i<numbPt;i++)
{ OutArray[i] = InputArray[row][i];
}
}
result.OutputArray = OutArray;
return result;
}
1D_Array_from_Col_of_2D_Array
==========================================
var OutArray = new Array();
function (
__number TotalNumb,
__structure OutputArray)
main (
__structure InputArray,
__number col)
{ var result = new Object();
var numbPt = 0;
if (!_testMode )
{ numbPt = InputArray.length;
result.TotalNumb = numbPt;
for (i=0;i<numbPt;i++)
{ OutArray[i] = InputArray[i][col];
}
}
result.OutputArray = OutArray;
return result;
}
2D_Array_2_Table
==========================================
var OutArray = new Array();
function (
__number VertNumb,
__number HorzNumb,
__string outputstring)
main (
__structure InputArray,
__number lenStr,
__string SepLine,
__string SepStr)
{ var result = new Object();
var numbPt, numbPt2, i ,j;
var str = "";
var str1 = "";
if (!_testMode )
{ numbPt = InputArray.length;
result.VertNumb = numbPt;
for (j=0;j<numbPt ;j++)
{ OutArray = InputArray[j];
numbPt2 = OutArray.length;
result.HorzNumb = numbPt2;
for (i=0;i<numbPt2 ;i++)
{ str1 = OutArray[i].toString() ;
str = str +str1.substring(0,lenStr) + SepStr ;
}
str = str + SepLine +"\n";
}
} result.outputstring = str;
return result;
}
1D array to MulitLine Str
==========================================
function (
__number Numb,
__string outputstring)
main (
__structure ArrayOrList,
__number lenStr)
{ var result = new Object();
var str = "";
var str1 = "";
var number = 0 ;
if (!_testMode)
{ result.Numb = ArrayOrList.length;
number = ArrayOrList.length;
for (i=0;i< number;i++)
{ str1 = ArrayOrList[i].toString();
str = str + str1.substring(0, lenStr) + "\n" ;
}
result.outputstring = str;
} return result;
}
Structure Index Member
DisplayValue
=====================ControlStructures=======================
CONTROL_STRUCT creates an object with key values
STRUCT_Key_Member Reads the array at the key position
function (
__structure ControlStruct)
main (
__number Control0,
__number Control1,
__numbe Control2,
__number Control3,
__number Control4)
{ params = new Object();
var result = new Object();
if(!_testMode)
{ // Create struct from control values
params["Control0"] = Control0;
params["Control1"] = Control1;
params["Control2"] = Control2;
params["Control3"] = Control3;
params["Control4"] = Control4;
// Set output struct to control value struct
result.ControlStruct = params;
return result;
}
}
================================Plot X/Y array.qtz======================
2D_X/Y array creats X/Y array
2D_Array_2_Table
DisplayValue
Structure Index Member
1D_Array_from_Row_of_2D_Array
X/Y PLOT ARRAY USING ITERATOR Can do X/Y plot using iterator
Kineme GL Line Structure Can Do X/y plot using Kineme GL Line Structure
2D_X/Y array
=========================
var myarray = new Array();
function (
__number Numb,
__structure ArrayOut)
main ( )
{ var result = new Object();
myarray[0] = new Array(-.7 , -.3 );
myarray[1] = new Array(.2 , .4 );
myarray[2] = new Array(.7 ,-.1 );
myarray[3] = new Array(.8 , .5 );
myarray[4] = new Array(.9 , -.5 );
result.Numb = myarray.length;
result.ArrayOut = myarray;
return result;
}
Read_1D_array
==================================
function (
__number Numb,
__number X0,
__number X1,
__number X2,
__number X3)
main (
__structure ArrayOrList)
{ var result = new Object();
if (!_testMode)
{ result.Numb = ArrayOrList.length;
result.X0 = ArrayOrList[0];
result.X1 = ArrayOrList[1];
result.X2 = ArrayOrList[2];
result.X3 = ArrayOrList[3];
} return result;
}
=========================GL_Point/Line_Structures======================
_1024_Structure_Wave Creates a XYZ sinewave structure
Smooth Adjusts rise fall times
_1024_Structure_Noise Creates a XYZ noise structure
===============================read_table_to_array.qtz===============
Kineme String With File Reads a text file
table_2_2D_Array_limit Convert text table into an array
2D_Array_2_Table convert array to table
DisplayValue display table
Kineme Text File Writer Writes to a text file
===============================Structures_IndexKey.qtz=================
SetStructureMember makes to structure with key value index and value
1D_Array_from_Row_of_2D_Array
1D_Array_to_Multiline_Str
2D_Array to Table
Structure Index Member
======================GLTools-structure-circle.qtz=================
GL_Line_Structure Take an XYZ array to draw lines
Javascript How to create a XYZ array
function (__structure Lines) main(__number Segments)
{ var result = new Object();
result.Lines = new Array();
for (i=0;i<Segments;++i)
{ result.Lines[i] = new Object();
result.Lines[i].X = Math.cos(i/Segments * 2 * 3.14)/2.0;
result.Lines[i].Y = Math.sin(i/Segments * 2 * 3.14)/2.0;
result.Lines[i].Z = 0.0;
}
return result;
}
Javascript way to do a 2D labeled array
=============================StructureHow2.qtz===============
Structure_Index_Member Access a member of a array by index
Kineme_Structure_from_File can read a xml file
Kineme_Structure_to_File ???
DisplayValue
1D_Array_to_Multiline_Str
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Year Of Birth</key> <integer>1965</integer>
<key>Pets Names</key> <array/>
<key>Picture</key> <data>PEKBpYGlmYFCPA==</data>
<key>City of Birth</key> <string>Springfield</string>
<key>Name</key> <string>John Doe</string>
<key>Kids Names</key> <array>
<string>John</string>
<string>Kyra</string>
</array>
</dict>
</plist>
============================JSStructureDemo_01.qtz===============
Constant_Color Creates color image (needs image crop)
Create_Control_Structure How to create a control structure
Structure_Key_Member Reads members by key values
function (__structure controlStruct)
main (__number PositionX,
__number PositionY,
__number Scale,
__structure Color)
{ var result = new Object();
__structure params = new Object();
if(!_testMode)
{ params["PositionX"]=PositionX;
params["PositionY"]=PositionY;
params["Scale"] =Scale;
params["Color"] =Color;
}
result.controlStruct = params;
return result;
}
=============================Structures_Circle.qtz=================
_1024_Structure_Circle Creates XYZ data for a circle
2D_Array_2_Table Read out the data
Kineme GL Point Structure Point plot XYZ data
_1024_Structure_Truncate Test tuncation
DisplayValue
==============================Structures_Noise.qtz=================
_1024_Structure_Noise Create XYZ noise data
Kineme GL Point Structure Ploint plot XYZ data
============================Structures_2d_Array.qtz=================
Mouse Can control red points
_1024_Structure_2d_Array Create a 2D XY array
_1024_Structure_ArrayViz View 2D XY array
2D_Array_2_Table Convert array to table
1D_Array_to_Multiline_Str View Viz values
Kineme GL Point Structure Point plot XY data
DisplayValue
======================GL_CubicCurve.qtz=================
Billboard
Render in Image
clear
_1024_GL_CubicCurve Creates a CUBIC display
Interpolation
sprite
=============================MATH_3D.qtz=================
Kineme_Structure_from_File can read a xml file
_1024_MATH_3D Can smooth translate between two sets of data
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>qcStructure_0</key> <dict><key>X</key><real>-0.05859375</real><key>Y</key><real>-0.46875</real><key>Z</key><real>0.0</real></dict>
<key>qcStructure_1</key> <dict><key>X</key><real>-0.05859375</real><key>Y</key><real>-0.47265625</real><key>Z</key><real>0.0</real></dict>
<key>qcStructure_10</key> <dict><key>X</key><real>0.0703125</real><key>Y</key><real>-0.47265625</real><key>Z</key><real>0.0</real></dict>
<key>qcStructure_11</key> <dict><key>X</key><real>0.09375</real><key>Y</key><real>-0.47265625</real><key>Z</key><real>0.0</real></dict>
<key>qcStructure_12</key> <dict><key>X</key><real>0.11328125</real><key>Y</key><real>-0.47265625</r
============================WaveGeneratorSimple.qtz=================
Random Constantly random between +/- 1
Queue Store 10 XY values
ACPlotter Plots the noise
1D_Array_to_Multiline_Str View the Queue
_1024_WaveGenerator Create sinwave data
2D_Array_2_Table
DisplayValue
Kineme GL Point Structure Point plot sine wave
Kineme GL Line Structure Line plot sinewave
===========================GL_Stuctures.qtz===============
Mouse
Kineme Struct Maker Converts Mouse into XY structure
Queue Store 10 XY values
1D_Array_to_Multiline_Str
DisplayVal_Limit
2D_Array_2_Table
Kineme GL Point Structure Point plot Queue
Kineme GL Line Structure Line plot Queue
========================GL_GEOS.qtz===============
How to make GL structures
======================pixel_at.qtz=================
Details to find pixel color of an image
Image Dimensions
Mouse
Rendering Destination Dimensions
Round
DisplayVal_Limit
Image Pixel
==============================GL_masks.qtz=================
Kineme Struct Maker Make Triangle Structure the long way
Render Triangle in Image Convert 3 XYZ points into a triangle
Billboard Use triangle as mask for cat
CI_msaSmartThreshold Thresshold a tiger image
Color Invert
Mask to Alpha Convert tiger image to alpha mask
Blend With Mask Blend cat image with tiger using triangle mask
The “input Triangles” are the 2D tble shown above X,Y,Z by three
======================Affine_Tile_Kaleidoscope.qtz=================
Coordinate adjustment details for Kaleidoscope
====================Render In Image.qtz==============
Render in image Turns displyed test into an image
Guassian Blur Will vary blur over time
Timeline Controls blur
settings for timeline (need option click) to adjust
UP/DOWN TimeLine example
===========================Paint.qtz============
How to do the PAINT FUNCTION using the accumulator
==============================GL_BezierSurface.qtz=================
Interaction Mouse can control and store a colored square
Display_Mouse_Handle Link to mouse to store XY values
_1024_GL_BezierSurface Can distort an image by a 16 point mesh
GRID Grid shows the distortion best
Image Texturing Properties the image needs to be rotated
Sprite
========================Vector_With_Curves.qtz=================
Vector Transform Scale and translate a vector
Vector with curves Creates a Bézier curve
Image with Vector Creates an iamge otu of a vector
======================Value_Historian=================
Structure Maker Convert X and Y into a 1D array
Structure Push Create a 2D array by pushing X/Y array point in to it
Value Historian Store X/Y points as samples in time
=========================Image_with_Vectors=================
Vector with string Creates a vector out of text
Json to structure Create vector using tings like moveto statments
Vector with Oval Creates an oval vector
Vector Transform Scalse and move a vectfor
Vector Combine Add two vectors together
=================================Vector_with_Line_Structure=================
Vector Star Creates a star vector line structure
Vector with Line structure Converts line structure to vector
Vector Close Closes a polygon
Create Polygon Javascript creating a polygon line structure
Vector Contains Points Detect if mouse within a polygon
function (
__number Xstart,
__number Ystart,
__structure Lines)
main(
__number Segments,
__number Radius)
{ var result = new Object();
result.Lines = new Array();
for (i=0;i<Segments;++i)
{ result.Lines[i] = new Object();
result.Lines[i].X = Math.cos(i/Segments * 2 * 3.14)*Radius;
result.Lines[i].Y = Math.sin(i/Segments * 2 * 3.14)*Radius;
result.Lines[i].Z = 0.0;
}
result.Xstart = Math.cos(0)*Radius;
result.Ystart = Math.sin(0)*Radius;
return result;
}
==============================MultiExpression=================
Creates multiple inputs and output with equations within one block
==============================Sample and Hold=================
Vector Push Pushes X/Y structures into a 2D array
Sample and Hold Sample and Hold a X/Y over time structure
============================FourCorner_Kernel.qtz=================
Functional, but still needs work
kernel vec4 FourCorner(
sampler input_image,
vec2 LT,
vec2 LB,
vec2 RT,
vec2 RB)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float SlopeL = (LT.x-LB.x)/(1.0-LB.y-LT.y);
float Xlb = LB.x -SlopeL*LB.y;
float Xlt = LT.x +SlopeL*LT.y;
float SlopeR = (RT.x-RB.x)/(1.0-RB.y-RT.y);
float Xrb = RB.x -SlopeR*RB.y;
float Xrt = RT.x +SlopeR*RT.y;
float SlopeB = (RB.y-LB.y)/(1.0-LB.x-RB.x);
float Ylb = LB.y -SlopeB*LB.x;
float Yrb = RB.y +SlopeB*RB.x;
float SlopeT = (RT.y-LT.y)/(1.0-LT.x-RT.x);
float Ylt = LT.y -SlopeT*LT.x;
float Yrt = RT.y +RT.x*SlopeT;
float FromBot = (pixel_coord.y/image_size.y);
float FromTop = 1.0-FromBot;
float FromLeft = (pixel_coord.x/image_size.x);
float FromRight = 1.0 -FromLeft;
float x_gain = 1.0 -(Xrt+Xlt)*FromBot - (Xrb+Xlb)*FromTop;
float x_offset = -image_size.x*(Xlt*FromBot +Xlb*FromTop);
float y_gain = 1.0 - (Yrt +Yrb)*FromLeft - (Ylt +Ylb)*FromRight;
float y_offset = -image_size.y*(+Yrb*FromLeft+Ylb*FromRight);
pixel_coord.x = pixel_coord.x/(x_gain) + x_offset/(x_gain);
pixel_coord.y = pixel_coord.y/(y_gain) + y_offset/(y_gain);
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
============================FourCorner_Kernel_2.qtz=================
kernel vec4 FourCorner(
sampler image,
vec2 LToff,
vec2 LBoff,
vec2 RToff,
vec2 RBoff)
{
vec2 image_size = samplerSize(image);
vec2 pixel_coord = samplerCoord(image);
vec2 LT, LB,RT, RB , P1, P2, P3;
float XX, YY;
LB.x = -LBoff.x;
LB.y = -LBoff.y;
LT.x = -LToff.x;
LT.y = image_size.y - LToff.y;
RB.x = image_size.x - RBoff.x;
RB.y = - RBoff.y;
RT.x = image_size.x - RToff.x;
RT.y = image_size.y - RToff.y;
XX = pixel_coord.x/image_size.x ;
YY = pixel_coord.y/image_size.y;
P1.x = LB.x + XX*(RB.x-LB.x);
P1.y = LB.y + XX*(RB.y-LB.y);
P2.x = LT.x + XX*(RT.x-LT.x);
P2.y = LT.y + XX*(RT.y-LT.y);
P3.x = P1.x + YY*(P2.x-P1.x);
P3.y = P1.y + YY*(P2.y-P1.y);
vec4 pixel = sample(image, P3);
return vec4(clamp(pixel, 0.0, 1.0));
}
======================Line_Overlay.qtz=================
Detects transitions
======================SampleHold/MovingAveTests.qtz=================
Process random signal on the fly
======================MovieTests.qtz=================
Shows how to run or step a movie
Select Timebase to run or select frames
The Image exporter can export a single image
======================ImageExporter Test.qtz=================
Exports a series of images to a folder
Need Render in Image to create an image to write to file
~/Desktop
==============Date Formatter========================
=================Number Formatter=====================
=================Fill_with_Gradient1============================
Rainbow_Image All colors
Image Resize Set Rainbow image to same size
Thresshold Thresshold image to black/white
Blend With Mask No background to mask to transparent
=================Fill_with_Gradient2============================
Rainbow_Image All colors
Image Resize Set Rainbow image to same size
Thresshold Thresshold image to black/white
Mask to Alpha Create an alpha from black/white
Billboard Use mask to make transparent
======================Color Map=================
Color Controls Use to make gray image
Color Map Needs gradient to be horizontal
======================MAKING_Gradients=================
======================Line Screen=================
Line Screen
======================Displacement Distortion=================
Displacement Distortion
======================Image_Info=================
Image Origin
Image Dimensions
Units to Pixels
Pixels to Units
======================Line=========================
============================Image Texturing Properties=================
Image Texturing Properties Use it to adjust an image
======================Filters=================
What Filters do
==================================ImageToStructure=================
_1024_Structure_ImageToStructure Covert pixels into XYZ points in a structure
_1024_Structure_MATH_3D Can adjust the blend of an image with noise
===============================================Convert_Mesh_to_XYZStructure===========
_1024_Structure_Convert_Mesh_to_XYZStructure Get Mesh Component
_1024_Structure_Truncate
======================SpinEarth.qtz=================
CUT_AND_PASTE_KERNEL_TEMPLATES
===============addEffect=======================
kernel vec4 addEffect(sampler image1, sampler image2)
{ return sample(image1, samplerCoord(image1)) + sample(image2, samplerCoord(image2));
}
function __image main(__image image1, __image image2)
{ return addEffect.apply(image1.definition, null, image1, image2);
}
=============Threshold=========================
kernel vec4 Threshold(sampler Image, float Threshold, float AAWidth)
{ float f = AAWidth/2.0;
float a = Threshold - f;
float b = Threshold + f;
vec4 pixel = sample(Image, samplerCoord(Image));
float x = (pixel.r + pixel.g + pixel.b) / 3.0;
float v = smoothstep(a, b, x);
return vec4(v);
}
======================================
smoothstep (float edge0, float edge1, genType x)
smooth jump from 0 -> 1 for edge0 < x < edge1
equivalent to:
t = clamp ((x – edge0) / (edge1 – edge0), 0, 1);
return t * t * (3 – 2 * t);
============SubtractEffect==========================
kernel vec4 SubtractEffect(sampler imageA, sampler imageB)
{ vec4 A = sample(imageA, samplerCoord(imageA));
vec4 B = sample(imageB, samplerCoord(imageB));
vec4 C = clamp(B-A, 0.0, 1.0);
C.a = 1.0;
return C ;
}
============softRect==========================
kernel vec4 softRect(sampler image, float radius)
{ vec4 sf;
vec2 v = samplerCoord(image);
vec2 s = samplerSize(image);
vec4 pixel = sample(image, v);
sf = vec4(v, s - v); // left bottom , right top
sf *= 1.0 / radius; // recip hoisted by CI, radius is constant parameter to this kernel
sf = smoothstep(0.0, 1.0, clamp(sf, 0.0, 1.0)); // make all 4 functions rounded
pixel.a = sf.x * sf.y * sf.z * sf.w; // product of 4 functions produces a nice alpha
return pixel;
}
============softRect_non_vect==========================
/*
A Core Image kernel routine that softens the edges of an input image by a given radius.
This example shows how each edge's contribution is computed serially.
*/
kernel vec4 softRect_non_vect(sampler image, float radius)
{ vec2 v = samplerCoord(image);
vec2 s = samplerSize(image);
vec4 pixel = sample(image, v);
// Left
pixel.a = compare(v.x - radius, smoothstep(0., radius, v.x) * pixel.a, pixel.a);
// Bottom
pixel.a = compare(v.y - radius, smoothstep(0., radius, v.y) * pixel.a, pixel.a);
// Right
pixel.a = compare(v.x - (s.x - radius), pixel.a, smoothstep(s.x, s.x - radius, v.x) * pixel.a);
// Top
pixel.a = compare (v.y - (s.y - radius), pixel.a, smoothstep(s.y, s.y - radius, v.y) * pixel.a);
return pixel;
}
==============plasma========================
kernel vec4 plasma(
__color color1,
__color color2,
float time,
float width,
float height,
float scale)
{ vec2 pos = destCoord();
pos.x = pos.x / (width * scale);
pos.y = pos.y / (height * scale);
float localTime = cos(time);
float temp1 = (0.0 + pos.x) * (pos.x + 0.0);
float temp2 = (0.0 + pos.y) * (pos.y + 0.0);
float intensity = 0.5 * (2.0 + (2.0 + sin(temp1) + cos(temp2) + 2.0 * localTime));
float j = fract(intensity);
vec4 i;
i.r = j*color1.r +(1.0-j)* color2.r ;
i.g = j*color1.g +(1.0-j)* color2.g ;
i.b = j*color1.b +(1.0-j)* color2.b ;
return vec4( i.r,i.g,i.b,1.0);
}
=============CIMirrorEdge=========================
kernel vec4 CIMirrorEdge(sampler image, vec2 sZ)
{ vec2 dC = (destCoord()-.5);
vec2 i;
dC = 1.-abs(2.*fract(.5*dC / sZ)-1.);
i = dC*(sZ-1.)+.5;
return sample(image, samplerTransform(image, i));
}
=======
function myROIFunction(samplerIndex, dstRect, srcRect)
{ if ((dstRect.width == 0.) || (dstRect.height == 0.)) return new Vec(0.,0.,0.,0.);
var roiRect = new Vec(dstRect);
roiRect.x = (roiRect.x - srcRect.x) % srcRect.width + srcRect.x; // Mod get origin in source image
roiRect.y = (roiRect.y - srcRect.y) % srcRect.height + srcRect.y;
if (dstRect.x < 0) roiRect.x += srcRect.width;
if (dstRect.y < 0) roiRect.y += srcRect.height;
// If roiRect goes further than source image origin_x + width, adapt its origin_x and width
if (roiRect.width > srcRect.width + srcRect.x - roiRect.x)
{ roiRect.width = srcRect.width + srcRect.x - roiRect.x;
roiRect.x = Math.max(Math.min (srcRect.width + srcRect.x - (dstRect.width - roiRect.width), roiRect.x), srcRect.x);
roiRect.width = srcRect.width + srcRect.x- roiRect.x;
} // If roiRect goes further than source image origin_y + height, adapt its origin_y and height
if (roiRect.height > srcRect.height + srcRect.y - roiRect.y)
{ roiRect.height = srcRect.height + srcRect.y - roiRect.y;
roiRect.y = Math.max(Math.min (srcRect.height + srcRect.y - (dstRect.height - roiRect.height), roiRect.y), srcRect.y);
roiRect.height = srcRect.height + srcRect.y - roiRect.y;
} // When the dstRect corresponds to mirrored region, mirror the roiRect
if (((Math.abs((dstRect.x - srcRect.x)/srcRect.width) % 2 >= 1) && (dstRect.x >= 0.))
|| ((Math.abs((dstRect.x - srcRect.x)/srcRect.width) % 2 < 1) && (dstRect.x < 0.)))
{ roiRect.x = srcRect.width - (roiRect.x - srcRect.x) + srcRect.x - roiRect.width;
}
if (((Math.abs((dstRect.y - srcRect.y)/srcRect.height) % 2 >= 1) && (dstRect.y >= 0.))
|| ((Math.abs((dstRect.y - srcRect.y)/srcRect.height) % 2 < 1) && (dstRect.y < 0.)))
{ roiRect.y = srcRect.height - (roiRect.y - srcRect.y) + srcRect.y - roiRect.height;
}
return roiRect;
}
CIMirrorEdge.ROIHandler = myROIFunction;
function __image main(__image image)
{ var DOD = null;
return CIMirrorEdge.apply(DOD, image.extent, image, new Vec(image.extent.width, image.extent.height));
}
===============maskRed=======================
/*
This simple kernel computes a mask from the red contents of an image.
*/
kernel vec4 maskRed(sampler image)
{ vec4 pixel = sample(image, samplerCoord(image));
float mask = 8.0 * (pixel.r - 1.2 * pixel.g);
return vec4(clamp(mask, 0.0, 1.0));
}
===============radarSweep=======================
kernel vec4 radarSweep(
sampler image,
__color color1,
__color color2,
float angle,
vec4 rect)
{ vec4 val = sample(image, samplerCoord(image));
vec2 locCart = destCoord();
float theta, r, frac, angleDist;
locCart.x = (locCart.x - rect.z/2.0) / (rect.z/2.0);
locCart.y = (locCart.y - rect.w/2.0) / (rect.w/2.0);
// locCart is now normalized
theta = degrees(atan(locCart.y, locCart.x));
theta = (theta < 0.0) ? theta + 360.0 : theta;
r = length(locCart);
angleDist = theta - angle;
angleDist = (angleDist < 0.0) ? angleDist + 360.0 : angleDist;
frac = 1.0 - angleDist/360.0;
// sum up 3 decaying phosphors with different time constants
val = val*exp2(-frac/.005) + (val+.1)*exp2(-frac/.25)*color1 + val*exp2(-frac/.021)*color2;
val = r > 1.0 ? vec4(0.0, 0.0,0.0,0.0) : val; // constrain to circle
return val;
}
===============drawLine=======================
kernel vec4 drawLine(vec2 p1, vec2 p2, float Thickness, __color Color, float AAWidth)
{ vec2 v = destCoord();
vec2 P;
float f = AAWidth/2.0;
float a = Thickness - f;
float b = Thickness + f;
float q = ((v.x-p1.x)*(p2.x-p1.x) + (v.y-p1.y)*(p2.y-p1.y)) /
(pow((p2.x-p1.x),2.) + pow((p2.y-p1.y),2.));
q = clamp(q, 0., 1.);
P.x = (1.- q)*p1.x + q*p2.x;
P.y = (1.-q)*p1.y + q*p2.y;
float d = distance(P,v);
float v = smoothstep(b, a, d);
return vec4(v) * Color;
}
======================
q = ((Vx-p1x)deltaX + (Vy-p1y)deltaY)/(lenght(P2-P1)^2)
==============invertColor========================
kernel vec4 invertColor(sampler source_image)
{ vec4 pixValue;
pixValue = sample(source_image, samplerCoord(source_image));
unpremultiply(pixValue);
pixValue.r = 1.0 - pixValue.r;
pixValue.g = 1.0 - pixValue.g;
pixValue.b = 1.0 - pixValue.b;
return premultiply(pixValue);
}
==============invertColor2========================
kernel vec4 _invertColor2(sampler source_image)
{ vec4 pixValue;
pixValue = sample(source_image, samplerCoord(source_image));
pixValue.rgb = pixValue.aaa - pixValue.rgb;
return pixValue;
}
==============RGB_to_GBR========================
kernel vec4 RGB_to_GBR(sampler source_image)
{ vec4 originalColor, twistedColor;
originalColor = sample(source_image, samplerCoord(source_image));
twistedColor.r = originalColor.g;
twistedColor.g = originalColor.b;
twistedColor.b = originalColor.r ;
twistedColor.a = originalColor.a;
return twistedColor;
}
===============monochrome=======================
kernel vec4 monochrome(sampler image, __color color)
{ vec4 pixel;
pixel = sample(image, samplerCoord(image));
pixel.g = pixel.b = pixel.r;
return pixel * color;
}
================multiplyEffect======================
kernel vec4 multiplyEffect (sampler image_source, __color multiplyColor)
{ return sample (image_source, samplerCoord (image_source)) * multiplyColor;
}
=================roundPixellate=====================
kernel vec4 roundPixellate(sampler src, float scale)
{ vec2 positionOfDestPixel, centerPoint;
float d, radius;
vec4 outValue;
float smooth = 0.5;
radius = scale / 2.0; // scale = 10
positionOfDestPixel = destCoord();
centerPoint = positionOfDestPixel;
centerPoint.x = centerPoint.x - mod(positionOfDestPixel.x, scale) + radius;
centerPoint.y = centerPoint.y - mod(positionOfDestPixel.y, scale) + radius;
d = distance(centerPoint, positionOfDestPixel);
outValue = sample(src, samplerTransform(src, centerPoint));
outValue.a = outValue.a * smoothstep((d - smooth), d, radius);
return premultiply(outValue);
}
==================_EdgyFilter====================
kernel vec4 _EdgyFilter(sampler image, float power)
{ const vec2 xy = destCoord();
vec4 p00,p01,p02, p10,p12, p20,p21,p22;
vec4 sumX, sumY, computedPixel;
float edgeValue;
p00 = sample(image, samplerTransform(image, xy+vec2(-1.0, -1.0)));
p01 = sample(image, samplerTransform(image, xy+vec2( 0.0, -1.0)));
p02 = sample(image, samplerTransform(image, xy+vec2(+1.0, -1.0)));
p10 = sample(image, samplerTransform(image, xy+vec2(-1.0, 0.0)));
p12 = sample(image, samplerTransform(image, xy+vec2(+1.0, 0.0)));
p20 = sample(image, samplerTransform(image, xy+vec2(-1.0, +1.0)));
p21 = sample(image, samplerTransform(image, xy+vec2( 0.0, +1.0)));
p22 = sample(image, samplerTransform(image, xy+vec2(+1.0, +1.0)));
sumX = (p22+p02-p20-p00) + 2.0*(p12-p10);
sumY = (p20+p22-p00-p02) + 2.0*(p21-p01);
edgeValue = sqrt(dot(sumX,sumX) + dot(sumY,sumY)) * power;
computedPixel = sample(image, samplerCoord(image));
computedPixel.rgb = computedPixel.rgb * edgeValue;
return computedPixel;
}
=================funHouse=====================
float mySmoothstep(float x) { return (x * -2.0 + 3.0) * x * x; }
kernel vec4 funHouse(
sampler src,
float center_x,
float inverse_radius,
float radius,
float scale)
{ float distance;
vec2 myTransform1, adjRadius;
myTransform1 = destCoord();
adjRadius.x = (myTransform1.x - center_x) * inverse_radius;
distance = clamp(abs(adjRadius.x), 0.0, 1.0);
distance = mySmoothstep(1.0 - distance) * (scale - 1.0) + 1.0;
myTransform1.x = adjRadius.x * distance * radius + center_x;
return sample(src, samplerTransform(src, myTransform1));
}
===============Gain_Offset============================
kernel vec4 _Gain_Offset(sampler source_image, float gain,float offset )
{ vec4 pixValue;
pixValue = sample(source_image, samplerCoord(source_image));
unpremultiply(pixValue);
pixValue.r = clamp(pixValue.r*gain + offset*gain, 0.0, 1.0);
pixValue.g = clamp(pixValue.g*gain + offset*gain, 0.0, 1.0);
pixValue.b = clamp(pixValue.b*gain + offset*gain, 0.0, 1.0);
return premultiply(pixValue);
}
===============Thresshold============================
kernel vec4 Thresshold(sampler image, float thresshold)
{ vec4 p = sample(image, samplerCoord(image));
float intensity = clamp(0.3* p.r + 0.59* p.g + 0.11* p.b, 0.0, 1.0);
intensity = step(intensity , thresshold);
return vec4(intensity, intensity, intensity, p.a);
}
===============ApplyAlpha============================
kernel vec4 ApplyAlpha(sampler image, sampler alphamask)
{ vec4 p = sample(image, samplerCoord(image));
vec4 am = sample(alphamask, samplerCoord(alphamask));
return vec4(p.r, p.g, p.b, am.r);
}
===============InvertColor============================
kernel vec4 _invertColor(sampler source_image)
{ vec4 pixValue;
pixValue = sample(source_image, samplerCoord(source_image));
unpremultiply(pixValue);
pixValue.r = 1.0 - pixValue.r;
pixValue.g = 1.0 - pixValue.g;
pixValue.b = 1.0 - pixValue.b;
return premultiply(pixValue);
}
===============average9============================
kernel vec4 average5(sampler image)
{ vec2 xy = samplerCoord(image);
return (sample(image, samplerTransform(image, xy+vec2(-1.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 1.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0,-1.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0, 1.0))) )/5.0;
}
kernel vec4 average9(sampler image)
{ vec2 xy = samplerCoord(image);
return (sample(image, samplerTransform(image, xy+vec2(-2.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2(-1.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 1.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 2.0, 0.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0,-2.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0,-1.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0, 1.0))) +
sample(image, samplerTransform(image, xy+vec2( 0.0, 2.0))) )/9.0;
}
===============grayscaleKernel============================
kernel vec4 grayscaleKernel(sampler image)
{ vec4 p = sample(image, samplerCoord(image));
float intensity = clamp(0.3* p.r + 0.59* p.g + 0.11* p.b, 0.0, 1.0);
return vec4(intensity, intensity, intensity, p.a);
}
kernel vec4 grayscaleKernel(sampler image)
{ vec4 p = sample(image, samplerCoord(image)); // get each pixel
float intensity = clamp(0.3* p.r + 0.59* p.g + 0.11* p.b, 0.0, 1.0); // calc intensity from rgb
return vec4(intensity, intensity, intensity, p.a); //set dest pixel to intensity
}
vec4 samplerExtent (uniform sampler src) sampler's world coordinates, as [x, y, width, height].
vec2 samplerOrigin (uniform sampler src) Equivalent to samplerExtent (src).xy.
vec2 samplerSize (uniform sampler src) Equivalent to samplerExtent (src).zw.
===============gradientImag============================
kernel vec4 gradientImag(
sampler image,
__color col1,
__color col2)
{ vec4 p = sample(image, samplerCoord(image));
float lev = clamp(0.3* p.r + 0.59* p.g + 0.11* p.b, 0.0, 1.0);
return vec4(lev*col1.r + (1.0-lev)*col2.r, lev*col1.g + (1.0-lev)*col2.g, lev*col1.b+(1.0-lev)*col2.b, p.a);
}
===============perspective============================
kernel vec4 perspective(
sampler input_image,
float topshrink,
float topoffset)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float x_gain = 1.0-topshrink*pixel_coord.y/image_size.y;
float x_offset = -50.0*topoffset*pixel_coord.y/image_size.y;
pixel_coord.x = pixel_coord.x + x_offset;
pixel_coord.x = pixel_coord.x/x_gain ;
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
===============roundedRect============================
kernel vec4 roundedRect(
vec2 bottomLeft,
vec2 topRight,
float radius,
__color color)
{ vec2 p = destCoord();
float dist = 0;
bottomLeft += radius;
topRight -= radius;
dist += p.x<bottomLeft.x ? pow(bottomLeft.x-p.x,2.0) : 0.0;
dist += p.y<bottomLeft.y ? pow(bottomLeft.y-p.y,2.0) : 0.0;
dist += p.x>topRight.x ? pow(topRight.x-p.x,2.0) : 0.0;
dist += p.y>topRight.y ? pow(topRight.y-p.y,2.0) : 0.0;
dist = sqrt(dist);
return color * clamp(radius - dist, 0.0, 1.0);
}
===============sobelFilter===============================
const float kern00 = -1;
const float kern01 = -2;
const float kern02 = -1;
const float kern10 = 0;
const float kern11 = 0;
const float kern12 = 0;
const float kern20 = 1;
const float kern21 = 2;
const float kern22 = 1;
float getMonoValue(sampler image, const vec2 xy, const vec2 off)
{ return sample(image,xy +off).r;
}
kernel vec4 sobelFilter(sampler image)
{ float accumV = 0.0;
float accumH = 0.0;
const vec2 xy = samplerCoord(image);
float pixel;
pixel = getMonoValue(image, xy, vec2(-1.0, -1.0));
accumV += pixel*kern00;
accumH += pixel*kern00;
pixel = getMonoValue(image, xy, vec2( 0.0, -1.0));
accumV += pixel*kern01;
accumH += pixel*kern10;
pixel = getMonoValue(image, xy, vec2( 1.0, -1.0));
accumV += pixel*kern02;
accumH += pixel*kern20;
pixel = getMonoValue(image, xy, vec2(-1.0, 0.0));
accumV += pixel*kern10;
accumH += pixel*kern01;
pixel = getMonoValue(image, xy, vec2( 0.0, 0.0));
accumV += pixel*kern11;
accumH += pixel*kern11;
pixel = getMonoValue(image, xy, vec2( 1.0, 0.0));
accumV += pixel*kern12;
accumH += pixel*kern21;
pixel = getMonoValue(image, xy, vec2(-1.0, 1.0));
accumV += pixel*kern20;
accumH += pixel*kern02;
pixel = getMonoValue(image, xy, vec2( 0.0, 1.0));
accumV += pixel*kern21;
accumH += pixel*kern12;
pixel = getMonoValue(image, xy, vec2( 1.0, 1.0));
accumV += pixel*kern22;
accumH += pixel*kern22;
float val = sqrt(accumH * accumH + accumV * accumV);
return vec4(val, val, val, 1.0);
}
/*
[-1][-2][-1] KernXY
[00][00][00]
[01][02][01]
[20][21][22] accumV
[10][11][12]
[00][01][02]
[02][12][22] accumH
[01][11][22]
[00][10][20]
*/
===============blur============================
kernel vec4 blur_4(sampler image, float radius)
{ vec2 basePos = destCoord();
int i, j;
vec2 delta;
vec4 sum = vec4(0.0);
for (i = -4; i <= 4; ++i)
{ delta.x = float(i);
for (j = -4; j <= 4; ++j)
{ delta.y = float(j);
sum += sample( image, basePos + delta );
}
}
sum.rgb /= sum.a;
sum.a = 1.0;
return sum;
}
kernel vec4 blur_2(sampler image, float radius)
{ vec2 basePos = destCoord();
int i, j;
vec2 delta;
vec4 sum = vec4(0.0);
for (i = -2; i <= 2; ++i)
{ delta.x = float(i);
for (j = -2; j <= 2; ++j)
{ delta.y = float(j);
sum += sample( image, basePos + delta );
}
}
sum.rgb /= sum.a;
sum.a = 1.0;
return sum;
}
===============msBlackSilkscreen============================
kernel vec4 msBlackSilkscreen(
sampler input_image,
float input_threshold)
{
vec2 center = samplerCoord(input_image);
vec4 pixel = sample(input_image, center);
float normal = dot(vec3(pixel),vec3(pixel));
float grey = clamp(float(normal>input_threshold),0.0,1.0);
float alpha = 1.0-grey;
pixel.r = grey;
pixel.g = grey;
pixel.b = grey;
pixel.a = alpha;
return pixel;
}
===========msBlackInvertRGBLeaveAlpha========================
kernel vec4 msBlackInvertRGBLeaveAlpha(sampler input_image)
{
vec4 pixel = sample(input_image, samplerCoord(input_image));
float average = 1.0-clamp((pixel.x+ pixel.y+ pixel.z)/3.0,0.0,1.0);
pixel.r = average;
pixel.g = average;
pixel.b = average;
return pixel;
}
=============msBlackHorizontalSawMask======================
const float M_PI = 3.1415926535897932384;
const float period_degrees = 180.0;
float inverse_saw(float in_angle_degrees)
{
float angle_degrees = clamp(in_angle_degrees,0.0, period_degrees);
float value_normal = angle_degrees/period_degrees;
float value_if_nz = (value_normal*2.0 - 1.0);
float value = (angle_degrees==0.0) ? 0.0 : -1.0*value_if_nz;
return value;
}
kernel vec4 msBlackHorizontalSawMask(
sampler input_image,
float input_frequency,
float input_amplitude,
float input_offset,
float input_phase)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, pixel_coord);
float pixel_y_normal = pixel_coord.y/image_size.y;
float degrees = (pixel_y_normal* period_degrees);
float phase = clamp(input_phase* period_degrees,0.0, period_degrees);
float alpha = input_offset + (input_amplitude * mod(phase+input_frequency* inverse_saw(degrees),1.0));
pixel.a = alpha*pixel.a;
return vec4(clamp(pixel, 0.0, 1.0));
}
const float M_PI = 3.1415926535897932384;
const float period_degrees = 180.0;
float inverse_saw(float in_angle_degrees)
{
float angle_degrees = clamp(in_angle_degrees,0.0, period_degrees); // in_angle_degrees 0=>180
float value_normal = angle_degrees/period_degrees; // value_normal 0=>1
float value_if_nz = (value_normal*2.0 - 1.0); // value_if_nz 0=>1 or -1.0
float value = (angle_degrees==0.0) ? 0.0 : -1.0*value_if_nz; // value 0 or 0=>-1
return value;
}
kernel vec4 msBlackHorizontalSawMask(
sampler input_image,
float input_frequency,
float input_amplitude,
float input_offset,
float input_phase)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, pixel_coord);
float pixel_y_normal = pixel_coord.y/image_size.y;
float degrees = (pixel_y_normal* period_degrees);
float phase = clamp(input_phase* period_degrees,0.0, period_degrees);
float alpha = input_offset + (input_amplitude * mod(phase+input_frequency* inverse_saw(degrees),1.0));
pixel.a = alpha*pixel.a;
return vec4(clamp(pixel, 0.0, 1.0));
}
==============msBlackSuperTileMask=====================
kernel vec4 msBlackSuperTileMask(
sampler input_image,
sampler mask_image,
float input_subdivisions )
{
float subdivisions = (input_subdivisions);
vec2 image_size = samplerSize(input_image);
vec2 mask_size = samplerSize(mask_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec2 normal_coord = mod(pixel_coord,box_size)/box_size;
vec2 mask_coord = normal_coord*mask_size;
vec4 pixel = sample(input_image, box_coord);
vec4 maxel = sample(mask_image, mask_coord);
pixel.a = clamp((maxel.x+maxel.y+maxel.z)/3.0,0.0,1.0);
return pixel;
}
=============msBlackSuperTile======================
kernel vec4 msBlackSuperTile(
sampler input_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0);
vec2 image_size = samplerSize(input_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec4 pixel = sample(input_image, box_coord);
return pixel;
}
kernel vec4 msBlackSuperTile(
sampler input_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0); // input_subdivisions set = 4
vec2 image_size = samplerSize(input_image); // image_size = (248,318)
vec2 box_size = floor(image_size/subdivisions); // box_size = ( 124,159 )
vec2 pixel_coord = samplerCoord(input_image); // pixel_coord = for x 0=> 248 y 0=> 318
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions; // box_coord = (mod( x,128)*2 , mod( y,159)*2)
vec4 pixel = sample(input_image, box_coord); // will sample over and over at box_coord
return pixel;
}
==============msBlackSuperTileMask=====================
kernel vec4 msBlackSuperTileMask(
sampler input_image,
sampler mask_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0);
vec2 image_size = samplerSize(input_image);
vec2 mask_size = samplerSize(mask_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec2 normal_coord = mod(pixel_coord,box_size)/box_size;
vec2 mask_coord = normal_coord*mask_size;
vec4 pixel = sample(input_image, box_coord);
vec4 maxel = sample(mask_image , mask_coord);
pixel.a = clamp((maxel.x+maxel.y+maxel.z)/3.0,0.0,1.0);
return pixel;
}
kernel vec4 msBlackSuperTileMask(
sampler input_image,
sampler mask_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0); // input_subdivisions =2
vec2 image_size = samplerSize(input_image); // image_size = (248,318)
vec2 mask_size = samplerSize(mask_image); // mask_size = (509,447)
vec2 box_size = floor(image_size/subdivisions); // box_size = (248,318)
vec2 pixel_coord = samplerCoord(input_image); // pixel_coord = for in_x 0=> 248 in_y 0=> 318
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions; // box_coord = (mod( in_x,248)*1 , mod( in_y,318)*2)
vec2 normal_coord = mod(pixel_coord,box_size)/box_size; // normal_coord = (in_x/248 , in_y/318)
vec2 mask_coord = normal_coord*mask_size; // mask_coord = (in_x*509/248 , in_y*447/318)
vec4 pixel = sample(input_image, box_coord); // sample rgb of input over and over at box_coord
vec4 maxel = sample(mask_image , mask_coord); // sample rgb of mask over and over at mask_coord
pixel.a = clamp((maxel.x+maxel.y+maxel.z)/3.0,0.0,1.0); // apply alpha of mask to input over mask_size
return pixel;
}
==============msBlackSoftBoxMask====================
float radians_from_degrees(const float in_degrees)
{ const float M_PI = 3.1415926535897932384;
return in_degrees * (M_PI/180.0);
}
kernel vec4 msBlackSoftBoxMask(
sampler input_image,
float input_pixels,
float input_angle_degrees,
float input_fade_power)
{
vec2 image_size = samplerSize(input_image);
vec2 image_center = image_size*0.5;
vec2 pixel_coord = samplerCoord(input_image);
vec2 pixel_xy = pixel_coord-image_center;
float theta = radians_from_degrees(input_angle_degrees);
float cos_theta = cos(theta);
float sin_theta = sin(theta);
vec2 rotate_x = vec2(cos_theta,-sin_theta);
vec2 rotate_y = vec2(sin_theta,cos_theta);
float xx = dot(rotate_x, pixel_xy);
float yy = dot(rotate_y, pixel_xy);
pixel_coord = image_center + vec2(xx,yy);
float dist_top = abs(pixel_coord.y-0.0);
float dist_left = abs(pixel_coord.x-0.0);
float dist_right = abs(image_size.x-pixel_coord.x);
float dist_bottom = abs(image_size.y-pixel_coord.y);
vec4 pixel = sample(input_image,samplerCoord(input_image));
const float opaque = 1.0;
float alpha = opaque;
const float power = input_fade_power;
float semi_transparent_left = clamp(pow(dist_left/input_pixels,power),0.0,1.0);
alpha = (dist_left<input_pixels) ? min(semi_transparent_left,alpha): alpha;
float semi_transparent_top = clamp(pow(dist_top/input_pixels,power),0.0,1.0);
alpha = (dist_top<input_pixels) ? min(semi_transparent_top,alpha): alpha;
float semi_transparent_right = clamp(pow(dist_right/input_pixels,power),0.0,1.0);
alpha = (dist_right<input_pixels) ? min(semi_transparent_right,alpha) : alpha;
float semi_transparent_bottom = clamp(pow(dist_bottom/input_pixels,power),0.0,1.0);
alpha = (dist_bottom<input_pixels) ? min(semi_transparent_bottom,alpha) : alpha;
pixel.a = alpha;
return pixel;
}
==============msBlackRadialPowerMask====================
kernel vec4 msBlackRadialPowerMask(
sampler input_image,
float input_max_radius,
float input_fade_power)
{
vec2 image_size = samplerSize(input_image);
vec2 image_center = image_size*0.5;
vec2 pixel_coord = samplerCoord(input_image);
float pel_distance = distance(pixel_coord,image_center);
vec4 pixel = sample(input_image, pixel_coord);
float distance_ratio = clamp(pel_distance/input_max_radius,0.0,1.0);
float alpha = clamp(1.0-(pow(distance_ratio,input_fade_power)),0.0,1.0);
pixel.a = alpha;
return pixel;
}
==============msBlackColorDisplaceYUV====================
kernel vec4 msBlackColorDisplaceYUV(sampler image, sampler distort_u_map, sampler distort_v_map, float amount_normal)
{
float input_amount = clamp(amount_normal,0.0,1.0);
float inverse_amount = 1.0-input_amount;
const vec3 rgb_y = vec3(0.257, 0.504, 0.098);
const vec3 rgb_u = vec3(-0.148, -0.291, 0.439);
const vec3 rgb_v = vec3(0.439, -0.368, -0.071);
const vec3 yuv_r = vec3(1.0000, 0.0000, 1.4022 );
const vec3 yuv_g = vec3( 1.0000, -0.3457, -0.7145);
const vec3 yuv_b = vec3(1.0000, 1.7710, 0.0000);
vec4 pixel = sample(image, samplerCoord(image));
vec3 pel = pixel;
vec3 distort_u = sample(distort_u_map, samplerCoord(distort_u_map));
vec3 distort_v = sample(distort_v_map, samplerCoord(distort_v_map));
float delta_u = clamp((distort_u.x+distort_u.y+distort_u.z)/3.0,0.0,1.0)-0.5;
float delta_v = clamp((distort_v.x+distort_v.y+distort_v.z)/3.0,0.0,1.0)-0.5;
vec3 pixel_yuv;
pixel_yuv.x = dot(pel,rgb_y);
pixel_yuv.y = dot(pel,rgb_u);
pixel_yuv.z = dot(pel,rgb_v);
pixel_yuv.y = clamp(pixel_yuv.y + delta_u,0.0,1.0);
pixel_yuv.z = clamp(pixel_yuv.z + delta_v,0.0,1.0);
pel.r = dot(pixel_yuv,yuv_r);
pel.g = dot(pixel_yuv,yuv_g);
pel.b = dot(pixel_yuv,yuv_b);
vec3 result = (input_amount*pel) + inverse_amount*vec3(pixel);
return vec4(result.r, result.g, result.b,pixel.a);
}
=============msBlackTexPhase=====================
kernel vec4 msBlackTexPhase(
sampler input_image,
float input_phase_x,
float input_phase_y)
{
float phase_x = clamp(input_phase_x,0.0,1.0)-0.5;
float phase_y = clamp(input_phase_y,0.0,1.0)-0.5;
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec2 normal_coord = pixel_coord/image_size;
normal_coord += vec2(phase_x,phase_y);
vec2 pel_coord = mod(normal_coord*image_size,image_size);
vec4 pel = sample(input_image, pel_coord);
return pel;
}
=============msBlackSuperTile=====================
kernel vec4 msBlackSuperTile(
sampler input_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0);
vec2 image_size = samplerSize(input_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec4 pixel = sample(input_image, box_coord);
return pixel;
}
=============msBlackSuperTileMask=====================
kernel vec4 msBlackSuperTileMask(
sampler input_image,
sampler mask_image,
float input_subdivisions)
{
float subdivisions = int(input_subdivisions/2.0);
vec2 image_size = samplerSize(input_image);
vec2 mask_size = samplerSize(mask_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec2 normal_coord = mod(pixel_coord,box_size)/box_size;
vec2 mask_coord = normal_coord*mask_size;
vec4 pixel = sample(input_image, box_coord);
vec4 maxel = sample(mask_image, mask_coord);
pixel.a = clamp((maxel.x+maxel.y+maxel.z)/3.0,0.0,1.0);
return pixel;
}
=============msBlackHorizontalSineMask======================
kernel vec4 msBlackHorizontalSineMask(
sampler input_image,
float input_frequency,
float input_amplitude,
float input_offset,
float input_phase)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, pixel_coord);
float pixel_y_normal = pixel_coord.y/image_size.y;
float M_PI = 3.14597;
float alpha = input_offset + (input_amplitude * sin(M_PI*(input_phase+(input_frequency*pixel_y_normal))));
pixel.a = alpha*pixel.a;
return vec4(clamp(pixel, 0.0, 1.0));
}
===============msBlackLensFlex====================
kernel vec4 msBlackLensFlex(
sampler image,
vec2 center,
float input_factor_normal,
float input_sign,
float input_scale_normal)
{
vec2 vector = destCoord() - center;
float distance_from_center = length(vector);
vec2 distance_normal = normalize(vector);
float input_factor = clamp(input_factor_normal,0.0,1.0);
float input_scale = -input_sign*((1.0-input_sign)-clamp(input_scale_normal,0.0,1.0));
float distance_sq = distance_from_center*distance_from_center;
vec2 image_size = samplerSize(image);
float max_factor = max(image_size.x,image_size.y);
float lens_factor = abs(input_factor)*max_factor;
float lens_factor_sq = input_sign*lens_factor*lens_factor;
float dxdy = input_scale * distance_from_center / (1.0 - (distance_sq/lens_factor_sq) );
vec2 pixel_offset = center + dxdy * distance_normal;
vec4 pixel = sample(image, samplerTransform(image, pixel_offset));
return pixel;
}
=============msBlackVerticalSineWave======================
kernel vec4 msBlackVerticalSineWave(
sampler input_image,
float input_frequency,
float input_amplitude_normal,
float input_offset,
float input_phase)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float input_amplitude = clamp(input_amplitude_normal,0.0,1.0)*0.1;
float pixel_y_normal = pixel_coord.y/image_size.y;
const float M_PI = 3.14597;
float sin_y = input_offset + (input_amplitude * sin(M_PI*(input_phase+(input_frequency*pixel_y_normal))));
pixel_coord.y += (sin_y * image_size.y);
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
=============msBlackDisplacementMaps======================
kernel vec4 msBlackDisplacementMaps(
sampler input_image,
sampler input_map_x,
sampler input_map_y,
float input_range_normal)
{
float input_range = clamp(input_range_normal,0.0,1.0);
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 maxel_x = sample(input_map_x, samplerCoord(input_map_x));
vec4 maxel_y = sample(input_map_y, samplerCoord(input_map_y));
float dx_normal = input_range*dot(vec3(maxel_x),vec3(maxel_x));
float dy_normal = input_range*dot(vec3(maxel_y),vec3(maxel_y));
pixel_coord.x += dx_normal * image_size.x;
pixel_coord.y += dy_normal * image_size.y;
return sample(input_image, pixel_coord);
}
==============msBlackDisplacementMaps2=====================
float as_radians(const float in_degrees)
{ return in_degrees * (3.14597/180.0);
}
vec2 from_polar(const float in_radius, const float in_theta)
{
float x = in_radius * sin(as_radians(in_theta));
float y = in_radius * cos(as_radians(in_theta));
return vec2(x,y);
}
kernel vec4 msBlackDisplacementMaps2(
sampler input_image,
sampler input_map_radius,
sampler input_map_angle,
float input_range_normal)
{
float input_range = clamp(input_range_normal,0.0,1.0);
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 maxel_radius = sample(input_map_radius, samplerCoord(input_map_radius));
vec4 maxel_angle = sample(input_map_angle, samplerCoord(input_map_angle));
float dr_normal = input_range*dot(vec3(maxel_radius),vec3(maxel_radius));
float dt_normal = dot(vec3(maxel_angle),vec3(maxel_angle));
float radius = dr_normal*max(image_size.x, image_size.y);
float angle = dt_normal*360.0;
pixel_coord += from_polar(radius, angle);
return sample(input_image, pixel_coord);
}
===============msBlackSinCityColorReplacement====================
kernel vec4 msBlackSinCityColorReplacement(
sampler image,
float input_threshold_normal,
float threshold_sensitivity,
__color find_color,
__color replace_color)
{
float input_threshold_sensitivity = 2.*(1.0-clamp(threshold_sensitivity,0.0,1.0));
float input_threshold = clamp(pow(input_threshold_normal, input_threshold_sensitivity),0.0,1.0);
vec3 pel_rgb = unpremultiply(sample(image, samplerCoord(image)));
vec3 find_pel = vec3(find_color.r,find_color.g,find_color.b);
vec4 replace_pel = vec3(replace_color.r, replace_color.g, replace_color.b);
replace_pel.a = 1.0;
float distance_in_rgb_cube = distance(find_pel,pel_rgb);
float distance_abs = sqrt(distance_in_rgb_cube*distance_in_rgb_cube);
vec4 pel_avg = (pel_rgb.r + pel_rgb.g + pel_rgb.b)/3.0;
vec4 result = (distance_abs <input_threshold) ? replace_pel : pel_avg;
return result;
}
============msBlackVerticalSineWave=======================
kernel vec4 msBlackVerticalSineWave(
sampler input_image,
float input_frequency,
float input_amplitude_normal,
float input_offset,
float input_phase)
{ vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float input_amplitude = clamp(input_amplitude_normal,0.0,1.0)*0.1; // input_amplitude 0=>0.1
float pixel_y_normal = pixel_coord.y/image_size.y; // pixel_y_normal 0=>1
const float M_PI = 3.14597;
float sin_y = input_offset + (input_amplitude * sin(M_PI*(input_phase+(input_frequency*pixel_y_normal))));
pixel_coord.y += (sin_y * image_size.y); // pixel_coord.y = pixel_coord.y + (sin_y * image_size.y);
vec4 pixel = sample(input_image, pixel_coord); // get sample at offsed pixel_coord
return vec4(clamp(pixel, 0.0, 1.0)); // return it clamped from 0=>1
}
============msBlackHorizontalSineWave======================
kernel vec4 msBlackHorizontalSineWave(
sampler input_image,
float input_frequency,
float input_amplitude_normal,
float input_offset,
float input_phase)
{ vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float input_amplitude = clamp(input_amplitude_normal,0.0,1.0)*0.1;
float pixel_x_normal = pixel_coord.x/image_size.x;
const float M_PI = 3.14597;
float sin_x = input_offset + (input_amplitude * sin(M_PI*(input_phase+(input_frequency*pixel_x_normal))));
pixel_coord.x += (sin_x * image_size.x);
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
==============Adaptive_Threshold=============================
vec2 localMinMax(sampler image, vec2 pt)
{ float p1 = sample(image, vec2(pt.x-1.0, pt.y-1.0));
float p2 = sample(image, vec2(pt.x , pt.y-1.0));
float p3 = sample(image, vec2(pt.x+1.0, pt.y-1.0));
float p4 = sample(image, vec2(pt.x-1.0, pt.y ));
float p5 = sample(image, vec2(pt.x , pt.y ));
float p6 = sample(image, vec2(pt.x+1.0, pt.y ));
float p7 = sample(image, vec2(pt.x-1.0, pt.y+1.0));
float p8 = sample(image, vec2(pt.x , pt.y+1.0));
float p9 = sample(image, vec2(pt.x+1.0, pt.y+1.0));
vec2 minmax;
minmax[0] = min(p1, min(p2, min(p3, min(p4, min(p5, min(p6, min(p7, min(p8, p9))))))));
minmax[1] = max(p1, max(p2, max(p3, max(p4, max(p5, max(p6, max(p7, max(p8, p9))))))));
return minmax;
}
kernel vec4 Adaptive_threshhold(sampler image, float minrange, __color foreground, __color background)
{ vec4 foregroundPix = unpremultiply(foreground);
vec4 backgroundPix = unpremultiply(background);
vec2 pt = samplerCoord(image);
vec4 pix = sample(image, pt);
vec2 minmax = localMinMax(image, pt);
float threshed = (minmax[1] - minmax[0] > minrange) ?
(minmax[0] + minmax[1])/2.0 :
(minmax[1] - minmax[0])/2.0;
vec4 thresh = vec4(threshed, threshed, threshed, 1.0);
vec4 newpix = compare(pix - thresh, foregroundPix, backgroundPix);
return newpix;
}
==============CI_msaSmartThreshold==========================
kernel vec4 msaSmartThreshold(sampler image, float fThreshold, float fSoftness)
{ vec4 pix = sample(image, samplerCoord(image));
float fValue = (pix.r *0.29+ pix.g*0.6 + pix.b*0.11);
float l1 = fThreshold - fSoftness * 0.5;
float l2 = l1 + fSoftness;
fValue = smoothstep(max(l1,0.0), min(l2, 1.0), fValue);
pix = vec4(fValue, fValue, fValue, 1.0);
return pix;
}
==============Select_Color_2_blk==========================
kernel vec4 SelectColor(sampler image, __color color, float Threshold)
{ vec4 pix = sample(image, samplerCoord(image));
float delta = pow(( pix.r - color.r) , 2.0);
delta = delta + pow(( pix.g - color.g) , 2.0);
delta = delta + pow(( pix.b - color.b) , 2.0);
delta = sqrt( delta);
float val = (delta > Threshold ? 1.0 : 0.0) ;
return vec4(val, val, val, pix.a);
}
==============RBG_2_HSL==============================
vec4 rgb2hsl(vec4 color)
{ float MAX = max(color.r, max(color.g, color.b));
float MIN = min(color.r, min(color.g, color.b));
MAX = max(MIN + 1e-6, MAX);
float l = MAX;
float s = (MAX < 0.01 ? 0.0 : (MAX - MIN) / MAX);
float h = (MAX == color.r ? (color.g - color.b) / (MAX - MIN) :
(MAX == color.g ? 2.0 + (color.b - color.r) / (MAX - MIN) :
4.0 + (color.r - color.g) / (MAX - MIN)));
h = h/6.0;
h = (h < 0.0 ? 1.0 + h : h);
return vec4(h, s, l, color.a);
}
kernel vec4 hsl(sampler image)
{ vec4 pixel = sample(image, samplerCoord(image));
return rgb2hsl(pixel);
}
==============HSL_2_RGB==============================
vec4 hsv2rgb(vec4 color)
{ float h = color.r;
float s = color.g;
float v = color.b;
h = h*6.0;
float i = floor( h );
float f = h -i ;
float p = v * ( 1.0 - s );
float q = v * ( 1.0 - s * f );
float t = v * ( 1.0 - s * ( 1.0 - f ) );
float r = (i == 0.0 ? v :
(i == 1.0 ? q :
(i == 2.0 ? p :
(i == 3.0 ? p :
(i == 4.0 ? t : v )))));
float g = (i == 0.0 ? t :
(i == 1.0 ? v :
(i == 2.0 ? v :
(i == 3.0 ? q :
(i == 4.0 ? p : p )))));
float b = (i == 0.0 ? p :
(i == 1.0 ? p :
(i == 2.0 ? t :
(i == 3.0 ? v :
(i == 4.0 ? v : q )))));
return vec4(r, g, b, color.a);
}
kernel vec4 hsl2rgb(sampler image)
{ vec4 pixel = sample(image, samplerCoord(image));
return hsv2rgb(pixel);
}
================Raindow_gradient_V==================================
vec4 hsv2rgb(vec4 color)
{ float h = color.r;
float s = color.g;
float v = color.b;
h = h*6.0;
float i = floor( h );
float f = h -i ;
float p = v * ( 1.0 - s );
float q = v * ( 1.0 - s * f );
float t = v * ( 1.0 - s * ( 1.0 - f ) );
float r = (i == 0.0 ? v :
(i == 1.0 ? q :
(i == 2.0 ? p :
(i == 3.0 ? p :
(i == 4.0 ? t : v )))));
float g = (i == 0.0 ? t :
(i == 1.0 ? v :
(i == 2.0 ? v :
(i == 3.0 ? q :
(i == 4.0 ? p : p )))));
float b = (i == 0.0 ? p :
(i == 1.0 ? p :
(i == 2.0 ? t :
(i == 3.0 ? v :
(i == 4.0 ? v : q )))));
return vec4(r, g, b, color.a);
}
kernel vec4 HueGradV(sampler image)
{ vec2 image_size = samplerSize(image);
vec2 pixel_coord = samplerCoord(image);
vec4 pixel = sample(image, pixel_coord);
float sat = 1.0;
float lum = 0.5;
float h = .5 + 2.0*pixel_coord.y/image_size.y;
h = mod(h,1.0);
vec4 pix = vec4(h, sat, lum, pixel.a);
return hsv2rgb( pix );
================Hue_Adjust_Image==================================
vec4 rgb2hsl(vec4 color)
{ float MAX = max(color.r, max(color.g, color.b));
float MIN = min(color.r, min(color.g, color.b));
MAX = max(MIN + 1e-6, MAX);
float l = MAX;
float s = (MAX < 0.01 ? 0.0 : (MAX - MIN) / MAX);
float h = (MAX == color.r ? (color.g - color.b) / (MAX - MIN) :
(MAX == color.g ? 2.0 + (color.b - color.r) / (MAX - MIN) :
4.0 + (color.r - color.g) / (MAX - MIN)));
h = h/6.0;
h = (h < 0.0 ? 1.0 + h : h);
return vec4(h, s, l, color.a);
}
vec4 hsv2rgb(vec4 color)
{ float h = color.r;
float s = color.g;
float v = color.b;
h = h*6.0;
float i = floor( h );
float f = h -i ;
float p = v * ( 1.0 - s );
float q = v * ( 1.0 - s * f );
float t = v * ( 1.0 - s * ( 1.0 - f ) );
float r = (i == 0.0 ? v :
(i == 1.0 ? q :
(i == 2.0 ? p :
(i == 3.0 ? p :
(i == 4.0 ? t : v )))));
float g = (i == 0.0 ? t :
(i == 1.0 ? v :
(i == 2.0 ? v :
(i == 3.0 ? q :
(i == 4.0 ? p : p )))));
float b = (i == 0.0 ? p :
(i == 1.0 ? p :
(i == 2.0 ? t :
(i == 3.0 ? v :
(i == 4.0 ? v : q )))));
return vec4(r, g, b, color.a);
}
kernel vec4 rotHue(sampler image, float angle)
{ vec4 pixel = sample(image, samplerCoord(image));
vec4 huePix = rgb2hsl(pixel);
float h = huePix.r + angle;
h = mod(h , 1.0);
vec4 pix = vec4(h, huePix.g, huePix.b,huePix.a);
return hsv2rgb( pix );
}
===============Grow_1_Pix============================
vec2 localMinMax(sampler image, vec2 pt)
{ float p1 = sample(image, vec2(pt.x-1.0, pt.y-1.0));
float p2 = sample(image, vec2(pt.x , pt.y-1.0));
float p3 = sample(image, vec2(pt.x+1.0, pt.y-1.0));
float p4 = sample(image, vec2(pt.x-1.0, pt.y ));
float p5 = sample(image, vec2(pt.x , pt.y ));
float p6 = sample(image, vec2(pt.x+1.0, pt.y ));
float p7 = sample(image, vec2(pt.x-1.0, pt.y+1.0));
float p8 = sample(image, vec2(pt.x , pt.y+1.0));
float p9 = sample(image, vec2(pt.x+1.0, pt.y+1.0));
vec2 minmax;
minmax[0] = min(p1, min(p2, min(p3, min(p4, min(p5, min(p6, min(p7, min(p8, p9))))))));
minmax[1] = max(p1, max(p2, max(p3, max(p4, max(p5, max(p6, max(p7, max(p8, p9))))))));
return minmax;
}
kernel vec4 Grow_1_Pix(sampler image )
{ vec2 pt = samplerCoord(image);
vec2 minmax = localMinMax(image, pt);
float max = minmax[1] ;
return vec4(max, max, max, 1.0);
}
===============shrink_1_Pix============================
vec2 localMinMax(sampler image, vec2 pt)
{ float p1 = sample(image, vec2(pt.x-1.0, pt.y-1.0));
float p2 = sample(image, vec2(pt.x , pt.y-1.0));
float p3 = sample(image, vec2(pt.x+1.0, pt.y-1.0));
float p4 = sample(image, vec2(pt.x-1.0, pt.y ));
float p5 = sample(image, vec2(pt.x , pt.y ));
float p6 = sample(image, vec2(pt.x+1.0, pt.y ));
float p7 = sample(image, vec2(pt.x-1.0, pt.y+1.0));
float p8 = sample(image, vec2(pt.x , pt.y+1.0));
float p9 = sample(image, vec2(pt.x+1.0, pt.y+1.0));
vec2 minmax;
minmax[0] = min(p1, min(p2, min(p3, min(p4, min(p5, min(p6, min(p7, min(p8, p9))))))));
minmax[1] = max(p1, max(p2, max(p3, max(p4, max(p5, max(p6, max(p7, max(p8, p9))))))));
return minmax;
}
kernel vec4 shrink_1_Pix(sampler image )
{ vec2 pt = samplerCoord(image);
vec2 minmax = localMinMax(image, pt);
float min = minmax[0] ;
return vec4(min, min, min, 1.0);
}
===============Noise============================
float rand(vec2 co)
{ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
kernel vec4 simpleRandomGrey(float Time)
{ return vec4(vec3(rand(destCoord() + Time)), 1.0);
}
========
function __image main(__number Time)
{ return simpleRandomGrey.apply(null, null, Time);
}
===========PerlinNoiseCIKernal===========================
// Improved Noise - Copyright 2002 Ken Perlin.
// conversion to CIKernel by smokris@kineme.net, 2009.02.26
float fade(float t)
{
return pow(t,3.) * (t * (t * 6. - 15.) + 10.);
}
float grad(float hash, float x, float y, float z)
{
int hashi = hash;
hash = float(hashi)+0.;
int h = mod(hash,16.);
float hf = h;
float u = h<8 ? x : y,
v = h<4 ? y :
h==12 ? x : (h==14?x:z);
bool h1 = mod(hf,2.);
bool h2 = mod(hf,4.)>1.;
return (h1 ? -u : u) + (h2 ? -v : v);
}
kernel vec4 perlin(sampler PerlinPermutation,float XScale,float YScale,float Time)
{
sampler p = PerlinPermutation;
vec2 dc = destCoord();
float x = dc.x*XScale,
y = dc.y*YScale,
z = Time;
int X = mod(floor(x),256.),
Y = mod(floor(y),256.),
Z = mod(floor(z),256.);
float Xf=X,Yf=Y,Zf=Z;
x -= floor(x);
y -= floor(y);
z -= floor(z);
float u = fade(x),
v = fade(y),
w = fade(z);
float A = sample(p,vec2(mod(Xf ,256.),0.)).r*255.0+Yf,
AA = sample(p,vec2(mod(A ,256.),0.)).r*255.0+Zf,
AB = sample(p,vec2(mod(A+1. ,256.),0.)).r*255.0+Zf,
B = sample(p,vec2(mod(Xf+1.,256.),0.)).r*255.0+Yf,
BA = sample(p,vec2(mod(B ,256.),0.)).r*255.0+Zf,
BB = sample(p,vec2(mod(B+1. ,256.),0.)).r*255.0+Zf;
return vec4(vec3(
mix( mix( mix( grad(sample(p,vec2(mod(AA ,256.),0.)).r*255.0, x , y , z ),
grad(sample(p,vec2(mod(BA ,256.),0.)).r*255.0, x-1., y , z ),u),
mix( grad(sample(p,vec2(mod(AB ,256.),0.)).r*255.0, x , y-1., z ),
grad(sample(p,vec2(mod(BB ,256.),0.)).r*255.0, x-1., y-1., z ),u),v),
mix( mix( grad(sample(p,vec2(mod(AA+1.,256.),0.)).r*255.0, x , y , z-1. ),
grad(sample(p,vec2(mod(BA+1.,256.),0.)).r*255.0, x-1., y , z-1. ),u),
mix( grad(sample(p,vec2(mod(AB+1.,256.),0.)).r*255.0, x , y-1., z-1. ),
grad(sample(p,vec2(mod(BB+1.,256.),0.)).r*255.0, x-1., y-1., z-1. ),u),v),w)
)/2.0+0.5,1.);
}
==============tb_randomGradients=============================
tb_randomGradients (CIFilter)
/* Kernel functions for random gradient effects toneburst 2009
http://machinesdontcare.wordpress.com
*/
kernel vec4 combineChannels(sampler ImageR, sampler ImageG, sampler ImageB)
{ float R = sample(ImageR, samplerCoord(ImageR)).r;
float G = sample(ImageG, samplerCoord(ImageG)).r;
float B = sample(ImageB, samplerCoord(ImageB)).r;
return vec4(R, G, B, 1.0);
}
kernel vec4 multiplyChannels(sampler ImageR, sampler ImageG, sampler ImageB)
{ float R = sample(ImageR, samplerCoord(ImageR)).r;
float G = sample(ImageG, samplerCoord(ImageG)).r;
float B = sample(ImageB, samplerCoord(ImageB)).r;
float shade = R * G * B;
return vec4(vec3(shade), 1.0);
}
================================
/* Random gradients, 3 variations toneburst 2009
http://machinesdontcare.wordpress.com
*/
function __image main(__boolean Trigger, __index Type)
{ var dims = new Vec(256,256); // Setup variables
var gradDims = new Vec(0,0,dims.x,dims.y);
var black = new Vec(0,0,0,1);
var white = new Vec(1,1,1,1);
var p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);// First gradient
var p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
var gradR = Filter.CILinearGradient(p0, p1, black, white);
gradR = Filter.CICrop(gradR, gradDims);
if(Type == 0) // Choose gradient-type
{ return gradR; // Greyscale, single gradient
} else // Create other 2 gradients
{ p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
var gradG = Filter.CILinearGradient(p0, p1, black, white);
gradG = Filter.CICrop(gradG, gradDims);
p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
var gradB = Filter.CILinearGradient(p0, p1, black, white);
gradB = Filter.CICrop(gradB, gradDims);
switch(Type) // Choose variation
{ case 1: // Greyscale, 3 gradients multiplied
return multiplyChannels.apply(gradR.definition, null, gradR, gradG, gradB);
break;
case 2: // Random RBG gradients
return combineChannels.apply(gradR.definition, null, gradR, gradG, gradB);
break;
}
}
}
==============perlin=============================
vec4 smoothNoise(sampler noise, float x, float y)
{ return sample(noise, vec2(x, y));
}
vec4 interpolateCosine(vec4 a, vec4 b, float x)
{ float ft = x * 3.1415927;
float f = (1.0 - cos(ft)) * .5;
return a*(1.0-f) + b*f;
}
vec4 interpolateLinear(vec4 a, vec4 b, float x)
{ return a*(1.0-x) + b * x;
}
vec4 interpolatedNoise(sampler noise, vec2 pt)
{ float wholeX = floor(pt.x);
float fractX = fract(pt.x);
float wholeY = floor(pt.y);
float fractY = fract(pt.y);
vec4 v1 = smoothNoise(noise, wholeX, wholeY);
vec4 v2 = smoothNoise(noise, wholeX + 1.0, wholeY);
vec4 v3 = smoothNoise(noise, wholeX, wholeY + 1.0);
vec4 v4 = smoothNoise(noise, wholeX + 1.0, wholeY + 1.0);
vec4 i1 = interpolateCosine(v1, v2, fractX);
vec4 i2 = interpolateCosine(v3, v4, fractX);
return interpolateCosine(i1, i2, fractY);
}
kernel vec4 perlin(sampler noise, float persistence, float brightness)
{ vec2 pt = samplerCoord(noise);
vec4 total = vec4(0.0, 0.0, 0.0, 0.0);
int octaves = 3;
for (int i = 0; i < octaves; i++)
{ float fi = i;
float frequency = pow(2.0, fi);
float amplitude = pow(persistence, fi);
total = total + interpolatedNoise(noise, vec2(pt.x * frequency, pt.y * frequency)) * (amplitude);
}
total += brightness;
return total;
}
==============compositor========================
/*
This kernel takes the current contents of the accumulator,
fade it out by multiplying it by "factor" (a value lower than 1.0)
and eventually add the star shine image. The resulting image is then put back into the accumulator.
*/
kernel vec4 compositor(sampler starImage, sampler accumImage, float factor)
{ vec4 a = sample(accumImage, samplerCoord(accumImage));
vec4 i = sample(starImage, samplerCoord(starImage));
return a * factor + i;
}
==============HUE_Gradient===========
================HueGradV======================
vec4 hsv2rgb(vec4 color)
{ float h = color.r;
float s = color.g;
float v = color.b;
float i = floor( h*6.0 );
float f = h*6.0 -i ;
float p = v * ( 1.0 - s );
float q = v * ( 1.0 - s*f );
float t = v * ( 1.0 - s*( 1.0 - f ) );
float r = (i == 0.0 ? v :
(i == 1.0 ? q :
(i == 2.0 ? p :
(i == 3.0 ? p :
(i == 4.0 ? t : v )))));
float g = (i == 0.0 ? t :
(i == 1.0 ? v :
(i == 2.0 ? v :
(i == 3.0 ? q :
(i == 4.0 ? p : p )))));
float b = (i == 0.0 ? p :
(i == 1.0 ? p :
(i == 2.0 ? t :
(i == 3.0 ? v :
(i == 4.0 ? v : q )))));
return vec4(r, g, b, color.a);
}
kernel vec4 HueGradV(sampler image)
{ vec2 image_size = samplerSize(image);
vec2 pixel_coord = samplerCoord(image);
vec4 pixel = sample(image, pixel_coord);
float sat = 1.0;
float lum = 1.0;
float h = 1.0*pixel_coord.y/image_size.y;
h = mod(h,1.0);
vec4 pix = vec4(h, sat, lum,pixel.a);
return hsv2rgb( pix );
}
==============HUE_ADJUST===========
Hue_Adjust
========================================
vec4 rgb2hsl(vec4 color)
{ float MAX = max(color.r, max(color.g, color.b));
float MIN = min(color.r, min(color.g, color.b));
MAX = max(MIN + 1e-6, MAX);
float l = MAX;
float s = (MAX < 0.01 ? 0.0 : (MAX - MIN) / MAX);
float h = (MAX == color.r ? (color.g - color.b) / (MAX - MIN) :
(MAX == color.g ? 2.0 + (color.b - color.r) / (MAX - MIN) :
4.0 + (color.r - color.g) / (MAX - MIN)));
h = h/6.0;
h = (h < 0.0 ? 1.0 + h : h);
return vec4(h, s, l, color.a);
}
vec4 hsv2rgb(vec4 color)
{ float h = color.r;
float s = color.g;
float v = color.b;
float i = floor( h*6.0 );
float f = h*6.0 -i ;
float p = v * ( 1.0 - s );
float q = v * ( 1.0 - s*f );
float t = v * ( 1.0 - s*( 1.0 - f ) );
float r = (i == 0.0 ? v :
(i == 1.0 ? q :
(i == 2.0 ? p :
(i == 3.0 ? p :
(i == 4.0 ? t : v )))));
float g = (i == 0.0 ? t :
(i == 1.0 ? v :
(i == 2.0 ? v :
(i == 3.0 ? q :
(i == 4.0 ? p : p )))));
float b = (i == 0.0 ? p :
(i == 1.0 ? p :
(i == 2.0 ? t :
(i == 3.0 ? v :
(i == 4.0 ? v : q )))));
return vec4(r, g, b, color.a);
}
kernel vec4 rotHue(sampler image, float angle)
{ vec4 pixel = sample(image, samplerCoord(image));
vec4 huePix = rgb2hsl(pixel);
float h = huePix.r + angle;
h = mod(h , 1.0);
vec4 pix = vec4(h, huePix.g, huePix.b,huePix.a);
return hsv2rgb( pix );
}
==================HUE_MATH=================================================
function rgbToHsv(r, g, b)
{ r = r/255, g = g/255, b = b/255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, v = max;
var d = max - min;
s = max == 0 ? 0 : d / max;
if(max == min)
{ h = 0; // achromatic }else
{ switch(max){
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [h, s, v];
}
function hsvToRgb(h, s, v)
{ var r, g, b;
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
switch(i % 6)
{ case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
return [r * 255, g * 255, b * 255];
}
======================FourCorners=================
Needs work
kernel vec4 FourCorner(
sampler input_image,
vec2 LT,
vec2 LB,
vec2 RT,
vec2 RB)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
float SlopeL = (LT.x-LB.x)/(1.0-LB.y-LT.y);
float Xlb = LB.x -SlopeL*LB.y;
float Xlt = LT.x +SlopeL*LT.y;
float SlopeR = (RT.x-RB.x)/(1.0-RB.y-RT.y);
float Xrb = RB.x -SlopeR*RB.y;
float Xrt = RT.x +SlopeR*RT.y;
float SlopeB = (RB.y-LB.y)/(1.0-LB.x-RB.x);
float Ylb = LB.y -SlopeB*LB.x;
float Yrb = RB.y +SlopeB*RB.x;
float SlopeT = (RT.y-LT.y)/(1.0-LT.x-RT.x);
float Ylt = LT.y -SlopeT*LT.x;
float Yrt = RT.y +RT.x*SlopeT;
float FromBot = (pixel_coord.y/image_size.y);
float FromTop = 1.0-FromBot;
float FromLeft = (pixel_coord.x/image_size.x);
float FromRight = 1.0 -FromLeft;
float x_gain = 1.0 -(Xrt+Xlt)*FromBot - (Xrb+Xlb)*FromTop;
float x_offset = -image_size.x*(Xlt*FromBot +Xlb*FromTop);
float y_gain = 1.0 - (Yrt +Yrb)*FromLeft - (Ylt +Ylb)*FromRight;
float y_offset = -image_size.y*(+Yrb*FromLeft+Ylb*FromRight);
pixel_coord.x = pixel_coord.x/(x_gain) + x_offset/(x_gain);
pixel_coord.y = pixel_coord.y/(y_gain) + y_offset/(y_gain);
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
kernel vec4 LeftTop(
sampler image,
float LTx
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
pixel_coord.x = pixel_coord.x*(1.0-LYx)*pixel_coord.y/image_size.y;
vec4 pixel = sample(input_image, pixel_coord);
return vec4(clamp(pixel, 0.0, 1.0));
}
======================Kernel_SHift=================
kernel vec4 ShiftHoz(
sampler image,
float LTx)
{
vec2 image_size = samplerSize(image);
vec2 pixel_coord = samplerCoord(image);
pixel_coord.x = pixel_coord.x -LTx*pixel_coord.y/image_size.y;
vec4 pixel = sample(image, pixel_coord);
return pixel;
}
kernel vec4 ShiftVert(
sampler image,
float LTy)
{
vec2 image_size = samplerSize(image);
vec2 pixel_coord = samplerCoord(image);
pixel_coord.y = pixel_coord.y -LTy*pixel_coord.x/image_size.x;
vec4 pixel = sample(image, pixel_coord);
return pixel;
}
========Bézier Curve===========
A cubic Bezier curve is defined by four points.
Two are endpoints. (x0,y0) is the origin endpoint.
(x3,y3) is the destination endpoint.
The points (x1,y1) and (x2,y2) are control points.
Two equations define the points on the curve.
Both are evaluated for an arbitrary number of values of t between 0 and 1.
One equation yields values for x, the other yields values for y.
As increasing values for t are supplied to the equations,
the point defined by x(t),y(t) moves from the origin to the destination.
===========t.txt===================
only numbers below
t x0 y0 x1 y1 x2 y2 x3 y3
==================================
0, 0, 0, .5, 0, .5, 1, 1, 1*
1, 1, 1, 1, 1, 10, 1, 10, 1*
10, 1, 1, 1, 1, 10, 1, 10, 1*
Two are endpoints. (x0,y0) is the origin endpoint. (x3,y3) is the destination endpoint.
The points (x1,y1) and (x2,y2) are control points.
var cx = 3*(x1 - x0)
var bx = 3*(x2 - x1) - cx
var ax = x3 - x0 - cx - bx
var cy = 3*(y1 - y0)
var by = 3*(y2 - y1) - cy
var ay = y3 - y0 - cy - by
var X = ax*t*t*t + bx*t*t + cx*t + x0
var Y = ay*t*t*t + by*t*t + cy*t + y0
===============JAVASCRIPT_DETAILS=============================
===============Persistent Memory===========================
Variables with var token are local and destroyed each iteration
use Math or Object objects to get persistent memory
Just add variables initialize as parameters to the object
if (Object.x == undefined) //initialize only once
{ Object.x = new Array(2); //create array variable
Object.x[0] = 0;
Object.x[1] = 0;
}
Object.name = "My Name" //re-initialized with each iteration
Object.x[0] += inputs[0]; //running total of input
with(Object)
{ outputs[0] = x[0];
outputs[1] = name;
}
============The main() function==============================
var i = 0; // i is a persistent global variable
function (
__string biography,
__number contestantNumber)
main (
__string name,
__number age,
__boolean canWhistle)
{ i++;
var result = new Object();
result.biography = "Contestant number " + i + " is " + name +
", who is " + age + " years old" + whistlingSummary(canWhistle);
result.contestantNumber = i;
return result;
}
function whistlingSummary
(__boolean canWhistle)
{ if (canWhistle)
{ return " and can whistle";
} else
{ return " but can't whistle";
}
}
================Types for all variables==========================
__boolean A simple boolean variable, evaluating to true or false
__index An integer number
__number Any number
__string A string
__image cannot do pixel processing but dime using .extent.width and .extent.height
__structure Array objects, .length, anArray[3], anArray.propertyName (keyed structures)
__virtual A metatype
================Types for all variables==========================
Booleans
function (__boolean boolOutput) main (__number a, __number b)
{ var result = new Object();
if (a > b)
result.boolOutput = true;
else
result.boolOutput = false;
return result;
}
Indexes
var count = 0;
function (__index indexOutput) main (__number ignored)
{ var result = new Object();
result.indexOutput = count;
count = count + 1;
return result;
}
Structures as Array.
function (__number outputNumber) main (__number inputNumber[2])
{ var result = new Object();
result.outputNumber = inputNumber[0] + inputNumber[1];
return result;
}
inputNumber is an array with 2 items, 0 and 1.
Structures as Objects use "keys".
A key is a string or a number.
Instead of using myArray[0],
you could use myArray["something"], where "something" is the "key".
So in Javascript, there are 2 ways to make structures:
var aStructure = new Array();
var anotherStructure = new Object();
var keyStructure = new Object();
keyStructure.cool = "42"; // we can do myStructure TheKeyName = something
keyStructure["rad"] = "4242"; //or we can do myStructure[TheKeyName]
you can also put Objects inside Objects.
var myStructure = new Object();
myStructure.something = new Object();
myStructure.something.amazing = new Object();
myStructure.something.amazing.here = "yes";
==============RETURN MULTIPLE VALUES============================
function (
__string message,
__number phoneNumber)
main ()
{ myResult = new Object;
myResult.message = "Hello World";
myResult.phoneNumber = 5551234;
return myResult;
}
==========================================
_testMode
Your JavaScript code is always executed first in a test mode
which is used to check the syntax of your code.
In test mode, the global variable _testMode equals true
and all inputs to your main() function will be null.
This means that any processing of inputs that are beyond simple types
(eg. iterating over a structure) will fail.
To handle this, check that _testMode is false before doing anything advanced:
===============KERNEL_FUNCTIONS=============================
vec4 premultiply (vec4_color_rgba) // Multiplies rgb by alpha
vec4 unpremultiply (vec4_color_rgba) // If alpha < 0, div rgb by alpha.
vec4 sample (image , vec2_point_xy ) // Returns pixel rgb at xy image
vec2 samplerCoord (image) // Returns current pixel x/y of output pixel
vec2 samplerTransform (image, vec2_point_xy ) // Returns position after transformation applied.
vec2 destCoord () // Returns current pixel x/y of destination
float dot (vec3_v1, vec3_v2) // Returns dot product x[0]•y [0]?x [1]•y[1]?...
vec3 cross (vec3_v1, vec3_v2) // Returns the cross product of x and y, i.e.
float distance (point0, point1) // Returns the distance between p0 and p1, i.e.
float length (vector0) // Returns the length of vector0
genType normalize (vector0) // Returns a vector in the same direction but with a length of 1.
vec4 samplerExtent (image ) // sampler's world coordinates, as [x, y, width, height].
vec2 samplerOrigin (image ) // Equivalent to samplerExtent (src).xy.
vec2 samplerSize (image ) // gets w/h_size of image
float radians (degrees) // Converts degrees to radians, i.e. .180 •degrees
float degrees (radians) // Converts radians to degrees, i.e.180
float sin (angle) // The standard trigonometric sine function.
float cos (angle) // The standard trigonometric cosine function.
float tan (angle) // The standard trigonometric tangent.
float asin (x) // Arc sine. Returns an angle whose sine is x. The range
float acos (x) // Arc cosine. Returns an angle whose cosine is x. The
float atan (y,x) // Arc tangent. Returns an angle whose tangent is y/x. The
float atan (y_over_x)
float pow (x, y) // Returns x raised to the y power, i.e., xy
float exp (x) // Returns the natural exponentiation of x, i.e., ex.
float log (x) // Returns the natural logarithm of x, i.e., returns the value
float exp2 (x) // Returns 2 raised to the x power, i.e., 2x
float log2 (x) // Returns the base 2 logarithm of x, i.e., returns the value
float sqrt (x) // Returns . x .
float inversesqrt (x) // Returns 1/sqrt(x)
float floor (x) // Returns a value equal to the nearest integer that is less
float ceil (x) // Returns a value equal to the nearest integer that is
float fract (x) // Returns x – floor (x)
float mod (x, y) // Modulus. Returns x – y * floor (x/y)
float mod (x, y) // Modulus. Returns x – y * floor (x/y)
float min (x, y)
float min (x, y) // Returns y if y < x, otherwise it returns x
float max (x, y)
float max (x, y) // Returns y if x < y, otherwise it returns x.
float clamp (x, minVal, maxVal)
float clamp (x, minVal, maxVal) // Returns min (max (x, minVal), maxVal)
float mix (x, y, a)
float mix (x, y, a) // Returns the linear blend of x and y, i.e.
float step (edge, x)
float step (edge, x) // Returns 0.0 if x < edge, otherwise it returns 1.0
float smoothstep (edge0, edge1, x) // Returns 0.0 if x <= edge0,1.0 if x >= edge1,smooth transition
genType compare (x, y, z) // For each component, returns x < 0 ? y : z.
===============KERNEL_FUNCTIONS_EXAMPLES=============================
float input_pos = clamp(position,0.0,1.0);
vec2 image_size = samplerSize(input_image);
vec2 image_xy = samplerCoord(input_image);
vec4 image_rgba0 = unpremultiply(sample(input_image, samplerCoord(input_image)));
vec2 image_size = samplerSize(input_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 pixel_coord = samplerCoord(input_image);
vec2 maxel_coord = samplerCoord(mask_image);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
vec2 normal_coord = mod(pixel_coord,box_size)/box_size;
vec2 mask_coord = normal_coord*mask_size;
vec4 pixel = sample(input_image, box_coord);
vec4 maxel = sample(mask_image, mask_coord);
pixel.a = clamp((maxel.x+maxel.y+maxel.z)/3.0,0.0,1.0);
float subdivisions = int(input_subdivisions/2.0);
vec2 mask_coord = normal_coord*mask_size;
float xx = dot(rotate_x, pixel_xy);
float dist_top = abs(pixel_coord.y-0.0);
float cos_theta = cos(theta);
float sin_theta = sin(theta);
float radius = dr_normal*max(image_size.x, image_size.y);
float dist_vector = distance(vector1,vector2);
const float M_PI = 3.14597;
float val = sin( M_PI*x )
float val = pow( x, power )
float val = sqrt( x )
float val = clamp( x, 0.0,1.0 )
float val = max( x1, x2 )
float val = smoothstep( max(l1,0.0), min(l2, 1.0), fValue )
vec2 image_size = samplerSize(input_image);
vec2 box_size = floor(image_size/subdivisions);
vec2 box_coord = mod(pixel_coord,box_size)*subdivisions;
float distan_vec = distance(vector1,vector2);
vec4 newpix = compare(pix - thresh, foregroundPix, backgroundPix);
vec2 pos = destCoord();
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, box_coord);
pixel.a = compare(v.x - radius, smoothstep(0., radius, v.x) * pixel.a, pixel.a);
vec2 pos = destCoord();
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, box_coord);
pixel.a = compare(v.x - radius, smoothstep(0., radius, v.x) * pixel.a, pixel.a);
vec4 pixels = vec4(0.5, 0.25, 0.5, 0.5);
pixels *= 2.0; // will result in "pixels" having the value (1.0, 0.5, 1.0, 1.0).
vec2 for (x, y) coordinates,
vec4's for (a, r, g, b) values, "a" being an alpha (transparency) channel.
Coordinate Spaces (0,0) at center of output window, 1.0 being the standard width.
Working Coordinates 1 unit is 1 pixel. , images exist in-infinitely large board
Sampler Coordinates 1 unit is 1 pixel. (0,0) bottom left , Only seen inside kernels
destCoord () current output point, in working coordinate space.
sample () needs coordinates space of sampler object, not in the working coordinate space
samplerTransform (x, p) working space point p, mapped into coordinate space of sampler x
samplerCoord(x) current output point, mapped into coordinate space of sampler x,
equivalent to samplerTransform (x, destCoord ())
If you want to forget all these details, create a new sampling function,
then just use working space coordinates everywhere:
vec4 sampleWorking (sampler x, vec2 p) {
return sample (x, samplerTransform (x, p));
}
===============KERNEL_PROGRAMING=============================
1)kernel will be called once for each **output** pixel, not for each input pixel, return a single vec4 for each output pixel.
2)only one image output (the return value of "vec4" from the kernel).
3)kernel's job for each output pixel to sample any input pixels it needs, can have any number of images
4)( The "? :" operator ) will NOT produce correct results for vector values. use "compare" instead,
5)cannot use "for" or "if" on any input values.
5)control (if, for, while, do while) supported only when loop condition inferred at compile.
5)kernel does not take images as input parameters, takes a sampler object associated with image.
5)All sampler objects set up as CISampler objects in Objective-C.
5)restricted to Core Image Kernel Language (CIKL) is a subset of OpenGL Shading Language (glslang),
5)kernel routine computes output pixel by inverse mapping back to corresponding pixels of input images.
5)A routine is faster if you unroll loops.
5)region of interest (ROI) is area of sampler source data that your kernel uses for per-pixel processing.
5)If mapping between source and the destination not one-to-one, define ROI in Objective-C filter file.
5)ROI method use following form: - (CGRect) regionOf:(int)samplerIndex destRect:(CGRect)r userInfo:obj;
============================================
Listing 3-1 A multipass filter that uses Core Image filters
// Assume myKernel is a routine defined in the top window.
// This code is the main function defined in the bottom window.
function __image main (__image image, __vec4 color){
var image1, image2;
var transform;
image1 = myKernel.apply(image.extent, null, image); // Apply the kernel that's defined in the top window.
image2 = Filter.sepiaTone(image1, 1.0); // Apply the Core Image Sepia filter.
transform = new AffineTransform().scale(0.5); // Set up and apply a transform
return Filter.affineTransform(image2,transform);
}
QC Show/Hide Private Patches
Run from Terminal:
defaults write -g QCShowPrivatePatches 1
defaults write -g QCShowPrivatePatches 0
hide patch private qc quartz composer show
QC 3.1 Patch Install Location
Quartz Composer 3.1 patch install location:
/Library/Graphics/Quartz Composer Patches/
~/Library/Graphics/Quartz Composer Patches/
and NOT
/Library/Graphics/Quartz Composer Plug-Ins/
~/Library/Graphics/Quartz Composer Plug-Ins
qc quartz composer