Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3748:ca36e3f1112c transcoding
transcoding to uncompressed transfer syntaxes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 13 Mar 2020 16:50:13 +0100 |
parents | 113a7b994a12 |
children | d55768319f8e |
comparison
equal
deleted
inserted
replaced
3747:7b6058f8f7aa | 3748:ca36e3f1112c |
---|---|
1944 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0; | 1944 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0; |
1945 | 1945 |
1946 virtual void GetCompressedFrame(std::string& target, | 1946 virtual void GetCompressedFrame(std::string& target, |
1947 unsigned int frame) = 0; | 1947 unsigned int frame) = 0; |
1948 | 1948 |
1949 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, | 1949 virtual bool Transcode(std::string& target, |
1950 bool allowNewSopInstanceUid) = 0; | 1950 std::set<DicomTransferSyntax> syntaxes, |
1951 bool allowNewSopInstanceUid) = 0; | |
1952 | |
1953 virtual void WriteToMemoryBuffer(std::string& target) = 0; | |
1951 }; | 1954 }; |
1952 | 1955 |
1953 | 1956 |
1954 class DcmtkTranscoder : public IDicomTranscoder | 1957 class DcmtkTranscoder : public IDicomTranscoder |
1955 { | 1958 { |
2038 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE | 2041 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE |
2039 { | 2042 { |
2040 return index_->GetFramesCount(); | 2043 return index_->GetFramesCount(); |
2041 } | 2044 } |
2042 | 2045 |
2046 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE | |
2047 { | |
2048 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_)) | |
2049 { | |
2050 throw OrthancException(ErrorCode_InternalError, | |
2051 "Cannot write the DICOM instance to a memory buffer"); | |
2052 } | |
2053 } | |
2054 | |
2043 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE | 2055 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE |
2044 { | 2056 { |
2045 assert(dicom_->getDataset() != NULL); | 2057 assert(dicom_->getDataset() != NULL); |
2046 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame); | 2058 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame); |
2047 } | 2059 } |
2048 | 2060 |
2049 virtual void GetCompressedFrame(std::string& target, | 2061 virtual void GetCompressedFrame(std::string& target, |
2050 unsigned int frame) ORTHANC_OVERRIDE | 2062 unsigned int frame) ORTHANC_OVERRIDE |
2051 { | 2063 { |
2052 #if 1 | |
2053 index_->GetRawFrame(target, frame); | 2064 index_->GetRawFrame(target, frame); |
2054 printf("%d: %d\n", frame, target.size()); | 2065 } |
2055 #endif | 2066 |
2056 | 2067 virtual bool Transcode(std::string& target, |
2057 #if 1 | 2068 std::set<DicomTransferSyntax> syntaxes, |
2058 assert(dicom_->getDataset() != NULL); | 2069 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE |
2059 DcmDataset& dataset = *dicom_->getDataset(); | 2070 { |
2060 | 2071 if (syntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != syntaxes.end() && |
2061 DcmPixelSequence* pixelSequence = FromDcmtkBridge::GetPixelSequence(dataset); | 2072 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianImplicit, NULL)) |
2062 | |
2063 if (pixelSequence != NULL && | |
2064 frame == 0 && | |
2065 pixelSequence->card() != GetFramesCount() + 1) | |
2066 { | 2073 { |
2067 printf("COMPRESSED\n"); | 2074 return true; |
2068 | |
2069 // Check out "djcodecd.cc" | |
2070 | |
2071 printf("%d fragments\n", pixelSequence->card()); | |
2072 | |
2073 // Skip the first fragment, that is the offset table | |
2074 for (unsigned long i = 1; ;i++) | |
2075 { | |
2076 DcmPixelItem *fragment = NULL; | |
2077 if (pixelSequence->getItem(fragment, i).good()) | |
2078 { | |
2079 printf("fragment %d %d\n", i, fragment->getLength()); | |
2080 } | |
2081 else | |
2082 { | |
2083 break; | |
2084 } | |
2085 } | |
2086 } | 2075 } |
2087 #endif | 2076 else if (syntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != syntaxes.end() && |
2088 } | 2077 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianExplicit, NULL)) |
2089 | 2078 { |
2090 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, | 2079 return true; |
2091 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE | 2080 } |
2092 { | 2081 else if (syntaxes.find(DicomTransferSyntax_BigEndianExplicit) != syntaxes.end() && |
2093 throw OrthancException(ErrorCode_NotImplemented); | 2082 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_BigEndianExplicit, NULL)) |
2083 { | |
2084 return true; | |
2085 } | |
2086 else | |
2087 { | |
2088 return false; | |
2089 } | |
2094 } | 2090 } |
2095 }; | 2091 }; |
2096 } | 2092 } |
2097 | 2093 |
2098 | 2094 |
2180 std::string s; | 2176 std::string s; |
2181 SystemToolbox::ReadFile(s, path); | 2177 SystemToolbox::ReadFile(s, path); |
2182 | 2178 |
2183 Orthanc::DcmtkTranscoder transcoder(s.c_str(), s.size()); | 2179 Orthanc::DcmtkTranscoder transcoder(s.c_str(), s.size()); |
2184 | 2180 |
2185 printf("[%s] [%s] [%s] %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()), | 2181 printf("[%s] [%s] [%s] %d %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()), |
2186 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(), | 2182 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(), |
2187 transcoder.GetFramesCount()); | 2183 transcoder.GetFramesCount(), transcoder.GetTransferSyntax()); |
2188 | 2184 |
2189 for (size_t i = 0; i < transcoder.GetFramesCount(); i++) | 2185 for (size_t i = 0; i < transcoder.GetFramesCount(); i++) |
2190 { | 2186 { |
2191 std::string f; | 2187 std::string f; |
2192 transcoder.GetCompressedFrame(f, i); | 2188 transcoder.GetCompressedFrame(f, i); |
2199 printf(">> %s\n", buf); | 2195 printf(">> %s\n", buf); |
2200 Orthanc::SystemToolbox::WriteFile(f, buf); | 2196 Orthanc::SystemToolbox::WriteFile(f, buf); |
2201 } | 2197 } |
2202 } | 2198 } |
2203 | 2199 |
2200 { | |
2201 std::string t; | |
2202 transcoder.WriteToMemoryBuffer(t); | |
2203 | |
2204 Orthanc::DcmtkTranscoder transcoder2(t.c_str(), t.size()); | |
2205 printf(">> %d %d ; %d bytes\n", transcoder.GetTransferSyntax(), transcoder2.GetTransferSyntax(), t.size()); | |
2206 } | |
2207 | |
2208 { | |
2209 std::set<DicomTransferSyntax> syntaxes; | |
2210 syntaxes.insert(DicomTransferSyntax_LittleEndianExplicit); | |
2211 | |
2212 std::string t; | |
2213 bool ok = transcoder.Transcode(t, syntaxes, false); | |
2214 printf("Transcoding: %d\n", ok); | |
2215 | |
2216 if (ok) | |
2217 { | |
2218 Orthanc::DcmtkTranscoder transcoder2(t.c_str(), t.size()); | |
2219 printf(" => transcoded transfer syntax %d ; %d bytes\n", transcoder2.GetTransferSyntax(), t.size()); | |
2220 } | |
2221 } | |
2222 | |
2204 printf("\n"); | 2223 printf("\n"); |
2205 } | 2224 } |
2206 | 2225 |
2207 TEST(Toto, Transcode) | 2226 TEST(Toto, Transcode) |
2208 { | 2227 { |