annotate OrthancFramework/Sources/Images/ImageAccessor.cpp @ 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
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
25 #include "../PrecompiledHeaders.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ImageAccessor.h"
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1397
diff changeset
28 #include "../Logging.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../OrthancException.h"
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
30 #include "../ChunkedBuffer.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <stdint.h>
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include <cassert>
1397
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
34 #include <boost/lexical_cast.hpp>
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
35
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
36
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 namespace Orthanc
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
40 template <typename PixelType>
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
41 static void ToMatlabStringInternal(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
42 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
43 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
44 target.AddChunk("double([ ");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
45
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
46 const unsigned int width = source.GetWidth();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
47 const unsigned int height = source.GetHeight();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
48
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
49 for (unsigned int y = 0; y < height; y++)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
51 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
52
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
53 std::string s;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
54 if (y > 0)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
55 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
56 s = "; ";
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
57 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
58
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
59 s.reserve(width * 8);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
60
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
61 for (unsigned int x = 0; x < width; x++, p++)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 {
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
63 s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " ";
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
64 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
65
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
66 target.AddChunk(s);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
67 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
68
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
69 target.AddChunk("])");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
70 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
71
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
72
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
73 static void RGB24ToMatlabString(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
74 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
75 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
76 assert(source.GetFormat() == PixelFormat_RGB24);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
77
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
78 target.AddChunk("double(permute(reshape([ ");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
79
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
80 const unsigned int width = source.GetWidth();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
81 const unsigned int height = source.GetHeight();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
82
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
83 for (unsigned int y = 0; y < height; y++)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
84 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
85 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
86
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
87 std::string s;
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
88 s.reserve(width * 3 * 8);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
89
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
90 for (unsigned int x = 0; x < 3 * width; x++, p++)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
91 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
92 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " ";
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
93 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
94
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
95 target.AddChunk(s);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
96 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
97
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
98 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(height) +
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
99 " " + boost::lexical_cast<std::string>(width) + " ]), [ 3 2 1 ]))");
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
100 }
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
101
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
102
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
103 ImageAccessor::ImageAccessor()
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
104 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
105 AssignEmpty(PixelFormat_Grayscale8);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
106 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
107
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
108 ImageAccessor::~ImageAccessor()
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
109 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
110 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
111
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
112 bool ImageAccessor::IsReadOnly() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
113 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
114 return readOnly_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
115 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
116
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
117 PixelFormat ImageAccessor::GetFormat() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
118 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
119 return format_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
120 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
121
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
122 unsigned int ImageAccessor::GetBytesPerPixel() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
123 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
124 return ::Orthanc::GetBytesPerPixel(format_);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
125 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
126
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
127 unsigned int ImageAccessor::GetWidth() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
128 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
129 return width_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
130 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
131
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
132 unsigned int ImageAccessor::GetHeight() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
133 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
134 return height_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
135 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
136
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
137 unsigned int ImageAccessor::GetPitch() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
138 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
139 return pitch_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
140 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
141
5838
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
142 size_t ImageAccessor::GetSize() const
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
143 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
144 return GetHeight() * GetPitch();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
145 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
146
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
147 const void *ImageAccessor::GetConstBuffer() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
148 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
149 return buffer_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
150 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
151
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
152 void* ImageAccessor::GetBuffer()
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
156 throw OrthancException(ErrorCode_ReadOnly,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
157 "Trying to write to a read-only image");
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 return buffer_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 const void* ImageAccessor::GetConstRow(unsigned int y) const
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 if (buffer_ != NULL)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
5838
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
168 return buffer_ + static_cast<size_t>(y) * static_cast<size_t>(pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
177 void* ImageAccessor::GetRow(unsigned int y)
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
181 throw OrthancException(ErrorCode_ReadOnly,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
182 "Trying to write to a read-only image");
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 if (buffer_ != NULL)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
5838
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
187 return buffer_ + static_cast<size_t>(y) * static_cast<size_t>(pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 return NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 void ImageAccessor::AssignEmpty(PixelFormat format)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 width_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 height_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 pitch_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 buffer_ = NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 void ImageAccessor::AssignReadOnly(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 const void *buffer)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 readOnly_ = true;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 pitch_ = pitch;
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
218 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer));
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
219
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
220 if (GetBytesPerPixel() * width_ > pitch_)
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
221 {
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
222 throw OrthancException(ErrorCode_ParameterOutOfRange);
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
223 }
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
226 void ImageAccessor::GetReadOnlyAccessor(ImageAccessor &target) const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
227 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
228 target.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
229 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
230
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 void ImageAccessor::AssignWritable(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 void *buffer)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 pitch_ = pitch;
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
243 buffer_ = reinterpret_cast<uint8_t*>(buffer);
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
244
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
245 if (GetBytesPerPixel() * width_ > pitch_)
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
246 {
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
247 throw OrthancException(ErrorCode_ParameterOutOfRange);
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
248 }
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
250
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
251
2865
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
252 void ImageAccessor::GetWriteableAccessor(ImageAccessor& target) const
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
253 {
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
254 if (readOnly_)
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
255 {
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
256 throw OrthancException(ErrorCode_ReadOnly);
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
257 }
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
258 else
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
259 {
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
260 target.AssignWritable(format_, width_, height_, pitch_, buffer_);
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
261 }
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
262 }
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
263
0f07bdae0805 ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
264
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
265 void ImageAccessor::ToMatlabString(std::string& target) const
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
266 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
267 ChunkedBuffer buffer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
268
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
269 switch (GetFormat())
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
270 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
271 case PixelFormat_Grayscale8:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
272 ToMatlabStringInternal<uint8_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
273 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
274
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
275 case PixelFormat_Grayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
276 ToMatlabStringInternal<uint16_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
277 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
278
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
279 case PixelFormat_Grayscale32:
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
280 ToMatlabStringInternal<uint32_t>(buffer, *this);
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
281 break;
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
282
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
283 case PixelFormat_Grayscale64:
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
284 ToMatlabStringInternal<uint64_t>(buffer, *this);
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
285 break;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
286
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
287 case PixelFormat_SignedGrayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
288 ToMatlabStringInternal<int16_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
289 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
290
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
291 case PixelFormat_Float32:
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
292 ToMatlabStringInternal<float>(buffer, *this);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
293 break;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1922
diff changeset
294
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
295 case PixelFormat_RGB24:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
296 RGB24ToMatlabString(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
297 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
298
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
299 default:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
300 throw OrthancException(ErrorCode_NotImplemented);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
301 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
302
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
303 buffer.Flatten(target);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
304 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
305
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
306
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
307
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
308 void ImageAccessor::GetRegion(ImageAccessor& accessor,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
309 unsigned int x,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
310 unsigned int y,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
311 unsigned int width,
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
312 unsigned int height) const
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
313 {
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
314 if (x + width > width_ ||
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
315 y + height > height_)
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
316 {
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
317 throw OrthancException(ErrorCode_ParameterOutOfRange);
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
318 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
319
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
320 if (width == 0 ||
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
321 height == 0)
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
322 {
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
323 accessor.AssignWritable(format_, 0, 0, 0, NULL);
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
324 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
325 else
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
326 {
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
327 uint8_t* p = (buffer_ +
5838
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
328 static_cast<size_t>(y) * static_cast<size_t>(pitch_) +
4b47151dea4c fix crashes if handling very large images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
329 static_cast<size_t>(x) * static_cast<size_t>(GetBytesPerPixel()));
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
330
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
331 if (readOnly_)
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
332 {
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
333 accessor.AssignReadOnly(format_, width, height, pitch_, p);
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
334 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
335 else
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
336 {
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
337 accessor.AssignWritable(format_, width, height, pitch_, p);
1922
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
338 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
339 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
340 }
369897749653 ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
341
2103
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
342
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
343 void ImageAccessor::SetFormat(PixelFormat format)
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
344 {
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
345 if (readOnly_)
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
346 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
347 throw OrthancException(ErrorCode_ReadOnly,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2865
diff changeset
348 "Trying to modify the format of a read-only image");
2103
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
349 }
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
350
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
351 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_))
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
352 {
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
353 throw OrthancException(ErrorCode_IncompatibleImageFormat);
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
354 }
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
355
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
356 format_ = format;
a89ca69ec1d1 ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
357 }
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
358
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
359
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
360 #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
361 void* ImageAccessor::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
362 {
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
363 return const_cast<ImageAccessor&>(*this).GetBuffer();
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
364 }
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
365
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
366 void* ImageAccessor::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
367 {
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
368 return const_cast<ImageAccessor&>(*this).GetRow(y);
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
369 }
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
370 #endif
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }