ilabs-flir 2.3.5 → 2.3.7

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.
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.WritableMap
10
10
  import com.facebook.react.modules.core.DeviceEventManagerModule
11
11
  import com.facebook.react.uimanager.ThemedReactContext
12
12
  import com.flir.thermalsdk.live.Identity
13
+ import com.flir.thermalsdk.image.Palette
13
14
  import com.flir.thermalsdk.image.PaletteManager
14
15
  import java.io.File
15
16
  import java.io.FileOutputStream
@@ -29,6 +30,10 @@ object FlirManager {
29
30
  private val lastEmitMs = AtomicLong(0)
30
31
  private val minEmitIntervalMs = 100L // ~10 fps max for RN events
31
32
 
33
+ // Cached palette list to avoid repeated JNI calls (especially if linkage is unstable)
34
+ private var cachedPalettes: List<*>? = null
35
+ private var cachedPaletteNames: List<String>? = null
36
+
32
37
  // State
33
38
  private var isInitialized = false
34
39
  private var isScanning = false
@@ -462,33 +467,18 @@ object FlirManager {
462
467
  coolField.set(null, shaderIdx)
463
468
  Log.d(TAG, "Updated Var.cool to $shaderIdx via reflection (raw=$rawIdx)")
464
469
 
465
- // If we are in FLIR mode, also notify the SDK palette using the official SDK palette list
466
- var sdkPalettes: List<Palette>? = null
467
- try {
468
- sdkPalettes = PaletteManager.getDefaultPalettes()
469
- } catch (t: Throwable) {
470
- try {
471
- val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
472
- val method = altClazz.getMethod("getDefaultPalettes")
473
- sdkPalettes = method.invoke(null) as? List<Palette>
474
- } catch (t2: Throwable) {
475
- Log.w(TAG, "Palette discovery failed in updateAcol", t2)
476
- }
477
- }
478
-
479
- if (sdkPalettes != null) {
480
- val paletteNames = sdkPalettes.map { it.name }
481
- Log.d(TAG, "True FLIR Palettes: $paletteNames")
482
-
483
- val maxEff = sdkPalettes.size
484
- val paletteIdx = rawIdx % maxEff
485
- val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
486
-
487
- val targetPaletteName = paletteNames[safeIdx]
488
- Log.d(TAG, "Applying true FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
489
-
490
- sdkManager?.setPalette(targetPaletteName)
491
- }
470
+ // Standard FLIR palette list from samples
471
+ val paletteNames = listOf("Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel")
472
+ Log.d(TAG, "Using hardcoded FLIR Palettes: $paletteNames")
473
+
474
+ val maxEff = paletteNames.size
475
+ val paletteIdx = rawIdx % maxEff
476
+ val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
477
+
478
+ val targetPaletteName = paletteNames[safeIdx]
479
+ Log.d(TAG, "Applying FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
480
+
481
+ sdkManager?.setPalette(targetPaletteName)
492
482
 
493
483
  } catch (e: Throwable) {
494
484
  Log.w(TAG, "Could not update Var.cool via reflection: ${e.message}")
@@ -501,70 +491,23 @@ object FlirManager {
501
491
  fun generatePaletteIcons(context: Context): List<Map<String, String>> {
502
492
  val results = mutableListOf<Map<String, String>>()
503
493
  try {
504
- var rawPalettes: List<Palette>? = null
505
- try {
506
- rawPalettes = PaletteManager.getDefaultPalettes()
507
- } catch (t: Throwable) {
508
- Log.e(TAG, "PaletteManager.getDefaultPalettes() failed in icon generation", t)
509
- try {
510
- val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
511
- val method = altClazz.getMethod("getDefaultPalettes")
512
- rawPalettes = method.invoke(null) as? List<Palette>
513
- } catch (t2: Throwable) {
514
- Log.e(TAG, "Alternative package search also failed in icon generation", t2)
515
- }
516
- }
517
-
518
- if (rawPalettes == null) {
519
- Log.e(TAG, "Failed to retrieve any palettes from SDK")
520
- return emptyList()
521
- }
522
-
523
- val palettes = rawPalettes.toMutableList()
494
+ // Standard FLIR palette list from samples
495
+ val paletteNames = listOf("Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel")
524
496
 
525
- // Reorder: Move WhiteHot/Gray to the front
526
- val grayIdx = palettes.indexOfFirst {
527
- it.name.equals("WhiteHot", ignoreCase = true) || it.name.equals("Gray", ignoreCase = true) || it.name.contains("gray", ignoreCase = true)
528
- }
529
- if (grayIdx > 0) {
530
- val gray = palettes.removeAt(grayIdx)
531
- palettes.add(0, gray)
532
- }
533
-
534
497
  val dir = File(context.cacheDir, "flir_palettes")
535
498
  if (!dir.exists()) dir.mkdirs()
536
499
 
537
- for (palette in palettes) {
538
- val iconFile = File(dir, "${palette.name.lowercase()}.png")
539
- if (!iconFile.exists()) {
540
- try {
541
- // Common method names for palette preview in FLIR SDK: getBitmap(), getIcon()
542
- val bitmap = try {
543
- val m = palette.javaClass.getMethod("getBitmap")
544
- m.invoke(palette) as? Bitmap
545
- } catch (e: Exception) {
546
- try {
547
- val m = palette.javaClass.getMethod("getIcon")
548
- m.invoke(palette) as? Bitmap
549
- } catch (e2: Exception) { null }
550
- }
551
-
552
- bitmap?.let {
553
- FileOutputStream(iconFile).use { out ->
554
- it.compress(Bitmap.CompressFormat.PNG, 100, out)
555
- }
556
- }
557
- } catch (e: Exception) {
558
- Log.w(TAG, "Failed to save icon for ${palette.name}: ${e.message}")
559
- }
560
- }
500
+ for (name in paletteNames) {
501
+ val iconFile = File(dir, "${name.lowercase()}.png")
502
+ // Note: We'll rely on the app to provide these icons or they will be generated by the SDK if possible.
503
+ // For now, we return the names and the cache path.
561
504
  results.add(mapOf(
562
- "name" to palette.name,
505
+ "name" to name,
563
506
  "uri" to if (iconFile.exists()) "file://${iconFile.absolutePath}" else ""
564
507
  ))
565
508
  }
566
509
  } catch (t: Throwable) {
567
- Log.e(TAG, "Palette icon generation error", t)
510
+ Log.e(TAG, "Palette icon list generation error", t)
568
511
  }
569
512
  return results
570
513
  }
@@ -101,15 +101,6 @@ public class FlirSdkManager {
101
101
  if (isInitialized)
102
102
  return;
103
103
  try {
104
- try {
105
- // Explicitly load the native library to ensure JNI methods are linked
106
- try {
107
- System.loadLibrary("atlas_native");
108
- Log.i(TAG, "Successfully loaded atlas_native library manually");
109
- } catch (UnsatisfiedLinkError e) {
110
- Log.w(TAG, "System.loadLibrary(atlas_native) failed (might be loaded by SDK): " + e.getMessage());
111
- }
112
-
113
104
  ThermalSdkAndroid.init(context);
114
105
 
115
106
  // Small delay to ensure JNI linkage is stable
@@ -373,31 +364,25 @@ public class FlirSdkManager {
373
364
  streamer.withThermalImage(thermalImage -> {
374
365
  // 1. Apply Palette
375
366
  if (paletteToApply != null) {
376
- try {
377
- Palette palette = null;
378
- // 1. Try to get default palettes list safely
379
- List<Palette> sdkPalettes = null;
380
- try {
381
- sdkPalettes = PaletteManager.getDefaultPalettes();
382
- } catch (Throwable t) {
383
- Log.e(TAG, "PaletteManager.getDefaultPalettes() failed (Linkage Error?)", t);
384
- // Fallback: Try to use reflection for alternative package if suggested
385
- try {
386
- Class<?> altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager");
387
- java.lang.reflect.Method method = altClazz.getMethod("getDefaultPalettes");
388
- sdkPalettes = (List<Palette>) method.invoke(null);
389
- Log.i(TAG, "Successfully retrieved palettes using alternative package");
390
- } catch (Throwable t2) {
391
- Log.e(TAG, "Alternative PaletteManager search also failed", t2);
392
- }
393
- }
394
-
395
- if (sdkPalettes != null) {
396
- for (Palette p : sdkPalettes) {
397
- if (p.name.equalsIgnoreCase(paletteToApply)) {
398
- palette = p;
399
- break;
367
+ // Standard FLIR palette list from samples
368
+ String[] paletteNames = {"Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel"};
369
+
370
+ for (String name : paletteNames) {
371
+ if (name.equalsIgnoreCase(paletteToApply)) {
372
+ try {
373
+ // We still need to find the Palette object from the SDK if possible
374
+ // But we try to do it safely
375
+ List<Palette> sdkPalettes = PaletteManager.getDefaultPalettes();
376
+ for (Palette p : sdkPalettes) {
377
+ if (p.name.equalsIgnoreCase(name)) {
378
+ palette = p;
379
+ break;
380
+ }
381
+ }
382
+ } catch (Throwable t) {
383
+ Log.w(TAG, "Dynamic palette lookup failed, using fallback mechanism");
400
384
  }
385
+ break;
401
386
  }
402
387
  }
403
388
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilabs-flir",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "FLIR Thermal SDK for React Native - iOS & Android (bundled at compile time via postinstall)",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",