Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__magick_read__.cc @ 10947:dc74ce93cfc4
initialize GraphicsMagick in all __magick_* functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 07 Sep 2010 12:38:35 +0200 |
parents | 89f4d7e294cc |
children | 71ad9c8f20f5 |
comparison
equal
deleted
inserted
replaced
10946:1094868ca10d | 10947:dc74ce93cfc4 |
---|---|
369 return retval; | 369 return retval; |
370 } | 370 } |
371 | 371 |
372 #endif | 372 #endif |
373 | 373 |
374 static void | |
375 maybe_initialize_magick (void) | |
376 { | |
377 #ifdef HAVE_MAGICK | |
378 | |
379 static bool initialized = false; | |
380 | |
381 if (! initialized) | |
382 { | |
383 // Save the locale as GraphicsMagick might change this (depending on version) | |
384 const char *static_locale = setlocale (LC_ALL, NULL); | |
385 const std::string locale (static_locale); | |
386 | |
387 std::string program_name = octave_env::get_program_invocation_name (); | |
388 | |
389 Magick::InitializeMagick (program_name.c_str ()); | |
390 | |
391 // Restore locale from before GraphicsMagick initialisation | |
392 setlocale (LC_ALL, locale.c_str ()); | |
393 | |
394 initialized = true; | |
395 } | |
396 #endif | |
397 } | |
398 | |
374 DEFUN_DLD (__magick_read__, args, nargout, | 399 DEFUN_DLD (__magick_read__, args, nargout, |
375 "-*- texinfo -*-\n\ | 400 "-*- texinfo -*-\n\ |
376 @deftypefn {Function File} {@var{m} =} __magick_read__(@var{fname}, @var{index})\n\ | 401 @deftypefn {Function File} {@var{m} =} __magick_read__(@var{fname}, @var{index})\n\ |
377 @deftypefnx {Function File} {[@var{m}, @var{colormap}] =} __magick_read__(@var{fname}, @var{index})\n\ | 402 @deftypefnx {Function File} {[@var{m}, @var{colormap}] =} __magick_read__(@var{fname}, @var{index})\n\ |
378 @deftypefnx {Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__(@var{fname}, @var{index})\n\ | 403 @deftypefnx {Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__(@var{fname}, @var{index})\n\ |
383 { | 408 { |
384 octave_value_list output; | 409 octave_value_list output; |
385 | 410 |
386 #ifdef HAVE_MAGICK | 411 #ifdef HAVE_MAGICK |
387 | 412 |
388 static bool initialized = false; | 413 maybe_initialize_magick (); |
389 | |
390 if (! initialized) | |
391 { | |
392 // Save the locale as GraphicsMagick might change this (depending on version) | |
393 const char *static_locale = setlocale (LC_ALL, NULL); | |
394 const std::string locale (static_locale); | |
395 | |
396 std::string program_name = octave_env::get_program_invocation_name (); | |
397 | |
398 Magick::InitializeMagick (program_name.c_str ()); | |
399 | |
400 // Restore locale from before GraphicsMagick initialisation | |
401 setlocale (LC_ALL, locale.c_str ()); | |
402 | |
403 initialized = true; | |
404 } | |
405 | 414 |
406 if (args.length () > 3 || args.length () < 1 || ! args(0).is_string () | 415 if (args.length () > 3 || args.length () < 1 || ! args(0).is_string () |
407 || nargout > 3) | 416 || nargout > 3) |
408 { | 417 { |
409 print_usage (); | 418 print_usage (); |
830 @end deftypefn") | 839 @end deftypefn") |
831 { | 840 { |
832 octave_value_list retval; | 841 octave_value_list retval; |
833 | 842 |
834 #ifdef HAVE_MAGICK | 843 #ifdef HAVE_MAGICK |
844 maybe_initialize_magick (); | |
845 | |
835 int nargin = args.length (); | 846 int nargin = args.length (); |
836 | 847 |
837 if (nargin > 2) | 848 if (nargin > 2) |
838 { | 849 { |
839 std::string filename = args(0).string_value (); | 850 std::string filename = args(0).string_value (); |
958 @end deftypefn") | 969 @end deftypefn") |
959 { | 970 { |
960 octave_value retval; | 971 octave_value retval; |
961 | 972 |
962 #ifdef HAVE_MAGICK | 973 #ifdef HAVE_MAGICK |
974 | |
975 maybe_initialize_magick (); | |
963 | 976 |
964 if (args.length () < 1 || ! args (0).is_string ()) | 977 if (args.length () < 1 || ! args (0).is_string ()) |
965 { | 978 { |
966 print_usage (); | 979 print_usage (); |
967 return retval; | 980 return retval; |