Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3320:0f721f015b85
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Mar 2019 13:37:21 +0100 |
parents | df90c2a56acd |
children | a48d652f1500 |
comparison
equal
deleted
inserted
replaced
3319:df90c2a56acd | 3320:0f721f015b85 |
---|---|
143 other.data = NULL; | 143 other.data = NULL; |
144 other.size = 0; | 144 other.size = 0; |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 void MemoryBuffer::Swap(MemoryBuffer& other) | |
149 { | |
150 std::swap(buffer_.data, other.buffer_.data); | |
151 std::swap(buffer_.size, other.buffer_.size); | |
152 } | |
153 | |
154 | |
148 OrthancPluginMemoryBuffer MemoryBuffer::Release() | 155 OrthancPluginMemoryBuffer MemoryBuffer::Release() |
149 { | 156 { |
150 OrthancPluginMemoryBuffer result = buffer_; | 157 OrthancPluginMemoryBuffer result = buffer_; |
151 | 158 |
152 buffer_.data = NULL; | 159 buffer_.data = NULL; |
1022 | 1029 |
1023 void OrthancImage::CompressPngImage(MemoryBuffer& target) const | 1030 void OrthancImage::CompressPngImage(MemoryBuffer& target) const |
1024 { | 1031 { |
1025 CheckImageAvailable(); | 1032 CheckImageAvailable(); |
1026 | 1033 |
1027 OrthancPluginMemoryBuffer tmp; | 1034 OrthancPlugins::MemoryBuffer answer; |
1028 OrthancPluginCompressPngImage(GetGlobalContext(), &tmp, GetPixelFormat(), | 1035 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), |
1029 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | 1036 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
1030 | 1037 |
1031 target.Assign(tmp); | 1038 target.Swap(answer); |
1032 } | 1039 } |
1033 | 1040 |
1034 | 1041 |
1035 void OrthancImage::CompressJpegImage(MemoryBuffer& target, | 1042 void OrthancImage::CompressJpegImage(MemoryBuffer& target, |
1036 uint8_t quality) const | 1043 uint8_t quality) const |
1037 { | 1044 { |
1038 CheckImageAvailable(); | 1045 CheckImageAvailable(); |
1039 | 1046 |
1040 OrthancPluginMemoryBuffer tmp; | 1047 OrthancPlugins::MemoryBuffer answer; |
1041 OrthancPluginCompressJpegImage(GetGlobalContext(), &tmp, GetPixelFormat(), | 1048 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), |
1042 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | 1049 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
1043 | 1050 |
1044 target.Assign(tmp); | 1051 target.Swap(answer); |
1045 } | 1052 } |
1046 | 1053 |
1047 | 1054 |
1048 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const | 1055 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const |
1049 { | 1056 { |
1578 if (index >= index_.size()) | 1585 if (index >= index_.size()) |
1579 { | 1586 { |
1580 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1587 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1581 } | 1588 } |
1582 | 1589 |
1583 OrthancPluginMemoryBuffer answer; | 1590 OrthancPlugins::MemoryBuffer answer; |
1584 uint16_t status; | 1591 uint16_t status; |
1585 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1592 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1586 (GetGlobalContext(), &answer, NULL, &status, peers_, | 1593 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1587 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), | 1594 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
1588 0, NULL, NULL, NULL, 0, timeout_); | 1595 0, NULL, NULL, NULL, 0, timeout_); |
1589 | 1596 |
1590 if (code == OrthancPluginErrorCode_Success) | 1597 if (code == OrthancPluginErrorCode_Success) |
1591 { | 1598 { |
1592 target.Assign(answer); | 1599 target.Swap(answer); |
1593 return (status == 200); | 1600 return (status == 200); |
1594 } | 1601 } |
1595 else | 1602 else |
1596 { | 1603 { |
1597 return false; | 1604 return false; |
1702 if (index >= index_.size()) | 1709 if (index >= index_.size()) |
1703 { | 1710 { |
1704 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1711 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1705 } | 1712 } |
1706 | 1713 |
1707 OrthancPluginMemoryBuffer answer; | 1714 OrthancPlugins::MemoryBuffer answer; |
1708 uint16_t status; | 1715 uint16_t status; |
1709 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1716 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1710 (GetGlobalContext(), &answer, NULL, &status, peers_, | 1717 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1711 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), | 1718 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
1712 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 1719 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
1713 | 1720 |
1714 if (code == OrthancPluginErrorCode_Success) | 1721 if (code == OrthancPluginErrorCode_Success) |
1715 { | 1722 { |
1716 target.Assign(answer); | 1723 target.Swap(answer); |
1717 return (status == 200); | 1724 return (status == 200); |
1718 } | 1725 } |
1719 else | 1726 else |
1720 { | 1727 { |
1721 return false; | 1728 return false; |
1730 if (index >= index_.size()) | 1737 if (index >= index_.size()) |
1731 { | 1738 { |
1732 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1739 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1733 } | 1740 } |
1734 | 1741 |
1735 OrthancPluginMemoryBuffer answer; | 1742 OrthancPlugins::MemoryBuffer answer; |
1736 uint16_t status; | 1743 uint16_t status; |
1737 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1744 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1738 (GetGlobalContext(), &answer, NULL, &status, peers_, | 1745 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1739 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), | 1746 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
1740 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 1747 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
1741 | 1748 |
1742 if (code == OrthancPluginErrorCode_Success) | 1749 if (code == OrthancPluginErrorCode_Success) |
1743 { | 1750 { |
1744 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer); | |
1745 return (status == 200); | 1751 return (status == 200); |
1746 } | 1752 } |
1747 else | 1753 else |
1748 { | 1754 { |
1749 return false; | 1755 return false; |
1767 if (index >= index_.size()) | 1773 if (index >= index_.size()) |
1768 { | 1774 { |
1769 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1775 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1770 } | 1776 } |
1771 | 1777 |
1772 OrthancPluginMemoryBuffer answer; | 1778 OrthancPlugins::MemoryBuffer answer; |
1773 uint16_t status; | 1779 uint16_t status; |
1774 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1780 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1775 (GetGlobalContext(), &answer, NULL, &status, peers_, | 1781 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1776 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | 1782 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), |
1777 0, NULL, NULL, NULL, 0, timeout_); | 1783 0, NULL, NULL, NULL, 0, timeout_); |
1778 | 1784 |
1779 if (code == OrthancPluginErrorCode_Success) | 1785 if (code == OrthancPluginErrorCode_Success) |
1780 { | 1786 { |
1781 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer); | |
1782 return (status == 200); | 1787 return (status == 200); |
1783 } | 1788 } |
1784 else | 1789 else |
1785 { | 1790 { |
1786 return false; | 1791 return false; |