Snap for 5289249 from 1a5387f472b510232e0fd3af0b06e350341c334d to qt-release

Change-Id: I8372d92fdd77321ea4c470068961d7eb24aa5066
diff --git a/Android.bp b/Android.bp
index b015217..b66d9d7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -50,3 +50,28 @@
         "libxml2",
     ],
 }
+
+cc_library_static {
+    name: "libdynamic_depth_ndk",
+    defaults: ["libdynamic_depth-defaults"],
+    vendor_available: false,
+    export_include_dirs: [
+        "includes",
+        "internal"
+    ],
+    srcs: ["internal/**/*.cc"],
+    shared_libs: [
+        "liblog",
+    ],
+    static_libs: [
+        "libimage_io_ndk",
+        "libbase_ndk",
+        "libxml2_ndk",
+    ],
+    cflags: [
+        "-fvisibility=hidden",
+        "-DSTATIC_LIBXML=1",
+    ],
+    sdk_version: "current",
+    stl: "c++_static",
+}
diff --git a/README.android b/README.android
index 7a8f454..00f3c0b 100644
--- a/README.android
+++ b/README.android
@@ -6,4 +6,4 @@
 Local patches
 -------------
 - Android depth photo validation sequence "ValidateAndroidDynamicDepthBuffer()".
-
+- Add NDK library variant.
diff --git a/includes/dynamic_depth/depth_jpeg.h b/includes/dynamic_depth/depth_jpeg.h
new file mode 100644
index 0000000..e4d7d26
--- /dev/null
+++ b/includes/dynamic_depth/depth_jpeg.h
@@ -0,0 +1,14 @@
+#ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_JPEG_H_  // NOLINT
+#define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_JPEG_H_  // NOLINT
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace dynamic_depth {
+
+// Android depth photo validation sequence
+int32_t ValidateAndroidDynamicDepthBuffer(const char* buffer, size_t buffer_length);
+
+}  // namespace dynamic_depth
+
+#endif  // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_JPEG_H_  // NOLINT
diff --git a/includes/dynamic_depth/dynamic_depth.h b/includes/dynamic_depth/dynamic_depth.h
index 5f8b760..966fc1f 100644
--- a/includes/dynamic_depth/dynamic_depth.h
+++ b/includes/dynamic_depth/dynamic_depth.h
@@ -31,7 +31,6 @@
 // Convenience method for the aboove.
 bool GetItemPayload(const string& input_image_filename, const Device* device,
                     const string& item_uri, string* out_payload);
-
 }  // namespace dynamic_depth
 
 #endif  // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_DYNAMIC_DEPTH_H_  // NOLINT
diff --git a/internal/dynamic_depth/depth_jpeg.cc b/internal/dynamic_depth/depth_jpeg.cc
new file mode 100644
index 0000000..ec5ab89
--- /dev/null
+++ b/internal/dynamic_depth/depth_jpeg.cc
@@ -0,0 +1,110 @@
+#include "dynamic_depth/depth_jpeg.h"
+
+#include <fstream>
+#include <sstream>
+
+#include "android-base/logging.h"
+#include "dynamic_depth/container.h"
+#include "dynamic_depth/device.h"
+#include "dynamic_depth/dynamic_depth.h"
+#include "dynamic_depth/item.h"
+#include "image_io/gcontainer/gcontainer.h"
+#include "xmpmeta/xmp_data.h"
+#include "xmpmeta/xmp_parser.h"
+#include "xmpmeta/xmp_writer.h"
+
+using ::dynamic_depth::xmpmeta::XmpData;
+
+namespace dynamic_depth {
+
+int32_t ValidateAndroidDynamicDepthBuffer(const char* buffer, size_t buffer_length) {
+  XmpData xmp_data;
+  const string image_data(buffer, buffer_length);
+  ReadXmpFromMemory(image_data, /*XmpSkipExtended*/ false, &xmp_data);
+
+  // Check device presence
+  std::unique_ptr<Device> device = Device::FromXmp(xmp_data);
+  if (device == nullptr) {
+    LOG(ERROR) << "Dynamic depth device element not present!";
+    return -1;
+  }
+
+  // Check profiles
+  const Profiles* profiles = device->GetProfiles();
+  if (profiles == nullptr) {
+    LOG(ERROR) << "No Profile found in the dynamic depth metadata";
+    return -1;
+  }
+
+  const std::vector<const Profile*> profile_list = profiles->GetProfiles();
+  // Stop at the first depth photo profile found.
+  bool depth_photo_profile_found = false;
+  int camera_index = 0;
+  for (auto profile : profile_list) {
+    depth_photo_profile_found = !profile->GetType().compare("DepthPhoto");
+    if (depth_photo_profile_found) {
+      // Use the first one if available.
+      auto indices = profile->GetCameraIndices();
+      if (!indices.empty()) {
+        camera_index = indices[0];
+      } else {
+        camera_index = -1;
+      }
+      break;
+    }
+  }
+
+  if (!depth_photo_profile_found || camera_index < 0) {
+    LOG(ERROR) << "No dynamic depth profile found";
+    return -1;
+  }
+
+  auto cameras = device->GetCameras();
+  if (cameras == nullptr || camera_index > cameras->GetCameras().size() ||
+      cameras->GetCameras()[camera_index] == nullptr) {
+    LOG(ERROR) << "No camera or depth photo data found";
+    return -1;
+  }
+
+  auto camera = cameras->GetCameras()[camera_index];
+  auto depth_map = camera->GetDepthMap();
+  if (depth_map == nullptr) {
+    LOG(ERROR) << "No depth map found";
+    return -1;
+  }
+
+  auto depth_uri = depth_map->GetDepthUri();
+  if (depth_uri.empty()) {
+    LOG(ERROR) << "Invalid depth map URI";
+    return -1;
+  }
+
+  auto depth_units = depth_map->GetUnits();
+  if (depth_units != dynamic_depth::DepthUnits::kMeters) {
+    LOG(ERROR) << "Unexpected depth map units";
+    return -1;
+  }
+
+  auto depth_format = depth_map->GetFormat();
+  if (depth_format != dynamic_depth::DepthFormat::kRangeInverse) {
+    LOG(ERROR) << "Unexpected depth map format";
+    return -1;
+  }
+
+  auto near = depth_map->GetNear();
+  auto far = depth_map->GetFar();
+  if ((near < 0.f) || (far < 0.f) || (near > far) || (near == far)) {
+    LOG(ERROR) << "Unexpected depth map near and far values";
+    return -1;
+  }
+
+  auto confidence_uri = depth_map->GetConfidenceUri();
+  if (confidence_uri.empty()) {
+    LOG(ERROR) << "No confidence URI";
+    return -1;
+  }
+
+  return 0;
+}
+
+}  // namespace dynamic_depth
diff --git a/internal/dynamic_depth/dynamic_depth.cc b/internal/dynamic_depth/dynamic_depth.cc
index fa3983e..2294289 100644
--- a/internal/dynamic_depth/dynamic_depth.cc
+++ b/internal/dynamic_depth/dynamic_depth.cc
@@ -8,7 +8,6 @@
 #include "dynamic_depth/item.h"
 #include "image_io/gcontainer/gcontainer.h"
 #include "xmpmeta/xmp_data.h"
-#include "xmpmeta/xmp_parser.h"
 #include "xmpmeta/xmp_writer.h"
 
 namespace dynamic_depth {
@@ -129,94 +128,4 @@
   return success;
 }
 
-extern "C" int32_t ValidateAndroidDynamicDepthBuffer(const char* buffer, size_t buffer_length) {
-  XmpData xmp_data;
-  const string image_data(buffer, buffer_length);
-  ReadXmpFromMemory(image_data, /*XmpSkipExtended*/ false, &xmp_data);
-
-  // Check device presence
-  std::unique_ptr<Device> device = Device::FromXmp(xmp_data);
-  if (device == nullptr) {
-    LOG(ERROR) << "Dynamic depth device element not present!";
-    return -1;
-  }
-
-  // Check profiles
-  const Profiles* profiles = device->GetProfiles();
-  if (profiles == nullptr) {
-    LOG(ERROR) << "No Profile found in the dynamic depth metadata";
-    return -1;
-  }
-
-  const std::vector<const Profile*> profile_list = profiles->GetProfiles();
-  // Stop at the first depth photo profile found.
-  bool depth_photo_profile_found = false;
-  int camera_index = 0;
-  for (auto profile : profile_list) {
-    depth_photo_profile_found = !profile->GetType().compare("DepthPhoto");
-    if (depth_photo_profile_found) {
-      // Use the first one if available.
-      auto indices = profile->GetCameraIndices();
-      if (!indices.empty()) {
-        camera_index = indices[0];
-      } else {
-        camera_index = -1;
-      }
-      break;
-    }
-  }
-
-  if (!depth_photo_profile_found || camera_index < 0) {
-    LOG(ERROR) << "No dynamic depth profile found";
-    return -1;
-  }
-
-  auto cameras = device->GetCameras();
-  if (cameras == nullptr || camera_index > cameras->GetCameras().size() ||
-      cameras->GetCameras()[camera_index] == nullptr) {
-    LOG(ERROR) << "No camera or depth photo data found";
-    return -1;
-  }
-
-  auto camera = cameras->GetCameras()[camera_index];
-  auto depth_map = camera->GetDepthMap();
-  if (depth_map == nullptr) {
-    LOG(ERROR) << "No depth map found";
-    return -1;
-  }
-
-  auto depth_uri = depth_map->GetDepthUri();
-  if (depth_uri.empty()) {
-    LOG(ERROR) << "Invalid depth map URI";
-    return -1;
-  }
-
-  auto depth_units = depth_map->GetUnits();
-  if (depth_units != dynamic_depth::DepthUnits::kMeters) {
-    LOG(ERROR) << "Unexpected depth map units";
-    return -1;
-  }
-
-  auto depth_format = depth_map->GetFormat();
-  if (depth_format != dynamic_depth::DepthFormat::kRangeInverse) {
-    LOG(ERROR) << "Unexpected depth map format";
-    return -1;
-  }
-
-  auto near = depth_map->GetNear();
-  auto far = depth_map->GetFar();
-  if ((near < 0.f) || (far < 0.f) || (near > far) || (near == far)) {
-    LOG(ERROR) << "Unexpected depth map near and far values";
-    return -1;
-  }
-
-  auto confidence_uri = depth_map->GetConfidenceUri();
-  if (confidence_uri.empty()) {
-    LOG(ERROR) << "No confidence URI";
-    return -1;
-  }
-
-  return 0;
-}
-
 }  // namespace dynamic_depth