diff scripts/image/private/__imwrite__.m @ 17855:bfbe5dcc9943

imwrite: implement DisposalMethod option. * __magick_read__.cc (F__magick_write__): set gifDisposeMethod() when writing an image to implement the DisposalMethod option. Set all the options in a single option rather than a loop per option. (init_reverse_disposal_methods): new method to return a reversed std::map of the disposal methods. (init_disposal_methods): move up, to be closer to the new init_reverse_disposal_methods() * private/__imwrite__.m: input check for the new option DisposalMethod and set its default. * imwrite.m: document new option.
author Carnë Draug <carandraug@octave.org>
date Tue, 05 Nov 2013 07:05:30 +0000
parents adb0ba0d0c13
children 4197fc428c7d
line wrap: on
line diff
--- a/scripts/image/private/__imwrite__.m	Tue Nov 05 05:48:56 2013 +0000
+++ b/scripts/image/private/__imwrite__.m	Tue Nov 05 07:05:30 2013 +0000
@@ -42,6 +42,7 @@
 
   ## set default for options
   options = struct ("writemode", "overwrite",
+                    "disposalmethod", {repmat({"doNotSpecify"}, 1, size (img, 4))},
                     "quality",   75,
                     "delaytime", ones (1, size (img, 4)) *500, # 0.5 seconds
                     "loopcount", 0, ## this is actually Inf
@@ -84,6 +85,30 @@
                  param_list{idx});
         endif
 
+      case "disposalmethod"
+        options.disposalmethod = param_list{idx+1};
+        if (! ischar (options.disposalmethod) &&
+            ! iscellstr (options.disposalmethod))
+          error ("imwrite: value for %s must be a string or cell array of strings",
+                 param_list{idx});
+        elseif (! iscell (options.disposalmethod))
+          options.disposalmethod = {options.disposalmethod};
+        endif
+        options.disposalmethod = tolower (options.disposalmethod);
+        matches = ismember (options.disposalmethod,
+                            {"donotspecify", "leaveinplace", "restorebg", "restoreprevious"});
+        if (any (! matches))
+          error ("imwrite: unknow method %s for option %s",
+                 options.disposalmethod{find (! matches, 1)},
+                 param_list{idx});
+        endif
+        if (isscalar (options.disposalmethod))
+          options.disposalmethod = repmat (options.disposalmethod, 1, size (img, 4));
+        elseif (numel (options.disposalmethod) != size (img, 4))
+          error ("imwrite: if value %s is a cell array must have same length as number of frames",
+                 param_list{idx});
+        endif
+
       case "loopcount"
         options.loopcount = param_list{idx+1};
         if (! isscalar (options.loopcount) || ! isnumeric (options.loopcount)