-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileSetViewer.cs
More file actions
10115 lines (9401 loc) · 422 KB
/
Copy pathTileSetViewer.cs
File metadata and controls
10115 lines (9401 loc) · 422 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
// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts,
// for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies.
// E:\VirtualTexturesEditor\TileSetViewer.exe
// TileSetViewer, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
// Global type: <Module>
// Entry point: tfViewer.Program.Main
// Architecture: x64
// Runtime: v4.0.30319
// This assembly was compiled using the /deterministic option.
// Hash algorithm: SHA1
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management;
using System.Net;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using GDEXSharp;
using Graphine.Core;
using GraphineLicenseManager.Ed25519b;
using Microsoft.Win32;
using Nixel;
using tfViewer.Properties;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("Graphine NV")]
[assembly: AssemblyProduct("Tile Set Viewer")]
[assembly: AssemblyCopyright("Copyright Graphine NV © 2013-2017")]
[assembly: AssemblyInformationalVersion("5.0.7.34144")]
[assembly: AssemblyDescription("Generated by cholleme@ZELDA from master/9a8e2032016ca90aea9bc098289abc7dc1f56d8c")]
[assembly: AssemblyTitle("Graphine Tile Set Viewer")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a40351f5-e12b-4387-a593-30885b56f044")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
namespace tfViewer
{
internal class AboutBox1 : Form
{
private IContainer components;
private TableLayoutPanel tableLayoutPanel;
private PictureBox logoPictureBox;
private Label labelProductName;
private Label labelVersion;
private Label labelCopyright;
private TextBox textBoxDescription;
private Button okButton;
private LinkLabel linkSilk;
private LinkLabel linkCompanyName;
public string AssemblyTitle
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false);
if (customAttributes.Length != 0)
{
AssemblyTitleAttribute assemblyTitleAttribute = (AssemblyTitleAttribute)customAttributes[0];
if (assemblyTitleAttribute.Title != "")
{
return assemblyTitleAttribute.Title;
}
}
return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyInformationalVersion
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), inherit: false);
if (customAttributes.Length == 0)
{
return "";
}
return ((AssemblyInformationalVersionAttribute)customAttributes[0]).InformationalVersion;
}
}
public string AssemblyDescription
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), inherit: false);
if (customAttributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), inherit: false);
if (customAttributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)customAttributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), inherit: false);
if (customAttributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)customAttributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), inherit: false);
if (customAttributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)customAttributes[0]).Company;
}
}
public AboutBox1()
{
InitializeComponent();
Text = "About " + AssemblyProduct;
labelProductName.Text = AssemblyProduct;
labelVersion.Text = "Version " + AssemblyInformationalVersion;
labelCopyright.Text = AssemblyCopyright;
linkCompanyName.Text = AssemblyCompany;
textBoxDescription.Text = AssemblyDescription;
}
private void linkCompanyName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(new ProcessStartInfo("http://www.graphinesoftware.com"));
}
private void linkSilk_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(new ProcessStartInfo("http://www.famfamfam.com/lab/icons/silk/"));
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.logoPictureBox = new System.Windows.Forms.PictureBox();
this.labelProductName = new System.Windows.Forms.Label();
this.labelVersion = new System.Windows.Forms.Label();
this.labelCopyright = new System.Windows.Forms.Label();
this.linkCompanyName = new System.Windows.Forms.LinkLabel();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.linkSilk = new System.Windows.Forms.LinkLabel();
this.tableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)this.logoPictureBox).BeginInit();
base.SuspendLayout();
this.tableLayoutPanel.ColumnCount = 3;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 63.59649f));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 36.40351f));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 174f));
this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0);
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.linkCompanyName, 1, 3);
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4);
this.tableLayoutPanel.Controls.Add(this.okButton, 2, 5);
this.tableLayoutPanel.Controls.Add(this.linkSilk, 1, 5);
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel.Location = new System.Drawing.Point(9, 9);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.RowCount = 6;
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.68376f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 9.82906f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.98039f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.58823f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20f));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20f));
this.tableLayoutPanel.Size = new System.Drawing.Size(397, 255);
this.tableLayoutPanel.TabIndex = 0;
this.logoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.logoPictureBox.Image = tfViewer.Properties.Resources.about_logo;
this.logoPictureBox.Location = new System.Drawing.Point(3, 3);
this.logoPictureBox.Name = "logoPictureBox";
this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 6);
this.logoPictureBox.Size = new System.Drawing.Size(135, 249);
this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.logoPictureBox.TabIndex = 12;
this.logoPictureBox.TabStop = false;
this.tableLayoutPanel.SetColumnSpan(this.labelProductName, 2);
this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelProductName.Location = new System.Drawing.Point(147, 0);
this.labelProductName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 17);
this.labelProductName.Name = "labelProductName";
this.labelProductName.Size = new System.Drawing.Size(247, 17);
this.labelProductName.TabIndex = 19;
this.labelProductName.Text = "Granite SDK by Graphine";
this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.tableLayoutPanel.SetColumnSpan(this.labelVersion, 2);
this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelVersion.Location = new System.Drawing.Point(147, 24);
this.labelVersion.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 17);
this.labelVersion.Name = "labelVersion";
this.labelVersion.Size = new System.Drawing.Size(247, 17);
this.labelVersion.TabIndex = 0;
this.labelVersion.Text = "1.9";
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.tableLayoutPanel.SetColumnSpan(this.labelCopyright, 2);
this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCopyright.Location = new System.Drawing.Point(147, 48);
this.labelCopyright.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 17);
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Size = new System.Drawing.Size(247, 17);
this.labelCopyright.TabIndex = 21;
this.labelCopyright.Text = "Copyright (c) 2012-2013";
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.linkCompanyName.AutoSize = true;
this.tableLayoutPanel.SetColumnSpan(this.linkCompanyName, 2);
this.linkCompanyName.Dock = System.Windows.Forms.DockStyle.Fill;
this.linkCompanyName.Location = new System.Drawing.Point(147, 74);
this.linkCompanyName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.linkCompanyName.Name = "linkCompanyName";
this.linkCompanyName.Size = new System.Drawing.Size(247, 24);
this.linkCompanyName.TabIndex = 26;
this.linkCompanyName.TabStop = true;
this.linkCompanyName.Text = "Graphine Software";
this.linkCompanyName.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(linkCompanyName_LinkClicked);
this.tableLayoutPanel.SetColumnSpan(this.textBoxDescription, 2);
this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxDescription.Location = new System.Drawing.Point(147, 101);
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.ReadOnly = true;
this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxDescription.Size = new System.Drawing.Size(247, 121);
this.textBoxDescription.TabIndex = 23;
this.textBoxDescription.TabStop = false;
this.textBoxDescription.Text = "Description";
this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.Location = new System.Drawing.Point(319, 228);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 24);
this.okButton.TabIndex = 24;
this.okButton.Text = "&OK";
this.linkSilk.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
this.linkSilk.AutoSize = true;
this.linkSilk.Location = new System.Drawing.Point(147, 232);
this.linkSilk.Margin = new System.Windows.Forms.Padding(6, 0, 3, 10);
this.linkSilk.Name = "linkSilk";
this.linkSilk.Size = new System.Drawing.Size(53, 13);
this.linkSilk.TabIndex = 25;
this.linkSilk.TabStop = true;
this.linkSilk.Text = "Silk Icons";
this.linkSilk.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(linkSilk_LinkClicked);
base.AcceptButton = this.okButton;
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(415, 273);
base.Controls.Add(this.tableLayoutPanel);
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
base.MaximizeBox = false;
base.MinimizeBox = false;
base.Name = "AboutBox1";
base.Padding = new System.Windows.Forms.Padding(9);
base.ShowIcon = false;
base.ShowInTaskbar = false;
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "About";
this.tableLayoutPanel.ResumeLayout(false);
this.tableLayoutPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)this.logoPictureBox).EndInit();
base.ResumeLayout(false);
}
}
internal class CachedReader : IDisposable
{
public struct CachedTileInfo
{
public Bitmap data;
public TileInfo info;
public bool decodeError;
public bool loaded;
public TileId tid;
public int layer;
}
private Thread hashThread;
private HashThreadClass hashThreadObject;
private HashResults hashResults;
private List<List<CachedTileInfo>> Cache;
private CachedTileInfo emptyTile;
private int topLeftX;
private int topLeftY;
private Size numTiles;
private Size tileSize;
private Size tileContentSize;
private int numLayers;
private int borderSize;
private Size cacheSize;
private int numMipLevels;
private Layout layerLayout;
private int currentLayer;
private DataType layerDataType;
private int level;
private bool showTileInfo;
private OutputMode outputMode;
private bool showTileBorders;
private bool showOverlappingTileBorders;
private int channelCount;
private int tileLayerSize;
private IGtsFileReader reader;
private bool isConnected;
public static double Exposure { get; set; }
public CachedReader(string fileName)
{
StringVector stringVector = new StringVector();
if (Settings.Default.SearchPaths != null)
{
StringEnumerator enumerator = Settings.Default.SearchPaths.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
string current = enumerator.Current;
stringVector.Add(current);
}
}
finally
{
if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}
}
}
NixelInitializationInfo initContext = default(NixelInitializationInfo);
ITileFileFactory.Initialize(ref initContext);
Error error = ITileFileFactory.CreateGtsFileReader(fileName, stringVector, 33554432u, out reader);
if (error != 0)
{
ITileFileFactory.GetLastError(out var errorInfo);
string empty = string.Empty;
if (1 == 0)
{
}
string text = error switch
{
Error.InvalidVersion => "The GTS file is incompatible with this version of the tools. Possibly, it was created using a newer version of the tools. Please upgrade the tools to the latest version.",
Error.InvalidPageFile => errorInfo.message,
_ => "Could not open the tile file due to the following error:\n" + error,
};
if (1 == 0)
{
}
MessageBox.Show(text, "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
isConnected = false;
}
else
{
isConnected = true;
TiledTopology topology = reader.GetTopology();
RasterTileDimension tileDimensions = reader.GetTileDimensions();
int width = (int)topology.width;
int height = (int)topology.height;
int width2 = (int)(tileDimensions.width + 2 * tileDimensions.border);
int height2 = (int)(tileDimensions.height + 2 * tileDimensions.border);
numTiles = new Size(width, height);
tileSize = new Size(width2, height2);
tileContentSize = new Size((int)tileDimensions.width, (int)tileDimensions.height);
numMipLevels = (int)topology.numLevels;
numLayers = (int)topology.numLayers;
borderSize = (int)tileDimensions.border;
emptyTile.loaded = false;
}
}
public void Dispose()
{
ITileFileFactory.Release();
reader.Dispose();
isConnected = false;
if (hashThread != null && hashThread.IsAlive)
{
if (hashThreadObject != null)
{
hashThreadObject.Abort();
}
else
{
hashThread.Abort();
}
}
}
public bool IsConnected()
{
return isConnected;
}
public void InitCache(Size cacheSize, int level, int currentLayer, Layout layerLayout, int viewPortX, int viewPortY)
{
this.level = level;
topLeftX = viewPortX;
topLeftY = viewPortY;
this.currentLayer = currentLayer;
this.layerLayout = layerLayout;
this.cacheSize = cacheSize;
layerDataType = reader.GetTopology().dataType[currentLayer];
tileLayerSize = DataTypeInfo.GetPixelSize(layerDataType) * tileSize.Width * tileSize.Height;
channelCount = DataTypeInfo.GetNumChannels(reader.GetTopology().dataType[currentLayer]);
if (outputMode == OutputMode.Decoded)
{
reader.SetOutputMode(TileDataMode.Decoded);
}
else if (outputMode == OutputMode.DecodedMip)
{
reader.SetOutputMode(TileDataMode.DecodedMip);
}
else if (outputMode == OutputMode.Transcoded)
{
reader.SetOutputMode(TileDataMode.Transcoded);
}
Cache = new List<List<CachedTileInfo>>();
for (int i = 0; i < this.cacheSize.Height; i++)
{
Cache.Add(new List<CachedTileInfo>());
for (int j = 0; j < this.cacheSize.Width; j++)
{
Cache.Last().Add(emptyTile);
}
}
FillEmptyTiles();
GC.Collect();
}
public void RefreshCache()
{
if (Cache == null)
{
return;
}
for (int i = 0; i < Cache.Count; i++)
{
for (int j = 0; j < Cache[i].Count; j++)
{
CachedTileInfo value = Cache[i][j];
value.loaded = false;
Cache[i][j] = value;
}
}
FillEmptyTiles();
}
public void SetOutputMode(OutputMode outputMode)
{
this.outputMode = outputMode;
InitCache(cacheSize, level, currentLayer, layerLayout, topLeftX, topLeftY);
}
public void SetShowTileInfo(bool showTileInfo)
{
this.showTileInfo = showTileInfo;
InitCache(cacheSize, level, currentLayer, layerLayout, topLeftX, topLeftY);
}
public void SetShowOverlappingTileBorders(bool showOverlappingTileBorders)
{
this.showOverlappingTileBorders = showOverlappingTileBorders;
InitCache(cacheSize, level, currentLayer, layerLayout, topLeftX, topLeftY);
}
public void SetShowTileBorders(bool showTileBorders)
{
this.showTileBorders = showTileBorders;
InitCache(cacheSize, level, currentLayer, layerLayout, topLeftX, topLeftY);
}
public void ChangeLayer(int currentLayer, Layout layerLayout)
{
InitCache(cacheSize, level, currentLayer, layerLayout, topLeftX, topLeftY);
}
public void ChangeLevel(int level, int viewPortX, int viewPortY)
{
InitCache(cacheSize, level, currentLayer, layerLayout, viewPortX, viewPortY);
}
public void ChangeCacheSize(int viewPortX, int viewPortY, Size newSize)
{
Size size = new Size(newSize.Width + 1, newSize.Height + 1);
if (size.Height > cacheSize.Height)
{
for (int i = 0; i < size.Height - cacheSize.Height; i++)
{
Cache.Add(new List<CachedTileInfo>());
for (int j = 0; j < cacheSize.Width; j++)
{
Cache.Last().Add(emptyTile);
}
}
}
else
{
for (int k = 0; k < cacheSize.Height - size.Height; k++)
{
Cache.Remove(Cache.Last());
}
}
cacheSize.Height = size.Height;
if (size.Width > cacheSize.Width)
{
for (int l = 0; l < cacheSize.Height; l++)
{
for (int m = 0; m < size.Width - cacheSize.Width; m++)
{
Cache[l].Add(emptyTile);
}
}
}
else
{
for (int n = 0; n < cacheSize.Height; n++)
{
for (int num = 0; num < cacheSize.Width - size.Width; num++)
{
Cache[n].Remove(Cache[n].Last());
}
}
}
cacheSize.Width = size.Width;
Update(viewPortX, viewPortY);
}
public void Update(int viewPortX, int viewPortY)
{
int num = Math.Abs(viewPortX - topLeftX);
int num2 = Math.Abs(viewPortY - topLeftY);
if (num >= cacheSize.Width || num2 >= cacheSize.Height)
{
InitCache(cacheSize, level, currentLayer, layerLayout, viewPortX, viewPortY);
return;
}
if (num2 > 0)
{
for (int i = 0; i < num2; i++)
{
if (viewPortY > topLeftY)
{
Cache.RemoveAt(0);
}
else
{
Cache.Remove(Cache.Last());
}
}
}
if (num > 0)
{
for (int j = 0; j < cacheSize.Height - num2; j++)
{
for (int k = 0; k < num; k++)
{
if (viewPortX > topLeftX)
{
Cache[j].RemoveAt(0);
}
else
{
Cache[j].Remove(Cache[j].Last());
}
}
}
}
if (num2 > 0)
{
for (int l = 0; l < num2; l++)
{
if (viewPortY > topLeftY)
{
Cache.Add(new List<CachedTileInfo>());
for (int m = 0; m < cacheSize.Width - num; m++)
{
Cache.Last().Add(emptyTile);
}
}
else
{
Cache.Insert(0, new List<CachedTileInfo>());
for (int n = 0; n < cacheSize.Width - num; n++)
{
Cache.First().Add(emptyTile);
}
}
}
}
if (num > 0)
{
for (int num3 = 0; num3 < cacheSize.Height; num3++)
{
for (int num4 = 0; num4 < num; num4++)
{
if (viewPortX > topLeftX)
{
Cache[num3].Add(emptyTile);
}
else
{
Cache[num3].Insert(0, emptyTile);
}
}
}
}
topLeftX = viewPortX;
topLeftY = viewPortY;
FillEmptyTiles();
GC.Collect();
}
public CachedTileInfo GetTile(int offsetX, int offsetY)
{
return Cache[offsetY][offsetX];
}
public Size GetCacheSize()
{
return cacheSize;
}
public void DisplayHeaderInfo(string fileName)
{
FileInfoForm fileInfoForm = new FileInfoForm();
fileInfoForm.FillData(fileName, ref reader);
fileInfoForm.ShowDialog();
}
public void DisplayThumbnails()
{
ThumbnailForm thumbnailForm = new ThumbnailForm();
thumbnailForm.InitializeThumbnails(ref reader);
thumbnailForm.ShowDialog();
}
public CachedTileInfo[,] GetTileMatrix()
{
CachedTileInfo[,] array = new CachedTileInfo[cacheSize.Width, cacheSize.Height];
for (int i = 0; i < cacheSize.Height; i++)
{
for (int j = 0; j < cacheSize.Width; j++)
{
array[j, i] = Cache[i][j];
}
}
return array;
}
public bool RequestLowestMipContent(out Bitmap data)
{
int levelWidth = (int)reader.GetTopology().GetLevelWidth((uint)(numMipLevels - 1));
int levelHeight = (int)reader.GetTopology().GetLevelHeight((uint)(numMipLevels - 1));
int width = tileContentSize.Width * levelWidth;
int height = tileContentSize.Height * levelHeight;
Bitmap bitmap = new Bitmap(width, height);
bool flag = true;
for (int i = 0; i < levelWidth; i++)
{
for (int j = 0; j < levelHeight; j++)
{
Bitmap pageBmp = new Bitmap(tileSize.Width, tileSize.Height);
flag &= RequestTile(ref pageBmp, i, j, numMipLevels - 1);
using Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(srcRect: new Rectangle(borderSize, borderSize, tileContentSize.Width, tileContentSize.Height), destRect: new Rectangle(tileContentSize.Width * i, tileContentSize.Height * j, tileContentSize.Width, tileContentSize.Height), image: pageBmp, srcUnit: GraphicsUnit.Pixel);
}
}
if (flag)
{
data = bitmap;
}
else
{
data = null;
}
return flag;
}
private CachedTileInfo loadCacheTile(int tx, int ty)
{
CachedTileInfo result = default(CachedTileInfo);
Bitmap pageBmp = new Bitmap(tileSize.Width, tileSize.Height);
result.decodeError = !RequestTile(ref pageBmp, tx, ty, level);
result.data = pageBmp;
result.layer = currentLayer;
TileId tid = (result.tid = new TileId((uint)tx, (uint)ty, (uint)level));
if (!IsValidTile(tx, ty, level) || reader.GetTileInfo(tid, out result.info) != 0)
{
result.info = default(TileInfo);
}
else
{
result.loaded = true;
}
return result;
}
private void FillEmptyTiles()
{
for (int i = 0; i < cacheSize.Height; i++)
{
for (int j = 0; j < cacheSize.Width; j++)
{
if (Cache[i][j].loaded)
{
continue;
}
CachedTileInfo tile = loadCacheTile(j + topLeftX, i + topLeftY);
if (tile.loaded)
{
if (showTileInfo)
{
DrawInfo(ref tile, j + topLeftX, i + topLeftY);
}
if (showTileBorders || showOverlappingTileBorders)
{
DrawBorders(ref tile);
}
}
if (IsValidTile(j + topLeftX, i + topLeftY, level))
{
DrawIconOverlay(ref tile);
}
Cache[i][j] = tile;
}
}
}
private void DrawBorders(ref CachedTileInfo tile)
{
int num = (tileSize.Width - tileContentSize.Width) / 2;
Graphics graphics = Graphics.FromImage(tile.data);
if (showTileBorders && showOverlappingTileBorders)
{
graphics.DrawRectangle(new Pen(System.Drawing.Color.White), new Rectangle(num, num, tileContentSize.Width, tileContentSize.Height));
graphics.DrawRectangle(new Pen(System.Drawing.Color.Black), new Rectangle(0, 0, tileSize.Width, tileSize.Height));
}
else if (showTileBorders)
{
graphics.DrawRectangle(new Pen(System.Drawing.Color.Black), new Rectangle(num, num, tileContentSize.Width, tileContentSize.Height));
}
graphics.Flush();
}
private void DrawInfo(ref CachedTileInfo tile, int x, int y)
{
Point point = new Point(0, 0);
point.X += (tileSize.Width - tileContentSize.Width) / 2 + 1;
point.Y += (tileSize.Height - tileContentSize.Height) / 2 + 1;
string text = "Tile [" + x + "," + y + "] @ " + level;
text = text + "\n TileSize: " + tile.info.totalTileSize;
text = text + "\n Page: " + tile.info.layerTile[currentLayer].pageId;
text = text + "\n PageFile: " + tile.info.layerTile[currentLayer].pageFileId;
text = text + "\n TileID: " + tile.info.layerTile[currentLayer].flatTileId;
text = text + "\n LayerSize: " + tile.info.layerTile[currentLayer].totalSize;
text = text + "\n Codec: " + tile.info.layerTile[currentLayer].codec;
text = text + "\n Param. bl.: " + tile.info.layerTile[currentLayer].parameterBlock;
Brush brush = new SolidBrush(System.Drawing.Color.White);
Brush brush2 = new SolidBrush(System.Drawing.Color.Black);
Font menuFont = SystemFonts.MenuFont;
Graphics graphics = Graphics.FromImage(tile.data);
graphics.DrawString(text, menuFont, brush2, new Point(point.X - 1, point.Y));
graphics.DrawString(text, menuFont, brush2, new Point(point.X, point.Y - 1));
graphics.DrawString(text, menuFont, brush2, new Point(point.X + 1, point.Y));
graphics.DrawString(text, menuFont, brush2, new Point(point.X, point.Y + 1));
graphics.DrawString(text, menuFont, brush, point);
graphics.Flush();
}
private void DrawIconOverlay(ref CachedTileInfo tile)
{
Point point = new Point(tileContentSize.Width - 16, tileContentSize.Height - 16);
Graphics graphics = Graphics.FromImage(tile.data);
string s = "";
if (tile.info.layerTile == null)
{
graphics.DrawImageUnscaled(Resources.cross, point);
s = "NoData";
}
else if (tile.info.layerTile[currentLayer].bNoDataTile)
{
graphics.DrawImageUnscaled(Resources.arrow_up, point);
s = "NoData";
}
else if (tile.decodeError)
{
graphics.DrawImageUnscaled(Resources.bomb, point);
s = "CodecErr";
}
Font font = new Font(SystemFonts.MenuFont.FontFamily, 6f);
Brush brush = new SolidBrush(System.Drawing.Color.Black);
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Far;
stringFormat.LineAlignment = StringAlignment.Far;
RectangleF layoutRectangle = new RectangleF(0f, 0f, tileContentSize.Width - Resources.cross.Width, tileContentSize.Height);
graphics.DrawString(s, font, brush, layoutRectangle, stringFormat);
graphics.Flush();
graphics.Dispose();
}
private bool IsValidTile(int x, int y, int l)
{
if (l >= numMipLevels)
{
return false;
}
Size size = LevelSizeInTiles(l);
if (x < 0 || y < 0 || x >= size.Width || y >= size.Height)
{
return false;
}
return true;
}
public bool RequestTile(ref Bitmap pageBmp, int x, int y, int l)
{
if (!IsValidTile(x, y, l))
{
DrawColoredTile(pageBmp, System.Drawing.Color.Transparent);
return false;
}
LayerTileId tid = new LayerTileId((uint)x, (uint)y, (uint)l, (uint)currentLayer);
MappedTileLayerRead outMappedTileLayer;
Error error = reader.MapTileLayerRead(tid, mapBorders: true, out outMappedTileLayer);
switch (error)
{
case Error.NoData:
DrawColoredTile(pageBmp, System.Drawing.Color.Cyan);
return true;
default:
DrawColoredTile(pageBmp, System.Drawing.Color.Cyan);
return false;
case Error.Ok:
{
int num = channelCount;
PixelFormat format;
switch (channelCount)
{
case 1:
case 2:
case 3:
num = 3;
format = PixelFormat.Format24bppRgb;
break;
case 4:
num = 4;
format = PixelFormat.Format32bppArgb;
break;
default:
DrawColoredTile(pageBmp, System.Drawing.Color.Cyan);
reader.UnMapTileLayerRead(tid);
return false;
}
float hdrMin = 0f;
float hdrMax = ((Exposure == 0.0) ? 1f : ((float)Math.Pow(2.0, 0.0 - Exposure)));
IntPtr intPtr = Marshal.AllocHGlobal(num * tileSize.Width * tileSize.Height);
switch (DataTypeInfo.GetChannelSize(layerDataType))
{
case 1:
if (channelCount == 1 || channelCount == 2)
{
intPtr = Marshal.AllocHGlobal(num * tileSize.Width * tileSize.Height);
if (Tools.ConvertData(layerDataType, outMappedTileLayer.data, (uint)(tileSize.Width * tileSize.Height), DataType.R8G8B8_SRGB, intPtr) == Error.Ok)
{
break;
}
Marshal.FreeHGlobal(intPtr);
goto default;
}
Utilities.CopyMemory(intPtr, outMappedTileLayer.data, (uint)(channelCount * tileSize.Width * tileSize.Height));
break;
case 2:
if (channelCount == 3)
{
error = Tools.ConvertData(layerDataType, outMappedTileLayer.data, (uint)(tileSize.Width * tileSize.Height), DataType.R8G8B8_SRGB, intPtr, hdrMin, hdrMax);
}
if (channelCount == 4)
{
error = Tools.ConvertData(layerDataType, outMappedTileLayer.data, (uint)(tileSize.Width * tileSize.Height), DataType.R8G8B8A8_SRGB, intPtr, hdrMin, hdrMax);
}
if (error == Error.Ok)
{
break;
}
Marshal.FreeHGlobal(intPtr);
goto default;
case 4:
if (channelCount == 3)
{
error = Tools.ConvertData(layerDataType, outMappedTileLayer.data, (uint)(tileSize.Width * tileSize.Height), DataType.R8G8B8_SRGB, intPtr, hdrMin, hdrMax);
}
if (channelCount == 4)
{
error = Tools.ConvertData(layerDataType, outMappedTileLayer.data, (uint)(tileSize.Width * tileSize.Height), DataType.R8G8B8A8_SRGB, intPtr, hdrMin, hdrMax);