summaryrefslogtreecommitdiffstats
path: root/doc/chalk/developers-scripting.docbook
blob: fec163db7f2fcc45367b6701b4fde4d1a8575a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<sect1 id="developers-scripting">
<title>Scripting</title>

<para>
In &chalk;, you can write scripts in Ruby or Python (the availability of the
interpreters might depend on what your distributions or the administrator of
your machine did install). Here you will find a description of the scripting
API.
</para><para>
Some examples are distributed with &chalk;, and you might find them in
<filename>/usr/share/apps/chalk/scripts</filename> (or
<filename>/opt/kde/share/apps/chalk/scripts</filename>).
</para>

<sect2 id="developers-scripting-variables">
<title>Variables in the <classname>Krosschalkcore</classname> module</title>

<itemizedlist>
<listitem><para><varname>ChalkDocument</varname> returns a
<classname>Document</classname> object</para></listitem>
<listitem><para><varname>ChalkScript</varname> returns a
<classname>ScriptProgress</classname> object</para></listitem>
</itemizedlist>

<para>
You can retrieve an object using the <function>get</function> function of the
<classname>Krosschalkcore</classname> module, in Ruby you will have to write something like that:
<programlisting>
doc = Krosschalkcore::get("ChalkDocument")
script = Krosschalkcore::get("ChalkScript")
</programlisting>
</para>

</sect2>

<sect2 id="developers-scripting-functions">
<title>Functions in the <classname>Krosschalkcore</classname> module</title>

<itemizedlist>
<listitem><para>Function: <function>getBrush</function></para><para>
This function returns a <classname>Brush</classname> taken from the list of
&chalk; resources. It takes one argument: the name of the brush.
For example (in Ruby):
<programlisting>
Krosschalkcore::getBrush("Circle (05)")
</programlisting></para></listitem>

<listitem><para>Function: <function>getFilter</function></para><para>
This function returns a <classname>Filter</classname> taken from the list of
&chalk; resources. It takes one argument: the name of the filter.
For example (in Ruby):
<programlisting>
Krosschalkcore::getFilter("invert")
</programlisting></para></listitem>

<listitem><para>Function: <function>getPattern</function></para><para>
This function returns a <classname>Pattern</classname> taken from the list of
&chalk; resources. It takes one argument: the name of the pattern.
For example (in Ruby):
<programlisting>
Krosschalkcore::getPattern("Bricks")
</programlisting></para></listitem>

<listitem><para>Function: <function>loadBrush</function></para><para>
This function loads a <classname>Brush</classname> and then returns it.
It takes one argument: the filename of the brush.</para></listitem>

<listitem><para>Function: <function>loadPattern</function></para><para>
This function loads a <classname>Pattern</classname> and then returns it.
It takes one argument: the filename of the pattern.</para></listitem>

<listitem><para>Function: <function>newCircleBrush</function></para><para>
This function returns a <classname>Brush</classname> with a circular shape. It
takes at least two arguments: width and height. It can take two other
arguments: width of the shading, and height of the shading. If the shading
is not specified, no shading will be used.
For example (in Ruby):
<programlisting>
Krosschalkcore::newCircleBrush(10,20) # create a plain circle
Krosschalkcore::newCircleBrush(10,20,5,10) # create a gradient
</programlisting></para></listitem>

<listitem><para>Function: <function>newHSVColor</function></para><para>
This function returns a new <classname>Color</classname> with the given HSV
triplet. It takes three arguments: hue component (0 to 255), saturation
component (0 to 255), value component (0 to 255).

For example (in Ruby):
<programlisting>
Krosschalkcore::newHSVColor(255,125,0)
</programlisting></para></listitem>

<listitem><para>Function: <function>newImage</function></para><para>
This function returns a new <classname>Image</classname>. It takes four arguments:
width, height, colorspace id, name of the image. And in return you get an
<classname>Image</classname> object.
For example (in Ruby):
<programlisting>
Krosschalkcore::newImage(10,20, "RGBA", "kikoo")
</programlisting></para></listitem>

<listitem><para>Function: <function>newRectBrush</function></para><para>
This function returns a <classname>Brush</classname> with a rectangular shape.
It takes at least two arguments: width and height. It can take two other
arguments: width of the shading and height of the shading. If the shading is
not specified, no shading will be used.
For example (in Ruby):
<programlisting>
 Krosschalkcore::newRectBrush(10,20) # create a plain rectangle
 Krosschalkcore::newRectBrush(10,20,5,10) # create a gradient
</programlisting></para></listitem>

<listitem><para>Function: <function>newRGBColor</function></para><para>
This function returns a new <classname>Color</classname> with the given RGB
triplet. It takes three arguments: red component (0 to 255), blue component (0 to
255), green component (0 to 255).
For example (in Ruby):
<programlisting>
Krosschalkcore::newRGBColor(255,0,0) # create a red color
Krosschalkcore::newRGBColor(255,255,255) # create a white color
</programlisting></para></listitem>
</itemizedlist>
</sect2>

<sect2 id="developers-scripting-objects">
<title>Descriptions and function lists for various objects in
<classname>Krosschalkcore</classname></title>

<itemizedlist>
<listitem><para>Object: PaintLayer</para>

<itemizedlist>
<listitem><para>Function: <function>beginPainting</function></para></listitem>

<listitem><para>Function: <function>convertToColorspace</function></para><para>
Convert the image to a colorspace. This function takes one argument: the name
of the destination colorspace.
For example (in Ruby):
<programlisting>
image.convertToColorspace("CMYK")
</programlisting></para></listitem>

<listitem><para>Function: <function>createHistogram</function></para><para>
This function creates a Histogram for this layer. It takes two arguments:
the type of the histogram ("RGB8HISTO"), and 0 if the histogram is linear, or
1 if it is logarithmic.</para></listitem>

<listitem><para>Function: <function>createHLineIterator</function></para><para>
Create an iterator over a layer, it will iterate on a row. This function takes three arguments:
<varname>x</varname> (start in the row), <varname>y</varname> (vertical
position of the row), width of the row.</para></listitem>

<listitem><para>Function: <function>createPainter</function></para><para>
This function creates a <classname>Painter</classname> which will allow you to
paint on the layer. </para></listitem>

<listitem><para>Function: <function>createRectIterator</function></para><para>
Create an iterator over a layer, it will iterate on a rectangular area. This
function takes four arguments: <varname>x</varname>, <varname>y</varname>,
width of the rectangle, height of the rectangle.</para></listitem>

<listitem><para>Function: <function>createVLineIterator</function></para><para>
Create an iterator over a layer, it will iterate on a column. This function
takes three arguments: <varname>x</varname> (horizontal position of the
column), <varname>y</varname> (start in the column), height of the column.</para></listitem>

<listitem><para>Function: <function>endPainting</function></para><para>
This function closes the current undo entry and adds it to the history.</para></listitem>

<listitem><para>Function: <function>fastWaveletTransformation</function></para><para>
Returns the fast wavelet transformation of the layer.</para></listitem>

<listitem><para>Function: <function>fastWaveletUntransformation</function></para><para>
Untransforms a fast wavelet into this layer. It takes one argument: a wavelet
object.
For example (in Ruby):
<programlisting>
wavelet = layer.fastWaveletTransformation()
layer.fastWaveletUntransformation(wavelet)
</programlisting></para></listitem>

<listitem><para>Function: <function>getHeight</function></para><para>
Return the height of the layer.</para></listitem>

<listitem><para>Function: <function>getWidth</function></para><para>
Return the width of the layer.</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>Filter</classname></para>
<itemizedlist>

<listitem><para>Function: <function>getFilterConfiguration</function></para><para>
This function returns the <classname>FilterConfiguration</classname>
associated with this filter.</para></listitem>

<listitem><para>Function: <function>process</function></para><para>
This function will apply the filter. It takes at least one argument: the
source layer. You can also use these four aguments: <varname>x</varname>,
<varname>y</varname>, <varname>width</varname>, <varname>height</varname>.
(<varname>x</varname>,<varname>y</varname>,<varname>width</varname>,<varname>height</varname>)
defines the rectangular area on which the filter
will be computed. If the rectangle is not defined, then the filter will be
applied on the entire source layer.
For example (in Ruby)
<programlisting>
doc = Krosschalkcore::get("ChalkDocument")
image = doc.getImage()
layer = image.getActivePaintLayer()
width = layer.getWidth()
height = layer.getHeight()
filter = Krosschalkcore::getFilter("invert")
filter.process(layer, layer)
filter.process(layer, layer, 10, 10, 20, 20 )
</programlisting></para></listitem>
</itemizedlist></listitem>

<listitem><para>Object: <classname>FilterConfiguration</classname></para>
<itemizedlist>

<listitem><para>Function: <function>getProperty</function></para><para>
This function returns the value of a parameter of the associated
<classname>Filter</classname>. It takes one argument: the name of the
parameter.</para></listitem>

<listitem><para>Function: <function>setProperty</function></para><para>
This function defines a parameter of the associated
<classname>Filter</classname>. It takes two arguments: the name of the
parameter and the value, whose type depends on the
<classname>Filter</classname>.</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>Histogram</classname></para>

<para>This class allows you to access the histogram of a
<classname>PaintLayer</classname>.
Example (in Ruby):
<programlisting>
 doc = krosschalkcore::get("ChalkDocument")
 image = doc.getImage()
 layer = image.getActiveLayer()
 histo = layer.createHistogram("RGB8HISTO",0)
 min = layer.getMin() * 255
 max = layer.getMax() * 255
 for i in min..max
   print layer.getValue(i)
   print "\n"
 end
</programlisting>
</para>

<itemizedlist>
<listitem><para>Function: <function>getChannel</function></para><para>
Return the selected channel.</para></listitem>

<listitem><para>Function: <function>getCount</function></para><para>
This function returns the number of pixels used by the histogram.</para></listitem>

<listitem><para>Function: <function>getHighest</function></para><para>
This function returns the highest value of the histogram.</para></listitem>

<listitem><para>Function: <function>getLowest</function></para><para>
This function returns the lowest value of the histogram.</para></listitem>

<listitem><para>Function: <function>getMax</function></para><para>
This function returns the maximum bound of the histogram (values at greater
position than the maximum are null). The value is in the range 0.0 &ndash; 1.0.</para></listitem>

<listitem><para>Function: <function>getMean</function></para><para>
This function returns the mean of the histogram.</para></listitem>

<listitem><para>Function: <function>getMin</function></para><para>
This function returns the minimum bound of the histogram (values at smaller
position than the minimum are null). The value is in the range 0.0 &ndash; 1.0.</para></listitem>

<listitem><para>Function: <function>getNumberOfBins</function></para><para>
Return the number of bins of this histogram. </para></listitem>

<listitem><para>Function: <function>getTotal</function></para><para>
This function returns the sum of all values of the histogram.</para></listitem>

<listitem><para>Function: <function>getValue</function></para><para>
Return the value of a bin of the histogram. This function takes one argument:
index, in the range [0..255].</para></listitem>

<listitem><para>Function: <function>setChannel</function></para><para>
Select the channel of the layer on which to get the result of the histogram.
This function takes one argument: the channel number.</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>ScriptProgress</classname></para>
<para><classname>ScriptProgress</classname> is used to manage the progress bar
of the status bar in &chalk;.
For example (in Ruby):
<programlisting>
script = Krosschalkcore::get("ChalkScript")
script.setProgressTotalSteps(1000)
script.setProgressStage("progressive", 0)
for i in 1..900
  script.incProgress()
end
script.setProgressStage("brutal", 1000)
</programlisting></para>

<itemizedlist>
<listitem><para>Function: <function>incProgress</function></para><para>
This function increments the progress by one step.</para></listitem>

<listitem><para>Function: <function>setProgress</function></para><para>
This function sets the value of the progress. It takes one argument:
the value of the progress.</para></listitem>

<listitem><para>Function: <function>setProgressStage</function></para><para>
This function sets the value of the progress and displays the text.</para></listitem>

<listitem><para>Function: <function>setProgressTotalSteps</function></para><para>
This function set the number of steps that the script will require. It takes
one argument: the maximum value of the progress</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>Wavelet</classname></para><para>
This object holds the coefficients of a wavelet transformation of a
<classname>PaintLayer</classname>.</para>
<itemizedlist>

<listitem><para>Function: <function>getDepth</function></para><para>
Returns the depth of the layer.</para></listitem>

<listitem><para>Function: <function>getNCoeff</function></para><para>
Returns the value of the Nth coefficient. The function takes one argument: the
index of the coefficient.</para></listitem>

<listitem><para>Function: <function>getNumCoeffs</function></para><para>
Returns the number of coefficients in this wavelet (= size * size * depth).</para></listitem>

<listitem><para>Function: <function>getSize</function></para><para>
Returns the size of the wavelet (size = width = height).</para></listitem>

<listitem><para>Function: <function>getXYCoeff</function></para><para>
Returns the value of a coefficient. The function takes two arguments:
<varname>x</varname> and <varname>y</varname>.</para></listitem>

<listitem><para>Function: <function>setNCoeff</function></para><para>
Set the value of the Nth coefficient. The function takes two arguments: the
index of the coefficient and the new value of the coefficient.</para></listitem>

<listitem><para>Function: <function>setXYCoeff</function></para><para>
Set the value of a coefficient. The function takes three arguments:
<varname>x</varname>, <varname>y</varname>, and the new value of the
coefficient.</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>Painter</classname></para>
<itemizedlist>

<listitem><para>Function: <function>convolve</function></para><para>
This function applies a convolution kernel to an image. It takes at least three arguments:
a list of kernels (all lists need to have the same size),
factor, and offset.
</para><para>
The value of a pixel will be given by the following function: K * P / factor + offset,
where K is the kernel and P is the neighbourhood.
</para><para>
It can take the following optional arguments: <varname>borderOp</varname>
(control how to convolve the pixels on the border of an image: 0 = use the
default color, 1 = use the pixel on the opposite side of the image, 2 = use
the border pixel, 3 = avoid border pixels), <varname>channel</varname> (1 for
color, 2 for alpha, 3 for both), <varname>x</varname>, <varname>y</varname>,
<varname>width</varname>, <varname>height</varname>.</para></listitem>

<listitem><para>Function: <function>setFillThreshold</function></para><para>
Sets the fill threshold. It takes one argument: the threshold.</para></listitem>

<listitem><para>Function: <function>fillColor</function></para><para>
Starts filling with a color. It takes two arguments: <varname>x</varname> and
<varname>y</varname>.</para></listitem>

<listitem><para>Function: <function>fillPattern</function></para><para>
Starts filling with a pattern. It takes two arguments: <varname>x</varname>
and <varname>y</varname>.</para></listitem>

<listitem><para>Function: <function>paintPolyline</function></para><para>
This function will paint a polyline. It takes two arguments: a list of x
positions, and a list of y positions.</para></listitem>

<listitem><para>Function: <function>paintLine</function></para><para>
This function will paint a line. It takes five arguments:
<varname>x1</varname>, <varname>y1</varname>, <varname>x2</varname>,
<varname>y2</varname>, and <varname>pressure</varname>. 
</para></listitem>

<listitem><para>Function: <function>paintBezierCurve</function></para><para>
This function will paint a Bezier curve. It takes ten arguments:
<varname>x1</varname>, <varname>y1</varname>, <varname>p1</varname>,
<varname>cx1</varname>, <varname>cy1</varname>, <varname>cx2</varname>,
<varname>cx2</varname>, <varname>x2</varname>, <varname>y2</varname>,
<varname>p2</varname>, where (<varname>x1</varname>,<varname>y1</varname>) is
the start position, <varname>p1</varname> is the pressure at the start,
(<varname>x2</varname>,<varname>y2</varname>) is the end position,
<varname>p2</varname> is the pressure at the end.
(<varname>cx1</varname>,<varname>cy1</varname>) and
(<varname>cx2</varname>,<varname>cy2</varname>) are the positions of the
control points.</para></listitem>

<listitem><para>Function: <function>paintEllipse</function></para><para>
This function will paint an ellipse. It takes five arguments:
<varname>x1</varname>, <varname>y1</varname>, <varname>x2</varname>,
<varname>y2</varname>, <varname>pressure</varname>, where
(<varname>x1</varname>,<varname>y1</varname>) and
(<varname>x2</varname>,<varname>y2</varname>) are the positions of the two
centers.</para></listitem>

<listitem><para>Function: <function>paintPolygon</function></para><para>
This function will paint a polygon. It takes two arguments: a list of x
positions and a list of y positions.</para></listitem>

<listitem><para>Function: <function>paintRect</function></para><para>
This function will paint a rectangle. It takes five arguments:
<varname>x</varname>, <varname>y</varname>, <varname>width</varname>
<varname>height</varname>, <varname>pressure</varname>.</para></listitem>

<listitem><para>Function: <function>paintAt</function></para><para>
This function will paint at a given position.
It takes three arguments: <varname>x</varname>, <varname>y</varname>,
<varname>pressure</varname>.</para></listitem>

<listitem><para>Function: <function>setPaintColor</function></para><para>
This function sets the paint color (also called foreground color). It takes
one argument: a <classname>Color</classname>.</para></listitem>

<listitem><para>Function: <function>setBackgroundColor</function></para><para>
This function sets the background color. It takes one argument: a
<classname>Color</classname>.</para></listitem>

<listitem><para>Function: <function>setPattern</function></para><para>
This function sets the pattern used for filling. It takes one argument: a
<classname>Pattern</classname> object.</para></listitem>

<listitem><para>Function: <function>setBrush</function></para><para>
This function sets the brush used for painting. It takes one argument: a
<classname>Brush</classname> object.</para></listitem>

<listitem><para>Function: <function>setPaintOp</function></para><para>
This function defines the paint operation. It takes one argument: the name of
the paint operation.</para></listitem>

<listitem><para>Function: <function>setDuplicateOffset</function></para><para>
This function defines the duplicate offset. It takes two arguments: the
horizontal offset and the vertical offset.</para></listitem>

<listitem><para>Function: <function>setOpacity</function></para><para>
This function set the opacity of the painting. It takes one argument: the
opacity, in the range 0 to 255.</para></listitem>

<listitem><para>Function: <function>setStrokeStyle</function></para><para>
This function sets the style of the stroke. It takes one argument: 0 for none,
or 1 for brush.</para></listitem>

<listitem><para>Function: <function>setFillStyle</function></para><para>
This function sets the fill style of the <classname>Painter</classname>.
It takes one argument: 0 for none, 1 for fill with foreground color, 2 for
fill with background color, 3 for fill with pattern.</para></listitem>
</itemizedlist>
</listitem>

<listitem><para>Object: <classname>Iterator</classname></para><para>
This object allows you to change pixel values one by one.
The name of some functions depends on the colorspace, for instance, if the
colorspace of the layer is RGB, you will have <function>setR</function>,
<function>setG</function> and <function>setB</function>, and for
CMYK: <function>setC</function>, <function>setM</function>,
<function>setY</function> and <function>setK</function>. In the documentation
below we will assume that the colorspace is called ABC, with three channels:
A, B and C.</para>

<itemizedlist>
<listitem><para>Functions: <function>setA</function>,
<function>setB</function>, <function>setC</function></para><para>
Those functions take one argument: the new value of one of the channels of
this pixel.</para></listitem>

<listitem><para>Function: <function>setABC</function></para><para>
Set the value of all channels. This function takes one argument: an array with
the new values for all channels.</para></listitem>

<listitem><para>Functions: <function>getA</function>,
<function>getB</function>, <function>getC</function></para><para>
Return the value of one of the channels of this pixel.</para></listitem>

<listitem><para>Function: <function>getABC</function></para><para>
Return an array with the values of all channels.</para></listitem>

<listitem><para>Function: <function>darken</function></para><para>
Darken a pixel. This function takes at least one argument:
<varname>shade</varname> (amount used to darken all color channels). This
function can take the following optional argument:
<varname>compensation</varname> (to limit the darkening).</para></listitem>

<listitem><para>Function: <function>invertColor</function></para><para>
Invert the color of a pixel.</para></listitem>

<listitem><para>Function: <function>next</function></para><para>
Increment the position, go to the next pixel.</para></listitem>

<listitem><para>Function: <function>isDone</function></para><para>
Return true if the iterator is at the end (no more pixels are
available).</para></listitem>
</itemizedlist>
</listitem>
</itemizedlist>

</sect2>

<sect2 id="developers-scripting-resources">
<title>Resources</title>

<para>
Here are hints or partial lists of resources for &chalk;.
</para><para>
For <classname>Brush</classname> and <classname>Pattern</classname>: You can get
the name and the associated brush or pattern from the selector in &chalk;'s
toolbar.
</para><para>
A list of ids for colorspaces in &chalk;: LABA, RGBA, RGBA16, RGBAF32,
RGBAF16HALF, LMSAF32, GRAYA, GRAYA16, CMYK, CMYKA16.
</para>
</sect2>

</sect1>