~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/aggpas/gamma_ctrl.dpr

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// AggPas 2.4 RM3 Demo application
3
 
// Note: Press F1 key on run to see more info about this demo
4
 
//
5
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
6
 
//
7
 
program
8
 
 gamma_ctrl_ ;
9
 
 
10
 
{DEFINE AGG_GRAY8 }
11
 
{$DEFINE AGG_BGR24 }
12
 
{DEFINE AGG_RGB24 }
13
 
{DEFINE AGG_BGRA32 }
14
 
{DEFINE AGG_RGBA32 }
15
 
{DEFINE AGG_ARGB32 }
16
 
{DEFINE AGG_ABGR32 }
17
 
{DEFINE AGG_RGB565 }
18
 
{DEFINE AGG_RGB555 }
19
 
 
20
 
uses
21
 
 agg_basics ,
22
 
 agg_platform_support ,
23
 
 
24
 
 agg_ctrl ,
25
 
 agg_gamma_ctrl ,
26
 
 
27
 
 agg_rasterizer_scanline_aa ,
28
 
 agg_scanline ,
29
 
 agg_scanline_p ,
30
 
 
31
 
 agg_renderer_base ,
32
 
 agg_renderer_scanline ,
33
 
 agg_render_scanlines ,
34
 
 
35
 
 agg_gsv_text ,
36
 
 agg_conv_stroke ,
37
 
 agg_conv_transform ,
38
 
 agg_path_storage ,
39
 
 agg_ellipse ,
40
 
 agg_trans_affine
41
 
 
42
 
{$I pixel_formats.inc }
43
 
{$I agg_mode.inc }
44
 
{$I- }
45
 
const
46
 
 flip_y = true;
47
 
 
48
 
var
49
 
 g_ctrl : gamma_ctrl;
50
 
 
51
 
type
52
 
 the_application = object(platform_support )
53
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
54
 
   destructor  Destruct;
55
 
 
56
 
   procedure on_init; virtual;
57
 
   procedure on_draw; virtual;
58
 
 
59
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
60
 
 
61
 
  end;
62
 
 
63
 
{ READ_GAMMA }
64
 
procedure read_gamma(fname : shortstring );
65
 
var
66
 
 fd : text;
67
 
 
68
 
 kx1 ,ky1 ,kx2 ,ky2 : double;
69
 
 
70
 
begin
71
 
 assignfile(fd ,fname );
72
 
 reset     (fd );
73
 
 
74
 
 readln(fd ,kx1 );
75
 
 readln(fd ,ky1 );
76
 
 readln(fd ,kx2 );
77
 
 readln(fd ,ky2 );
78
 
 
79
 
 g_ctrl.values(kx1 ,ky1 ,kx2 ,ky2 );
80
 
 
81
 
 close(fd );
82
 
 
83
 
end;
84
 
 
85
 
{ WRITE_GAMMA_BIN }
86
 
procedure write_gamma_bin(fname : shortstring );
87
 
var
88
 
 fd : file;
89
 
 
90
 
 gamma : char_ptr;
91
 
 
92
 
begin
93
 
 gamma:=g_ctrl.gamma;
94
 
 
95
 
 assignfile(fd ,fname );
96
 
 rewrite   (fd ,1 );
97
 
 blockwrite(fd ,gamma^ ,256 );
98
 
 close     (fd );
99
 
 
100
 
end;
101
 
 
102
 
{ WRITE_GAMMA_TXT }
103
 
procedure write_gamma_txt(fname : shortstring );
104
 
var
105
 
 fd : text;
106
 
 
107
 
 gamma : char_ptr;
108
 
 i ,j  : int;
109
 
 
110
 
 kx1 ,ky1 ,kx2 ,ky2 : double;
111
 
 
112
 
begin
113
 
 gamma:=g_ctrl.gamma;
114
 
 
115
 
 assignfile(fd ,fname );
116
 
 rewrite   (fd );
117
 
 
118
 
 g_ctrl.values(@kx1 ,@ky1 ,@kx2 ,@ky2 );
119
 
 
120
 
 writeln(fd ,kx1:1:3 );
121
 
 writeln(fd ,ky1:1:3 );
122
 
 writeln(fd ,kx2:1:3 );
123
 
 writeln(fd ,ky2:1:3 );
124
 
 
125
 
 for i:=0 to 15 do
126
 
  begin
127
 
   for j:= 0 to 15 do
128
 
    write(fd ,int8u_ptr(ptrcomp(gamma ) + i * 16 + j )^:3 ,',' );
129
 
 
130
 
   writeln(fd );
131
 
 
132
 
  end;
133
 
 
134
 
 close(fd );
135
 
 
136
 
end;
137
 
 
138
 
{ CONSTRUCT }
139
 
constructor the_application.Construct;
140
 
begin
141
 
 inherited Construct(format_ ,flip_y_ );
142
 
 
143
 
 add_ctrl(@g_ctrl );
144
 
 
145
 
end;
146
 
 
147
 
{ DESTRUCT }
148
 
destructor the_application.Destruct;
149
 
begin
150
 
 inherited Destruct;
151
 
 
152
 
 write_gamma_txt('gamma.txt' );
153
 
 write_gamma_bin('gamma.bin' );
154
 
 
155
 
end;
156
 
 
157
 
{ ON_INIT }
158
 
procedure the_application.on_init;
159
 
begin
160
 
 read_gamma('gamma.txt' );
161
 
 
162
 
end;
163
 
 
164
 
{ ON_DRAW }
165
 
procedure the_application.on_draw;
166
 
var
167
 
 ewidth ,ecenter : double;
168
 
 
169
 
 i : int;
170
 
 
171
 
 pixf : pixel_formats;
172
 
 
173
 
 rb : renderer_base;
174
 
 r  : renderer_scanline_aa_solid;
175
 
 
176
 
 ras : rasterizer_scanline_aa;
177
 
 sl  : scanline_p8;
178
 
 
179
 
 rgba  : aggclr;
180
 
 elli  : ellipse;
181
 
 poly  : conv_stroke;
182
 
 tpoly : conv_transform;
183
 
 
184
 
 mtx : trans_affine;
185
 
 tas : trans_affine_skewing;
186
 
 tar : trans_affine_rotation;
187
 
 tat : trans_affine_translation;
188
 
 
189
 
 text  : gsv_text;
190
 
 text1 : gsv_text_outline;
191
 
 path  : path_storage;
192
 
 trans : conv_transform; 
193
 
 
194
 
begin
195
 
// Initialize structures
196
 
 ewidth :=_initial_width / 2 - 10;
197
 
 ecenter:=_initial_width / 2;
198
 
 
199
 
 pixfmt(pixf ,rbuf_window );
200
 
 
201
 
 rb.Construct(@pixf );
202
 
 r.Construct (@rb );
203
 
 
204
 
 rgba.ConstrDbl(1 ,1 ,1 );
205
 
 rb.clear      (@rgba );
206
 
 
207
 
 g_ctrl.text_size_(10.0 ,12.0 );
208
 
 
209
 
 ras.Construct;
210
 
 sl.Construct;
211
 
 
212
 
// Render the controls
213
 
 render_ctrl(@ras ,@sl ,@r ,@g_ctrl );
214
 
 
215
 
 ras.gamma(@g_ctrl );
216
 
 
217
 
// Ellipses
218
 
 elli.Construct;
219
 
 poly.Construct (@elli );
220
 
 tpoly.Construct(@poly ,_trans_affine_resizing );
221
 
 
222
 
 rgba.ConstrInt(0 ,0 ,0 );
223
 
 r.color_      (@rgba );
224
 
 
225
 
 elli.init   (ecenter ,220 ,ewidth ,15 ,100 );
226
 
 poly.width_ (2.0 );
227
 
 ras.add_path(@tpoly ,0 );
228
 
 
229
 
 render_scanlines(@ras ,@sl ,@r );
230
 
 
231
 
 elli.init   (ecenter ,220 ,11 ,11 ,100 );
232
 
 poly.width_ (2.0 );
233
 
 ras.add_path(@tpoly ,0 );
234
 
 
235
 
 render_scanlines(@ras ,@sl ,@r );
236
 
 
237
 
 rgba.ConstrInt(127 ,127 ,127 );
238
 
 r.color_      (@rgba );
239
 
 
240
 
 elli.init   (ecenter ,260 ,ewidth ,15 ,100 );
241
 
 poly.width_ (2.0 );
242
 
 ras.add_path(@tpoly ,0 );
243
 
 
244
 
 render_scanlines(@ras ,@sl ,@r );
245
 
 
246
 
 elli.init   (ecenter ,260 ,11 ,11 ,100 );
247
 
 poly.width_ (2.0 );
248
 
 ras.add_path(@tpoly ,0 );
249
 
 
250
 
 render_scanlines(@ras ,@sl ,@r );
251
 
 
252
 
 rgba.ConstrInt(192 ,192 ,192 );
253
 
 r.color_      (@rgba );
254
 
 
255
 
 elli.init   (ecenter ,300 ,ewidth ,15 ,100 );
256
 
 poly.width_ (2.0 );
257
 
 ras.add_path(@tpoly ,0 );
258
 
 
259
 
 render_scanlines(@ras ,@sl ,@r );
260
 
 
261
 
 elli.init   (ecenter ,300 ,11 ,11 ,100 );
262
 
 poly.width_ (2.0 );
263
 
 ras.add_path(@tpoly ,0 );
264
 
 
265
 
 render_scanlines(@ras ,@sl ,@r );
266
 
 
267
 
 rgba.ConstrDbl(0.0 ,0.0 ,0.4 );
268
 
 r.color_      (@rgba );
269
 
 
270
 
 elli.init   (ecenter ,340 ,ewidth ,15.5 ,100 );
271
 
 poly.width_ (1.0 );
272
 
 ras.add_path(@tpoly ,0 );
273
 
 
274
 
 render_scanlines(@ras ,@sl ,@r );
275
 
 
276
 
 elli.init   (ecenter ,340 ,10.5 ,10.5 ,100 );
277
 
 poly.width_ (1.0 );
278
 
 ras.add_path(@tpoly ,0 );
279
 
 
280
 
 render_scanlines(@ras ,@sl ,@r );
281
 
 
282
 
 elli.init   (ecenter ,380 ,ewidth ,15.5 ,100 );
283
 
 poly.width_ (0.4 );
284
 
 ras.add_path(@tpoly ,0 );
285
 
 
286
 
 render_scanlines(@ras ,@sl ,@r );
287
 
 
288
 
 elli.init   (ecenter ,380 ,10.5 ,10.5 ,100 );
289
 
 poly.width_ (0.4 );
290
 
 ras.add_path(@tpoly ,0 );
291
 
 
292
 
 render_scanlines(@ras ,@sl ,@r );
293
 
 
294
 
 elli.init   (ecenter ,420 ,ewidth ,15.5 ,100 );
295
 
 poly.width_ (0.1 );
296
 
 ras.add_path(@tpoly ,0 );
297
 
 
298
 
 render_scanlines(@ras ,@sl ,@r );
299
 
 
300
 
 elli.init   (ecenter ,420 ,10.5 ,10.5 ,100 );
301
 
 poly.width_ (0.1 );
302
 
 ras.add_path(@tpoly ,0 );
303
 
 
304
 
 render_scanlines(@ras ,@sl ,@r );
305
 
 
306
 
// Text
307
 
 mtx.Construct;
308
 
 tas.Construct(0.15 ,0.0 );
309
 
 mtx.Multiply (@tas );
310
 
 mtx.Multiply (_trans_affine_resizing );
311
 
 
312
 
 text.Construct;
313
 
 text1.Construct(@text ,@mtx );
314
 
 
315
 
 text.text_       ('Text 2345' );
316
 
 text.size_       (50 ,20 );
317
 
 text1.width_     (2.0 );
318
 
 text.start_point_(320 ,10 );
319
 
 
320
 
 rgba.ConstrDbl(0.0 ,0.5 ,0.0 );
321
 
 r.color_      (@rgba );
322
 
 
323
 
 ras.add_path    (@text1 ,0 );
324
 
 render_scanlines(@ras ,@sl ,@r );
325
 
 
326
 
// Triangled circle
327
 
 rgba.ConstrDbl(0.5 ,0.0 ,0.0 );
328
 
 r.color_      (@rgba );
329
 
 
330
 
 path.Construct;
331
 
 path.move_to(30 ,-1.0 );
332
 
 path.line_to(60 ,0.0 );
333
 
 path.line_to(30 ,1.0 );
334
 
 
335
 
 path.move_to(27 ,-1.0 );
336
 
 path.line_to(10 ,0.0 );
337
 
 path.line_to(27 ,1.0 );
338
 
 
339
 
 trans.Construct(@path ,@mtx );
340
 
 
341
 
 for i:=0 to 34 do
342
 
  begin
343
 
   tar.Construct(i / 35.0 * pi * 2.0 );
344
 
   tat.construct(400 ,130 );
345
 
 
346
 
   mtx.reset;
347
 
   mtx.multiply(@tar );
348
 
   mtx.multiply(@tat );
349
 
   mtx.multiply(_trans_affine_resizing );
350
 
 
351
 
   ras.add_path    (@trans ,0 );
352
 
   render_scanlines(@ras ,@sl ,@r );
353
 
 
354
 
  end;
355
 
 
356
 
// Free AGG resources
357
 
 ras.Destruct;
358
 
 sl.Destruct;
359
 
 
360
 
 poly.Destruct;
361
 
 text.Destruct;
362
 
 text1.Destruct;
363
 
 path.Destruct;
364
 
 
365
 
end;
366
 
 
367
 
{ ON_KEY }
368
 
procedure the_application.on_key;
369
 
begin
370
 
 if key = key_f1 then
371
 
  message_(
372
 
   'This is another experiment with gamma correction. See also Gamma Correction. '#13 +
373
 
   'I presumed that we can do better than with a traditional power function. '#13 +
374
 
   'So, I created a special control to have an arbitrary gamma function. '#13 +
375
 
   'The conclusion is that we can really achieve a better visual result with '#13 +
376
 
   'this control, but still, in practice, the traditional power function is good '#13 +
377
 
   'enough too.'#13#13 +
378
 
   'How to play with:'#13#13 +
379
 
   'Feel free to change the gamma curve. The shape you''ll set up, will be'#13 +
380
 
   'stored in external file "gamma.txt".' +
381
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
382
 
 
383
 
end;
384
 
 
385
 
VAR
386
 
 app : the_application;
387
 
 
388
 
BEGIN
389
 
 g_ctrl.Construct(10.0 ,10.0 ,300.0 ,200.0 ,not flip_y );
390
 
 
391
 
 app.Construct(pix_format ,flip_y );
392
 
 app.caption_ ('Anti-Aliasing Gamma Correction (F1-Help)' );
393
 
 
394
 
 if app.init(500 ,400 ,window_resize ) then
395
 
  app.run;
396
 
 
397
 
 app.Destruct;
398
 
 g_ctrl.Destruct;
399
 
 
400
 
END.
 
 
b'\\ No newline at end of file'