-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmap_clarity_unit.pas
More file actions
1440 lines (1036 loc) · 52.4 KB
/
map_clarity_unit.pas
File metadata and controls
1440 lines (1036 loc) · 52.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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
================================================================================
This file is part of OpenTemplot2024, a computer program for the design of model railway track.
Copyright (C) 2024 Martin Wynne. email: martin@85a.uk
This program is free software: you may redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation, either version 3 of the Licence, 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 Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program. See the file: licence.txt
Or if not, refer to the web site: https://www.gnu.org/licenses/
================================================================================
This file was saved from Delphi5
This file was derived from Templot2 version 244e
================================================================================
ResampleFilters: array[0..6] of record
Name: string; // Filter name
Filter: TFilterProc;// Filter implementation
Width: Single; // Suggested sampling width/radius
end = (
(Name: 'Box'; Filter: BoxFilter; Width: 0.5),
(Name: 'Triangle'; Filter: TriangleFilter; Width: 1.0),
(Name: 'Hermite'; Filter: HermiteFilter; Width: 1.0),
(Name: 'Bell'; Filter: BellFilter; Width: 1.5),
(Name: 'B-Spline'; Filter: SplineFilter; Width: 2.0),
(Name: 'Lanczos3'; Filter: Lanczos3Filter; Width: 3.0),
(Name: 'Mitchell'; Filter: MitchellFilter; Width: 2.0)
);
*)
unit map_clarity_unit;
{$MODE Delphi}
{$ALIGN OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;
type
Tmap_clarity_form = class(TForm)
go_button: TButton;
Label1: TLabel;
interpolation_groupbox: TGroupBox;
two_tone_groupbox: TGroupBox;
map_list_label: TLabel;
map_name_listbox: TListBox;
GroupBox4: TGroupBox;
res_x2_radio: TRadioButton;
res_x3_radio: TRadioButton;
res_x4_radio: TRadioButton;
GroupBox5: TGroupBox;
triangle_radio: TRadioButton;
mitchell_radio: TRadioButton;
spline_radio: TRadioButton;
threshold_trackbar: TTrackBar;
threshold_panel: TPanel;
threshold_label: TLabel;
colour1_label: TLabel;
high_colour_panel: TPanel;
high_colour_button: TButton;
colour2_label: TLabel;
low_colour_panel: TPanel;
low_colour_button: TButton;
function_groupbox: TGroupBox;
datestamp_label: TLabel;
undo_button: TButton;
reset_button: TButton;
selected_image_radio: TRadioButton;
all_tiled_map_radio: TRadioButton;
interpolation_only_radio: TRadioButton;
two_tone_only_radio: TRadioButton;
interpolation_first_radio: TRadioButton;
two_tone_first_radio: TRadioButton;
threshold_position_label: TLabel;
low_contrast_radio: TRadioButton;
negative_radio: TRadioButton;
match_trackpad_colour_button: TButton;
match_trackpad_grid_button: TButton;
Label2: TLabel;
bgnd_shapes_button: TButton;
Label3: TLabel;
Shape1: TShape;
help_button: TButton;
low_contrast_groupbox: TGroupBox;
black_radio: TRadioButton;
dark_grey_radio: TRadioButton;
medium_grey_radio: TRadioButton;
light_grey_radio: TRadioButton;
white_radio: TRadioButton;
Label4: TLabel;
progress_bar: TProgressBar;
Label5: TLabel;
Label6: TLabel;
help_shape: TShape;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure high_colour_buttonClick(Sender: TObject);
procedure low_colour_buttonClick(Sender: TObject);
procedure threshold_trackbarChange(Sender: TObject);
procedure threshold_trackbarEnter(Sender: TObject);
procedure match_trackpad_colour_buttonClick(Sender: TObject);
procedure bgnd_shapes_buttonClick(Sender: TObject);
procedure go_buttonClick(Sender: TObject);
procedure undo_buttonClick(Sender: TObject);
procedure help_buttonClick(Sender: TObject);
procedure match_trackpad_grid_buttonClick(Sender: TObject);
procedure reset_buttonClick(Sender: TObject);
procedure Label2Click(Sender: TObject);
procedure map_name_listboxClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
map_clarity_form: Tmap_clarity_form;
implementation
uses
bgnd_unit, colour_unit, pad_unit, alert_unit, math_unit, {OT2024 resample,} control_room, wait_message;
{$R *.lfm}
//______________________________________________________________________________
procedure clear_rotated_bitmap(i:integer); // 234e if image has been modified, will need to recreate the rotated bitmap (done in print_unit)
begin
with bgnd_form.bgnd_shapes_listbox.Items do begin
if Count<1 then EXIT; // ???
if (i<0) or (i>Count-1) then EXIT; // ???
with Tbgshape(Objects[i]) do begin
if bgnd_shape.shape_code<>-1 then EXIT; // ???
if bgnd_shape.picture_is_metafile=True then EXIT; // ???
if bgimage.image_shape.rotated_bitmap.Empty=True then EXIT; // nothing to clear
bgimage.image_shape.rotated_bitmap.Width:=0; // clear it..
bgimage.image_shape.rotated_bitmap.Height:=0;
end;//with
end;//with
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.FormShow(Sender: TObject);
var
n:integer;
list_str,found_str:string;
begin
// fill list with existing maps ...
map_name_listbox.Items.Clear;
with bgnd_form.bgnd_shapes_listbox.Items do begin
if Count<1 then EXIT; // no shapes ???
for n:=0 to Count-1 do begin
if Pos('map::',Strings[n])=1
then begin
found_str:=Strings[n];
list_str:=Trim(Copy(found_str,6,15));
if map_name_listbox.Items.IndexOf(list_str)=-1
then map_name_listbox.Items.Add(list_str);
end;
end;//next
end;//with
if map_name_listbox.Items.Count>0 then map_name_listbox.ItemIndex:=0; // select topmost
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.FormCreate(Sender: TObject);
begin
AutoScroll:=False;
ClientWidth:=860;
ClientHeight:=408;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.high_colour_buttonClick(Sender: TObject);
var
colour:TColor;
begin
colour:=high_colour_panel.Color;
colour:=get_colour('choose the high colour for 2-tone reduction',colour);
high_colour_panel.Color:=colour;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.low_colour_buttonClick(Sender: TObject);
var
colour:TColor;
begin
colour:=low_colour_panel.Color;
colour:=get_colour('choose the low colour for 2-tone reduction',colour);
low_colour_panel.Color:=colour;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.threshold_trackbarChange(Sender: TObject);
var
canv:TControlCanvas;
focus_rect:TRect;
red,green,blue:integer;
begin
canv:=TControlCanvas.Create;
canv.Control:=threshold_trackbar;
canv.pen.Color:=two_tone_groupbox.Color;
canv.Brush.Style:=bsClear;
focus_rect:=Rect(0,0,threshold_trackbar.Width,threshold_trackbar.Height);
canv.Rectangle(focus_rect); // remove it focus rectangle.
canv.Free;
threshold_position_label.Caption:=IntToStr(threshold_trackbar.Position);
red:=threshold_trackbar.Position;
green:=red;
blue:=red;
threshold_panel.Color:=(blue*$10000)+(green*$100)+red;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.threshold_trackbarEnter(Sender: TObject);
var
canv:TControlCanvas;
focus_rect:TRect;
begin
canv:=TControlCanvas.Create;
canv.Control:=threshold_trackbar;
canv.pen.Color:=two_tone_groupbox.Color;
canv.Brush.Style:=bsClear;
focus_rect:=Rect(0,0,threshold_trackbar.Width,threshold_trackbar.Height);
canv.Rectangle(focus_rect); // remove it focus rectangle.
canv.Free;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.match_trackpad_colour_buttonClick(Sender: TObject);
begin
high_colour_panel.Color:=paper_colour;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.match_trackpad_grid_buttonClick(Sender: TObject);
begin
low_colour_panel.Color:=grid_colour;
end;
//______________________________________________________________________________
procedure Tmap_clarity_form.bgnd_shapes_buttonClick(Sender: TObject);
begin
selected_image_radio.Checked:=True;
do_bgnd(False); // False = show new shape tab
end;
//______________________________________________________________________________
function make_negative_image(n:integer; alerts:boolean):boolean;
var
inrow,incol,outrow,outcol:integer;
inwidth,inheight:integer;
pixel_colour:TColor;
saved_screen_cursor:TCursor;
meta_str:string;
begin
RESULT:=False; // init
with bgnd_form.bgnd_shapes_listbox do begin
with Items do begin
if (Count<1) or (n<0) or (n>(Count-1)) then EXIT;
with Tbgshape(Objects[n]) do begin
if (bgnd_shape.shape_code<>-1) // not a picture shape.
or (bgnd_shape.shape_name=empty_picture_str)
or (bgimage=nil) // no existing bitmap.
then begin
show_modal_message('error: '+bgnd_shape.shape_name+' : no image content to convert'+#13+#13+'Select a picture shape in the list.');
EXIT;
end;
if alerts=True
then begin
if alert(4,' convert to negative image ?',
'This function will convert the image in the selected picture shape:||'
+bgnd_shape.shape_name
+'||to a negative image.'
+'||This can be helpful when working over a background map so that it does not become too distracting and allows the track templates to be clearly seen.'
+'||This negative function can be reversed by repeating it.'
+'||On large images conversion may take some time to complete.'
+'||Do you want to proceed with the negative conversion?',
'','','','','cancel conversion','yes - continue',0)=5 then EXIT;
end;
// first convert matafile to bitmap if necessary ...
(* OT2024
if bgnd_shape.picture_is_metafile=True
then begin
if alerts=True
then begin
if (bgimage.image_shape.image_metafile.Width>4800) // arbitrary
and (bgimage.image_shape.image_metafile.Height>3600) // arbitrary
then meta_str:='||This picture shape is a large image. Conversion may be slow.'
else meta_str:='';
if alert(4,' convert metafile ?',
'The selected picture shape||'
+bgnd_shape.shape_name
+'||contains a metafile image (EMF file). Metafile (vector) images can be zoomed without becoming fuzzy, pixelated or blocky.'
+'||Converting this picture shape to a negative image will convert it to a conventional bitmap image (as in a scanned image).'
+'||Bitmap images can become fuzzy, pixelated or blocky when zoomed.'
+meta_str
+'||Do you want to proceed with the negative conversion?',
'','','','','cancel conversion','continue - convert picture shape',0)=5
then EXIT;
end;
try
with bgimage.image_shape do begin
image_bitmap.Width:=image_metafile.Width;
image_bitmap.Height:=image_metafile.Height;
with image_bitmap.Canvas do begin // first blank the picture area...
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
Draw(0,0,image_metafile); // draw the metafile on it
end;//with
end;//with
except
show_modal_message('error - unable to convert matafile to bitmap');
EXIT;
end;//try
bgnd_shape.picture_is_metafile:=False;
end;
*)
// convert to 24-bit colour if necessary ...
if bgimage.image_shape.image_bitmap.PixelFormat<>pf24bit
then begin
try
bgimage.image_shape.image_bitmap.PixelFormat:=pf24bit;
except
show_modal_message('Sorry, unable to convert image: '+bgnd_shape.shape_name);
EXIT;
end;//try
end;
saved_screen_cursor:=Screen.Cursor;
Screen.Cursor:=crHourglass;
with bgimage.image_shape do begin
if undo_bitmap=nil then undo_bitmap:=TBitmap.Create;
undo_bitmap.Assign(image_bitmap); // save for undo
inwidth:=image_bitmap.Width;
inheight:=image_bitmap.Height;
map_clarity_form.progress_bar.Max:=inheight;
map_clarity_form.progress_bar.Position:=0;
for inrow:=0 to do_truncx(inheight-1) do begin
for incol:=0 to do_truncx(inwidth-1) do begin
pixel_colour:=image_bitmap.Canvas.Pixels[incol,inrow];
pixel_colour:=pixel_colour XOR $00FFFFFF; // negative image
image_bitmap.Canvas.Pixels[incol,inrow]:=pixel_colour;
end;//for
map_clarity_form.progress_bar.Position:=inrow;
Application.ProcessMessages;
end;//for
end;//with image
Screen.Cursor:=saved_screen_cursor;
map_clarity_form.progress_bar.Position:=0; // reset
Application.ProcessMessages;
end;//with shape
end;//with items
end;//with listbox
RESULT:=True;
clear_rotated_bitmap(n); // 234e
shapes_saved:=False; // need a resave.
shapes_current_state;
redraw_pad(True,False);
end;
//______________________________________________________________________________
function make_low_contrast_image(n,shade_code:integer; alerts:boolean):boolean;
var
m:integer;
bias:integer;
red,green,blue:integer;
inrow,incol,outrow,outcol:integer;
inwidth,inheight:integer;
pixel_colour:TColor;
saved_screen_cursor:TCursor;
meta_str:string;
new_shape:Tbgnd_shape;
begin
RESULT:=False; // init
with bgnd_form.bgnd_shapes_listbox do begin
with Items do begin
if (Count<1) or (n<0) or (n>(Count-1)) then EXIT;
with Tbgshape(Objects[n]) do begin
if (bgnd_shape.shape_code<>-1) // not a picture shape.
or (bgnd_shape.shape_name=empty_picture_str)
or (bgimage=nil) // no existing bitmap.
then begin
show_modal_message('error: '+bgnd_shape.shape_name+' : no image content to convert'+#13+#13+'Select a picture shape in the list.');
EXIT;
end;
end;//with
if alerts=True // doing a selected image, make duplicate as backup...
then begin
with Tbgshape(Objects[n]) do begin
new_shape:=bgnd_shape;
new_shape.shape_name:='* '+bgnd_shape.shape_name;
new_shape.hide_bits:=bgnd_shape.hide_bits OR $01; // toggle bit on, hide shape
m:=n;
InsertObject(n,new_shape.shape_name,Tbgshape.Create); // inserted at lower index
n:=n+1; // first picture shape
Tbgshape(Objects[m]).bgnd_shape:=new_shape; // put data in list.
end;// with
with Tbgshape(Objects[m]) do begin // copy existing data
bgimage:=Tbgimage.Create; // create new image.
with bgimage.image_shape do begin
image_bitmap:=TBitmap.Create;
rotated_bitmap:=TBitmap.Create;
(* OT2024
image_metafile:=TMetafile.Create;
rotated_metafile:=TMetafile.Create;
rotated_picture:=TPicture.Create;
image_bitmap.Assign(Tbgshape(Items.Objects[n]).bgimage.image_shape.image_bitmap);
rotated_bitmap.Assign(Tbgshape(Items.Objects[n]).bgimage.image_shape.rotated_bitmap);
image_metafile.Assign(Tbgshape(Items.Objects[n]).bgimage.image_shape.image_metafile);
rotated_metafile.Assign(Tbgshape(Items.Objects[n]).bgimage.image_shape.rotated_metafile);
rotated_picture.Assign(Tbgshape(Items.Objects[n]).bgimage.image_shape.rotated_picture);
*)
end;//with
end;//with
shapes_current_state;
end;
with Tbgshape(Objects[n]) do begin
// first convert matafile to bitmap if necessary ...
(* OT2024
if bgnd_shape.picture_is_metafile=True
then begin
if alerts=True
then begin
if (bgimage.image_shape.image_metafile.Width>4800) // arbitrary
and (bgimage.image_shape.image_metafile.Height>3600) // arbitrary
then meta_str:='||This picture shape is a large image. Conversion may be slow.'
else meta_str:='';
if alert(4,' convert metafile ?',
'The selected picture shape||'
+bgnd_shape.shape_name
+'||contains a metafile image (EMF file). Metafile (vector) images can be zoomed without becoming fuzzy, pixelated or blocky.'
+'||Converting this picture shape to low-contrast will convert it to a conventional bitmap image (as in a scanned image).'
+'||Bitmap images can become fuzzy, pixelated or blocky when zoomed.'
+meta_str
+'||Do you want to proceed with the low-contrast conversion?',
'','','','','cancel conversion','continue - convert picture shape',0)=5
then EXIT;
end;
try
with bgimage.image_shape do begin
image_bitmap.Width:=image_metafile.Width;
image_bitmap.Height:=image_metafile.Height;
with image_bitmap.Canvas do begin // first blank the picture area...
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
Draw(0,0,image_metafile); // draw the metafile on it
end;//with
end;//with
except
show_modal_message('error - unable to convert matafile to bitmap');
EXIT;
end;//try
bgnd_shape.picture_is_metafile:=False;
end;
*)
// convert to 24-bit colour if necessary ...
if bgimage.image_shape.image_bitmap.PixelFormat<>pf24bit
then begin
try
bgimage.image_shape.image_bitmap.PixelFormat:=pf24bit;
except
show_modal_message('Sorry, unable to convert image: '+bgnd_shape.shape_name);
EXIT;
end;//try
end;
saved_screen_cursor:=Screen.Cursor;
Screen.Cursor:=crHourglass;
with bgimage.image_shape do begin
if undo_bitmap=nil then undo_bitmap:=TBitmap.Create;
undo_bitmap.Assign(image_bitmap); // save for undo
inwidth:=image_bitmap.Width;
inheight:=image_bitmap.Height;
map_clarity_form.progress_bar.Max:=inheight;
map_clarity_form.progress_bar.Position:=0;
for inrow:=0 to do_truncx(inheight-1) do begin
for incol:=0 to do_truncx(inwidth-1) do begin
pixel_colour:=image_bitmap.Canvas.Pixels[incol,inrow];
// extract colours ...
red:=(pixel_colour AND $000000FF);
green:=(pixel_colour AND $0000FF00) div $100;
blue:=(pixel_colour AND $00FF0000) div $10000;
case shade_code of
1: bias:=0; // black
2: bias:=41; // dark grey
3: bias:=84; // medium grey
4: bias:=127; // light grey
5: bias:=170; // white
else bias:=0; // keep compiler happy
end;//case
red:=bias+(red DIV 3); // 3 arbitrary = 0..85
green:=bias+(green DIV 3);
blue:=bias+(blue DIV 3);
if red>255 then red:=255;
if green>255 then green:=255;
if blue>255 then blue:=255;
pixel_colour:=(blue*$10000)+(green*$100)+red;
image_bitmap.Canvas.Pixels[incol,inrow]:=pixel_colour;
end;//for
map_clarity_form.progress_bar.Position:=inrow;
Application.ProcessMessages;
end;//for
end;//with image
Screen.Cursor:=saved_screen_cursor;
map_clarity_form.progress_bar.Position:=0; // reset
Application.ProcessMessages;
end;//with shape
end;//with items
end;//with listbox
RESULT:=True;
clear_rotated_bitmap(n); // 234e
shapes_saved:=False; // need a resave.
shapes_current_state;
redraw_pad(True,False);
end;
//______________________________________________________________________________
function make_2_tone_image(n,threshold:integer; hi_colour,lo_colour:TColor; alerts:boolean):boolean;
var
inrow,incol,outrow,outcol:integer;
inwidth,inheight:integer;
red,green,blue,grey:integer;
pixel_colour:TColor;
saved_screen_cursor:TCursor;
meta_str:string;
begin
RESULT:=False; // init
with bgnd_form.bgnd_shapes_listbox do begin
with Items do begin
if (Count<1) or (n<0) or (n>(Count-1)) then EXIT;
with Tbgshape(Objects[n]) do begin
if (bgnd_shape.shape_code<>-1) // not a picture shape.
or (bgnd_shape.shape_name=empty_picture_str)
or (bgimage=nil) // no existing bitmap.
then begin
show_modal_message('error: '+bgnd_shape.shape_name+' : no image content to convert'+#13+#13+'Select a picture shape in the list.');
EXIT;
end;
if alerts=True
then begin
if alert(4,' convert to 2-tone image ?',
'This function will convert the image in the selected picture shape:||'
+bgnd_shape.shape_name
+'||to a 2-tone image.'
+'||This can be helpful when working over a background map so that the map features can be clearly seen.'
+'||On large images conversion may take some time to complete.'
+'||Do you want to proceed with the 2-tone conversion?',
'','','','','cancel conversion','yes - continue',0)=5 then EXIT;
end;
// first convert matafile to bitmap if necessary ...
(* OT2024
if bgnd_shape.picture_is_metafile=True
then begin
if alerts=True
then begin
if (bgimage.image_shape.image_metafile.Width>4800) // arbitrary
and (bgimage.image_shape.image_metafile.Height>3600) // arbitrary
then meta_str:='||This picture shape is a large image. Conversion may be slow.'
else meta_str:='';
if alert(4,' convert metafile ?',
'The selected picture shape||'
+bgnd_shape.shape_name
+'||contains a metafile image (EMF file). Metafile (vector) images can be zoomed without becoming fuzzy, pixelated or blocky.'
+'||Converting this picture shape to a 2-tone image will convert it to a conventional bitmap image (as in a scanned image).'
+'||Bitmap images can become fuzzy, pixelated or blocky when zoomed.'
+meta_str
+'||Do you want to proceed with the 2-tone conversion?',
'','','','','cancel conversion','continue - convert picture shape',0)=5
then EXIT;
end;
try
with bgimage.image_shape do begin
image_bitmap.Width:=image_metafile.Width;
image_bitmap.Height:=image_metafile.Height;
with image_bitmap.Canvas do begin // first blank the picture area...
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
Draw(0,0,image_metafile); // draw the metafile on it
end;//with
end;//with
except
show_modal_message('error - unable to convert matafile to bitmap');
EXIT;
end;//try
bgnd_shape.picture_is_metafile:=False;
end;
*)
// convert to 24-bit colour if necessary ...
if bgimage.image_shape.image_bitmap.PixelFormat<>pf24bit
then begin
try
bgimage.image_shape.image_bitmap.PixelFormat:=pf24bit;
except
show_modal_message('Sorry, unable to convert image: '+bgnd_shape.shape_name);
EXIT;
end;//try
end;
saved_screen_cursor:=Screen.Cursor;
Screen.Cursor:=crHourglass;
with bgimage.image_shape do begin
if undo_bitmap=nil then undo_bitmap:=TBitmap.Create;
undo_bitmap.Assign(image_bitmap); // save for undo
inwidth:=image_bitmap.Width;
inheight:=image_bitmap.Height;
map_clarity_form.progress_bar.Max:=inheight;
map_clarity_form.progress_bar.Position:=0;
for inrow:=0 to do_truncx(inheight-1) do begin
for incol:=0 to do_truncx(inwidth-1) do begin
pixel_colour:=image_bitmap.Canvas.Pixels[incol,inrow];
// extract colours ...
red:=(pixel_colour AND $000000FF);
green:=(pixel_colour AND $0000FF00) div $100;
blue:=(pixel_colour AND $00FF0000) div $10000;
grey:=(red+green+blue) DIV 3;
if grey<threshold
then image_bitmap.Canvas.Pixels[incol,inrow]:=lo_colour
else image_bitmap.Canvas.Pixels[incol,inrow]:=hi_colour;
end;//for
map_clarity_form.progress_bar.Position:=inrow;
Application.ProcessMessages;
end;//for
end;//with image
Screen.Cursor:=saved_screen_cursor;
map_clarity_form.progress_bar.Position:=0; // reset
Application.ProcessMessages;
end;//with shape
end;//with items
end;//with listbox
RESULT:=True;
clear_rotated_bitmap(n); // 234e
shapes_saved:=False; // need a resave.
shapes_current_state;
redraw_pad(True,False);
end;
//______________________________________________________________________________
function make_interpolated_image(n,filter_index,zoom_size:integer; alerts:boolean):boolean;
var
new_bmp:TBitmap;
meta_str:string;
begin
RESULT:=False; // init
with bgnd_form.bgnd_shapes_listbox do begin
with Items do begin
if (Count<1) or (n<0) or (n>(Count-1)) then EXIT;
with Tbgshape(Objects[n]) do begin
if (bgnd_shape.shape_code<>-1) // not a picture shape.
or (bgnd_shape.shape_name=empty_picture_str)
or (bgimage=nil) // no existing bitmap.
then begin
show_modal_message('error: '+bgnd_shape.shape_name+' : no image content to convert'+#13+#13+'Select a picture shape in the list.');
EXIT;
end;
// first convert matafile to bitmap if necessary ...
(* OT2024
if bgnd_shape.picture_is_metafile=True
then begin
if alerts=True
then begin
if (bgimage.image_shape.image_metafile.Width>4800) // arbitrary
and (bgimage.image_shape.image_metafile.Height>3600) // arbitrary
then meta_str:='||This picture shape is a large image. Conversion may be slow.'
else meta_str:='';
if alert(4,' convert metafile ?',
'The selected picture shape||'
+bgnd_shape.shape_name
+'||contains a metafile image (EMF file). Metafile (vector) images can be zoomed without becoming fuzzy, pixelated or blocky.'
+'||Converting this picture shape to a 2-tone image will convert it to a conventional bitmap image (as in a scanned image).'
+'||Bitmap images can become fuzzy, pixelated or blocky when zoomed.'
+meta_str
+'||Do you want to proceed with the 2-tone conversion?',
'','','','','cancel conversion','continue - convert picture shape',0)=5
then EXIT;
end;
try
with bgimage.image_shape do begin
image_bitmap.Width:=image_metafile.Width;
image_bitmap.Height:=image_metafile.Height;
with image_bitmap.Canvas do begin // first blank the picture area...
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
Draw(0,0,image_metafile); // draw the metafile on it
end;//with
end;//with
except
show_modal_message('error - unable to convert matafile to bitmap');
EXIT;
end;//try
bgnd_shape.picture_is_metafile:=False;
end;
*)
// convert to 24-bit colour if necessary ...
if bgimage.image_shape.image_bitmap.PixelFormat<>pf24bit
then begin
try
bgimage.image_shape.image_bitmap.PixelFormat:=pf24bit;
except
show_modal_message('Sorry, unable to convert image: '+bgnd_shape.shape_name);
EXIT;
end;//try
end;
with bgimage.image_shape do begin
if undo_bitmap=nil then undo_bitmap:=TBitmap.Create;
undo_bitmap.Assign(image_bitmap); // save for undo
new_bmp:=TBitmap.Create;
new_bmp.Width:=zoom_size;
new_bmp.Height:=zoom_size;
if (new_bmp.Width<image_bitmap.Width) or (new_bmp.Height<image_bitmap.Height)
then begin
showmessage('error: downscaling not supported: '+IntToStr(image_bitmap.Width)+'x'+IntToStr(image_bitmap.Height)+' > '+IntToStr(new_bmp.Width)+'x'+IntToStr(new_bmp.Height));
new_bmp.Free;
EXIT;
end;
// OT2024 stretch_bitmap(image_bitmap,new_bmp,ResampleFilters[filter_index].Filter, ResampleFilters[filter_index].Width); // also steps the progress bar
image_bitmap.Assign(new_bmp); // replace the shape image
image_width:=new_bmp.Width; // update the shape info
image_height:=new_bmp.Height;
new_bmp.Free;
end;//with
end;//with shape
end;//with items
end;//with listbox
map_clarity_form.progress_bar.Position:=0; // reset
Application.ProcessMessages;
RESULT:=True;
clear_rotated_bitmap(n); // 234e
shapes_saved:=False; // need a resave.