Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[r1]: tags / 16 / Forms / formPostProcess.pas Maximize Restore History

Download this file

formPostProcess.pas    524 lines (462 with data), 15.4 kB

  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
{
Apophysis Copyright (C) 2001-2004 Mark Townsend
Apophysis Copyright (C) 2005-2006 Ronald Hordijk, Piotr Borys, Peter Sdobnov
Apophysis Copyright (C) 2007-2008 Piotr Borys, Peter Sdobnov
Apophysis "3D hack" Copyright (C) 2007-2008 Peter Sdobnov
Apophysis "7X" Copyright (C) 2009-2010 Georg Kiehne
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
unit formPostProcess;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RenderingInterface, controlpoint, StdCtrls, ComCtrls,
Translation;
type
TfrmPostProcess = class(TForm)
Panel1: TPanel;
ScrollBox1: TScrollBox;
Image: TImage;
pnlBackColor: TPanel;
ColorDialog: TColorDialog;
ProgressBar1: TProgressBar;
txtFilterRadius: TEdit;
txtGamma: TEdit;
txtVibrancy: TEdit;
txtContrast: TEdit;
txtBrightness: TEdit;
pnlGamma: TPanel;
pnlBrightness: TPanel;
pnlContrast: TPanel;
pnlVibrancy: TPanel;
pnlFilter: TPanel;
shBack: TShape;
pnlBackground: TPanel;
btnSave: TButton;
chkFitToWindow: TCheckBox;
btnApply: TButton;
procedure chkFitToWindowClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure pnlBackColorClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure DragPanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DragPanelMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure DragPanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DragPanelDblClick(Sender: TObject);
procedure shBackMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
FRenderer: TBaseRenderer;
FCP: TControlPoint;
FImagename: string;
pnlDragMode, pnlDragged, pnlMM: boolean;
pnlDragPos, pnlDragOld: integer;
pnlDragValue: double;
mousepos: TPoint;
BkgColor: TColor;
Filter,
Gamma, Brightness,
Contrast, Vibrancy: double;
procedure UpdateFlame;
procedure SetDefaultValues;
procedure OnProgress(prog: double);
public
cp : TControlPoint;
procedure SetRenderer(Renderer: TBaseRenderer);
procedure SetControlPoint(CP: TControlPoint);
procedure SetImageName(imagename: string);
end;
var
frmPostProcess: TfrmPostProcess;
implementation
uses
Registry, Global, Main;
{$R *.dfm}
{ TfrmPostProcess }
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.SetRenderer(Renderer: TBaseRenderer);
begin
if assigned(FRenderer) then
FRenderer.Free;
FRenderer := Renderer;
Frenderer.OnProgress := OnProgress;
Image.Picture.Graphic := FRenderer.GetImage;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.FormShow(Sender: TObject);
var
Registry: TRegistry;
begin
{ Read posution from registry }
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('Software\' + APP_NAME + '\Forms\PostProcess', False) then begin
if Registry.ValueExists('Left') then
Left := Registry.ReadInteger('Left');
if Registry.ValueExists('Top') then
Top := Registry.ReadInteger('Top');
//if Registry.ValueExists('Width') then
//Width := Registry.ReadInteger('Width');
//if Registry.ValueExists('Height') then
// Height := Registry.ReadInteger('Height');
end;
Registry.CloseKey;
finally
Registry.Free;
end;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.FormClose(Sender: TObject; var Action: TCloseAction);
var
Registry: TRegistry;
begin
{ Write position to registry }
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('\Software\' + APP_NAME + '\Forms\PostProcess', True) then
begin
Registry.WriteInteger('Top', Top);
Registry.WriteInteger('Left', Left);
// Registry.WriteInteger('Width', Width);
// Registry.WriteInteger('Height', Height);
end;
finally
Registry.Free;
end;
FRenderer.Free; // weirdness!!! :-/
FRenderer := nil;
Image.Picture.Graphic := nil;
FCP.Free;
FCP := nil;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.SetDefaultValues;
begin
BkgColor := RGB(Fcp.background[0], Fcp.background[1], Fcp.background[2]);
pnlBackColor.Color := BkgColor;
shBack.Brush.Color := BkgColor;
Filter := FCP.spatial_filter_radius;
txtFilterRadius.Text := FloatTostr(Filter);
Gamma := FCP.gamma;
txtGamma.Text := FloatTostr(Gamma);
Vibrancy := FCP.vibrancy;
txtVibrancy.Text := FloatTostr(Vibrancy);
Contrast := FCP.contrast;
txtContrast.Text := FloatTostr(Contrast);
Brightness := FCP.brightness;
txtBrightness.Text := FloatTostr(brightness);
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.SetControlPoint(CP: TControlPoint);
begin
if assigned(FCP) then
FCP.Free;
FCP := cp.Clone;
SetDefaultValues;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.pnlBackColorClick(Sender: TObject);
var
col: Longint;
begin
ColorDialog.Color := shBack.Brush.Color;
if ColorDialog.Execute then begin
pnlBackColor.Color := ColorDialog.Color;
shBack.Brush.Color := ColorDialog.Color;
col := ColorToRGB(ColorDialog.Color);
Fcp.background[0] := col and 255;
Fcp.background[1] := (col shr 8) and 255;
Fcp.background[2] := (col shr 16) and 255;
UpdateFlame;
end;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.UpdateFlame;
begin
Screen.Cursor := crHourGlass;
FRenderer.UpdateImage(FCP);
Image.Picture.Graphic := FRenderer.GetImage;
Screen.Cursor := crDefault;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.FormDestroy(Sender: TObject);
begin
if assigned(FRenderer) then
FRenderer.Free;
if assigned(FCP) then
FCP.Free;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.OnProgress(prog: double);
begin
ProgressBar1.Position := round(100 * prog);
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.btnApplyClick(Sender: TObject);
var
temp: double;
begin
TryStrToFloat(txtFilterRadius.Text, FCP.spatial_filter_radius);
if FCP.spatial_filter_radius > 2 then begin
FCP.spatial_filter_radius := 2;
txtFilterRadius.Text := '2';
end else if FCP.spatial_filter_radius < 0 then begin
FCP.spatial_filter_radius := 0.01;
txtFilterRadius.Text := FloatTostr(0.01);
end;
TryStrToFloat(txtGamma.Text, FCP.gamma);
if FCP.gamma > 10 then begin
FCP.gamma := 10;
txtGamma.Text := '10';
end else if FCP.gamma < 0.01 then begin
FCP.gamma := 0.01;
txtGamma.Text := FloatTostr(0.01);
end;
TryStrToFloat(txtVibrancy.Text, FCP.vibrancy);
if FCP.vibrancy > 10 then begin
FCP.vibrancy := 10;
txtVibrancy.Text := '10';
end else if FCP.vibrancy < 0.01 then begin
FCP.vibrancy := 0.01;
txtVibrancy.Text := FloatTostr(0.01);
end;
TryStrToFloat(txtContrast.Text, FCP.contrast);
if FCP.contrast > 10 then begin
FCP.contrast := 10;
txtContrast.Text := '10';
end else if FCP.contrast < 0.01 then begin
FCP.contrast := 0.01;
txtContrast.Text := FloatTostr(0.01);
end;
if TryStrToFloat(txtBrightness.Text, temp) then FCP.brightness := temp;
//TryStrToFloat(txtBrightness.Text, FCP.brightness);
if FCP.brightness > 100 then begin
FCP.brightness := 100;
txtBrightness.Text := '100';
end else if FCP.brightness < 0.01 then begin
FCP.brightness := 0.01;
txtBrightness.Text := FloatTostr(0.01);
end;
UpdateFlame;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.btnSaveClick(Sender: TObject);
begin
FRenderer.SaveImage(FImagename);
end;
///////////////////////////////////////////////////////////////////////////////
procedure TfrmPostProcess.SetImageName(imagename: string);
begin
FImagename := imagename;
end;
// -----------------------------------------------------------------------------
procedure TfrmPostProcess.DragPanelMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button <> mbLeft then exit;
if (Sender = pnlFilter) then
pnlDragValue := fcp.spatial_filter_radius * 10
else if (Sender = pnlGamma) then
pnlDragValue := fcp.gamma
else if (Sender = pnlBrightness) then
pnlDragValue := fcp.brightness
else if (Sender = pnlContrast) then
pnlDragValue := fcp.contrast
else if (Sender = pnlVibrancy) then
pnlDragValue := fcp.vibrancy
else exit;//assert(false);
pnlDragMode := true;
pnlDragPos := 0;
pnlDragOld := x;
pnlMM := false;
SetCaptureControl(TControl(Sender));
Screen.Cursor := crHSplit;
GetCursorPos(mousepos); // hmmm
pnlDragged := false;
end;
procedure TfrmPostProcess.DragPanelMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
v: double;
pEdit: ^TEdit;
enableDrag : boolean;
begin
if pnlMM then // hack: to skip MouseMove event
begin
pnlMM:=false;
end
else
if pnlDragMode and (x <> pnlDragOld) then
begin
Inc(pnlDragPos, x - pnlDragOld);
if GetKeyState(VK_MENU) < 0 then v := 100000
else if GetKeyState(VK_CONTROL) < 0 then v := 10000
else if GetKeyState(VK_SHIFT) < 0 then v := 100
else v := 1000;
v := Round6(pnlDragValue + pnlDragPos / v);
SetCursorPos(MousePos.x, MousePos.y); // hmmm
pnlMM:=true;
enableDrag := true;
if (Sender = pnlFilter) then
begin
v := v / 10;
if v > 2 then v := 2
else if v < 0.01 then v := 0.01;
fcp.spatial_filter_radius := v;
pEdit := @txtFilterRadius;
end
else if (Sender = pnlGamma) then
begin
if v > 10 then v := 10
else if v < 0.01 then v := 0.01;
fcp.gamma := v;
pEdit := @txtGamma;
end
else if (Sender = pnlBrightness) then
begin
if v > 100 then v := 100
else if v < 0.01 then v := 0.01;
fcp.brightness := v;
pEdit := @txtBrightness;
end
else if (Sender = pnlContrast) then
begin
if v > 10 then v := 10
else if v < 0.01 then v := 0.01;
fcp.contrast := v;
pEdit := @txtContrast;
end
else if (Sender = pnlVibrancy) then
begin
if v > 10 then v := 10
else if v < 0.01 then v := 0.01;
fcp.vibrancy := v;
pEdit := @txtVibrancy;
end else exit;
if enableDrag then begin
pEdit^.Text := FloatToStr(v);
//pEdit.Refresh;
pnlDragged := True;
// TODO: image preview (?)
//DrawPreview;
end;
end;
end;
procedure TfrmPostProcess.DragPanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button <> mbLeft then exit;
if pnlDragMode then
begin
SetCaptureControl(nil);
pnlDragMode := false;
Screen.Cursor := crDefault;
if pnlDragged then
begin
//UpdateFlame;
pnlDragged := False;
end;
end;
end;
procedure TfrmPostProcess.DragPanelDblClick(Sender: TObject);
var
pValue: ^double;
pDefaultValue: ^double;
pEdit: ^TEdit;
begin
if (Sender = pnlFilter) then
begin
pValue := @fcp.spatial_filter_radius;
pDefaultValue := @Filter;
pEdit := @txtFilterRadius;
end
else if (Sender = pnlGamma) then
begin
pValue := @fcp.gamma;
pDefaultValue := @Gamma;
pEdit := @txtGamma;
end
else if (Sender = pnlBrightness) then
begin
{
pValue := @fcp.brightness;
pDefaultValue := @Brightness;
pEdit := @txtBrightness;
}
if fcp.brightness = Brightness then exit;
fcp.brightness := Brightness;
txtBrightness.Text := FloatToStr(fcp.brightness);
exit;
end
else if (Sender = pnlContrast) then
begin
pValue := @fcp.contrast;
pDefaultValue := @Contrast;
pEdit := @txtContrast
end
else if (Sender = pnlVibrancy) then
begin
pValue := @fcp.vibrancy;
pDefaultValue := @Vibrancy;
pEdit := @txtVibrancy;
end
else exit; //assert(false);
if pValue^ = pDefaultValue^ then exit;
pValue^ := pDefaultValue^;
pEdit^.Text := FloatToStr(pValue^);
//UpdateFlame;
end;
procedure TfrmPostProcess.shBackMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
pnlBackColorClick(sender);
end;
procedure TfrmPostProcess.FormCreate(Sender: TObject);
begin
btnApply.Caption := TextByKey('common-apply');
pnlFilter.Caption := TextByKey('common-filterradius');
pnlGamma.Caption := TextByKey('common-gamma');
pnlBrightness.Caption := TextByKey('common-brightness');
pnlContrast.Caption := TextByKey('common-contrast');
pnlVibrancy.Caption := TextByKey('common-vibrancy');
pnlBackground.Caption := TextByKey('common-background');
pnlFilter.Hint := TextByKey('common-dragpanelhint');
pnlGamma.Hint := TextByKey('common-dragpanelhint');
pnlBrightness.Hint := TextByKey('common-dragpanelhint');
pnlVibrancy.Hint := TextByKey('common-dragpanelhint');
pnlContrast.Hint := TextByKey('common-dragpanelhint');
self.Caption := TextByKey('postprocess-title');
btnSave.Caption := TextByKey('postprocess-save');
chkFitToWindow.Caption := TextByKey('postprocess-fittowindow');
end;
procedure TfrmPostProcess.chkFitToWindowClick(Sender: TObject);
begin
{if (chkFitToWindow.Checked) then begin
Image.Stretch := true;
Image.Align := alClient;
end else begin
Image.Stretch := false;
Image.Align := alNone;
end; }
end;
end.