Skip to content

Commit 537e42f

Browse files
committed
Work on image scanning
1 parent a43d8fe commit 537e42f

File tree

10 files changed

+388
-319
lines changed

10 files changed

+388
-319
lines changed

SmartImage 3/App/Integration.cs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Diagnostics;
1111
using System.Reflection;
12+
using System.Runtime.CompilerServices;
1213
using System.Runtime.InteropServices;
1314
using System.Runtime.Versioning;
1415
using System.Text;
16+
using Kantan.Text;
1517
using Novus.OS;
1618
using Novus;
19+
using Novus.FileTypes;
1720
using Novus.Win32;
1821
using Novus.Win32.Structures.User32;
1922
using SmartImage.Lib;
@@ -323,27 +326,43 @@ public static string[] OpenFile(OpenFileNameFlags flags = 0)
323326
unsafe {
324327
const int ss = 4096;
325328

326-
Memory<sbyte> p1 = new sbyte[ss];
327-
Memory<sbyte> p2 = new sbyte[ss];
329+
Span<sbyte> p1 = stackalloc sbyte[ss];
330+
Span<sbyte> p2 = stackalloc sbyte[ss];
331+
ref sbyte p1p = ref p1.GetPinnableReference();
332+
ref sbyte p2p = ref p2.GetPinnableReference();
328333

329-
var p1p = p1.Pin();
330-
var p2p = p2.Pin();
334+
// var p1p = p1.Pin();
335+
// var p2p = p2.Pin();
336+
337+
var ext = new[] { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" };
338+
339+
/*var ext2 = FileType.Image.Select(f => "*." + f.MediaType.Split('/')[1])
340+
.Distinct();*/
341+
342+
const string wildcard = "*.*";
343+
344+
string extStr = string.Join(";", ext);
345+
346+
var p1pp = (nint) Unsafe.AsPointer(ref p1p);
347+
348+
var p2pp = (nint) Unsafe.AsPointer(ref p2p);
331349

332350
var ofn = new OpenFileName
333351
{
334352
lStructSize = Marshal.SizeOf<OpenFileName>(),
335-
lpstrFilter = "All Files\0*.*\0\0",
353+
lpstrFilter = $"Image files\0{extStr}\0\0",
336354
// lpstrFile = new string(p1),
337355
// lpstrFileTitle = new string(p2),
338-
lpstrFile = (nint) p1p.Pointer,
339-
lpstrFileTitle = (nint) p2p.Pointer,
340-
356+
// lpstrFile = (nint) p1p.Pointer,
357+
// lpstrFileTitle = (nint) p2p.Pointer,
358+
lpstrFile =p1pp,
359+
lpstrFileTitle = p2pp,
341360
lpstrInitialDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures),
342361
lpstrTitle = "Pick an image",
343362
Flags = (int) flags,
344363
// ofn.nMaxFile = ofn.lpstrFile.Length;
345364
nMaxFile = ss,
346-
nMaxFileTitle = ss
365+
nMaxFileTitle = ss,
347366
};
348367

349368
// ofn.nMaxFileTitle = ofn.lpstrFileTitle.Length;
@@ -356,7 +375,8 @@ public static string[] OpenFile(OpenFileNameFlags flags = 0)
356375
goto ret;
357376
}
358377

359-
var pd = Marshal.PtrToStringAuto((nint) p1p.Pointer);
378+
var pd = Marshal.PtrToStringAuto((nint) p1pp);
379+
// var pd = Marshal.PtrToStringAuto((nint) p1p.Pointer);
360380

361381
if (!(flags.HasFlag(OpenFileNameFlags.OFN_ALLOWMULTISELECT)) /*!Directory.Exists(pd)&&File.Exists(pd)*/) {
362382
files.Add(pd);
@@ -369,7 +389,8 @@ public static string[] OpenFile(OpenFileNameFlags flags = 0)
369389
}
370390

371391
var ofs = (ofn.nFileOffset * 2);
372-
var ptr1 = (((byte*) p1p.Pointer) + ofs);
392+
// var ptr1 = (((byte*) p1p.Pointer) + ofs);
393+
var ptr1 = (((byte*) p1pp) + ofs);
373394

374395
while (true) {
375396

@@ -390,8 +411,8 @@ public static string[] OpenFile(OpenFileNameFlags flags = 0)
390411
}
391412

392413
ret:
393-
p1p.Dispose();
394-
p2p.Dispose();
414+
// p1p.Dispose();
415+
// p2p.Dispose();
395416
return files.ToArray();
396417

397418
}

SmartImage 3/Mode/Shell/Assets/UI.Styles.cs

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static partial class UI
1818
{
1919
internal static readonly Attribute Atr_Green_Black = Attribute.Make(Color.Green, Color.Black);
2020
internal static readonly Attribute Atr_Green_White = Attribute.Make(Color.Green, Color.White);
21-
internal static readonly Attribute Atr_Green_Gray = Attribute.Make(Color.Green, Color.Gray);
21+
internal static readonly Attribute Atr_Green_Gray = Attribute.Make(Color.Green, Color.Gray);
2222
internal static readonly Attribute Atr_Green_DarkGray = Attribute.Make(Color.Green, Color.DarkGray);
2323
internal static readonly Attribute Atr_BrightGreen_White = Attribute.Make(Color.BrightGreen, Color.White);
2424
internal static readonly Attribute Atr_BrightGreen_Gray = Attribute.Make(Color.BrightGreen, Color.Gray);
@@ -29,7 +29,7 @@ internal static partial class UI
2929
internal static readonly Attribute Atr_Red_White = Attribute.Make(Color.Red, Color.White);
3030
internal static readonly Attribute Atr_Red_DarkGray = Attribute.Make(Color.Red, Color.DarkGray);
3131
internal static readonly Attribute Atr_BrightYellow_Black = Attribute.Make(Color.BrightYellow, Color.Black);
32-
32+
3333
internal static readonly Attribute Atr_White_Black = Attribute.Make(Color.White, Color.Black);
3434
internal static readonly Attribute Atr_White_Blue = Attribute.Make(Color.White, Color.Blue);
3535
internal static readonly Attribute Atr_White_Cyan = Attribute.Make(Color.White, Color.Cyan);
@@ -41,6 +41,7 @@ internal static partial class UI
4141
internal static readonly Attribute Atr_Cyan_Black = Attribute.Make(Color.Cyan, Color.Black);
4242
internal static readonly Attribute Atr_Cyan_White = Attribute.Make(Color.Cyan, Color.White);
4343
internal static readonly Attribute Atr_Blue_White = Attribute.Make(Color.Blue, Color.White);
44+
internal static readonly Attribute Atr_Blue_Gray = Attribute.Make(Color.Blue, Color.Gray);
4445
internal static readonly Attribute Atr_BrightBlue_White = Attribute.Make(Color.BrightBlue, Color.White);
4546
internal static readonly Attribute Atr_BrightBlue_Gray = Attribute.Make(Color.BrightBlue, Color.Gray);
4647
internal static readonly Attribute Atr_BrightRed_Black = Attribute.Make(Color.BrightRed, Color.Black);
@@ -54,8 +55,11 @@ internal static partial class UI
5455
private static readonly Attribute Atr_Brown_Black = Attribute.Make(Color.Brown, Color.Black);
5556
private static readonly Attribute Atr_DarkGray_White = Attribute.Make(Color.DarkGray, Color.White);
5657
internal static readonly Attribute Atr_Black_DarkGray = Attribute.Make(Color.Black, Color.DarkGray);
57-
58-
internal static readonly Attribute Atr_Brown_Gray = Attribute.Make(Color.Brown, Color.Gray);
58+
internal static readonly Attribute Atr_Black_Gray = Attribute.Make(Color.Black, Color.Gray);
59+
internal static readonly Attribute Atr_Brown_Gray = Attribute.Make(Color.Brown, Color.Gray);
60+
internal static readonly Attribute Atr_Brown_DarkGray = Attribute.Make(Color.Brown, Color.DarkGray);
61+
internal static readonly Attribute Atr_Yellow_DarkGray = Attribute.Make(Color.BrightYellow, Color.DarkGray);
62+
internal static readonly Attribute Atr_Yellow_White = Attribute.Make(Color.Brown, Color.White);
5963

6064
internal static readonly ColorScheme Cs_Err = Make(Atr_BrightRed_White, disabled: Atr_BrightRed_Gray);
6165
internal static readonly ColorScheme Cs_Ok = Make(Atr_BrightGreen_White, disabled: Atr_BrightGreen_Gray);
@@ -64,11 +68,13 @@ internal static partial class UI
6468

6569
internal static readonly ColorScheme Cs_Btn1x = new()
6670
{
67-
Normal = Atr_White_Cyan,
68-
Disabled = Atr_DarkGray_Blue,
69-
HotNormal = Atr_White_Cyan,
70-
HotFocus = Atr_White_BrightCyan,
71+
Normal = Atr_White_Cyan,
72+
Disabled = Atr_DarkGray_Blue,
73+
// HotNormal = Atr_White_Cyan,
74+
// HotFocus = Atr_White_BrightCyan,
7175
Focus = Atr_White_BrightCyan,
76+
HotNormal = Attribute.Make(Color.BrightYellow, Color.Cyan),
77+
HotFocus = Attribute.Make(Color.BrightYellow, Color.BrightCyan)
7278
};
7379

7480
internal static readonly ColorScheme Cs_Btn1 = new()
@@ -88,6 +94,7 @@ internal static partial class UI
8894
HotFocus = Atr_BrightGreen_Gray,
8995
Focus = Atr_BrightGreen_Gray
9096
};
97+
9198
internal static readonly ColorScheme Cs_Btn2x = new()
9299
{
93100
Normal = Atr_Green_White,
@@ -96,6 +103,7 @@ internal static partial class UI
96103
HotFocus = Atr_Green_Gray,
97104
Focus = Atr_Green_Gray
98105
};
106+
99107
internal static readonly ColorScheme Cs_Btn3 = new()
100108
{
101109
Normal = Atr_Black_DarkGray,
@@ -114,6 +122,8 @@ internal static partial class UI
114122
Focus = Atr_BrightRed_White
115123
};
116124

125+
internal static readonly ColorScheme Cs_Btn5 = Make(Atr_Yellow_White, Atr_Yellow_DarkGray, Atr_DarkGray_White);
126+
117127
internal static readonly ColorScheme Cs_Elem2 = new()
118128
{
119129
Normal = Atr_White_Cyan,
@@ -134,16 +144,14 @@ internal static partial class UI
134144
Normal = Atr_Red_Black,
135145
Focus = Atr_BrightRed_Black
136146
};
147+
137148
internal static readonly ColorScheme Cs_Lbl4 = new()
138149
{
139-
Normal = Atr_Red_Black,
150+
Normal = Atr_Red_Black,
140151
HotNormal = Atr_Red_Black,
141152
};
142-
internal static readonly ColorScheme Cs_Win2 = new()
143-
{
144-
Normal = Atr_White_Black,
145-
Focus = Atr_Blue_White,
146-
};
153+
154+
internal static readonly ColorScheme Cs_Win2 = Make(Atr_White_DarkGray, Atr_Blue_White);
147155

148156
internal static readonly ColorScheme Cs_ListView = new()
149157
{
@@ -154,6 +162,14 @@ internal static partial class UI
154162
HotFocus = Atr_Green_Black
155163
};
156164

165+
internal static readonly ColorScheme Cs_ListView2 = new()
166+
{
167+
Normal = Atr_Black_Gray,
168+
HotNormal = Atr_Black_Gray,
169+
Focus = Atr_Blue_Gray,
170+
HotFocus = Atr_Blue_Gray
171+
};
172+
157173
internal static readonly ColorScheme Cs_Lbl1 = new()
158174
{
159175
Normal = Atr_White_Black,
@@ -162,6 +178,14 @@ internal static partial class UI
162178
HotFocus = Atr_Cyan_Black,
163179
};
164180

181+
internal static readonly ColorScheme Cs_Lbl1x = new()
182+
{
183+
Normal = Atr_White_DarkGray,
184+
HotNormal = Atr_White_DarkGray,
185+
Focus = Atr_BrightYellow_Black,
186+
HotFocus = Atr_BrightYellow_Black,
187+
};
188+
165189
internal static readonly ColorScheme Cs_Lbl2 = new()
166190
{
167191
Normal = Atr_BrightCyan_DarkGray,
@@ -196,6 +220,7 @@ internal static partial class UI
196220
Focus = Cs_Lbl1.Focus,
197221
HotFocus = Cs_Lbl1.HotFocus
198222
};
223+
199224
internal static readonly ColorScheme Cs_Lbl1_Success = new ColorScheme()
200225
{
201226
Normal = Atr_BrightGreen_Black,
@@ -204,14 +229,14 @@ internal static partial class UI
204229
Focus = Cs_Lbl1.Focus,
205230
HotFocus = Cs_Lbl1.HotFocus
206231
};
232+
207233
internal static readonly Dim Dim_30_Pct = Dim.Percent(30);
208234
internal static readonly Dim Dim_80_Pct = Dim.Percent(80);
209235

210236
static UI() { }
211237

212238
internal static ColorScheme Make(Attribute norm, Attribute focus = default, Attribute disabled = default)
213239
{
214-
215240
if (focus.Equals(default(Attribute))) {
216241
focus = Attribute.Get();
217242
}
@@ -222,12 +247,10 @@ internal static ColorScheme Make(Attribute norm, Attribute focus = default, Attr
222247

223248
return new ColorScheme()
224249
{
225-
Normal = norm,
226-
HotNormal = norm,
227-
Focus = focus,
228-
HotFocus = focus,
229-
Disabled = disabled
230-
};
250+
Normal = norm,
251+
Focus = focus,
252+
Disabled = disabled
253+
}.NormalizeHot();
231254
}
232255

233256
internal static void WithScheme(this View v, Action<View> f, ColorScheme cs)

SmartImage 3/Mode/Shell/Assets/UI.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections;
77
using System.Diagnostics;
8+
using System.Numerics;
89
using System.Runtime.CompilerServices;
910
using Kantan.Console;
1011
using Kantan.Net.Utilities;
@@ -33,7 +34,7 @@ internal static bool QueueProgress(CancellationTokenSource cts, ProgressBar pbr,
3334
}, cts.Token);
3435
}
3536

36-
internal static Button CreateLinkButton(Dialog d, string text, string? url = null, Action? urlAction = null)
37+
internal static Button CreateLinkButton(this Dialog d, string text, string? url = null, Action? urlAction = null)
3738
{
3839
var b = new Button
3940
{
@@ -52,7 +53,7 @@ internal static Button CreateLinkButton(Dialog d, string text, string? url = nul
5253
return b;
5354
}
5455

55-
internal static void SetLabelStatus(Label lbl, bool? b)
56+
internal static void SetLabelStatus(this Label lbl, bool? b)
5657
{
5758

5859
switch (b) {
@@ -194,10 +195,25 @@ internal static void OnEngineSelected(ListView lv, ListViewItemEventArgs lvie, r
194195
lv.SetNeedsDisplay();
195196
Debug.WriteLine($"{val} {args.Item} -> {e} {isMarked}", nameof(OnEngineSelected));
196197
}*/
198+
197199
public static ColorScheme NormalizeHot(this ColorScheme cs)
198200
{
199201
cs.HotFocus = cs.Focus;
200202
cs.HotNormal = cs.Normal;
201203
return cs;
202204
}
205+
206+
private const int BRIGHT_DELTA = 0b1000;
207+
208+
public static Color ToBrightVariant(this Color c)
209+
{
210+
// +8
211+
return (Color) ((int) c + BRIGHT_DELTA);
212+
}
213+
214+
public static Color ToDarkVariant(this Color c)
215+
{
216+
// +8
217+
return (Color) ((int) c - BRIGHT_DELTA);
218+
}
203219
}

0 commit comments

Comments
 (0)