Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1598:c6b50b803387
primitives for image encoding/decoding in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Aug 2015 17:37:54 +0200 |
parents | e1e54a73ba8b |
children | dd1f9e81f891 |
comparison
equal
deleted
inserted
replaced
1597:415dfd1d1c61 | 1598:c6b50b803387 |
---|---|
41 #include "../../OrthancServer/OrthancInitialization.h" | 41 #include "../../OrthancServer/OrthancInitialization.h" |
42 #include "../../OrthancServer/ServerContext.h" | 42 #include "../../OrthancServer/ServerContext.h" |
43 #include "../../OrthancServer/ServerToolbox.h" | 43 #include "../../OrthancServer/ServerToolbox.h" |
44 #include "../../Core/Compression/ZlibCompressor.h" | 44 #include "../../Core/Compression/ZlibCompressor.h" |
45 #include "../../Core/Compression/GzipCompressor.h" | 45 #include "../../Core/Compression/GzipCompressor.h" |
46 #include "../../Core/ImageFormats/PngReader.h" | |
47 #include "../../Core/ImageFormats/PngWriter.h" | |
46 | 48 |
47 #include <boost/regex.hpp> | 49 #include <boost/regex.hpp> |
48 | 50 |
49 namespace Orthanc | 51 namespace Orthanc |
50 { | 52 { |
101 case ChangeType_StableSeries: | 103 case ChangeType_StableSeries: |
102 return OrthancPluginChangeType_StableSeries; | 104 return OrthancPluginChangeType_StableSeries; |
103 | 105 |
104 case ChangeType_StableStudy: | 106 case ChangeType_StableStudy: |
105 return OrthancPluginChangeType_StableStudy; | 107 return OrthancPluginChangeType_StableStudy; |
108 | |
109 default: | |
110 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
111 } | |
112 } | |
113 | |
114 | |
115 static OrthancPluginPixelFormat Convert(PixelFormat format) | |
116 { | |
117 switch (format) | |
118 { | |
119 case PixelFormat_Grayscale16: | |
120 return OrthancPluginPixelFormat_Grayscale16; | |
121 | |
122 case PixelFormat_Grayscale8: | |
123 return OrthancPluginPixelFormat_Grayscale8; | |
124 | |
125 case PixelFormat_RGB24: | |
126 return OrthancPluginPixelFormat_RGB24; | |
127 | |
128 case PixelFormat_RGBA32: | |
129 return OrthancPluginPixelFormat_RGBA32; | |
130 | |
131 case PixelFormat_SignedGrayscale16: | |
132 return OrthancPluginPixelFormat_SignedGrayscale16; | |
133 | |
134 default: | |
135 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
136 } | |
137 } | |
138 | |
139 | |
140 static PixelFormat Convert(OrthancPluginPixelFormat format) | |
141 { | |
142 switch (format) | |
143 { | |
144 case OrthancPluginPixelFormat_Grayscale16: | |
145 return PixelFormat_Grayscale16; | |
146 | |
147 case OrthancPluginPixelFormat_Grayscale8: | |
148 return PixelFormat_Grayscale8; | |
149 | |
150 case OrthancPluginPixelFormat_RGB24: | |
151 return PixelFormat_RGB24; | |
152 | |
153 case OrthancPluginPixelFormat_RGBA32: | |
154 return PixelFormat_RGBA32; | |
155 | |
156 case OrthancPluginPixelFormat_SignedGrayscale16: | |
157 return PixelFormat_SignedGrayscale16; | |
106 | 158 |
107 default: | 159 default: |
108 throw OrthancException(ErrorCode_ParameterOutOfRange); | 160 throw OrthancException(ErrorCode_ParameterOutOfRange); |
109 } | 161 } |
110 } | 162 } |
224 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || | 276 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || |
225 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || | 277 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || |
226 sizeof(int32_t) != sizeof(OrthancPluginContentType) || | 278 sizeof(int32_t) != sizeof(OrthancPluginContentType) || |
227 sizeof(int32_t) != sizeof(OrthancPluginResourceType) || | 279 sizeof(int32_t) != sizeof(OrthancPluginResourceType) || |
228 sizeof(int32_t) != sizeof(OrthancPluginChangeType) || | 280 sizeof(int32_t) != sizeof(OrthancPluginChangeType) || |
281 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || | |
229 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || | 282 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || |
230 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) | 283 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) |
231 { | 284 { |
232 /* Sanity check of the compiler */ | 285 /* Sanity check of the compiler */ |
233 throw OrthancException(ErrorCode_Plugin); | 286 throw OrthancException(ErrorCode_Plugin); |
991 | 1044 |
992 CopyToMemoryBuffer(*p.target, result); | 1045 CopyToMemoryBuffer(*p.target, result); |
993 } | 1046 } |
994 | 1047 |
995 | 1048 |
1049 void OrthancPlugins::UncompressImage(const void* parameters) | |
1050 { | |
1051 const _OrthancPluginUncompressImage& p = reinterpret_cast<const _OrthancPluginUncompressImage&>(parameters); | |
1052 | |
1053 switch (p.format) | |
1054 { | |
1055 case OrthancPluginImageFormat_Png: | |
1056 { | |
1057 std::auto_ptr<PngReader> image(new PngReader); | |
1058 image->ReadFromMemory(p.data, p.size); | |
1059 *(p.target) = reinterpret_cast<OrthancPluginImage*>(image.release()); | |
1060 return; | |
1061 } | |
1062 | |
1063 case OrthancPluginImageFormat_Jpeg: | |
1064 // TODO | |
1065 | |
1066 default: | |
1067 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1068 } | |
1069 } | |
1070 | |
1071 | |
1072 void OrthancPlugins::CompressImage(const void* parameters) | |
1073 { | |
1074 const _OrthancPluginCompressImage& p = reinterpret_cast<const _OrthancPluginCompressImage&>(parameters); | |
1075 | |
1076 std::string compressed; | |
1077 | |
1078 switch (p.imageFormat) | |
1079 { | |
1080 case OrthancPluginImageFormat_Png: | |
1081 { | |
1082 PngWriter writer; | |
1083 writer.WriteToMemory(compressed, p.width, p.height, p.pitch, Convert(p.pixelFormat), p.buffer); | |
1084 break; | |
1085 } | |
1086 | |
1087 case OrthancPluginImageFormat_Jpeg: | |
1088 // TODO | |
1089 | |
1090 default: | |
1091 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1092 } | |
1093 | |
1094 CopyToMemoryBuffer(*p.target, compressed.size() > 0 ? compressed.c_str() : NULL, compressed.size()); | |
1095 } | |
1096 | |
1097 | |
996 bool OrthancPlugins::InvokeService(_OrthancPluginService service, | 1098 bool OrthancPlugins::InvokeService(_OrthancPluginService service, |
997 const void* parameters) | 1099 const void* parameters) |
998 { | 1100 { |
999 VLOG(1) << "Calling plugin service: " << service; | 1101 VLOG(1) << "Calling plugin service: " << service; |
1000 | 1102 |
1295 *reinterpret_cast<const _OrthancPluginGetErrorDescription*>(parameters); | 1397 *reinterpret_cast<const _OrthancPluginGetErrorDescription*>(parameters); |
1296 *(p.target) = EnumerationToString(static_cast<ErrorCode>(p.error)); | 1398 *(p.target) = EnumerationToString(static_cast<ErrorCode>(p.error)); |
1297 return true; | 1399 return true; |
1298 } | 1400 } |
1299 | 1401 |
1402 case _OrthancPluginService_GetImagePixelFormat: | |
1403 { | |
1404 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1405 *(p.resultPixelFormat) = Convert(reinterpret_cast<const ImageAccessor*>(p.image)->GetFormat()); | |
1406 return true; | |
1407 } | |
1408 | |
1409 case _OrthancPluginService_GetImageWidth: | |
1410 { | |
1411 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1412 *(p.resultUint32) = reinterpret_cast<const ImageAccessor*>(p.image)->GetWidth(); | |
1413 return true; | |
1414 } | |
1415 | |
1416 case _OrthancPluginService_GetImageHeight: | |
1417 { | |
1418 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1419 *(p.resultUint32) = reinterpret_cast<const ImageAccessor*>(p.image)->GetHeight(); | |
1420 return true; | |
1421 } | |
1422 | |
1423 case _OrthancPluginService_GetImagePitch: | |
1424 { | |
1425 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1426 *(p.resultUint32) = reinterpret_cast<const ImageAccessor*>(p.image)->GetPitch(); | |
1427 return true; | |
1428 } | |
1429 | |
1430 case _OrthancPluginService_GetImageBuffer: | |
1431 { | |
1432 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1433 *(p.resultBuffer) = reinterpret_cast<const ImageAccessor*>(p.image)->GetBuffer(); | |
1434 return true; | |
1435 } | |
1436 | |
1437 case _OrthancPluginService_FreeImage: | |
1438 { | |
1439 const _OrthancPluginGetImageInfo& p = reinterpret_cast<const _OrthancPluginGetImageInfo&>(parameters); | |
1440 delete reinterpret_cast<const ImageAccessor*>(p.image); | |
1441 return true; | |
1442 } | |
1443 | |
1444 case _OrthancPluginService_UncompressImage: | |
1445 UncompressImage(parameters); | |
1446 return true; | |
1447 | |
1448 case _OrthancPluginService_CompressImage: | |
1449 CompressImage(parameters); | |
1450 return true; | |
1451 | |
1300 default: | 1452 default: |
1301 // This service is unknown by the Orthanc plugin engine | 1453 { |
1454 // This service is unknown to the Orthanc plugin engine | |
1302 return false; | 1455 return false; |
1456 } | |
1303 } | 1457 } |
1304 } | 1458 } |
1305 | 1459 |
1306 | 1460 |
1307 bool OrthancPlugins::HasStorageArea() const | 1461 bool OrthancPlugins::HasStorageArea() const |