PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
codec_factory.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
15
16#include <array>
17
19
20namespace {
21
28static constexpr std::array<std::string_view, 16> kSupportedTransferSyntaxes = {{
29 rle_codec::kTransferSyntaxUID, // 1.2.840.10008.1.2.5
30 jpeg_baseline_codec::kTransferSyntaxUID, // 1.2.840.10008.1.2.4.50
31 jpeg_lossless_codec::kTransferSyntaxUID, // 1.2.840.10008.1.2.4.70
32 jpeg_ls_codec::kTransferSyntaxUIDLossless, // 1.2.840.10008.1.2.4.80
33 jpeg_ls_codec::kTransferSyntaxUIDNearLossless, // 1.2.840.10008.1.2.4.81
34 jpeg2000_codec::kTransferSyntaxUIDLossless, // 1.2.840.10008.1.2.4.90
35 jpeg2000_codec::kTransferSyntaxUIDLossy, // 1.2.840.10008.1.2.4.91
36 hevc_codec::kTransferSyntaxUIDMain, // 1.2.840.10008.1.2.4.107
37 hevc_codec::kTransferSyntaxUIDMain10, // 1.2.840.10008.1.2.4.108
38 jpegxl_codec::kTransferSyntaxUIDLossless, // 1.2.840.10008.1.2.4.110
40 jpegxl_codec::kTransferSyntaxUIDLossy, // 1.2.840.10008.1.2.4.112
41 htj2k_codec::kTransferSyntaxUIDLossless, // 1.2.840.10008.1.2.4.201
42 htj2k_codec::kTransferSyntaxUIDRPCL, // 1.2.840.10008.1.2.4.202
43 htj2k_codec::kTransferSyntaxUIDLossy, // 1.2.840.10008.1.2.4.203
44 frame_deflate_codec::kTransferSyntaxUID, // 1.2.840.10008.1.2.11
45}};
46
47} // namespace
48
49std::unique_ptr<compression_codec> codec_factory::create(
50 std::string_view transfer_syntax_uid) {
51
52 // RLE Lossless (1.2.840.10008.1.2.5)
53 if (transfer_syntax_uid == rle_codec::kTransferSyntaxUID) {
54 return std::make_unique<rle_codec>();
55 }
56
57 // JPEG Baseline (Process 1)
58 if (transfer_syntax_uid == jpeg_baseline_codec::kTransferSyntaxUID) {
59 return std::make_unique<jpeg_baseline_codec>();
60 }
61
62 // JPEG Lossless (Process 14, Selection Value 1)
63 if (transfer_syntax_uid == jpeg_lossless_codec::kTransferSyntaxUID) {
64 return std::make_unique<jpeg_lossless_codec>();
65 }
66
67 // JPEG-LS Lossless (1.2.840.10008.1.2.4.80)
68 if (transfer_syntax_uid == jpeg_ls_codec::kTransferSyntaxUIDLossless) {
69 return std::make_unique<jpeg_ls_codec>(true); // lossless = true
70 }
71
72 // JPEG-LS Near-Lossless (1.2.840.10008.1.2.4.81)
73 if (transfer_syntax_uid == jpeg_ls_codec::kTransferSyntaxUIDNearLossless) {
74 return std::make_unique<jpeg_ls_codec>(false); // lossless = false
75 }
76
77 // JPEG 2000 Lossless Only (1.2.840.10008.1.2.4.90)
78 if (transfer_syntax_uid == jpeg2000_codec::kTransferSyntaxUIDLossless) {
79 return std::make_unique<jpeg2000_codec>(true); // lossless = true
80 }
81
82 // JPEG 2000 (1.2.840.10008.1.2.4.91) - can be lossy or lossless
83 if (transfer_syntax_uid == jpeg2000_codec::kTransferSyntaxUIDLossy) {
84 return std::make_unique<jpeg2000_codec>(false); // lossless = false (default lossy)
85 }
86
87 // HEVC/H.265 Main Profile (1.2.840.10008.1.2.4.107)
88 if (transfer_syntax_uid == hevc_codec::kTransferSyntaxUIDMain) {
89 return std::make_unique<hevc_codec>(false); // main10 = false
90 }
91
92 // HEVC/H.265 Main 10 Profile (1.2.840.10008.1.2.4.108)
93 if (transfer_syntax_uid == hevc_codec::kTransferSyntaxUIDMain10) {
94 return std::make_unique<hevc_codec>(true); // main10 = true
95 }
96
97 // JPEG XL Lossless (1.2.840.10008.1.2.4.110)
98 if (transfer_syntax_uid == jpegxl_codec::kTransferSyntaxUIDLossless) {
99 return std::make_unique<jpegxl_codec>(true, false);
100 }
101
102 // JPEG XL JPEG Recompression (1.2.840.10008.1.2.4.111)
103 if (transfer_syntax_uid == jpegxl_codec::kTransferSyntaxUIDJPEGRecompression) {
104 return std::make_unique<jpegxl_codec>(true, true);
105 }
106
107 // JPEG XL (1.2.840.10008.1.2.4.112) - lossy
108 if (transfer_syntax_uid == jpegxl_codec::kTransferSyntaxUIDLossy) {
109 return std::make_unique<jpegxl_codec>(false);
110 }
111
112 // HTJ2K Lossless Only (1.2.840.10008.1.2.4.201)
113 if (transfer_syntax_uid == htj2k_codec::kTransferSyntaxUIDLossless) {
114 return std::make_unique<htj2k_codec>(true, false);
115 }
116
117 // HTJ2K with RPCL Options (1.2.840.10008.1.2.4.202)
118 if (transfer_syntax_uid == htj2k_codec::kTransferSyntaxUIDRPCL) {
119 return std::make_unique<htj2k_codec>(true, true);
120 }
121
122 // HTJ2K (1.2.840.10008.1.2.4.203) - lossy
123 if (transfer_syntax_uid == htj2k_codec::kTransferSyntaxUIDLossy) {
124 return std::make_unique<htj2k_codec>(false);
125 }
126
127 // Frame Deflate (1.2.840.10008.1.2.11)
128 if (transfer_syntax_uid == frame_deflate_codec::kTransferSyntaxUID) {
129 return std::make_unique<frame_deflate_codec>();
130 }
131
132 return nullptr;
133}
134
135std::unique_ptr<compression_codec> codec_factory::create(
136 const transfer_syntax& ts) {
137 return create(ts.uid());
138}
139
140std::vector<std::string_view> codec_factory::supported_transfer_syntaxes() {
141 return {kSupportedTransferSyntaxes.begin(), kSupportedTransferSyntaxes.end()};
142}
143
144bool codec_factory::is_supported(std::string_view transfer_syntax_uid) {
145 for (const auto& uid : kSupportedTransferSyntaxes) {
146 if (uid == transfer_syntax_uid) {
147 return true;
148 }
149 }
150 return false;
151}
152
154 return is_supported(ts.uid());
155}
156
157} // namespace kcenon::pacs::encoding::compression
static std::unique_ptr< compression_codec > create(std::string_view transfer_syntax_uid)
Creates a codec instance for the given Transfer Syntax UID.
static std::vector< std::string_view > supported_transfer_syntaxes()
Returns a list of all supported Transfer Syntax UIDs.
static bool is_supported(std::string_view transfer_syntax_uid)
Checks if a Transfer Syntax is supported for compression.
static constexpr std::string_view kTransferSyntaxUID
DICOM Transfer Syntax UID for Frame Deflate.
static constexpr std::string_view kTransferSyntaxUIDMain10
DICOM Transfer Syntax UID for HEVC/H.265 Main 10 Profile / Level 5.1.
Definition hevc_codec.h:52
static constexpr std::string_view kTransferSyntaxUIDMain
DICOM Transfer Syntax UID for HEVC/H.265 Main Profile / Level 5.1.
Definition hevc_codec.h:48
static constexpr std::string_view kTransferSyntaxUIDLossy
DICOM Transfer Syntax UID for HTJ2K (Lossy)
Definition htj2k_codec.h:58
static constexpr std::string_view kTransferSyntaxUIDLossless
DICOM Transfer Syntax UID for HTJ2K Lossless Only.
Definition htj2k_codec.h:50
static constexpr std::string_view kTransferSyntaxUIDRPCL
DICOM Transfer Syntax UID for HTJ2K with RPCL Options (Lossless Only)
Definition htj2k_codec.h:54
static constexpr std::string_view kTransferSyntaxUIDLossy
DICOM Transfer Syntax UID for JPEG 2000 (Lossy or Lossless)
static constexpr std::string_view kTransferSyntaxUIDLossless
DICOM Transfer Syntax UID for JPEG 2000 Lossless Only.
static constexpr std::string_view kTransferSyntaxUID
DICOM Transfer Syntax UID for JPEG Baseline.
static constexpr std::string_view kTransferSyntaxUID
DICOM Transfer Syntax UID for JPEG Lossless (Process 14, Selection Value 1)
static constexpr std::string_view kTransferSyntaxUIDLossless
DICOM Transfer Syntax UID for JPEG-LS Lossless.
static constexpr std::string_view kTransferSyntaxUIDNearLossless
DICOM Transfer Syntax UID for JPEG-LS Near-Lossless (Lossy)
static constexpr std::string_view kTransferSyntaxUIDJPEGRecompression
DICOM Transfer Syntax UID for JPEG XL JPEG Recompression.
static constexpr std::string_view kTransferSyntaxUIDLossy
DICOM Transfer Syntax UID for JPEG XL (any mode)
static constexpr std::string_view kTransferSyntaxUIDLossless
DICOM Transfer Syntax UID for JPEG XL Lossless.
static constexpr std::string_view kTransferSyntaxUID
DICOM Transfer Syntax UID for RLE Lossless.
Definition rle_codec.h:52
Represents a DICOM Transfer Syntax.
Transfer Syntax UIDs.
Definition main.cpp:78
std::string_view uid