changeset 6820:f300221d97d6 streaming

added missing files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2026 20:41:04 +0200
parents 28cd72b0960a
children ee0a1ce93912
files OrthancFramework/Sources/DicomParsing/TranscodingCallable.cpp OrthancFramework/Sources/DicomParsing/TranscodingCallable.h
diffstat 2 files changed, 176 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DicomParsing/TranscodingCallable.cpp	Tue May 19 20:41:04 2026 +0200
@@ -0,0 +1,101 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeaders.h"
+#include "TranscodingCallable.h"
+
+#include "../OrthancException.h"
+
+#include <dcmtk/dcmdata/dcfilefo.h>
+
+
+namespace Orthanc
+{
+  TranscodingCallable::TranscodingCallable() :
+    mode_(TranscodingSopInstanceUidMode_AllowNew),
+    hasLossyQuality_(false),
+    lossyQuality_(0)
+  {
+  }
+
+
+  void TranscodingCallable::SetTranscoder(const boost::shared_ptr<IDicomTranscoder>& transcoder)
+  {
+    if (transcoder_.get() == NULL)
+    {
+      transcoder_ = transcoder;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  void TranscodingCallable::SetLossyQuality(unsigned int quality)
+  {
+    hasLossyQuality_ = true;
+    lossyQuality_ = quality;
+  }
+
+
+  IDynamicObject* TranscodingCallable::Call()
+  {
+    if (transcoder_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+
+    std::unique_ptr<IDicomTranscoder::DicomImage> transcoded(new IDicomTranscoder::DicomImage);
+    bool success;
+
+    if (hasLossyQuality_)
+    {
+      success = transcoder_->Transcode(*transcoded, source_, allowedSyntaxes_, mode_, lossyQuality_);
+    }
+    else
+    {
+      success = transcoder_->Transcode(*transcoded, source_, allowedSyntaxes_, mode_);
+    }
+
+    if (success)
+    {
+      return transcoded.release();
+    }
+    else
+    {
+      if (allowedSyntaxes_.size() == 1)
+      {
+        DicomTransferSyntax syntax = *allowedSyntaxes_.begin();
+        throw OrthancException(ErrorCode_InternalError,
+                               "Cannot transcode to transfer syntax: " +
+                               std::string(GetTransferSyntaxUid(syntax)));
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_NotImplemented, "Cannot transcode DICOM image");
+      }
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DicomParsing/TranscodingCallable.h	Tue May 19 20:41:04 2026 +0200
@@ -0,0 +1,75 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IDicomTranscoder.h"
+#include "../MultiThreading/ICallable.h"
+
+#include <boost/shared_ptr.hpp>
+
+
+namespace Orthanc
+{
+  class TranscodingCallable : public ICallable
+  {
+  private:
+    boost::shared_ptr<IDicomTranscoder>  transcoder_;
+    IDicomTranscoder::DicomImage         source_;
+    std::set<DicomTransferSyntax>        allowedSyntaxes_;
+    TranscodingSopInstanceUidMode        mode_;
+    bool                                 hasLossyQuality_;
+    unsigned int                         lossyQuality_;
+
+  public:
+    // By default, allow new SOP instance UID
+    TranscodingCallable();
+
+    void AcquireParsed(ParsedDicomFile& parsed /* will be invalidated */)
+    {
+      source_.AcquireParsed(parsed);
+    }
+
+    void AcquireBuffer(std::string& buffer /* will be swapped */)
+    {
+      source_.AcquireBuffer(buffer);
+    }
+
+    void SetTranscoder(const boost::shared_ptr<IDicomTranscoder>& transcoder);
+
+    void SetMode(TranscodingSopInstanceUidMode mode)
+    {
+      mode_ = mode;
+    }
+
+    void AddTransferSyntax(DicomTransferSyntax syntax)
+    {
+      allowedSyntaxes_.insert(syntax);
+    }
+
+    void SetLossyQuality(unsigned int quality);
+
+    virtual IDynamicObject* Call() ORTHANC_OVERRIDE;
+  };
+}