Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3744:accf1b60b108
accessing raw pixel data
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Mar 2020 17:58:34 +0100 |
parents | 33c19a6643e1 |
children | 113a7b994a12 |
comparison
equal
deleted
inserted
replaced
3743:33c19a6643e1 | 3744:accf1b60b108 |
---|---|
1917 | 1917 |
1918 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 | 1918 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
1919 | 1919 |
1920 #include "../Core/DicomFormat/DicomImageInformation.h" | 1920 #include "../Core/DicomFormat/DicomImageInformation.h" |
1921 | 1921 |
1922 #include <dcmtk/dcmdata/dcostrmb.h> | |
1923 #include <dcmtk/dcmdata/dcpixel.h> | |
1924 #include <dcmtk/dcmdata/dcpxitem.h> | |
1925 | |
1926 | |
1922 namespace Orthanc | 1927 namespace Orthanc |
1923 { | 1928 { |
1924 class IDicomTranscoder : public boost::noncopyable | 1929 class IDicomTranscoder : public boost::noncopyable |
1925 { | 1930 { |
1926 public: | 1931 public: |
1934 | 1939 |
1935 virtual std::string GetSopInstanceUid() = 0; | 1940 virtual std::string GetSopInstanceUid() = 0; |
1936 | 1941 |
1937 virtual unsigned int GetFramesCount() = 0; | 1942 virtual unsigned int GetFramesCount() = 0; |
1938 | 1943 |
1944 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0; | |
1945 | |
1946 virtual void GetCompressedFrame(std::string& target, | |
1947 unsigned int frame) = 0; | |
1948 | |
1939 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, | 1949 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, |
1940 bool allowNewSopInstanceUid) = 0; | 1950 bool allowNewSopInstanceUid) = 0; |
1941 | |
1942 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0; | |
1943 | |
1944 virtual void GetCompressedFrame(std::string& target, | |
1945 unsigned int frame) = 0; | |
1946 }; | 1951 }; |
1947 | 1952 |
1948 | 1953 |
1949 class DcmtkTranscoder : public IDicomTranscoder | 1954 class DcmtkTranscoder : public IDicomTranscoder |
1950 { | 1955 { |
2010 size_t size) | 2015 size_t size) |
2011 { | 2016 { |
2012 Setup(FromDcmtkBridge::LoadFromMemoryBuffer(dicom, size)); | 2017 Setup(FromDcmtkBridge::LoadFromMemoryBuffer(dicom, size)); |
2013 } | 2018 } |
2014 | 2019 |
2015 DcmtkTranscoder(const ParsedDicomFile& dicom) | |
2016 { | |
2017 Setup(new DcmFileFormat(dicom.GetDcmtkObject())); | |
2018 } | |
2019 | |
2020 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE | 2020 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE |
2021 { | 2021 { |
2022 return transferSyntax_; | 2022 return transferSyntax_; |
2023 } | 2023 } |
2024 | 2024 |
2035 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE | 2035 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE |
2036 { | 2036 { |
2037 return info_->GetNumberOfFrames(); | 2037 return info_->GetNumberOfFrames(); |
2038 } | 2038 } |
2039 | 2039 |
2040 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE | |
2041 { | |
2042 assert(dicom_->getDataset() != NULL); | |
2043 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame); | |
2044 } | |
2045 | |
2046 virtual void GetCompressedFrame(std::string& target, | |
2047 unsigned int frame) ORTHANC_OVERRIDE | |
2048 { | |
2049 assert(dicom_->getDataset() != NULL); | |
2050 DcmDataset& dataset = *dicom_->getDataset(); | |
2051 | |
2052 DcmPixelSequence* pixelSequence = FromDcmtkBridge::GetPixelSequence(dataset); | |
2053 | |
2054 if (pixelSequence == NULL) | |
2055 { | |
2056 // This is an uncompressed frame | |
2057 | |
2058 DcmElement* element = NULL; | |
2059 if (dataset.findAndGetElement(DCM_PixelData, element).good() && | |
2060 element != NULL) | |
2061 { | |
2062 Uint8* pixelData = NULL; | |
2063 | |
2064 if (element->getUint8Array(pixelData).good() && | |
2065 pixelData != NULL) | |
2066 { | |
2067 // TODO => use "pixelData" | |
2068 printf("RAW %d\n", element->getLength()); | |
2069 } | |
2070 else | |
2071 { | |
2072 throw OrthancException(ErrorCode_BadFileFormat, | |
2073 "Cannot access uncompressed pixel data"); | |
2074 } | |
2075 } | |
2076 else | |
2077 { | |
2078 std::string decoded; | |
2079 if (DicomImageDecoder::DecodePsmctRle1(decoded, dataset)) | |
2080 { | |
2081 // TODO => use "decoded" | |
2082 } | |
2083 else | |
2084 { | |
2085 throw OrthancException(ErrorCode_BadFileFormat, | |
2086 "Cannot access uncompressed pixel data"); | |
2087 } | |
2088 } | |
2089 } | |
2090 else | |
2091 { | |
2092 printf("COMPRESSED\n"); | |
2093 | |
2094 // Check out "djcodecd.cc" | |
2095 | |
2096 printf("%d fragments\n", pixelSequence->card()); | |
2097 | |
2098 // Skip the first fragment, that is the offset table | |
2099 for (unsigned long i = 1; ;i++) | |
2100 { | |
2101 DcmPixelItem *fragment = NULL; | |
2102 if (pixelSequence->getItem(fragment, i).good()) | |
2103 { | |
2104 printf("fragment %d %d\n", i, fragment->getLength()); | |
2105 } | |
2106 else | |
2107 { | |
2108 break; | |
2109 } | |
2110 } | |
2111 } | |
2112 } | |
2113 | |
2040 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, | 2114 virtual IDicomTranscoder* Transcode(std::set<DicomTransferSyntax> syntaxes, |
2041 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE | 2115 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE |
2042 { | 2116 { |
2043 throw OrthancException(ErrorCode_NotImplemented); | 2117 throw OrthancException(ErrorCode_NotImplemented); |
2044 } | 2118 } |
2045 | |
2046 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE | |
2047 { | |
2048 throw OrthancException(ErrorCode_NotImplemented); | |
2049 } | |
2050 | |
2051 virtual void GetCompressedFrame(std::string& target, | |
2052 unsigned int frame) ORTHANC_OVERRIDE | |
2053 { | |
2054 throw OrthancException(ErrorCode_NotImplemented); | |
2055 } | |
2056 }; | 2119 }; |
2057 } | 2120 } |
2058 | 2121 |
2059 | 2122 |
2060 | 2123 |
2061 #include <dcmtk/dcmdata/dcostrmb.h> | |
2062 | 2124 |
2063 static bool Transcode(std::string& buffer, | 2125 static bool Transcode(std::string& buffer, |
2064 DcmDataset& dataSet, | 2126 DcmDataset& dataSet, |
2065 E_TransferSyntax xfer) | 2127 E_TransferSyntax xfer) |
2066 { | 2128 { |
2142 std::string s; | 2204 std::string s; |
2143 SystemToolbox::ReadFile(s, path); | 2205 SystemToolbox::ReadFile(s, path); |
2144 | 2206 |
2145 Orthanc::DcmtkTranscoder transcoder(s.c_str(), s.size()); | 2207 Orthanc::DcmtkTranscoder transcoder(s.c_str(), s.size()); |
2146 | 2208 |
2147 printf("[%s] [%s] [%s] %d\n\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()), | 2209 printf("[%s] [%s] [%s] %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()), |
2148 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(), | 2210 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(), |
2149 transcoder.GetFramesCount()); | 2211 transcoder.GetFramesCount()); |
2212 | |
2213 std::string f; | |
2214 transcoder.GetCompressedFrame(f, 0); | |
2215 | |
2216 printf("\n"); | |
2150 } | 2217 } |
2151 | 2218 |
2152 TEST(Toto, Transcode) | 2219 TEST(Toto, Transcode) |
2153 { | 2220 { |
2154 if (0) | 2221 if (0) |