annotate Core/ImageFormats/ImageBuffer.cpp @ 860:80c7e53a69b5 jpeg

bugfix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 07 Jun 2014 10:32:15 +0200
parents 839be3022203
children 3c0d0836f704
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
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
36 #include <stdio.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
37
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 void ImageBuffer::Allocate()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if (changed_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
844
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
44 /*
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
45 if (forceMinimalPitch_)
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
46 {
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
47 TODO: Align pitch and memory buffer to optimal size for SIMD.
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
48 }
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
49 */
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
50
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 pitch_ = GetBytesPerPixel() * width_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 data_.resize(pitch_ * height_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 if (data_.size() > 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 buffer_ = &data_[0];
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 buffer_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 changed_ = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
68 ImageBuffer::ImageBuffer(unsigned int width,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
69 unsigned int height,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
70 PixelFormat format)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
71 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
72 Initialize();
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
73 SetWidth(width);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
74 SetHeight(height);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
75 SetFormat(format);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
76 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
77
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
78
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 844
diff changeset
79 void ImageBuffer::Initialize()
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 changed_ = false;
844
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
82 forceMinimalPitch_ = true;
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 format_ = PixelFormat_Grayscale8;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 width_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 height_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 pitch_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 buffer_ = NULL;
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 void ImageBuffer::SetFormat(PixelFormat format)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 format_ = format;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 void ImageBuffer::SetWidth(unsigned int width)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 width_ = width;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 void ImageBuffer::SetHeight(unsigned int height)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 changed_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 height_ = height;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ImageAccessor ImageBuffer::GetAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 Allocate();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ImageAccessor accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 accessor.AssignWritable(format_, width_, height_, pitch_, buffer_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 return accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ImageAccessor ImageBuffer::GetConstAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 Allocate();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ImageAccessor accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 accessor.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 return accessor;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
844
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
130
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
131
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
132 void ImageBuffer::SetMinimalPitchForced(bool force)
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
133 {
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
134 changed_ = true;
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
135 forceMinimalPitch_ = force;
502c49adb5ad jpeg lossless
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
136 }
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }