changeset 31141:af4519cbfcae

Tiff.m: prevented calling methods after the image file is closed.
author magedrifaat <magedrifaat@gmail.com>
date Fri, 29 Jul 2022 00:46:44 +0200
parents 5f70efad6e2c
children 97e7ee3b27b7
files scripts/io/Tiff.m
diffstat 1 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/io/Tiff.m	Thu Jul 28 23:32:23 2022 +0200
+++ b/scripts/io/Tiff.m	Fri Jul 29 00:46:44 2022 +0200
@@ -1,4 +1,4 @@
-classdef Tiff
+classdef Tiff < handle
   properties (Constant = true)
     TagID = struct(
         "SubFileType", 254,
@@ -74,7 +74,8 @@
   endproperties
 
   properties (Access = private)
-    tiff_handle
+    tiff_handle;
+    closed=false;
   endproperties
 
   methods
@@ -88,22 +89,37 @@
     endfunction
 
     function close (t)
-      __close_tiff__ (t.tiff_handle);
+      if (! t.closed)
+        __close_tiff__ (t.tiff_handle);
+        t.closed = true;
+      endif
     endfunction
 
     function tag = getTag (t, tag_name)
+      if (t.closed)
+        error ("Image file was closed");
+      endif
       tag = __tiff_get_tag__ (t.tiff_handle, tag_name);
     endfunction
 
     function setTag (t, varargin)
+      if (t.closed)
+        error ("Image file was closed");
+      endif
       __tiff_set_tag__ (t.tiff_handle, varargin{:});
     endfunction
 
     function argout = read (t)
+      if (t.closed)
+        error ("Image file was closed");
+      endif
       argout = __tiff_read__ (t.tiff_handle);
     endfunction
 
     function writeEncodedStrip (t, stripNumber, imageData)
+      if (t.closed)
+        error ("Image file was closed");
+      endif
       __tiff_write_encoded_strip__ (t.tiff_handle, stripNumber, imageData);
     endfunction