Просмотр исходного кода

Fix alignment HTTP blocking and publish complete ROI JPEG snapshots

SybexXx 1 день назад
Родитель
Сommit
5b1782e486
1 измененных файлов с 15 добавлено и 9 удалено
  1. 15 9
      code/components/jomjol_image_proc/CFindTemplate.cpp

+ 15 - 9
code/components/jomjol_image_proc/CFindTemplate.cpp

@@ -29,7 +29,7 @@ static bool getTemplateBufferSize(int width, int height, int channels, size_t* s
 // #define DEBUG_DETAIL_ON  
 
 
-bool CFindTemplate::FindTemplate(RefInfo *_ref)
+bool CFindTemplate::FindTemplate(RefInfo *_ref, bool sourceIsStableSnapshot)
 {
     if (_ref == NULL || rgb_image == NULL || width <= 0 || height <= 0 || channels <= 0) {
         LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "FindTemplate: source image or reference is unavailable");
@@ -54,11 +54,17 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
         return false;
     }
 
-    uint8_t* source = RGBImageLock();
-    if (source == NULL) {
-        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "FindTemplate: source image is locked");
-        stbi_image_free(rgb_template);
-        return false;
+    // Alignment passes an immutable copy in the shared tmpImage workspace.
+    // Searching that snapshot must not hold the global image mutex for seconds.
+    uint8_t* source = rgb_image;
+    const bool sourceLocked = !sourceIsStableSnapshot;
+    if (sourceLocked) {
+        source = RGBImageLock();
+        if (source == NULL) {
+            LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "FindTemplate: source image is locked");
+            stbi_image_free(rgb_template);
+            return false;
+        }
     }
 
     if (_ref->search_x == 0) {
@@ -81,7 +87,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
 
     if (ow_stop < ow_start || oh_stop < oh_start) {
         LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "FindTemplate: search window does not intersect source image");
-        RGBImageRelease();
+        if (sourceLocked) RGBImageRelease();
         stbi_image_free(rgb_template);
         return false;
     }
@@ -100,7 +106,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
 #endif
         _ref->found_x = _ref->fastalg_x;
         _ref->found_y = _ref->fastalg_y;
-        RGBImageRelease();
+        if (sourceLocked) RGBImageRelease();
         stbi_image_free(rgb_template);
         return true;
     }
@@ -154,7 +160,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
     _ref->fastalg_max = max;
     _ref->fastalg_SAD = SAD;
 
-    RGBImageRelease();
+    if (sourceLocked) RGBImageRelease();
     stbi_image_free(rgb_template);
     return false;
 }