ilabs-flir 2.4.5 → 2.4.6

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.
@@ -254,20 +254,19 @@ object FlirManager {
254
254
  val bitmap = latestBitmap ?: return null
255
255
 
256
256
  // Map UI normalized (0..1) to Raw sensor normalized (0..1) based on display rotation
257
- val rawCoords = when (rotation) {
258
- 0 -> Pair(nx, ny)
259
- 90, -270 -> Pair(ny, 1.0 - nx)
260
- 180, -180 -> Pair(1.0 - nx, 1.0 - ny)
261
- 270, -90 -> Pair(1.0 - ny, nx)
262
- else -> Pair(1.0 - ny, nx) // Default to -90 for backward compatibility
263
- }
257
+ // Using generic trigonometric rotation formula for total precision
258
+ val angle = -rotation.toDouble() // Inverse the display rotation
259
+ val rad = Math.toRadians(angle)
260
+ val cosA = Math.cos(rad)
261
+ val sinA = Math.sin(rad)
264
262
 
265
- val rawX = rawCoords.first
266
- val rawY = rawCoords.second
263
+ // Rotate around center (0.5, 0.5)
264
+ val dx = nx - 0.5
265
+ val dy = ny - 0.5
266
+ val rawX = dx * cosA - dy * sinA + 0.5
267
+ val rawY = dx * sinA + dy * cosA + 0.5
267
268
 
268
- val px = (rawX * bitmap.width).toInt().coerceIn(0, bitmap.width - 1)
269
- val py = (rawY * bitmap.height).toInt().coerceIn(0, bitmap.height - 1)
270
- return getTemperatureAt(px, py)
269
+ return FlirSdkManager.getInstance(reactContext).getTemperatureAtNormalized(rawX, rawY)
271
270
  }
272
271
 
273
272
  fun getTemperatureAtPoint(x: Int, y: Int): Double? = getTemperatureAt(x, y)
@@ -579,6 +579,37 @@ public class FlirSdkManager {
579
579
  return result[0];
580
580
  }
581
581
 
582
+ /**
583
+ * Samples temperature using normalized coordinates (0.0 to 1.0)
584
+ * This avoids clamping bugs when UI dimensions differ from sensor dimensions.
585
+ */
586
+ public double getTemperatureAtNormalized(double nx, double ny) {
587
+ final double[] result = { Double.NaN };
588
+ synchronized (this) {
589
+ if (streamer == null) return Double.NaN;
590
+ try {
591
+ streamer.withThermalImage(thermalImage -> {
592
+ try {
593
+ int w = thermalImage.getWidth();
594
+ int h = thermalImage.getHeight();
595
+ // Map normalized 0..1 to sensor pixels 0..w-1
596
+ int cx = (int) Math.max(0, Math.min(w - 1, nx * w));
597
+ int cy = (int) Math.max(0, Math.min(h - 1, ny * h));
598
+ ThermalValue value = thermalImage.getValueAt(new Point(cx, cy));
599
+ if (value != null) {
600
+ result[0] = value.asCelsius().value;
601
+ }
602
+ } catch (Exception e) {
603
+ Log.w(TAG, "Normalized temp query error", e);
604
+ }
605
+ });
606
+ } catch (Exception e) {
607
+ Log.w(TAG, "Normalized temp query failed", e);
608
+ }
609
+ }
610
+ return result[0];
611
+ }
612
+
582
613
  // ==================== LISTENERS ====================
583
614
 
584
615
  public void setPalette(String paletteName) {
@@ -478,22 +478,17 @@ import ThermalSDK
478
478
  let h = Double(thermalImage.getHeight())
479
479
 
480
480
  // Map UI normalized (0..1) to Raw sensor normalized (0..1) based on display rotation
481
- var rawX = nx
482
- var rawY = y
481
+ // Using generic trigonometric rotation formula for total precision
482
+ let angle = -Double(rotation) // Inverse the display rotation
483
+ let rad = angle * .pi / 180.0
484
+ let cosA = cos(rad)
485
+ let sinA = sin(rad)
483
486
 
484
- switch rotation {
485
- case 90, -270:
486
- rawX = y
487
- rawY = 1.0 - nx
488
- case 180, -180:
489
- rawX = 1.0 - nx
490
- rawY = 1.0 - y
491
- case 270, -90:
492
- rawX = 1.0 - y
493
- rawY = nx
494
- default:
495
- break // 0 deg or default
496
- }
487
+ // Rotate around center (0.5, 0.5)
488
+ let dx = nx - 0.5
489
+ let dy = y - 0.5
490
+ let rawX = dx * cosA - dy * sinA + 0.5
491
+ let rawY = dx * sinA + dy * cosA + 0.5
497
492
 
498
493
  // Map normalized (0.0 - 1.0) to actual sensor pixels
499
494
  let cx = max(0, min(Int(w) - 1, Int(rawX * w)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilabs-flir",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
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",