Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/PamWriter.cpp @ 4564:5a0adc1c19a9 db-changes
avoid copy of objects in ServerIndex
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Mar 2021 11:08:03 +0100 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
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 |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4325
diff
changeset
|
5 * Copyright (C) 2017-2021 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 |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
2699
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 * 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
|
13 * 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
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
20 **/ |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
21 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
22 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
24 #include "PamWriter.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
25 |
2703 | 26 #include "../Endianness.h" |
27 #include "../OrthancException.h" | |
28 #include "../Toolbox.h" | |
29 | |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
30 #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
|
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 namespace Orthanc |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
34 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
35 static void GetPixelFormatInfo(const PixelFormat& format, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
36 unsigned int& maxValue, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
37 unsigned int& channelCount, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
38 unsigned int& bytesPerChannel, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
39 std::string& tupleType) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
40 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
41 switch (format) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
42 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
43 case PixelFormat_Grayscale8: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
44 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
45 channelCount = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
46 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
47 tupleType = "GRAYSCALE"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
48 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
49 |
3377
05881bf99c83
Allow the serialization of signed 16bpp images in PAM format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
50 case PixelFormat_SignedGrayscale16: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
51 case PixelFormat_Grayscale16: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
52 maxValue = 65535; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
53 channelCount = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
54 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
55 tupleType = "GRAYSCALE"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
56 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
57 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
58 case PixelFormat_RGB24: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
59 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
60 channelCount = 3; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
61 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
62 tupleType = "RGB"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
63 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
64 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
65 case PixelFormat_RGB48: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
66 maxValue = 255; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
67 channelCount = 3; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
68 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
69 tupleType = "RGB"; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
70 break; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
71 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
72 default: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
73 throw OrthancException(ErrorCode_NotImplemented); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
74 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
75 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
76 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
77 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
78 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
|
79 unsigned int width, |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
80 unsigned int height, |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
81 unsigned int sourcePitch, |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
82 PixelFormat format, |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
83 const void* buffer) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
84 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
85 unsigned int maxValue, channelCount, bytesPerChannel; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
86 std::string tupleType; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
87 GetPixelFormatInfo(format, maxValue, channelCount, bytesPerChannel, tupleType); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
88 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
89 target = (std::string("P7") + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 std::string("\nTUPLTYPE ") + tupleType + |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
95 std::string("\nENDHDR\n")); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
96 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
97 if (bytesPerChannel != 1 && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
98 bytesPerChannel != 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
99 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
100 throw OrthancException(ErrorCode_NotImplemented); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
101 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
102 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
103 size_t targetPitch = channelCount * bytesPerChannel * width; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
104 size_t offset = target.size(); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
105 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
106 target.resize(offset + targetPitch * height); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
107 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
108 assert(target.size() != 0); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
109 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
110 if (Toolbox::DetectEndianness() == Endianness_Little && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
111 bytesPerChannel == 2) |
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 // Byte swapping |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
114 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
|
115 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
116 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
|
117 (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
|
118 uint16_t* q = reinterpret_cast<uint16_t*> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
119 (reinterpret_cast<uint8_t*>(&target[offset]) + h * targetPitch); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
120 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
121 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
|
122 { |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
123 /** |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
124 * This is Little-Endian computer, and PAM uses |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
125 * Big-Endian. Need to do a 16-bit swap. We DON'T use |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
126 * "htobe16()", as the latter only works if the "pixel" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
127 * pointer is 16-bit aligned (which is not the case if |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
128 * "offset" is an odd number), and the trick that was used |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
129 * in Orthanc <= 1.8.0 (i.e. make a "memcpy()" to a local |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
130 * uint16_t variable) doesn't seem work for WebAssembly. We |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
131 * thus use a plain old C implementation. Check out issue |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
132 * #99: https://bugs.orthanc-server.com/show_bug.cgi?id=99 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
133 **/ |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
134 const uint8_t* a = reinterpret_cast<const uint8_t*>(p); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
135 uint8_t* b = reinterpret_cast<uint8_t*>(q); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
136 b[0] = a[1]; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
137 b[1] = a[0]; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
138 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
139 p++; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
140 q++; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
141 } |
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 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
145 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
146 // Either "bytesPerChannel == 1" (and endianness is not |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
147 // 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
|
148 // 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
|
149 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
150 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
|
151 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
152 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
|
153 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
|
154 memcpy(q, p, targetPitch); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
155 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
156 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
157 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
158 } |