annotate OrthancFramework/Resources/Graveyard/TestTranscoding.cpp @ 5660:e4d9a872998f

replaced incorrect macro WIN32 by _WIN32
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 23 Jun 2024 10:24:31 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4120
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
1 /**
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4120
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * This program is free software: you can redistribute it and/or
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
13 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
14 * This program is distributed in the hope that it will be useful, but
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
22 **/
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
23
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
24
3885
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
25 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
26 DcmFileFormat& dicom,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
27 DicomTransferSyntax syntax)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
28 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
29 E_TransferSyntax xfer;
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
30 if (!LookupDcmtkTransferSyntax(xfer, syntax))
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
31 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
32 return false;
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
33 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
34 else if (!dicom.validateMetaInfo(xfer).good())
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
35 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
36 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
37 "Cannot setup the transfer syntax to write a DICOM instance");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
38 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
39 else
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
40 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
41 return SaveToMemoryBufferInternal(buffer, dicom, xfer);
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
42 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
43 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
44
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
45
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
46 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
47 DcmFileFormat& dicom)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
48 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
49 E_TransferSyntax xfer = dicom.getDataset()->getCurrentXfer();
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
50 if (xfer == EXS_Unknown)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
51 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
52 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
53 "Cannot write a DICOM instance with unknown transfer syntax");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
54 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
55 else if (!dicom.validateMetaInfo(xfer).good())
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
56 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
57 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
58 "Cannot setup the transfer syntax to write a DICOM instance");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
59 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
60 else
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
61 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
62 return SaveToMemoryBufferInternal(buffer, dicom, xfer);
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
63 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
64 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
65
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
66
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
67
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
68
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
69
3884
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 #include <dcmtk/dcmdata/dcostrmb.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 #include <dcmtk/dcmdata/dcpixel.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 #include <dcmtk/dcmdata/dcpxitem.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 #include "../Core/DicomParsing/Internals/DicomFrameIndex.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 namespace Orthanc
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 class IParsedDicomImage : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 virtual ~IParsedDicomImage()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 virtual DicomTransferSyntax GetTransferSyntax() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 virtual std::string GetSopClassUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 virtual std::string GetSopInstanceUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 virtual unsigned int GetFramesCount() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 // Can return NULL, for compressed transfer syntaxes
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 virtual void WriteToMemoryBuffer(std::string& target) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 class IDicomImageReader : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 virtual ~IDicomImageReader()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 virtual IParsedDicomImage* Read(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 size_t size) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 virtual IParsedDicomImage* Transcode(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 size_t size,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 bool allowNewSopInstanceUid) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 class DcmtkImageReader : public IDicomImageReader
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 class Image : public IParsedDicomImage
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 std::unique_ptr<DcmFileFormat> dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 std::unique_ptr<DicomFrameIndex> index_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 DicomTransferSyntax transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::string sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 static std::string GetStringTag(DcmDataset& dataset,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 const DcmTagKey& tag)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 const char* value = NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (!dataset.findAndGetString(tag, value).good() ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 value == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 "Missing SOP class/instance UID in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return std::string(value);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 Image(DcmFileFormat* dicom,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 DicomTransferSyntax syntax) :
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 dicom_(dicom),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 transferSyntax_(syntax)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if (dicom == NULL ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 dicom_->getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 throw OrthancException(ErrorCode_NullPointer);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 DcmDataset& dataset = *dicom_->getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 index_.reset(new DicomFrameIndex(dataset));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 return transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 return sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 return sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return index_->GetFramesCount();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 assert(dicom_.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, transferSyntax_))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 throw OrthancException(ErrorCode_InternalError,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 "Cannot write the DICOM instance to a memory buffer");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 assert(dicom_.get() != NULL &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 assert(index_.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 index_->GetRawFrame(target, frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 unsigned int lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 static DicomTransferSyntax DetectTransferSyntax(DcmFileFormat& dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 if (dicom.getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 throw OrthancException(ErrorCode_InternalError);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 DcmDataset& dataset = *dicom.getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 E_TransferSyntax xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 dataset.updateOriginalXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 "Cannot determine the transfer syntax of the DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 DicomTransferSyntax syntax;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 if (FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, xfer))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 return syntax;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 throw OrthancException(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 static uint16_t GetBitsStored(DcmFileFormat& dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (dicom.getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 throw OrthancException(ErrorCode_InternalError);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 uint16_t bitsStored;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (dicom.getDataset()->findAndGetUint16(DCM_BitsStored, bitsStored).good())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 return bitsStored;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 "Missing \"Bits Stored\" tag in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 DcmtkImageReader() :
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 lossyQuality_(90)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 void SetLossyQuality(unsigned int quality)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 if (quality <= 0 ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 quality > 100)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 throw OrthancException(ErrorCode_ParameterOutOfRange);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 lossyQuality_ = quality;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 unsigned int GetLossyQuality() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 return lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 virtual IParsedDicomImage* Read(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 size_t size)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 if (dicom.get() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 throw OrthancException(ErrorCode_BadFileFormat);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 DicomTransferSyntax transferSyntax = DetectTransferSyntax(*dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 return new Image(dicom.release(), transferSyntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 virtual IParsedDicomImage* Transcode(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 size_t size,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 bool allowNewSopInstanceUid)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 if (dicom.get() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 throw OrthancException(ErrorCode_BadFileFormat);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 const uint16_t bitsStored = GetBitsStored(*dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 if (syntax == DetectTransferSyntax(*dicom))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 // No transcoding is needed
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianImplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_BigEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 bitsStored == 8)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 bitsStored <= 12)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 //LOG(INFO) << "Unable to transcode DICOM image using the built-in reader";
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 return NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 class IDicomTranscoder1 : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 virtual ~IDicomTranscoder1()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 virtual DcmFileFormat& GetDicom() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 virtual DicomTransferSyntax GetTransferSyntax() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 virtual std::string GetSopClassUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 virtual std::string GetSopInstanceUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 virtual unsigned int GetFramesCount() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 // NB: Transcoding can change the value of "GetSopInstanceUid()"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 // and "GetTransferSyntax()" if lossy compression is applied
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 virtual bool Transcode(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 bool allowNewSopInstanceUid) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 virtual void WriteToMemoryBuffer(std::string& target) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 class DcmtkTranscoder2 : public IDicomTranscoder1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 std::unique_ptr<DcmFileFormat> dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 std::unique_ptr<DicomFrameIndex> index_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 DicomTransferSyntax transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 std::string sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 std::string sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 uint16_t bitsStored_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 unsigned int lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 static std::string GetStringTag(DcmDataset& dataset,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 const DcmTagKey& tag)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 const char* value = NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 if (!dataset.findAndGetString(tag, value).good() ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 value == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 "Missing SOP class/instance UID in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 return std::string(value);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 void Setup(DcmFileFormat* dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 lossyQuality_ = 90;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 dicom_.reset(dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 if (dicom == NULL ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 dicom_->getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 throw OrthancException(ErrorCode_NullPointer);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 DcmDataset& dataset = *dicom_->getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 index_.reset(new DicomFrameIndex(dataset));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 E_TransferSyntax xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 dataset.updateOriginalXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 "Cannot determine the transfer syntax of the DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(transferSyntax_, xfer))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 throw OrthancException(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 if (!dataset.findAndGetUint16(DCM_BitsStored, bitsStored_).good())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 "Missing \"Bits Stored\" tag in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 DcmtkTranscoder2(DcmFileFormat* dicom) // Takes ownership
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 Setup(dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 DcmtkTranscoder2(const void* dicom,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 size_t size)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 Setup(FromDcmtkBridge::LoadFromMemoryBuffer(dicom, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 void SetLossyQuality(unsigned int quality)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 if (quality <= 0 ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 quality > 100)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 throw OrthancException(ErrorCode_ParameterOutOfRange);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 lossyQuality_ = quality;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 unsigned int GetLossyQuality() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 return lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 unsigned int GetBitsStored() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 return bitsStored_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 virtual DcmFileFormat& GetDicom()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 assert(dicom_ != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 return *dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 return transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 return sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 return sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 return index_->GetFramesCount();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 throw OrthancException(ErrorCode_InternalError,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 "Cannot write the DICOM instance to a memory buffer");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 assert(dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 index_->GetRawFrame(target, frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 virtual bool Transcode(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 assert(dicom_ != NULL &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 if (syntax == GetTransferSyntax())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 printf("NO TRANSCODING\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 // No change in the transfer syntax => simply serialize the current dataset
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 printf(">> %d\n", bitsStored_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 transferSyntax_ = DicomTransferSyntax_LittleEndianImplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 transferSyntax_ = DicomTransferSyntax_LittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 transferSyntax_ = DicomTransferSyntax_BigEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 transferSyntax_ = DicomTransferSyntax_DeflatedLittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 GetBitsStored() == 8)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 transferSyntax_ = DicomTransferSyntax_JPEGProcess1;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 GetBitsStored() <= 12)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 transferSyntax_ = DicomTransferSyntax_JPEGProcess2_4;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 return false;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 #include <boost/filesystem.hpp>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 static void TestFile(const std::string& path)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 static unsigned int count = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 count++;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 printf("** %s\n", path.c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 std::string s;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 SystemToolbox::ReadFile(s, path);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 Orthanc::DcmtkTranscoder2 transcoder(s.c_str(), s.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 /*if (transcoder.GetBitsStored() != 8) // TODO
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 return; */
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 sprintf(buf, "/tmp/source-%06d.dcm", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 Orthanc::SystemToolbox::WriteFile(s, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 printf("[%s] [%s] [%s] %d %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 transcoder.GetFramesCount(), transcoder.GetTransferSyntax());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 for (size_t i = 0; i < transcoder.GetFramesCount(); i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 std::string f;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 transcoder.GetCompressedFrame(f, i);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 if (i == 0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 sprintf(buf, "/tmp/frame-%06d.raw", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 Orthanc::SystemToolbox::WriteFile(f, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 std::string t;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 transcoder.WriteToMemoryBuffer(t);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 printf(">> %d %d ; %lu bytes\n", transcoder.GetTransferSyntax(), transcoder2.GetTransferSyntax(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 std::string a = transcoder.GetSopInstanceUid();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 DicomTransferSyntax b = transcoder.GetTransferSyntax();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 DicomTransferSyntax syntax = DicomTransferSyntax_JPEGProcess2_4;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 //DicomTransferSyntax syntax = DicomTransferSyntax_LittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 std::string t;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 bool ok = transcoder.Transcode(t, syntax, true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 printf("Transcoding: %d\n", ok);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 if (ok)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 printf("[%s] => [%s]\n", a.c_str(), transcoder.GetSopInstanceUid().c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 printf("[%s] => [%s]\n", GetTransferSyntaxUid(b),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 GetTransferSyntaxUid(transcoder.GetTransferSyntax()));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 sprintf(buf, "/tmp/transcoded-%06d.dcm", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 Orthanc::SystemToolbox::WriteFile(t, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 printf(" => transcoded transfer syntax %d ; %lu bytes\n", transcoder2.GetTransferSyntax(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 printf("\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 TEST(Toto, DISABLED_Transcode)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 //OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 if (1)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 const char* const PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes";
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 for (boost::filesystem::directory_iterator it(PATH);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 it != boost::filesystem::directory_iterator(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 if (boost::filesystem::is_regular_file(it->status()))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 TestFile(it->path().string());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 if (0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Multiframe.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Issue44/Monochrome1-Jpeg.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 if (0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/1.2.840.10008.1.2.1.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 TEST(Toto, DISABLED_Transcode2)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 DicomTransferSyntax a = (DicomTransferSyntax) i;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 std::string(GetTransferSyntaxUid(a)) + ".dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 if (Orthanc::SystemToolbox::IsRegularFile(path))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 printf("\n======= %s\n", GetTransferSyntaxUid(a));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 std::string source;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 Orthanc::SystemToolbox::ReadFile(source, path);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 DcmtkImageReader reader;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 std::unique_ptr<IParsedDicomImage> image(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 reader.Read(source.c_str(), source.size()));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 ASSERT_TRUE(image.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 ASSERT_EQ(a, image->GetTransferSyntax());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 std::string target;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 image->WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 for (int j = 0; j <= DicomTransferSyntax_XML; j++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 DicomTransferSyntax b = (DicomTransferSyntax) j;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 //if (a == b) continue;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 std::unique_ptr<IParsedDicomImage> image(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 reader.Transcode(source.c_str(), source.size(), b, true));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 if (image.get() != NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 printf("[%s] -> [%s]\n", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 std::string target;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 image->WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 sprintf(buf, "/tmp/%s-%s.dcm", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 SystemToolbox::WriteFile(target, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 else if (a != DicomTransferSyntax_JPEG2000 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 a != DicomTransferSyntax_JPEG2000LosslessOnly)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 ASSERT_TRUE(b != DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 b != DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 b != DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 b != DicomTransferSyntax_DeflatedLittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 #include "../Core/DicomNetworking/DicomAssociation.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 #include "../Core/DicomNetworking/DicomControlUserConnection.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 #include "../Core/DicomNetworking/DicomStoreUserConnection.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 TEST(Toto, DISABLED_DicomAssociation)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 params.SetRemoteApplicationEntityTitle("PACS");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 params.SetRemotePort(2001);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 #if 0
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 DicomAssociation assoc;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 assoc.ProposeGenericPresentationContext(UID_StorageCommitmentPushModelSOPClass);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 assoc.ProposeGenericPresentationContext(UID_VerificationSOPClass);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 DicomTransferSyntax_JPEGProcess1);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 DicomTransferSyntax_JPEGProcess2_4);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 assoc.Open(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 int presID = ASC_findAcceptedPresentationContextID(&assoc.GetDcmtkAssociation(), UID_ComputedRadiographyImageStorage);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 printf(">> %d\n", presID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 std::map<DicomTransferSyntax, uint8_t> pc;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 printf(">> %d\n", assoc.LookupAcceptedPresentationContext(pc, UID_ComputedRadiographyImageStorage));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 for (std::map<DicomTransferSyntax, uint8_t>::const_iterator
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 it = pc.begin(); it != pc.end(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 printf("[%s] => %d\n", GetTransferSyntaxUid(it->first), it->second);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 #else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 DicomControlUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 try
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 printf(">> %d\n", assoc.Echo());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 catch (OrthancException&)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 params.SetRemoteApplicationEntityTitle("PACS");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 DicomControlUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 printf(">> %d\n", assoc.Echo());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 static void TestTranscode(DicomStoreUserConnection& scu,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 const std::string& sopClassUid,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 DicomTransferSyntax transferSyntax)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 std::set<DicomTransferSyntax> accepted;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 scu.LookupTranscoding(accepted, sopClassUid, transferSyntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 if (accepted.empty())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 throw OrthancException(ErrorCode_NetworkProtocol,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 "The SOP class is not supported by the remote modality");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 unsigned int count = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 for (std::set<DicomTransferSyntax>::const_iterator
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 it = accepted.begin(); it != accepted.end(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 LOG(INFO) << "available for transcoding " << (count++) << ": " << sopClassUid
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 << " / " << GetTransferSyntaxUid(*it);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 if (accepted.find(transferSyntax) != accepted.end())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 printf("**** OK, without transcoding !! [%s]\n", GetTransferSyntaxUid(transferSyntax));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 // Transcoding - only in Orthanc >= 1.7.0
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 const DicomTransferSyntax uncompressed[] = {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 DicomTransferSyntax_LittleEndianImplicit, // Default transfer syntax
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 DicomTransferSyntax_LittleEndianExplicit,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 DicomTransferSyntax_BigEndianExplicit
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 bool found = false;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 for (size_t i = 0; i < 3; i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 if (accepted.find(uncompressed[i]) != accepted.end())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 printf("**** TRANSCODING to %s\n", GetTransferSyntaxUid(uncompressed[i]));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 found = true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 break;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 if (!found)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 printf("**** KO KO KO\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 TEST(Toto, DISABLED_Store)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 params.SetRemoteApplicationEntityTitle("STORESCP");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 DicomStoreUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess1);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess2_4);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 //assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 //assoc.SetUncompressedSyntaxesProposed(false); // Necessary for transcoding
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 assoc.SetCommonClassesProposed(false);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 assoc.SetRetiredBigEndianProposed(true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 TEST(Toto, DISABLED_Store2)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 params.SetRemoteApplicationEntityTitle("STORESCP");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 DicomStoreUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 //assoc.SetCommonClassesProposed(false);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 assoc.SetRetiredBigEndianProposed(true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 std::string s;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 Orthanc::SystemToolbox::ReadFile(s, "/tmp/i/" + std::string(GetTransferSyntaxUid(DicomTransferSyntax_BigEndianExplicit)) +".dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 std::string c, i;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 assoc.Store(c, i, s.c_str(), s.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 printf("[%s] [%s]\n", c.c_str(), i.c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991