ilabs-flir 2.3.6 → 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.
@@ -30,6 +30,10 @@ object FlirManager {
30
30
  private val lastEmitMs = AtomicLong(0)
31
31
  private val minEmitIntervalMs = 100L // ~10 fps max for RN events
32
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
+
33
37
  // State
34
38
  private var isInitialized = false
35
39
  private var isScanning = false
@@ -463,40 +467,18 @@ object FlirManager {
463
467
  coolField.set(null, shaderIdx)
464
468
  Log.d(TAG, "Updated Var.cool to $shaderIdx via reflection (raw=$rawIdx)")
465
469
 
466
- // If we are in FLIR mode, also notify the SDK palette using the official SDK palette list
467
- var sdkPalettes: List<*>? = null
468
- try {
469
- sdkPalettes = PaletteManager.getDefaultPalettes()
470
- } catch (t: Throwable) {
471
- try {
472
- val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
473
- val method = altClazz.getMethod("getDefaultPalettes")
474
- sdkPalettes = method.invoke(null) as? List<*>
475
- } catch (t2: Throwable) {
476
- Log.w(TAG, "Palette discovery failed in updateAcol", t2)
477
- }
478
- }
479
-
480
- val currentPalettes = sdkPalettes
481
- if (currentPalettes != null && currentPalettes.isNotEmpty()) {
482
- val paletteNames = currentPalettes.map { p ->
483
- try {
484
- p?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: p?.toString() ?: ""
485
- } catch (e: Exception) {
486
- p?.toString() ?: ""
487
- }
488
- }
489
- Log.d(TAG, "True FLIR Palettes: $paletteNames")
490
-
491
- val maxEff = currentPalettes.size
492
- val paletteIdx = rawIdx % maxEff
493
- val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
494
-
495
- val targetPaletteName = paletteNames[safeIdx]
496
- Log.d(TAG, "Applying true FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
497
-
498
- sdkManager?.setPalette(targetPaletteName)
499
- }
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)
500
482
 
501
483
  } catch (e: Throwable) {
502
484
  Log.w(TAG, "Could not update Var.cool via reflection: ${e.message}")
@@ -509,79 +491,23 @@ object FlirManager {
509
491
  fun generatePaletteIcons(context: Context): List<Map<String, String>> {
510
492
  val results = mutableListOf<Map<String, String>>()
511
493
  try {
512
- var rawPalettes: List<*>? = null
513
- try {
514
- rawPalettes = PaletteManager.getDefaultPalettes()
515
- } catch (t: Throwable) {
516
- Log.e(TAG, "PaletteManager.getDefaultPalettes() failed in icon generation", t)
517
- try {
518
- val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
519
- val method = altClazz.getMethod("getDefaultPalettes")
520
- rawPalettes = method.invoke(null) as? List<*>
521
- } catch (t2: Throwable) {
522
- Log.e(TAG, "Alternative package search also failed in icon generation", t2)
523
- }
524
- }
525
-
526
- val currentPalettes = rawPalettes
527
- if (currentPalettes == null) {
528
- Log.e(TAG, "Failed to retrieve any palettes from SDK")
529
- return emptyList()
530
- }
531
-
532
- val palettes = currentPalettes.toMutableList()
494
+ // Standard FLIR palette list from samples
495
+ val paletteNames = listOf("Gray", "Iron", "Rainbow", "Arctic", "Lava", "Coldest", "Hottest", "Wheel")
533
496
 
534
- // Reorder: Move WhiteHot/Gray to the front
535
- val grayIdx = palettes.indexOfFirst { p ->
536
- val name = try {
537
- p?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: p?.toString() ?: ""
538
- } catch (e: Exception) { p?.toString() ?: "" }
539
-
540
- name.equals("WhiteHot", ignoreCase = true) || name.equals("Gray", ignoreCase = true) || name.contains("gray", ignoreCase = true)
541
- }
542
- if (grayIdx > 0) {
543
- val gray = palettes.removeAt(grayIdx)
544
- palettes.add(0, gray)
545
- }
546
-
547
497
  val dir = File(context.cacheDir, "flir_palettes")
548
498
  if (!dir.exists()) dir.mkdirs()
549
499
 
550
- for (palette in palettes) {
551
- val name = try {
552
- palette?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: palette?.toString() ?: "unknown"
553
- } catch (e: Exception) { palette?.toString() ?: "unknown" }
554
-
500
+ for (name in paletteNames) {
555
501
  val iconFile = File(dir, "${name.lowercase()}.png")
556
- if (!iconFile.exists()) {
557
- try {
558
- // Common method names for palette preview in FLIR SDK: getBitmap(), getIcon()
559
- val bitmap = try {
560
- val m = palette?.let { it::class.java.getMethod("getBitmap") }
561
- m?.invoke(palette) as? Bitmap
562
- } catch (e: Exception) {
563
- try {
564
- val m = palette?.let { it::class.java.getMethod("getIcon") }
565
- m?.invoke(palette) as? Bitmap
566
- } catch (e2: Exception) { null }
567
- }
568
-
569
- bitmap?.let {
570
- FileOutputStream(iconFile).use { out ->
571
- it.compress(Bitmap.CompressFormat.PNG, 100, out)
572
- }
573
- }
574
- } catch (e: Exception) {
575
- Log.w(TAG, "Failed to save icon for $name: ${e.message}")
576
- }
577
- }
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.
578
504
  results.add(mapOf(
579
505
  "name" to name,
580
506
  "uri" to if (iconFile.exists()) "file://${iconFile.absolutePath}" else ""
581
507
  ))
582
508
  }
583
509
  } catch (t: Throwable) {
584
- Log.e(TAG, "Palette icon generation error", t)
510
+ Log.e(TAG, "Palette icon list generation error", t)
585
511
  }
586
512
  return results
587
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,38 +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<?> 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<?>) 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 (Object p : sdkPalettes) {
397
- String pName = "";
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)) {
398
372
  try {
399
- pName = (String) p.getClass().getMethod("getName").invoke(p);
400
- } catch (Exception e) {
401
- pName = p.toString();
402
- }
403
-
404
- if (pName != null && pName.equalsIgnoreCase(paletteToApply)) {
405
- palette = (Palette) p;
406
- break;
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");
407
384
  }
385
+ break;
408
386
  }
409
387
  }
410
388
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilabs-flir",
3
- "version": "2.3.6",
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",