ilabs-flir 2.3.7 → 2.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,6 +34,9 @@ object FlirManager {
|
|
|
34
34
|
private var cachedPalettes: List<*>? = null
|
|
35
35
|
private var cachedPaletteNames: List<String>? = null
|
|
36
36
|
|
|
37
|
+
// Cached reflection for performance
|
|
38
|
+
private var coolField: java.lang.reflect.Field? = null
|
|
39
|
+
|
|
37
40
|
// State
|
|
38
41
|
private var isInitialized = false
|
|
39
42
|
private var isScanning = false
|
|
@@ -122,15 +125,6 @@ object FlirManager {
|
|
|
122
125
|
|
|
123
126
|
isInitialized = true
|
|
124
127
|
Log.i(TAG, "FlirManager initialized")
|
|
125
|
-
|
|
126
|
-
// Generate palette icons on background thread
|
|
127
|
-
Thread {
|
|
128
|
-
try {
|
|
129
|
-
generatePaletteIcons(context)
|
|
130
|
-
} catch (e: Exception) {
|
|
131
|
-
Log.e(TAG, "Initial palette icon generation failed", e)
|
|
132
|
-
}
|
|
133
|
-
}.start()
|
|
134
128
|
}
|
|
135
129
|
|
|
136
130
|
/**
|
|
@@ -450,38 +444,32 @@ object FlirManager {
|
|
|
450
444
|
fun forceEmulatorMode(type: String = "FLIR_ONE_EDGE") { startDiscovery() }
|
|
451
445
|
fun setPreferredEmulatorType(type: String) { }
|
|
452
446
|
fun updateAcol(value: Float) {
|
|
453
|
-
Log.
|
|
454
|
-
// Use reflection to update ilabs.libs.io.data.Var.cool to avoid circular dependency
|
|
447
|
+
// Log.v(TAG, "updateAcol: $value")
|
|
455
448
|
try {
|
|
456
|
-
|
|
457
|
-
|
|
449
|
+
if (coolField == null) {
|
|
450
|
+
val varClass = Class.forName("ilabs.libs.io.data.Var")
|
|
451
|
+
coolField = varClass.getField("cool")
|
|
452
|
+
}
|
|
458
453
|
|
|
459
|
-
// Modular logic for palettes: if index > 7, wrap around (17 mod 8)
|
|
460
|
-
// But we keep shader variants (14, 15, 16) as-is if within that range
|
|
461
454
|
val rawIdx = value.toInt()
|
|
462
455
|
var shaderIdx = rawIdx
|
|
463
456
|
if (shaderIdx > 16) {
|
|
464
457
|
shaderIdx = shaderIdx % 16 // Shader loop
|
|
465
458
|
}
|
|
466
459
|
|
|
467
|
-
coolField
|
|
468
|
-
Log.d(TAG, "Updated Var.cool to $shaderIdx via reflection (raw=$rawIdx)")
|
|
460
|
+
coolField?.set(null, shaderIdx)
|
|
469
461
|
|
|
470
|
-
// Standard FLIR palette list
|
|
462
|
+
// Standard FLIR palette list
|
|
471
463
|
val paletteNames = listOf("Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel")
|
|
472
|
-
Log.d(TAG, "Using hardcoded FLIR Palettes: $paletteNames")
|
|
473
|
-
|
|
474
464
|
val maxEff = paletteNames.size
|
|
475
465
|
val paletteIdx = rawIdx % maxEff
|
|
476
466
|
val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
|
|
477
467
|
|
|
478
468
|
val targetPaletteName = paletteNames[safeIdx]
|
|
479
|
-
Log.d(TAG, "Applying FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
|
|
480
|
-
|
|
481
469
|
sdkManager?.setPalette(targetPaletteName)
|
|
482
470
|
|
|
483
471
|
} catch (e: Throwable) {
|
|
484
|
-
Log.w(TAG, "
|
|
472
|
+
Log.w(TAG, "updateAcol reflection failed: ${e.message}")
|
|
485
473
|
}
|
|
486
474
|
}
|
|
487
475
|
|
|
@@ -108,12 +108,9 @@ public class FlirSdkManager {
|
|
|
108
108
|
|
|
109
109
|
isInitialized = true;
|
|
110
110
|
Log.i(TAG, "FLIR SDK initialized successfully. Arch: " + System.getProperty("os.arch"));
|
|
111
|
+
Log.d(TAG, "SDK initialized");
|
|
111
112
|
} catch (Throwable e) {
|
|
112
113
|
Log.e(TAG, "Critical failure during FLIR SDK initialization", e);
|
|
113
|
-
}
|
|
114
|
-
Log.d(TAG, "SDK initialized");
|
|
115
|
-
} catch (Exception e) {
|
|
116
|
-
Log.e(TAG, "SDK init failed", e);
|
|
117
114
|
notifyError("SDK init failed: " + e.getMessage());
|
|
118
115
|
}
|
|
119
116
|
}
|
|
@@ -364,6 +361,8 @@ public class FlirSdkManager {
|
|
|
364
361
|
streamer.withThermalImage(thermalImage -> {
|
|
365
362
|
// 1. Apply Palette
|
|
366
363
|
if (paletteToApply != null) {
|
|
364
|
+
try {
|
|
365
|
+
Palette palette = null;
|
|
367
366
|
// Standard FLIR palette list from samples
|
|
368
367
|
String[] paletteNames = {"Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel"};
|
|
369
368
|
|
|
@@ -520,72 +520,34 @@ import ThermalSDK
|
|
|
520
520
|
}
|
|
521
521
|
|
|
522
522
|
@objc public func setPaletteFromAcol(_ acol: Float) {
|
|
523
|
-
// Map acol to dynamic palette names
|
|
524
523
|
let palettes = getAvailablePalettes()
|
|
525
524
|
let idx = Int(acol)
|
|
526
|
-
|
|
527
|
-
|
|
525
|
+
let maxEff = palettes.count
|
|
526
|
+
if maxEff > 0 {
|
|
527
|
+
let paletteIdx = idx % maxEff
|
|
528
|
+
let safeIdx = paletteIdx < 0 ? paletteIdx + maxEff : paletteIdx
|
|
529
|
+
setPalette(palettes[safeIdx])
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
532
|
|
|
531
533
|
@objc public func getAvailablePalettes() -> [String] {
|
|
532
|
-
|
|
533
|
-
if let streamer = streamer {
|
|
534
|
-
var names: [String] = []
|
|
535
|
-
streamer.withThermalImage { img in
|
|
536
|
-
var palettes = img.paletteManager.getDefaultPalettes().map { $0.name }
|
|
537
|
-
// Reorder: Move WhiteHot/Gray to the front
|
|
538
|
-
if let grayIdx = palettes.firstIndex(where: { $0.lowercased() == "whitehot" || $0.lowercased() == "gray" }) {
|
|
539
|
-
let gray = palettes.remove(at: grayIdx)
|
|
540
|
-
palettes.insert(gray, at: 0)
|
|
541
|
-
}
|
|
542
|
-
names = palettes
|
|
543
|
-
}
|
|
544
|
-
if !names.isEmpty { return names }
|
|
545
|
-
}
|
|
546
|
-
#endif
|
|
547
|
-
return ["WhiteHot", "iron", "rainbow", "arctic", "lava", "contrast", "hotcold", "medical"]
|
|
534
|
+
return ["Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel"]
|
|
548
535
|
}
|
|
549
536
|
|
|
550
537
|
@objc public func generatePaletteIcons() -> [[String: String]] {
|
|
551
|
-
|
|
552
|
-
#if FLIR_ENABLED
|
|
553
|
-
guard let streamer = streamer else { return [] }
|
|
554
|
-
|
|
538
|
+
let paletteNames = getAvailablePalettes()
|
|
555
539
|
let fileManager = FileManager.default
|
|
556
540
|
let cacheDir = fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
|
557
541
|
let paletteDir = cacheDir.appendingPathComponent("flir_palettes")
|
|
558
542
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
// Reorder: Move WhiteHot/Gray to the front
|
|
567
|
-
if let grayIdx = palettes.firstIndex(where: { $0.name.lowercased() == "whitehot" || $0.name.lowercased() == "gray" }) {
|
|
568
|
-
let gray = palettes.remove(at: grayIdx)
|
|
569
|
-
palettes.insert(gray, at: 0)
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
for palette in palettes {
|
|
573
|
-
let iconURL = paletteDir.appendingPathComponent("\(palette.name.lowercased()).png")
|
|
574
|
-
if !fileManager.fileExists(atPath: iconURL.path) {
|
|
575
|
-
// Assuming palette.icon exists (common in FLIR SDK)
|
|
576
|
-
if let icon = palette.icon {
|
|
577
|
-
if let data = icon.pngData() {
|
|
578
|
-
try? data.write(to: iconURL)
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
results.append([
|
|
583
|
-
"name": palette.name,
|
|
584
|
-
"uri": fileManager.fileExists(atPath: iconURL.path) ? iconURL.absoluteString : ""
|
|
585
|
-
])
|
|
586
|
-
}
|
|
543
|
+
var results: [[String: String]] = []
|
|
544
|
+
for name in paletteNames {
|
|
545
|
+
let iconURL = paletteDir.appendingPathComponent("\(name.lowercased()).png")
|
|
546
|
+
results.append([
|
|
547
|
+
"name": name,
|
|
548
|
+
"uri": fileManager.fileExists(atPath: iconURL.path) ? iconURL.absoluteString : ""
|
|
549
|
+
])
|
|
587
550
|
}
|
|
588
|
-
#endif
|
|
589
551
|
return results
|
|
590
552
|
}
|
|
591
553
|
|