PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
jpegxl_codec.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
7
9
11 bool jpeg_recompression,
12 float quality_distance)
13 : lossless_(lossless),
14 jpeg_recompression_(jpeg_recompression),
15 quality_distance_(quality_distance) {}
16
18
19jpegxl_codec::jpegxl_codec(jpegxl_codec&&) noexcept = default;
20jpegxl_codec& jpegxl_codec::operator=(jpegxl_codec&&) noexcept = default;
21
22std::string_view jpegxl_codec::transfer_syntax_uid() const noexcept {
23 if (lossless_) {
24 return jpeg_recompression_
25 ? kTransferSyntaxUIDJPEGRecompression
26 : kTransferSyntaxUIDLossless;
27 }
28 return kTransferSyntaxUIDLossy;
29}
30
31std::string_view jpegxl_codec::name() const noexcept {
32 if (lossless_) {
34 ? "JPEG XL JPEG Recompression"
35 : "JPEG XL (Lossless)";
36 }
37 return "JPEG XL (Lossy)";
38}
39
40bool jpegxl_codec::is_lossy() const noexcept {
41 return !lossless_;
42}
43
44bool jpegxl_codec::can_encode(const image_params& params) const noexcept {
45 if (params.width == 0 || params.height == 0) {
46 return false;
47 }
48
49 if (params.samples_per_pixel != 1 && params.samples_per_pixel != 3) {
50 return false;
51 }
52
53 if (params.bits_stored < 1 || params.bits_stored > 16) {
54 return false;
55 }
56
57 return true;
58}
59
60bool jpegxl_codec::can_decode(const image_params& params) const noexcept {
61 return can_encode(params);
62}
63
64bool jpegxl_codec::is_lossless_mode() const noexcept {
65 return lossless_;
66}
67
71
72float jpegxl_codec::quality_distance() const noexcept {
73 return quality_distance_;
74}
75
76// JPEG XL library not yet integrated -- return not-available errors
77
79 [[maybe_unused]] std::span<const uint8_t> pixel_data,
80 [[maybe_unused]] const image_params& params,
81 [[maybe_unused]] const compression_options& options) const {
84 "JPEG XL codec not available: libjxl library not found at build time. "
85 "Build with PACS_WITH_JPEGXL=ON to enable.");
86}
87
89 [[maybe_unused]] std::span<const uint8_t> compressed_data,
90 [[maybe_unused]] const image_params& params) const {
93 "JPEG XL codec not available: libjxl library not found at build time. "
94 "Build with PACS_WITH_JPEGXL=ON to enable.");
95}
96
97} // namespace kcenon::pacs::encoding::compression
JPEG XL codec implementation (Supplement 232).
codec_result decode(std::span< const uint8_t > compressed_data, const image_params &params) const override
Decompresses compressed pixel data.
std::string_view name() const noexcept override
Returns a human-readable name for the codec.
bool can_encode(const image_params &params) const noexcept override
Checks if this codec supports the given image parameters.
bool can_decode(const image_params &params) const noexcept override
Checks if this codec can decode data with given parameters.
bool is_lossy() const noexcept override
Checks if this codec produces lossy compression.
jpegxl_codec(bool lossless=true, bool jpeg_recompression=false, float quality_distance=kDefaultQualityDistance)
Constructs a JPEG XL codec instance.
codec_result encode(std::span< const uint8_t > pixel_data, const image_params &params, const compression_options &options={}) const override
Compresses uncompressed pixel data.
constexpr int compression_error
Definition result.h:78
constexpr int decompression_error
Definition result.h:79
Result< T > pacs_error(int code, const std::string &message, const std::string &details="")
Create a PACS error result with module context.
Definition result.h:234
Result<T> type aliases and helpers for PACS system.
Compression quality settings for lossy codecs.
Parameters describing image pixel data.