Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1827:4b6673e828f4
"OrthancPluginCreateImage()" and "OrthancPluginCreateImageAccessor()" to create images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2015 16:39:03 +0100 |
parents | ac5b0b4e2434 |
children | a71d74987090 |
comparison
equal
deleted
inserted
replaced
1826:ac5b0b4e2434 | 1827:4b6673e828f4 |
---|---|
428 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || | 428 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || |
429 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || | 429 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || |
430 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || | 430 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || |
431 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || | 431 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || |
432 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || | 432 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || |
433 sizeof(int32_t) != sizeof(OrthancPluginDicomFromJsonFlags) || | 433 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || |
434 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) || | 434 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) || |
435 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || | 435 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || |
436 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || | 436 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || |
437 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) || | 437 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) || |
438 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) || | 438 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) || |
439 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) || | 439 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) || |
440 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) || | 440 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) || |
441 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) || | 441 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) || |
442 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii) || | 442 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii) || |
443 static_cast<int>(OrthancPluginDicomFromJsonFlags_DecodeDataUriScheme) != static_cast<int>(DicomFromJsonFlags_DecodeDataUriScheme) || | 443 static_cast<int>(OrthancPluginCreateDicomFlags_DecodeDataUriScheme) != static_cast<int>(DicomFromJsonFlags_DecodeDataUriScheme) || |
444 static_cast<int>(OrthancPluginDicomFromJsonFlags_GenerateIdentifiers) != static_cast<int>(DicomFromJsonFlags_GenerateIdentifiers)) | 444 static_cast<int>(OrthancPluginCreateDicomFlags_GenerateIdentifiers) != static_cast<int>(DicomFromJsonFlags_GenerateIdentifiers)) |
445 | 445 |
446 { | 446 { |
447 throw OrthancException(ErrorCode_Plugin); | 447 throw OrthancException(ErrorCode_Plugin); |
448 } | 448 } |
449 | 449 |
1447 Json::FastWriter writer; | 1447 Json::FastWriter writer; |
1448 *p.result = CopyString(writer.write(json)); | 1448 *p.result = CopyString(writer.write(json)); |
1449 } | 1449 } |
1450 | 1450 |
1451 | 1451 |
1452 void OrthancPlugins::ApplyDicomFromJson(_OrthancPluginService service, | 1452 void OrthancPlugins::ApplyCreateDicom(_OrthancPluginService service, |
1453 const void* parameters) | 1453 const void* parameters) |
1454 { | 1454 { |
1455 const _OrthancPluginDicomFromJson& p = | 1455 const _OrthancPluginCreateDicom& p = |
1456 *reinterpret_cast<const _OrthancPluginDicomFromJson*>(parameters); | 1456 *reinterpret_cast<const _OrthancPluginCreateDicom*>(parameters); |
1457 | 1457 |
1458 Json::Value json; | 1458 Json::Value json; |
1459 Json::Reader reader; | 1459 Json::Reader reader; |
1460 if (!reader.parse(p.json, json)) | 1460 if (!reader.parse(p.json, json)) |
1461 { | 1461 { |
1465 std::string dicom; | 1465 std::string dicom; |
1466 | 1466 |
1467 { | 1467 { |
1468 std::auto_ptr<ParsedDicomFile> file | 1468 std::auto_ptr<ParsedDicomFile> file |
1469 (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(p.flags))); | 1469 (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(p.flags))); |
1470 | |
1471 if (p.pixelData) | |
1472 { | |
1473 file->EmbedImage(*reinterpret_cast<const ImageAccessor*>(p.pixelData)); | |
1474 } | |
1475 | |
1470 file->SaveToMemoryBuffer(dicom); | 1476 file->SaveToMemoryBuffer(dicom); |
1471 } | 1477 } |
1472 | 1478 |
1473 CopyToMemoryBuffer(*p.target, dicom); | 1479 CopyToMemoryBuffer(*p.target, dicom); |
1480 } | |
1481 | |
1482 | |
1483 void OrthancPlugins::ApplyCreateImage(_OrthancPluginService service, | |
1484 const void* parameters) | |
1485 { | |
1486 const _OrthancPluginCreateImage& p = | |
1487 *reinterpret_cast<const _OrthancPluginCreateImage*>(parameters); | |
1488 | |
1489 std::auto_ptr<ImageAccessor> result; | |
1490 | |
1491 if (service == _OrthancPluginService_CreateImage) | |
1492 { | |
1493 result.reset(new Image(Plugins::Convert(p.format), p.width, p.height)); | |
1494 } | |
1495 else | |
1496 { | |
1497 result.reset(new ImageAccessor); | |
1498 result->AssignWritable(Plugins::Convert(p.format), p.width, p.height, p.pitch, p.buffer); | |
1499 } | |
1500 | |
1501 *(p.target) = reinterpret_cast<OrthancPluginImage*>(result.release()); | |
1474 } | 1502 } |
1475 | 1503 |
1476 | 1504 |
1477 void OrthancPlugins::DatabaseAnswer(const void* parameters) | 1505 void OrthancPlugins::DatabaseAnswer(const void* parameters) |
1478 { | 1506 { |
2001 case _OrthancPluginService_DicomBufferToJson: | 2029 case _OrthancPluginService_DicomBufferToJson: |
2002 case _OrthancPluginService_DicomInstanceToJson: | 2030 case _OrthancPluginService_DicomInstanceToJson: |
2003 ApplyDicomToJson(service, parameters); | 2031 ApplyDicomToJson(service, parameters); |
2004 return true; | 2032 return true; |
2005 | 2033 |
2006 case _OrthancPluginService_DicomFromJson: | 2034 case _OrthancPluginService_CreateDicom: |
2007 ApplyDicomFromJson(service, parameters); | 2035 ApplyCreateDicom(service, parameters); |
2008 return true; | 2036 return true; |
2009 | 2037 |
2010 case _OrthancPluginService_WorklistAddAnswer: | 2038 case _OrthancPluginService_WorklistAddAnswer: |
2011 { | 2039 { |
2012 const _OrthancPluginWorklistAnswersOperation& p = | 2040 const _OrthancPluginWorklistAnswersOperation& p = |
2037 *reinterpret_cast<const _OrthancPluginWorklistQueryOperation*>(parameters); | 2065 *reinterpret_cast<const _OrthancPluginWorklistQueryOperation*>(parameters); |
2038 reinterpret_cast<const WorklistHandler*>(p.query)->GetDicomQuery(*p.target); | 2066 reinterpret_cast<const WorklistHandler*>(p.query)->GetDicomQuery(*p.target); |
2039 return true; | 2067 return true; |
2040 } | 2068 } |
2041 | 2069 |
2070 case _OrthancPluginService_CreateImage: | |
2071 case _OrthancPluginService_CreateImageAccessor: | |
2072 ApplyCreateImage(service, parameters); | |
2073 return true; | |
2074 | |
2042 default: | 2075 default: |
2043 { | 2076 { |
2044 // This service is unknown to the Orthanc plugin engine | 2077 // This service is unknown to the Orthanc plugin engine |
2045 return false; | 2078 return false; |
2046 } | 2079 } |