annotate Core/ImageFormats/ImageBuffer.cpp @ 824:a811bdf8b8eb

precompiled headers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Jun 2014 11:36:07 +0200
parents 262feb14f92f
children 502c49adb5ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 801
diff changeset
33 #include "../PrecompiledHeaders.h"
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ImageBuffer.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 void ImageBuffer::Allocate()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (changed_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 pitch_ = GetBytesPerPixel() * width_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 data_.resize(pitch_ * height_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 if (data_.size() > 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 buffer_ = &data_[0];
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 buffer_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 changed_ = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ImageBuffer::ImageBuffer() : changed_(false)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 changed_ = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 format_ = PixelFormat_Grayscale8;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 width_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 height_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 pitch_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 buffer_ = NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 void ImageBuffer::SetFormat(PixelFormat format)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 format_ = format;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 void ImageBuffer::SetWidth(unsigned int width)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 width_ = width;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 void ImageBuffer::SetHeight(unsigned int height)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 height_ = height;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ImageAccessor ImageBuffer::GetAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 Allocate();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ImageAccessor accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 accessor.AssignWritable(format_, width_, height_, pitch_, buffer_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 return accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ImageAccessor ImageBuffer::GetConstAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 Allocate();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ImageAccessor accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 accessor.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }