annotate OrthancFramework/Sources/Images/ImageAccessor.h @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents 4b47151dea4c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 983
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #pragma once
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
27 #include "../Compatibility.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../Enumerations.h"
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1396
ac4efabeb80c Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
30 #include <string>
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
31 #include <stdint.h>
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
32 #include <boost/noncopyable.hpp>
1396
ac4efabeb80c Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
33
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace Orthanc
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36 class ORTHANC_PUBLIC ImageAccessor : public boost::noncopyable
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 private:
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
39 template <PixelFormat Format>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
40 friend struct ImageTraits;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
41
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 bool readOnly_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 PixelFormat format_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 unsigned int width_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 unsigned int height_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 unsigned int pitch_;
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
47 uint8_t *buffer_;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
49 template <typename T>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
50 const T& GetPixelUnchecked(unsigned int x,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
51 unsigned int y) const
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
52 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
53 const uint8_t* row = reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
54 return reinterpret_cast<const T*>(row) [x];
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
55 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
56
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
57
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
58 template <typename T>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
59 T& GetPixelUnchecked(unsigned int x,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
60 unsigned int y)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
61 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
62 uint8_t* row = reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
63 return reinterpret_cast<T*>(row) [x];
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
64 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
65
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
66 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
67 // Alias for binary compatibility with Orthanc Framework 1.7.2 => don't use it anymore
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
68 void* GetBuffer() const;
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
69 void* GetRow(unsigned int y) const;
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
70 #endif
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
71
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 public:
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
73 ImageAccessor();
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
75 virtual ~ImageAccessor();
1605
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1396
diff changeset
76
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
77 bool IsReadOnly() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
79 PixelFormat GetFormat() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
81 unsigned int GetBytesPerPixel() const;
983
80d4f1618b33 Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
82
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
83 unsigned int GetWidth() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
85 unsigned int GetHeight() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
87 unsigned int GetPitch() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
5838
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
89 size_t GetSize() const;
844
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
90
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
91 const void* GetConstBuffer() const;
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
93 void* GetBuffer();
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const void* GetConstRow(unsigned int y) const;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
97 void* GetRow(unsigned int y);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 void AssignEmpty(PixelFormat format);
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 void AssignReadOnly(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 const void *buffer);
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
107 void GetReadOnlyAccessor(ImageAccessor& target) const;
2865
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
108
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 void AssignWritable(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 void *buffer);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
114
2865
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
115 void GetWriteableAccessor(ImageAccessor& target) const;
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
116
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
117 void ToMatlabString(std::string& target) const;
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
118
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
119 void GetRegion(ImageAccessor& accessor,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
120 unsigned int x,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
121 unsigned int y,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
122 unsigned int width,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
123 unsigned int height) const;
2103
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
124
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
125 void SetFormat(PixelFormat format);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 };
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }