2 summary:: filter class to use with SCImage
4 related:: Classes/SCImage, Classes/SCImageKernel
8 currently this class represents the CoreImage Filters you can apply to a SCImage. All the built-in filters and docs: http://developer.apple.com/documentation/GraphicsImaging/Reference/CoreImageFilterReference/Reference/reference.html
12 PRIVATE::prFilterSet, prGetFilterAttributes, initClass, prGetFilterNames
16 f = SCImageFilter.new(\CIStarShineGenerator);
19 // or you can do also Synth like style if you already know the attributes of this synth
20 f = SCImageFilter.new(\CIStarShineGenerator, [\center, [200,200], \radius, 200*0.05]);
25 The filter name link::Classes/Symbol:: or link::Classes/String::
28 The filter name link::Classes/Symbol:: or link::Classes/String::
30 METHOD::filterCategories
31 Returns a Dictionary containing all the filters associated by categories.
33 // getting filter categories (dictionary)
35 SCImageFilter.filterCategories.keysDo({|cat|
41 // getting Filters for a category - returns a SymbolArray
42 SCImageFilter.filterCategories.at(\CICategoryGeometryAdjustment);
43 SCImageFilter.filterCategories.at(\CICategoryGenerator);
45 // finding Non Built In Plugins usually plugins loaded in (/Library/Graphics/Image Units/)
46 // all plugins are loaded at startup
47 // you can find free plugins at http://www.noiseindustries.com/products/
50 SCImageFilter.filterCategories.do ({
52 symbolArray.do ({|pluginName|
53 if(pluginName.asString.beginsWith("CI").not, {
54 ("External Filter Found: " ++ pluginName).postln;
59 (n + "plugins found").postln;
66 PRIVATE::prAttributeRange, doesNotUnderstand
69 returns an link::Classes/IdentityDictionary:: containing for each association:
71 ## the attribute/property name as the key.
72 ## the supercollider link::Classes/Class:: you should use as an argument to set the attribute.
74 Once you know the attributes you can set them like using normal instance setters, use the name and append '_'.
77 f = SCImageFilter.new(\CIStarShineGenerator);
78 f.attributes.keysValuesDo({|k, v|
79 ("CIStarShineGenerator responds to "++k.asString++"_("++v.asString++")").postln;
87 METHOD::attributeRange
88 get the numerical range and the default Value for an attribute. returns an Array as code::[ min, max, default ]::. min, max, or default may be a link::Classes/Float::, a link::Classes/Color::, an link::Classes/Array:: or link::Classes/Nil::.
91 f = SCImageFilter.new(\CIFlashTransition);
97 f.attributeRange(\time);
99 // getting all attributes MIN - MAX possible values
101 f.attributes.keysDo({|attr|
102 (attr ++ " = " + f.attributeRange(attr)).postln; // nil results means there is no min max for those attributes
108 returns all the values you setted for each attributes. If a value is not explicitely setted for an attribute, it will be set to default when applied to the SCImage.
111 f = SCImageFilter.new(\CIStarShineGenerator);
112 f.center_([200,200]);
114 f.color_(Color.blue);
117 f.crossOpacity_(-4.0);
123 set the attributes for this SCImageFilter
126 f = SCImageFilter.new(\CIStarShineGenerator);
127 f.set(\center, [200,200], \radius, 200*0.05, \color, Color.blue, \crossWidth, 2.0);
133 enable or not the Filter when applied to a SCImage.
136 If this is false, applying the filter will do nothing.
141 // thor's fast experimentation request
142 // example with the filters array wich allows you to use filters without applying them in place
143 // convenient for RT use / test or whatever...
145 // here scale down the image otherwise with the zoomblur it will take your computer
146 // to its knees using addFilter and not applyFilter
147 // kinda fast swapping test
149 a = SCImage.new("/Library/Desktop Pictures/Plants/Peony.jpg").scalesWhenResized_(true).setSize(500, 400);
150 a.plot; // look at me first - i am beautiful
152 // but i want you to be posterize
154 h = SCImageFilter.new(\CIColorPosterize);
155 a.addFilter(h); // first call needed
156 a.plot; // there should have it
159 // then you can freely access and set the slot directly - easier
161 a.filters[0] = SCImageFilter.new(\CIColorInvert);
167 a.filters[0] = SCImageFilter.new(\CIZoomBlur);
173 a.filters[0] = SCImageFilter.new(\CIRandomGenerator);
179 a.plot(freeOnClose:true);
183 // ** Masking Example **
185 f = SCImageFilter.new(\CIColorMonochrome); // create a GrayScale image
186 g = SCImageFilter.new(\CISourceInCompositing); // compositing we will use
187 f.color_(Color.black);
189 a = SCImage.new(SCDoc.helpSourceDir +/+ "images/vduck2.jpg");
191 b = SCImage.new(SCDoc.helpSourceDir +/+ "images/flowers2.jpg");
192 a.applyFilters([f, SCImageFilter(\CIColorInvert), SCImageFilter(\CIMaskToAlpha)]); // grayscale + invert + maskToAlpha = create a mask
193 g.backgroundImage_(a); // set up background image
194 b.applyFilters(g); // create masked image
196 w = b.plot(freeOnClose:true, background:Color.clear); // set to clear color to see plainly the image
200 // *** Kinda very simple real time FX using the .filters property of SCImage **
201 // SCImage.filters provides a way to set up filters to apply in the rendering chain
202 // this can be useful to modify in RT some filter properties
203 // but they won't be processed inplace, they will be computed at each rendering
204 // here the filter calc is performed at each rendering call
205 // so this is convenient but not optimal
208 var width=500, height=500, centerVector;
209 var controller, specs;
211 centerVector = [width*0.5, height*0.5];
212 a = SCImage.new(500@500);
213 a.accelerated_(true);
214 f = SCImageFilter.new(\CIStarShineGenerator);
215 g = SCImageFilter.new(\CIPixellate);
216 h = SCImageFilter.new(\CIZoomBlur);
218 f.center_(centerVector);
219 f.radius_(width*0.05);
220 f.color_(Color.green);
223 f.crossOpacity_(-4.0);
224 g.center_(centerVector);
225 h.center_(centerVector);
228 // simple example control
230 [f, \crossOpacity_, [-8, 0].asSpec, -4],
231 [f, \crossAngle_, [-pi, pi].asSpec, 0.0],
232 [h, \amount_, [0, 200].asSpec, 50],
234 ]; // CIStarShine opacity, CIZoomBlur
236 controller = SCWindow.new("Close Me First !!!", Rect(400,400,300,specs.size * 40));
237 controller.view.decorator = FlowLayout(controller.view.bounds.insetBy(10), 10@10);
239 SCSlider.new(controller, Rect(0,0,150,20))
241 specs[i][0].perform(specs[i][1], specs[i][2].map(obj.value));
244 .value_(specs[i][2].unmap(specs[i][3]));
245 controller.view.decorator.nextLine;
253 a.filters.do {|filt, i|
255 SCButton.new(controller, Rect(0,0,20,20))
257 filt.enable_(obj.value != 1);
260 .states_([["", Color.white], ["", Color.white, Color.black]]);
265 w = a.plot(background:Color.black);
267 controller.onClose_({
276 // ******** Using EXTERNAL NI Image Units Generator + FX *******
277 // Download them --- MIGHT BE 10.5 Only so
278 // http://www.noiseindustries.com/downloads/Units.dmg
279 // When using for the first time an Image plugin, it might take some extra time due to the plugin loading
282 f = SCImageFilter.new(\NINoiseGenerator);
283 f.width_(500); f.height_(500);
285 a = SCImage.new(500@500);
287 w = a.plot(freeOnClose:true, background:Color.black);
292 f = SCImageFilter.new(\NIDropShadow);
296 f.shadowColor_(Color.red);
297 a = SCImage.new("vduck2.jpg");
298 a.applyFilters(f, a.bounds.outsetBy(500));
299 w = a.plot(freeOnClose:true, background:Color.clear);
304 f = SCImageFilter.new(\NIDotsGenerator);
306 a = SCImage.new(500@500);
308 w = a.plot(freeOnClose:true, background:Color.black);
312 f = SCImageFilter.new(\NICircle);
313 a = SCImage.new(500@500);
315 w = a.plot(freeOnClose:true);