Not as easy as it looks.
Getting started
First, think of a way to get the same results without writing an external. For example, borrow other code, use javascript, gen, Processing, or MSPaint.
Apparently that didn’t work out. Well I can only get you so far.
Assuming that you have already done the following
Learn how to write non-Jitter externals:
Edit the examples
Currently the Jitter examples in the SDK are in the folders: examples/matrix and examples/gl. We’ll pretend we didn’t see GL.
Here’s a sensible approach on Mac OS.
- Duplicate the example folder: jit.clip and rename the duplicate to something like jit.cliptz
- Inside jit.cliptz open the Xcode project
- Rename the Xcode project while in Xcode by single-clicking on the project name and editing it.
- Now feel free to alter the code in any way. Look in jit.clip.c
In jit.clip.c, find the functions starting with
void jit_clip_vector_char(long n, t_jit_clip_vecdata *vecdata, t_jit_op_info *in, t_jit_op_info *out)
These are functions that processing the matrix vectors for char, long, and float matrixes respectively. We’ll work with the char function.
Change the code so that the pixel values are inverted as well as clipped by subtracting pixel values from 255.
Change two lines of code, marked here by the comment: // invert
if ((is==1)&&(os==1)) {
++n;--op;--ip;
while (--n) {
tmp = *++ip;
*++op = 255 - tmp>max?max:tmp<min?min:tmp; // invert
}
} else {
while (n--) {
tmp = *ip;
*op = 255 - tmp>max?max:tmp<min?min:tmp; // invert
ip+=is;op+=os;
}
}
- Clean and build the project.
- The .mxo file will be under the Products folder. <Ctrl> click to show in finder
- Copy the .mxo file into the same folder as your Max patch
- What Max patch? This one:
The window on the left is inverted because its getting that way in the object we just hacked.
That’s all
I didn’t really explain anything. Sometimes going through the motions is a start. If I had to do this for a living I would find the example that is most like a desired result and hack away.
Download
https://github.com/tkzic/max-projects
folder: jitter-dev
files:
- test-object.maxpat
- jit.cliptz.mxo (external) you will make your own version of this in Xcode