Sfoglia il codice sorgente

Serialize rotation and translation metadata updates

SybexXx 3 giorni fa
parent
commit
6fd2658d9c
1 ha cambiato i file con 41 aggiunte e 0 eliminazioni
  1. 41 0
      code/components/jomjol_image_proc/CRotateImage.cpp

+ 41 - 0
code/components/jomjol_image_proc/CRotateImage.cpp

@@ -6,6 +6,22 @@
 
 static const char *TAG = "C ROTATE IMG";
 
+class ScopedImageAccess
+{
+    CImageBasis* image;
+    bool locked;
+public:
+    explicit ScopedImageAccess(CImageBasis* value) : image(value), locked(false)
+    {
+        if (image != NULL) locked = image->RGBImageLock() != NULL;
+    }
+    ~ScopedImageAccess()
+    {
+        if (locked) image->RGBImageRelease();
+    }
+    bool isLocked() const { return locked; }
+};
+
 static bool getRotateBufferSize(int width, int height, int channels, size_t* size)
 {
     if (size == NULL || width <= 0 || height <= 0 || channels <= 0) return false;
@@ -41,6 +57,11 @@ CRotateImage::CRotateImage(std::string _name, CImageBasis *_org, CImageBasis *_t
 
 void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
 {
+    ScopedImageAccess sourceAccess(ImageOrg != NULL ? ImageOrg : this);
+    if (!sourceAccess.isLocked()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image transform: unable to lock source image");
+        return;
+    }
     if ((_angle == 0) && !doflip) {  // identity transform, the copy would leave the image unchanged
         return;
     }
@@ -174,6 +195,11 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
 
 void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
 {
+    ScopedImageAccess sourceAccess(ImageOrg != NULL ? ImageOrg : this);
+    if (!sourceAccess.isLocked()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image transform: unable to lock source image");
+        return;
+    }
     int org_width, org_height;
     float m[2][3];
 
@@ -323,18 +349,33 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
 
 void CRotateImage::Rotate(float _angle)
 {
+    ScopedImageAccess sourceAccess(ImageOrg != NULL ? ImageOrg : this);
+    if (!sourceAccess.isLocked()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image transform: unable to lock source image");
+        return;
+    }
 //    ESP_LOGD(TAG, "width %d, height %d", width, height);
     Rotate(_angle, width / 2, height / 2);
 }
 
 void CRotateImage::RotateAntiAliasing(float _angle)
 {
+    ScopedImageAccess sourceAccess(ImageOrg != NULL ? ImageOrg : this);
+    if (!sourceAccess.isLocked()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image transform: unable to lock source image");
+        return;
+    }
 //    ESP_LOGD(TAG, "width %d, height %d", width, height);
     RotateAntiAliasing(_angle, width / 2, height / 2);
 }
 
 void CRotateImage::Translate(int _dx, int _dy)
 {
+    ScopedImageAccess sourceAccess(ImageOrg != NULL ? ImageOrg : this);
+    if (!sourceAccess.isLocked()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image transform: unable to lock source image");
+        return;
+    }
     if ((_dx == 0) && (_dy == 0)) {  // identity transform, the copy would leave the image unchanged
         return;
     }