# HG changeset patch # User Sebastien Jodogne # Date 1779216064 -7200 # Node ID f300221d97d660b59c7c74fd38c3c8564ce0f9bf # Parent 28cd72b0960a99c3d7d0d71495607d537fe3ac4c added missing files diff -r 28cd72b0960a -r f300221d97d6 OrthancFramework/Sources/DicomParsing/TranscodingCallable.cpp --- /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 + * . + **/ + + +#include "../PrecompiledHeaders.h" +#include "TranscodingCallable.h" + +#include "../OrthancException.h" + +#include + + +namespace Orthanc +{ + TranscodingCallable::TranscodingCallable() : + mode_(TranscodingSopInstanceUidMode_AllowNew), + hasLossyQuality_(false), + lossyQuality_(0) + { + } + + + void TranscodingCallable::SetTranscoder(const boost::shared_ptr& 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 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"); + } + } + } +} diff -r 28cd72b0960a -r f300221d97d6 OrthancFramework/Sources/DicomParsing/TranscodingCallable.h --- /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 + * . + **/ + + +#pragma once + +#include "IDicomTranscoder.h" +#include "../MultiThreading/ICallable.h" + +#include + + +namespace Orthanc +{ + class TranscodingCallable : public ICallable + { + private: + boost::shared_ptr transcoder_; + IDicomTranscoder::DicomImage source_; + std::set 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& transcoder); + + void SetMode(TranscodingSopInstanceUidMode mode) + { + mode_ = mode; + } + + void AddTransferSyntax(DicomTransferSyntax syntax) + { + allowedSyntaxes_.insert(syntax); + } + + void SetLossyQuality(unsigned int quality); + + virtual IDynamicObject* Call() ORTHANC_OVERRIDE; + }; +}