From: dirk Date: Tue, 14 Jan 2014 20:30:45 +0000 (+0000) Subject: Moved functions to Functions.h. X-Git-Tag: 7.0.1-0~2879 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b53451c6449a4a5c6f846000044a7c65aee828b1;p=imagemagick Moved functions to Functions.h. Added methods to enable/disable OpenCL. Removed deprecated method 'cacheThreshold' from Image.cpp. --- diff --git a/Magick++/lib/Functions.cpp b/Magick++/lib/Functions.cpp index 2d3a9d4ed..671995eca 100644 --- a/Magick++/lib/Functions.cpp +++ b/Magick++/lib/Functions.cpp @@ -14,9 +14,67 @@ using namespace std; #include "Magick++/Functions.h" +#include "Magick++/Exception.h" + +#define GetPPException \ + ExceptionInfo \ + exceptionInfo; \ + GetExceptionInfo(&exceptionInfo) +#define ThrowPPException \ + throwException(exceptionInfo); \ + (void) DestroyExceptionInfo(&exceptionInfo) + +static bool magick_initialized=false; // Clone C++ string as allocated C string, de-allocating any existing string -void Magick::CloneString( char **destination_, const std::string &source_ ) +void Magick::CloneString(char **destination_, const std::string &source_) +{ + MagickCore::CloneString(destination_,source_.c_str()); +} + +MagickPPExport void Magick::CacheThreshold(const MagickSizeType threshold_) { - MagickCore::CloneString( destination_, source_.c_str() ); + (void) SetMagickResourceLimit(MemoryResource,threshold_); } + +MagickPPExport MagickCore::MagickSizeType Magick::CacheThreshold(void) +{ + return GetMagickResourceLimit(MemoryResource); +} + +MagickPPExport void Magick::DisableOpenCL(void) +{ + GetPPException; + MagickCore::InitImageMagickOpenCL(MagickCore::MAGICK_OPENCL_OFF,NULL,NULL, + &exceptionInfo); + ThrowPPException; +} + +MagickPPExport void Magick::EnableOpenCL(const bool useCache_) +{ + GetPPException; + if (useCache_) + MagickCore::InitImageMagickOpenCL( + MagickCore::MAGICK_OPENCL_DEVICE_SELECT_AUTO,NULL,NULL,&exceptionInfo); + else + MagickCore::InitImageMagickOpenCL( + MagickCore::MAGICK_OPENCL_DEVICE_SELECT_AUTO_CLEAR_CACHE,NULL,NULL, + &exceptionInfo); + ThrowPPException; +} + +MagickPPExport void Magick::InitializeMagick(const char *path_) +{ + MagickCore::MagickCoreGenesis(path_,MagickFalse); + if (!magick_initialized) + magick_initialized=true; +} + +MagickPPExport void Magick::TerminateMagick(void) +{ + if (magick_initialized) + { + magick_initialized=false; + MagickCore::MagickCoreTerminus(); + } +} \ No newline at end of file diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 280b75bde..7d7304546 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -51,8 +51,6 @@ MagickPPExport const char *Magick::borderGeometryDefault="6x6+0+0"; MagickPPExport const char *Magick::frameGeometryDefault="25x25+6+6"; MagickPPExport const char *Magick::raiseGeometryDefault="6x6+0+0"; -static bool magick_initialized=false; - MagickPPExport int Magick::operator == (const Magick::Image &left_, const Magick::Image &right_) { @@ -94,22 +92,6 @@ MagickPPExport int Magick::operator <= (const Magick::Image &left_, return((left_ < right_) || ( left_ == right_)); } -MagickPPExport void Magick::InitializeMagick(const char *path_) -{ - MagickCore::MagickCoreGenesis(path_,MagickFalse); - if (!magick_initialized) - magick_initialized=true; -} - -MagickPPExport void Magick::TerminateMagick(void) -{ - if (magick_initialized) - { - magick_initialized=false; - MagickCore::MagickCoreTerminus(); - } -} - Magick::Image::Image(void) : _imgRef(new ImageRef) { @@ -518,11 +500,6 @@ Magick::Color Magick::Image::boxColor(void) const return(constOptions()->boxColor()); } -void Magick::Image::cacheThreshold(const MagickSizeType threshold_) -{ - SetMagickResourceLimit(MemoryResource, threshold_); -} - void Magick::Image::channelDepth(const size_t depth_) { modifyImage(); diff --git a/Magick++/lib/Magick++.h b/Magick++/lib/Magick++.h index a85f7da58..740d51ef5 100644 --- a/Magick++/lib/Magick++.h +++ b/Magick++/lib/Magick++.h @@ -7,6 +7,7 @@ // #ifndef MagickPlusPlus_Header #include +#include #include #include #include diff --git a/Magick++/lib/Magick++/Functions.h b/Magick++/lib/Magick++/Functions.h index 2cbea429a..938a58882 100644 --- a/Magick++/lib/Magick++/Functions.h +++ b/Magick++/lib/Magick++/Functions.h @@ -14,7 +14,25 @@ namespace Magick { - void MagickPPExport CloneString( char **destination_, const std::string &source_ ); + // Pixel cache threshold in bytes. Once this memory threshold is exceeded, + // all subsequent pixels cache operations are to/from disk + MagickPPExport void CacheThreshold(const MagickSizeType threshold_); + MagickPPExport MagickSizeType CacheThreshold(void); + // Clone C++ string as allocated C string, de-allocating any existing string + MagickPPExport void CloneString(char **destination_, + const std::string &source_); + + // Disable OpenCL acceleration (only works when build with OpenCL support) + MagickPPExport void DisableOpenCL(void); + + // Enable OpenCL acceleration (only works when build with OpenCL support) + MagickPPExport void EnableOpenCL(const bool useCache_=true); + + // C library initialization routine + MagickPPExport void InitializeMagick(const char *path_); + + // C library initialization routine + MagickPPExport void TerminateMagick(); } #endif // Magick_Functions_header diff --git a/Magick++/lib/Magick++/Image.h b/Magick++/lib/Magick++/Image.h index 4c8cd1788..9e57dc2b7 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -43,10 +43,6 @@ namespace Magick MagickPPExport int operator <= (const Magick::Image &left_,const Magick::Image &right_); - // C library initialization routine - MagickPPExport void InitializeMagick(const char *path_); - MagickPPExport void TerminateMagick(); - // // Image is the representation of an image. In reality, it actually // a handle object which contains a pointer to a shared reference @@ -181,11 +177,6 @@ namespace Magick void boxColor(const Color &boxColor_); Color boxColor(void) const; - // Pixel cache threshold in bytes. Once this memory threshold - // is exceeded, all subsequent pixels cache operations are to/from - // disk. This setting is shared by all Image objects. - static void cacheThreshold(const MagickSizeType threshold_); - // Set or obtain modulus channel depth void channelDepth(const size_t depth_); size_t channelDepth(); diff --git a/MagickCore/MagickCore.h b/MagickCore/MagickCore.h index 6670b8f3a..ce6b94ecf 100644 --- a/MagickCore/MagickCore.h +++ b/MagickCore/MagickCore.h @@ -124,6 +124,7 @@ extern "C" { #include "MagickCore/monitor.h" #include "MagickCore/montage.h" #include "MagickCore/morphology.h" +#include "MagickCore/opencl.h" #include "MagickCore/option.h" #include "MagickCore/paint.h" #include "MagickCore/pixel.h"