annotate Core/ImageFormats/ImageAccessor.cpp @ 1198:1169528a9a5f db-changes

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Oct 2014 13:52:01 +0200
parents 80d4f1618b33
children 6e7e5ed91c2d
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../OrthancException.h"
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
37 #include "../ChunkedBuffer.h"
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <stdint.h>
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
40 #include <cassert>
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
41 #include <glog/logging.h>
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
42 #include <boost/lexical_cast.hpp>
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace Orthanc
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
46 template <typename PixelType>
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
47 static void ToMatlabStringInternal(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
48 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
49 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 target.AddChunk("double([ ");
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 for (unsigned int y = 0; y < source.GetHeight(); y++)
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 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(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 std::string s;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
57 if (y > 0)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
58 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
59 s = "; ";
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
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 s.reserve(source.GetWidth() * 8);
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 for (unsigned int x = 0; x < source.GetWidth(); x++, p++)
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 s += boost::lexical_cast<std::string>(static_cast<int>(*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
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
69 target.AddChunk(s);
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 target.AddChunk("])");
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
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 static void RGB24ToMatlabString(ChunkedBuffer& target,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
77 const ImageAccessor& source)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
78 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
79 assert(source.GetFormat() == PixelFormat_RGB24);
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 target.AddChunk("double(permute(reshape([ ");
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 for (unsigned int y = 0; y < source.GetHeight(); y++)
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;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
88 s.reserve(source.GetWidth() * 3 * 8);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
89
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
90 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
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
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
98 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) +
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
99 " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
100 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
101
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
102
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
103 void* ImageAccessor::GetBuffer() const
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
107 LOG(ERROR) << "Trying to write on a read-only image";
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 throw OrthancException(ErrorCode_ReadOnly);
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return buffer_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
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 const void* ImageAccessor::GetConstRow(unsigned int y) const
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if (buffer_ != NULL)
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 return reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 return NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
128 void* ImageAccessor::GetRow(unsigned int y) const
798
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 if (readOnly_)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
132 LOG(ERROR) << "Trying to write on a read-only image";
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 throw OrthancException(ErrorCode_ReadOnly);
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (buffer_ != NULL)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 return reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 else
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 return NULL;
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 }
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 void ImageAccessor::AssignEmpty(PixelFormat format)
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 width_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 height_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 pitch_ = 0;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 buffer_ = NULL;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
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
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 void ImageAccessor::AssignReadOnly(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 const void *buffer)
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 readOnly_ = true;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 pitch_ = pitch;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 buffer_ = const_cast<void*>(buffer);
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
170
983
80d4f1618b33 Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
171 assert(GetBytesPerPixel() * width_ <= pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
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 void ImageAccessor::AssignWritable(PixelFormat format,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 unsigned int width,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 unsigned int height,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 unsigned int pitch,
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 void *buffer)
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 readOnly_ = false;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 format_ = format;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 width_ = width;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 height_ = height;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 pitch_ = pitch;
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 buffer_ = buffer;
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
187
983
80d4f1618b33 Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
188 assert(GetBytesPerPixel() * width_ <= pitch_);
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
190
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
191
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
192 void ImageAccessor::ToMatlabString(std::string& target) const
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
193 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
194 ChunkedBuffer buffer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
195
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
196 switch (GetFormat())
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
197 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
198 case PixelFormat_Grayscale8:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
199 ToMatlabStringInternal<uint8_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
200 break;
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 case PixelFormat_Grayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
203 ToMatlabStringInternal<uint16_t>(buffer, *this);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
204 break;
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_SignedGrayscale16:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
207 ToMatlabStringInternal<int16_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_RGB24:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
211 RGB24ToMatlabString(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 default:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
215 throw OrthancException(ErrorCode_NotImplemented);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
216 }
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 buffer.Flatten(target);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
219 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
220
798
e1d27ee2114a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }