PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
image_params.h
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
11#ifndef PACS_ENCODING_COMPRESSION_IMAGE_PARAMS_HPP
12#define PACS_ENCODING_COMPRESSION_IMAGE_PARAMS_HPP
13
14#include <cstdint>
15#include <string>
16
18
34
40[[nodiscard]] inline std::string to_string(photometric_interpretation pi) {
41 switch (pi) {
43 return "MONOCHROME1";
45 return "MONOCHROME2";
47 return "RGB";
49 return "YBR_FULL";
51 return "YBR_FULL_422";
53 return "PALETTE COLOR";
54 default:
55 return "UNKNOWN";
56 }
57}
58
65 const std::string& str) {
66 if (str == "MONOCHROME1") return photometric_interpretation::monochrome1;
67 if (str == "MONOCHROME2") return photometric_interpretation::monochrome2;
68 if (str == "RGB") return photometric_interpretation::rgb;
69 if (str == "YBR_FULL") return photometric_interpretation::ycbcr_full;
70 if (str == "YBR_FULL_422") return photometric_interpretation::ycbcr_full_422;
71 if (str == "PALETTE COLOR") return photometric_interpretation::palette_color;
73}
74
83 uint16_t width{0};
84
86 uint16_t height{0};
87
90 uint16_t bits_allocated{0};
91
94 uint16_t bits_stored{0};
95
98 uint16_t high_bit{0};
99
102 uint16_t samples_per_pixel{1};
103
107
111
114
116 uint32_t number_of_frames{1};
117
122 [[nodiscard]] size_t frame_size_bytes() const noexcept {
123 size_t bits_per_pixel = static_cast<size_t>(bits_allocated) * samples_per_pixel;
124 size_t total_bits = static_cast<size_t>(width) * height * bits_per_pixel;
125 return (total_bits + 7) / 8; // Round up to byte boundary
126 }
127
132 [[nodiscard]] bool is_grayscale() const noexcept {
133 return samples_per_pixel == 1;
134 }
135
140 [[nodiscard]] bool is_color() const noexcept {
141 return samples_per_pixel > 1;
142 }
143
148 [[nodiscard]] bool is_signed() const noexcept {
149 return pixel_representation == 1;
150 }
151
160 [[nodiscard]] bool valid_for_jpeg_baseline() const noexcept {
161 if (bits_allocated != 8 || bits_stored != 8) return false;
162 if (samples_per_pixel != 1 && samples_per_pixel != 3) return false;
163 return true;
164 }
165
175 [[nodiscard]] bool valid_for_jpeg_lossless() const noexcept {
176 if (bits_stored < 2 || bits_stored > 16) return false;
177 if (bits_allocated != 8 && bits_allocated != 16) return false;
178 if (samples_per_pixel != 1) return false;
179 return true;
180 }
181
192 [[nodiscard]] bool valid_for_jpeg2000() const noexcept {
193 if (bits_stored < 1 || bits_stored > 16) return false;
194 if (bits_allocated != 8 && bits_allocated != 16) return false;
195 if (samples_per_pixel != 1 && samples_per_pixel != 3) return false;
196 if (width == 0 || height == 0) return false;
197 return true;
198 }
199
210 [[nodiscard]] bool valid_for_jpeg_ls() const noexcept {
211 if (bits_stored < 2 || bits_stored > 16) return false;
212 if (bits_allocated != 8 && bits_allocated != 16) return false;
213 if (samples_per_pixel != 1 && samples_per_pixel != 3) return false;
214 if (width == 0 || height == 0) return false;
215 if (width > 65535 || height > 65535) return false;
216 return true;
217 }
218
229 [[nodiscard]] bool valid_for_rle() const noexcept {
230 if (bits_allocated != 8 && bits_allocated != 16) return false;
232 if (width == 0 || height == 0) return false;
233 if (width > 65535 || height > 65535) return false;
234 // Check segment count limit (max 15 segments)
235 int bytes_per_sample = (bits_allocated + 7) / 8;
236 int num_segments = samples_per_pixel * bytes_per_sample;
237 if (num_segments > 15) return false;
238 return true;
239 }
240};
241
242} // namespace kcenon::pacs::encoding::compression
243
244#endif // PACS_ENCODING_COMPRESSION_IMAGE_PARAMS_HPP
std::string to_string(photometric_interpretation pi)
Converts photometric interpretation to DICOM string value.
photometric_interpretation parse_photometric_interpretation(const std::string &str)
Parses a DICOM photometric interpretation string.
photometric_interpretation
Photometric interpretation of pixel data.
@ monochrome2
Minimum pixel value displayed as black.
@ monochrome1
Minimum pixel value displayed as white.
Parameters describing image pixel data.
uint16_t samples_per_pixel
Number of samples per pixel (0028,0002) 1 for grayscale, 3 for color.
uint16_t bits_allocated
Bits allocated per pixel sample (0028,0100) Valid values: 8, 16.
uint16_t height
Image height in pixels (Rows - 0028,0010)
size_t frame_size_bytes() const noexcept
Calculates the size of uncompressed pixel data in bytes.
bool is_color() const noexcept
Checks if the image is color (multiple samples per pixel).
bool valid_for_rle() const noexcept
Validates image parameters for RLE Lossless compression.
photometric_interpretation photometric
Photometric interpretation (0028,0004)
uint16_t planar_configuration
Planar configuration (0028,0006) 0 = interleaved (R1G1B1R2G2B2...), 1 = separate planes (RRR....
uint16_t pixel_representation
Pixel representation (0028,0103) 0 = unsigned, 1 = signed.
uint16_t width
Image width in pixels (Columns - 0028,0011)
uint16_t bits_stored
Bits stored per pixel sample (0028,0101) Must be <= bits_allocated.
bool valid_for_jpeg_lossless() const noexcept
Validates image parameters for JPEG Lossless compression.
bool valid_for_jpeg2000() const noexcept
Validates image parameters for JPEG 2000 compression.
bool is_signed() const noexcept
Checks if pixel values are signed integers.
bool valid_for_jpeg_baseline() const noexcept
Validates image parameters for JPEG Baseline compression.
bool is_grayscale() const noexcept
Checks if the image is grayscale (single sample per pixel).
uint32_t number_of_frames
Number of frames in multi-frame image (0028,0008)
uint16_t high_bit
High bit position (0028,0102) Typically bits_stored - 1.
bool valid_for_jpeg_ls() const noexcept
Validates image parameters for JPEG-LS compression.