annotate Core/Images/ImageAccessor.cpp @ 1674:4fc502d469f4 db-changes

fix build if SSL is disabled
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Oct 2015 13:31:39 +0200
parents 96582230ddcb
children b1291df2f780
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 983
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 983
diff changeset
4 * Department, University Hospital of Liege, Belgium
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
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 * 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
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
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
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
33 #include "../PrecompiledHeaders.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ImageAccessor.h"
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1397
diff changeset
36 #include "../Logging.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../OrthancException.h"
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
38 #include "../ChunkedBuffer.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <stdint.h>
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
41 #include <cassert>
1397
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
42 #include <boost/lexical_cast.hpp>
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
43
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
44
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
48 template <typename PixelType>
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
49 static void ToMatlabStringInternal(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
51 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
52 target.AddChunk("double([ ");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
53
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
54 for (unsigned int y = 0; y < source.GetHeight(); y++)
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 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
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 std::string s;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
59 if (y > 0)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
60 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
61 s = "; ";
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
63
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
64 s.reserve(source.GetWidth() * 8);
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 for (unsigned int x = 0; x < source.GetWidth(); x++, p++)
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 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " ";
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
69 }
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 target.AddChunk(s);
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
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
74 target.AddChunk("])");
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
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 static void RGB24ToMatlabString(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
79 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
80 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
81 assert(source.GetFormat() == PixelFormat_RGB24);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
82
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
83 target.AddChunk("double(permute(reshape([ ");
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 for (unsigned int y = 0; y < source.GetHeight(); 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 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
88
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
89 std::string s;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
90 s.reserve(source.GetWidth() * 3 * 8);
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 for (unsigned int x = 0; x < 3 * source.GetWidth(); x++, 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 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " ";
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
95 }
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 target.AddChunk(s);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
98 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
99
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
100 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) +
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
101 " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
102 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
103
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
104
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
105 void* ImageAccessor::GetBuffer() const
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
1491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
109 #if ORTHANC_ENABLE_LOGGING == 1
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
110 LOG(ERROR) << "Trying to write on a read-only image";
1491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
111 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
112
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 throw OrthancException(ErrorCode_ReadOnly);
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return buffer_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 const void* ImageAccessor::GetConstRow(unsigned int y) const
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (buffer_ != NULL)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 return reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 return NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
133 void* ImageAccessor::GetRow(unsigned int y) const
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
1491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
137 #if ORTHANC_ENABLE_LOGGING == 1
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
138 LOG(ERROR) << "Trying to write on a read-only image";
1491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
139 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
140
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 throw OrthancException(ErrorCode_ReadOnly);
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 if (buffer_ != NULL)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 void ImageAccessor::AssignEmpty(PixelFormat format)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 width_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 height_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 pitch_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 buffer_ = NULL;
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
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 void ImageAccessor::AssignReadOnly(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const void *buffer)
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 readOnly_ = true;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 pitch_ = pitch;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 buffer_ = const_cast<void*>(buffer);
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
178
983
80d4f1618b33 Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
179 assert(GetBytesPerPixel() * width_ <= pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 void ImageAccessor::AssignWritable(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 void *buffer)
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 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 pitch_ = pitch;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 buffer_ = buffer;
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
195
983
80d4f1618b33 Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
196 assert(GetBytesPerPixel() * width_ <= pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
198
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
199
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
200 void ImageAccessor::ToMatlabString(std::string& target) const
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
201 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
202 ChunkedBuffer buffer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
203
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
204 switch (GetFormat())
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
205 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
206 case PixelFormat_Grayscale8:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
207 ToMatlabStringInternal<uint8_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
208 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
209
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
210 case PixelFormat_Grayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
211 ToMatlabStringInternal<uint16_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
212 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
213
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
214 case PixelFormat_SignedGrayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
215 ToMatlabStringInternal<int16_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
216 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
217
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
218 case PixelFormat_RGB24:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
219 RGB24ToMatlabString(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
220 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
221
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
222 default:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
223 throw OrthancException(ErrorCode_NotImplemented);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
224 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
225
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
226 buffer.Flatten(target);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
227 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
228
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }