Mercurial > hg > orthanc-wsi
changeset 366:465aef69a587
fix Resources/OrthancWSIClearCache.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Mar 2025 16:58:51 +0100 (2 months ago) |
parents | 71bbdc4b4790 |
children | c2e9c4fbfb0b |
files | Resources/OrthancWSIClearCache.py ViewerPlugin/Plugin.cpp |
diffstat | 2 files changed, 60 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/OrthancWSIClearCache.py Wed Feb 19 17:54:25 2025 +0100 +++ b/Resources/OrthancWSIClearCache.py Thu Mar 13 16:58:51 2025 +0100 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # Orthanc - A Lightweight, RESTful DICOM Store # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics @@ -40,10 +40,13 @@ exit(-1) -METADATA=4200 +METADATA = [ + 4200, # For versions <= 0.7 of the plugin + 4201, # For versions >= 1.0 of the plugin +] -def RunHttpRequest(uri, method, body = None): +def RunHttpRequest(uri, method, ignore_errors, body = None): http = httplib2.Http() headers = { } @@ -65,7 +68,7 @@ body = body, headers = headers) - if resp.status != 200: + if not ignore_errors and resp.status != 200: raise Exception('Cannot %s on URL %s, HTTP status %d ' '(Is Orthanc running? Is there a password?)' % (method, url, resp.status)) @@ -73,8 +76,9 @@ return content.decode('utf8') -for instance in json.loads(RunHttpRequest('/instances', 'GET')): +for instance in json.loads(RunHttpRequest('/instances', 'GET', ignore_errors = False)): print('Clearing cache for instance %s' % instance) - RunHttpRequest('/instances/%s/metadata/%s' % (instance, METADATA), 'DELETE') + for metadata in METADATA: + RunHttpRequest('/instances/%s/metadata/%s' % (instance, metadata), 'DELETE', ignore_errors = True) print('The WSI cache was successfully cleared')
--- a/ViewerPlugin/Plugin.cpp Wed Feb 19 17:54:25 2025 +0100 +++ b/ViewerPlugin/Plugin.cpp Thu Mar 13 16:58:51 2025 +0100 @@ -27,6 +27,7 @@ #include "DicomPyramidCache.h" #include "IIIF.h" #include "RawTile.h" +#include "../Framework/ColorSpaces.h" #include "../Framework/Inputs/DecodedTiledPyramid.h" #include "../Framework/Inputs/OnTheFlyPyramid.h" #include "../Framework/Inputs/DecodedPyramidCache.h" @@ -405,6 +406,12 @@ } +static bool IsNear(float a, float b) +{ + return std::abs(a - b) < 100.0f * std::numeric_limits<float>::epsilon(); +} + + extern "C" { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) @@ -439,6 +446,49 @@ Orthanc::Logging::Initialize(context); #endif + try + { + /** + + C.10.7.1.1 Encoding of CIELab Values + + Attributes such as Graphic Layer Recommended Display CIELab + Value (0070,0401) consist of three unsigned short values: + + An L value linearly scaled to 16 bits, such that 0x0000 + corresponds to an L of 0.0, and 0xFFFF corresponds to an L of + 100.0. + + An a* then a b* value, each linearly scaled to 16 bits and + offset to an unsigned range, such that 0x0000 corresponds to + an a* or b* of -128.0, 0x8080 corresponds to an a* or b* of + 0.0 and 0xFFFF corresponds to an a* or b* of 127.0 + + **/ + + OrthancWSI::LABColor lab; + if (!OrthancWSI::LABColor::DecodeDicomRecommendedAbsentPixelCIELab(lab, "65535\\0\\0") || + !IsNear(lab.GetL(), 100.0f) || + !IsNear(lab.GetA(), -128.0f) || + !IsNear(lab.GetB(), -128.0f)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + if (!OrthancWSI::LABColor::DecodeDicomRecommendedAbsentPixelCIELab(lab, "0\\32896\\65535") || + !IsNear(lab.GetL(), 0.0f) || + !IsNear(lab.GetA(), 0.0f) || + !IsNear(lab.GetB(), 127.0f)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << "Exception in startup tests: " << e.What(); + return -1; + } + // Limit the number of PNG transcoders to the number of available // hardware threads (e.g. number of CPUs or cores or // hyperthreading units)