Mercurial > octave-libtiff
changeset 31163:d701c6a4cda1
Tiff: improved handling LibTIFF error output silencing.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 10 Aug 2022 20:59:51 +0200 |
parents | 28817158ca86 |
children | 3155aa74c62e |
files | libinterp/corefcn/__tiff__.cc |
diffstat | 1 files changed, 25 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:46:56 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:59:51 2022 +0200 @@ -16,7 +16,8 @@ #if defined (HAVE_TIFF) # include <tiffio.h> -TIFFErrorHandler tiff_default_handler = NULL; +TIFFErrorHandler tiff_default_error_handler = NULL; +TIFFErrorHandler tiff_default_warning_handler = NULL; #endif namespace octave @@ -2373,12 +2374,30 @@ "Enables or Disables error output from LibTIFF") { #if defined (HAVE_TIFF) - if (args (0).bool_value ()) - TIFFSetErrorHandler (tiff_default_handler); - else if (tiff_default_handler == NULL) - tiff_default_handler = TIFFSetErrorHandler (NULL); + // Get the default error handlers the first time this function is called + if (tiff_default_error_handler == NULL) + { + tiff_default_error_handler = TIFFSetErrorHandler (NULL); + tiff_default_warning_handler = TIFFSetWarningHandler (NULL); + } + + if (args.length () == 0) + error ("No state argument provided"); + + if (! args(0).is_bool_scalar ()) + error ("Expected logical value as argument"); + + // Set the error and warning handlers according to the bool parameter + if (args(0).bool_value ()) + { + TIFFSetErrorHandler (tiff_default_error_handler); + TIFFSetWarningHandler (tiff_default_warning_handler); + } else - TIFFSetErrorHandler (NULL); + { + TIFFSetErrorHandler (NULL); + TIFFSetWarningHandler (NULL); + } return octave_value_list (); #else