Mercurial > hg > orthanc-python
changeset 216:dff82fbd0a15
added PythonThreadsAllower in some custom functions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 15:48:12 +0200 |
parents | b124c74e6968 |
children | f764ba66e409 |
files | Sources/Plugin.cpp |
diffstat | 1 files changed, 38 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/Sources/Plugin.cpp Wed Jul 03 15:33:21 2024 +0200 +++ b/Sources/Plugin.cpp Wed Jul 03 15:48:12 2024 +0200 @@ -35,8 +35,9 @@ #include "StorageArea.h" #include "StorageCommitmentScpCallback.h" +#include "PythonModule.h" +#include "PythonThreadsAllower.h" #include "RestCallbacks.h" -#include "PythonModule.h" #include "Autogenerated/sdk.h" @@ -71,8 +72,13 @@ else { OrthancPluginDictionaryEntry entry; + OrthancPluginErrorCode code; + + { + PythonThreadsAllower allower; + code = OrthancPluginLookupDictionary(OrthancPlugins::GetGlobalContext(), &entry, name); + } - OrthancPluginErrorCode code = OrthancPluginLookupDictionary(OrthancPlugins::GetGlobalContext(), &entry, name); if (code == OrthancPluginErrorCode_Success) { /** @@ -134,8 +140,14 @@ { OrthancPluginDicomInstance* instance = reinterpret_cast<sdk_OrthancPluginDicomInstance_Object*>(self)->object_; - const void* data = OrthancPluginGetInstanceData(OrthancPlugins::GetGlobalContext(), instance); - size_t size = OrthancPluginGetInstanceSize(OrthancPlugins::GetGlobalContext(), instance); + const void* data; + size_t size; + + { + PythonThreadsAllower allower; + data = OrthancPluginGetInstanceData(OrthancPlugins::GetGlobalContext(), instance); + size = OrthancPluginGetInstanceSize(OrthancPlugins::GetGlobalContext(), instance); + } if (data == NULL && size != 0) @@ -170,9 +182,15 @@ { OrthancPluginImage* image = reinterpret_cast<sdk_OrthancPluginImage_Object*>(self)->object_; - const void* buffer = OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image); - size_t size = (OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image) * - OrthancPluginGetImageHeight(OrthancPlugins::GetGlobalContext(), image)); + const void* buffer; + size_t size; + + { + PythonThreadsAllower allower; + buffer = OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image); + size = (OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image) * + OrthancPluginGetImageHeight(OrthancPlugins::GetGlobalContext(), image)); + } if (buffer == NULL && size != 0) @@ -215,8 +233,19 @@ } else { - OrthancPluginImage* image = OrthancPluginCreateImage( - OrthancPlugins::GetGlobalContext(), static_cast<OrthancPluginPixelFormat>(format), width, height); + OrthancPluginImage* image; + unsigned long targetPitch = 0; + + { + PythonThreadsAllower allower; + image = OrthancPluginCreateImage( + OrthancPlugins::GetGlobalContext(), static_cast<OrthancPluginPixelFormat>(format), width, height); + + if (image != NULL) + { + targetPitch = OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image); + } + } if (image == NULL) { @@ -228,8 +257,6 @@ else { // Copy the image line by line - unsigned long targetPitch = OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image); - const uint8_t* sourcePixels = reinterpret_cast<const uint8_t*>(buffer.buf); uint8_t* targetPixels = reinterpret_cast<uint8_t*>(OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image));