changeset 812:94c119801c1c

Use warning ("off", ID, "local") instead of an unwind_protect block. * rgb2gray.m: use the "local" option for warning(), available with new version of Octave, to simplify turning off warnings for broadcasting locally. We are already dependent on that version for other reasons anyway. * wavelength2rgb.m: ditto.
author Carnë Draug <carandraug@octave.org>
date Tue, 29 Oct 2013 17:07:21 +0000
parents 547221feb08f
children d26a8681dd22
files inst/rgb2gray.m inst/wavelength2rgb.m
diffstat 2 files changed, 50 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/inst/rgb2gray.m
+++ b/inst/rgb2gray.m
@@ -36,37 +36,26 @@
 
   if (iscolormap (rgb))
     gray = rgb2ntsc (rgb) (:, 1) * ones (1, 3);
+
   elseif (isimage (rgb) && ndims (rgb) == 3)
-
-    ## FIXME when warning for broadcasting is turned off by default, this
-    ## unwind_protect block could be removed
+    warning ("off", "Octave:broadcast", "local");
 
-    ## we are using broadcasting on the code below so we turn off the
-    ## warnings but will restore to previous state at the end
-    bc_warn = warning ("query", "Octave:broadcast");
-    unwind_protect
-      warning ("off", "Octave:broadcast");
-
-      ## mutiply each color by the luminance factor (this is also matlab compatible)
-      ##      0.29894 * red + 0.58704 * green + 0.11402 * blue
-      gray = im2double (rgb) .* permute ([0.29894, 0.58704, 0.11402], [1, 3, 2]);
-      gray = sum (gray, 3);
+    ## mutiply each color by the luminance factor (this is also matlab compatible)
+    ##      0.29894 * red + 0.58704 * green + 0.11402 * blue
+    gray = im2double (rgb) .* permute ([0.29894, 0.58704, 0.11402], [1, 3, 2]);
+    gray = sum (gray, 3);
 
-      switch (class (rgb))
-      case {"single", "double"}
-        ## do nothing. All is good
-      case "uint8"
-        gray = im2uint8 (gray);
-      case "uint16"
-        gray = im2uint16 (gray);
-      otherwise
-        error ("rgb2gray: unsupported class %s", class(rgb));
-      endswitch
+    switch (class (rgb))
+    case {"single", "double"}
+      ## do nothing. All is good
+    case "uint8"
+      gray = im2uint8 (gray);
+    case "uint16"
+      gray = im2uint16 (gray);
+    otherwise
+      error ("rgb2gray: unsupported class %s", class(rgb));
+    endswitch
 
-    unwind_protect_cleanup
-      ## restore broadcats warning status
-      warning (bc_warn.state, "Octave:broadcast");
-    end_unwind_protect
   else
     error ("rgb2gray: the input must either be an RGB image or a colormap");
   endif
--- a/inst/wavelength2rgb.m
+++ b/inst/wavelength2rgb.m
@@ -93,52 +93,45 @@
   ## we already initialized the matrix with zeros()
   get_rgb_mask = @(mask) repmat (mask, [ones(1, ndims (mask) - size_adjust) 3]);
 
-  ## FIXME when warning for broadcasting is turned off by default, this
-  ## unwind_protect block could be removed
-  bc_warn = warning ("query", "Octave:broadcast");
-  unwind_protect
-    warning ("off", "Octave:broadcast");
-    mask    = wavelength >= 380 & wavelength < 440;
-    rgbmask = get_rgb_mask (mask);
-    rgb(rgbmask & Rmask) = -(wavelength(mask) - 440) / 60; # 60 comes from 440-380
-    ## skiping green channel (values of zero)
-    rgb(rgbmask & Bmask) = 1;
+  warning ("off", "Octave:broadcast", "local");
+
+  mask    = wavelength >= 380 & wavelength < 440;
+  rgbmask = get_rgb_mask (mask);
+  rgb(rgbmask & Rmask) = -(wavelength(mask) - 440) / 60; # 60 comes from 440-380
+  ## skiping green channel (values of zero)
+  rgb(rgbmask & Bmask) = 1;
 
-    mask    = wavelength >= 440 & wavelength < 490;
-    rgbmask = get_rgb_mask (mask);
-    ## skiping red channel (values of zero)
-    rgb(rgbmask & Gmask) = (wavelength(mask) - 440) / 50; # 50 comes from 490-440
-    rgb(rgbmask & Bmask) = 1;
+  mask    = wavelength >= 440 & wavelength < 490;
+  rgbmask = get_rgb_mask (mask);
+  ## skiping red channel (values of zero)
+  rgb(rgbmask & Gmask) = (wavelength(mask) - 440) / 50; # 50 comes from 490-440
+  rgb(rgbmask & Bmask) = 1;
 
-    mask    = wavelength >= 490 & wavelength < 510;
-    rgbmask = get_rgb_mask (mask);
-    ## skiping red channel (values of zero)
-    rgb(rgbmask & Gmask) = 1;
-    rgb(rgbmask & Bmask) = -(wavelength(mask) - 510) / 20; # 20 comes from 510-490
+  mask    = wavelength >= 490 & wavelength < 510;
+  rgbmask = get_rgb_mask (mask);
+  ## skiping red channel (values of zero)
+  rgb(rgbmask & Gmask) = 1;
+  rgb(rgbmask & Bmask) = -(wavelength(mask) - 510) / 20; # 20 comes from 510-490
 
-    mask    = wavelength >= 510 & wavelength < 580;
-    rgbmask = get_rgb_mask (mask);
-    rgb(rgbmask & Rmask) = (wavelength(mask) - 510) / 70; # 70 comes from 580-510
-    rgb(rgbmask & Gmask) = 1;
-    ## skiping blue channel (values of zero)
-
-    mask    = wavelength >= 580 & wavelength < 645;
-    rgbmask = get_rgb_mask (mask);
-    rgb(rgbmask & Rmask) = 1;
-    rgb(rgbmask & Gmask) = -(wavelength(mask) - 645) / 65; # 65 comes from 645-580
-    ## skiping blue channel (values of zero)
+  mask    = wavelength >= 510 & wavelength < 580;
+  rgbmask = get_rgb_mask (mask);
+  rgb(rgbmask & Rmask) = (wavelength(mask) - 510) / 70; # 70 comes from 580-510
+  rgb(rgbmask & Gmask) = 1;
+  ## skiping blue channel (values of zero)
 
-    mask    = wavelength >= 645 & wavelength <= 780;
-    rgbmask = get_rgb_mask (mask);
-    rgb(rgbmask & Rmask) = 1;
-    ## skiping green channel (values of zero)
-    ## skiping blue channel (values of zero)
+  mask    = wavelength >= 580 & wavelength < 645;
+  rgbmask = get_rgb_mask (mask);
+  rgb(rgbmask & Rmask) = 1;
+  rgb(rgbmask & Gmask) = -(wavelength(mask) - 645) / 65; # 65 comes from 645-580
+  ## skiping blue channel (values of zero)
 
-    ## all other wavelengths have values of zero in all channels (black)
-  unwind_protect_cleanup
-    ## restore broadcats warning status
-    warning (bc_warn.state, "Octave:broadcast");
-  end_unwind_protect
+  mask    = wavelength >= 645 & wavelength <= 780;
+  rgbmask = get_rgb_mask (mask);
+  rgb(rgbmask & Rmask) = 1;
+  ## skiping green channel (values of zero)
+  ## skiping blue channel (values of zero)
+
+  ## all other wavelengths have values of zero in all channels (black)
 
   ## let intensity fall off near the vision limits
   ## set the factor