Mercurial > hg > orthanc
annotate Core/Images/PamWriter.cpp @ 3218:9a83d94b2a1e
kanji encoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 11:32:14 +0100 |
parents | 4e43e67f8ecf |
children | 05881bf99c83 |
rev | line source |
---|---|
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
1 /** |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
6 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
11 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
23 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
27 * General Public License for more details. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
28 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
31 **/ |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
32 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
33 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
35 #include "PamWriter.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
36 |
2703 | 37 #include "../Endianness.h" |
38 #include "../OrthancException.h" | |
39 #include "../Toolbox.h" | |
40 | |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
41 #include <boost/lexical_cast.hpp> |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
42 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
43 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
44 namespace Orthanc |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
45 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
46 static void GetPixelFormatInfo(const PixelFormat& format, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
47 unsigned int& maxValue, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
48 unsigned int& channelCount, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
49 unsigned int& bytesPerChannel, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
50 std::string& tupleType) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
51 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
52 switch (format) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
53 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
54 case PixelFormat_Grayscale8: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
55 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
56 channelCount = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
57 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
58 tupleType = "GRAYSCALE"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
59 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
60 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
61 case PixelFormat_Grayscale16: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
62 maxValue = 65535; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
63 channelCount = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
64 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
65 tupleType = "GRAYSCALE"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
66 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
67 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
68 case PixelFormat_RGB24: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
69 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
70 channelCount = 3; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
71 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
72 tupleType = "RGB"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
73 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
74 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
75 case PixelFormat_RGB48: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
76 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
77 channelCount = 3; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
78 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
79 tupleType = "RGB"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
80 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
81 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
82 default: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
83 throw OrthancException(ErrorCode_NotImplemented); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
84 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
85 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
86 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
87 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
88 void PamWriter::WriteToMemoryInternal(std::string& target, |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
89 unsigned int width, |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
90 unsigned int height, |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
91 unsigned int sourcePitch, |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
92 PixelFormat format, |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
93 const void* buffer) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
94 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
95 unsigned int maxValue, channelCount, bytesPerChannel; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
96 std::string tupleType; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
97 GetPixelFormatInfo(format, maxValue, channelCount, bytesPerChannel, tupleType); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
98 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
99 target = (std::string("P7") + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
100 std::string("\nWIDTH ") + boost::lexical_cast<std::string>(width) + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
101 std::string("\nHEIGHT ") + boost::lexical_cast<std::string>(height) + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
102 std::string("\nDEPTH ") + boost::lexical_cast<std::string>(channelCount) + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
103 std::string("\nMAXVAL ") + boost::lexical_cast<std::string>(maxValue) + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
104 std::string("\nTUPLTYPE ") + tupleType + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
105 std::string("\nENDHDR\n")); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
106 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
107 if (bytesPerChannel != 1 && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
108 bytesPerChannel != 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
109 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
110 throw OrthancException(ErrorCode_NotImplemented); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
111 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
112 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
113 size_t targetPitch = channelCount * bytesPerChannel * width; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
114 size_t offset = target.size(); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
115 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
116 target.resize(offset + targetPitch * height); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
117 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
118 assert(target.size() != 0); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
119 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
120 if (Toolbox::DetectEndianness() == Endianness_Little && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
121 bytesPerChannel == 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
122 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
123 // Byte swapping |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
124 for (unsigned int h = 0; h < height; ++h) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
125 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
126 const uint16_t* p = reinterpret_cast<const uint16_t*> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
127 (reinterpret_cast<const uint8_t*>(buffer) + h * sourcePitch); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
128 uint16_t* q = reinterpret_cast<uint16_t*> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
129 (reinterpret_cast<uint8_t*>(&target[offset]) + h * targetPitch); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
130 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
131 for (unsigned int w = 0; w < width * channelCount; ++w) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
132 { |
2807
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
133 // memcpy() is necessary to avoid segmentation fault if the |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
134 // "pixel" pointer is not 16-bit aligned (which is the case |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
135 // if "offset" is an odd number). Check out issue #99: |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
136 // https://bitbucket.org/sjodogne/orthanc/issues/99 |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
137 uint16_t v = htobe16(*p); |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
138 memcpy(q, &v, sizeof(uint16_t)); |
6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2705
diff
changeset
|
139 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
140 p++; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
141 q++; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
142 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
143 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
144 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
145 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
146 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
147 // Either "bytesPerChannel == 1" (and endianness is not |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
148 // relevant), or we run on a big endian architecture (and no |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
149 // byte swapping is necessary, as PAM uses big endian) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
150 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
151 for (unsigned int h = 0; h < height; ++h) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
152 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
153 const void* p = reinterpret_cast<const uint8_t*>(buffer) + h * sourcePitch; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
154 void* q = reinterpret_cast<uint8_t*>(&target[offset]) + h * targetPitch; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
155 memcpy(q, p, targetPitch); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
156 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
157 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
158 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
159 } |