annotate OrthancServer/Internals/DicomImageDecoder.cpp @ 2172:84d1d392a9ab

GenerateUuid() not available in sandboxed environments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Nov 2016 12:06:00 +0100
parents dd609a99d39a
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1206
diff changeset
4 * Department, University Hospital of Liege, Belgium
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
48016722c770 refactoring
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
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../PrecompiledHeadersServer.h"
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "DicomImageDecoder.h"
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
36
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
37 /*=========================================================================
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
38
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
39 This file is based on portions of the following project
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
40 (cf. function "DecodePsmctRle1()"):
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
41
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
42 Program: GDCM (Grassroots DICOM). A DICOM library
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
43 Module: http://gdcm.sourceforge.net/Copyright.html
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
44
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
45 Copyright (c) 2006-2011 Mathieu Malaterre
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
46 Copyright (c) 1993-2005 CREATIS
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
47 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
48 All rights reserved.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
49
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 Redistribution and use in source and binary forms, with or without
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
51 modification, are permitted provided that the following conditions are met:
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
52
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
53 * Redistributions of source code must retain the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
54 this list of conditions and the following disclaimer.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
55
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
56 * Redistributions in binary form must reproduce the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
57 this list of conditions and the following disclaimer in the documentation
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
58 and/or other materials provided with the distribution.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
59
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
60 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
61 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 endorse or promote products derived from this software without specific
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
63 prior written permission.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
64
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
65 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
66 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
67 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
68 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
69 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
70 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
71 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
72 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
73 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
74 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
75
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
76 =========================================================================*/
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
77
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
78
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
79 #include "../../Core/Logging.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #include "../../Core/OrthancException.h"
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
81 #include "../../Core/Images/Image.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
82 #include "../../Core/Images/ImageProcessing.h"
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
83 #include "../../Core/Images/PngWriter.h"
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
84 #include "../../Core/Images/JpegWriter.h"
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
85 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 #include "../ToDcmtkBridge.h"
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
87 #include "../FromDcmtkBridge.h"
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
88 #include "../ParsedDicomFile.h"
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
89 #include "../OrthancInitialization.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
91 #include <boost/lexical_cast.hpp>
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
92
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
93 #include <dcmtk/dcmdata/dcfilefo.h>
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
94 #include <dcmtk/dcmdata/dcrleccd.h>
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
95 #include <dcmtk/dcmdata/dcrlecp.h>
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
96
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
97 #if ORTHANC_ENABLE_JPEG_LOSSLESS == 1
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
98 # include <dcmtk/dcmjpls/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
99 # include <dcmtk/dcmjpls/djcparam.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
100 # include <dcmtk/dcmjpeg/djrplol.h>
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #endif
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
103 #if ORTHANC_ENABLE_JPEG == 1
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
104 # include <dcmtk/dcmjpeg/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
105 # include <dcmtk/dcmjpeg/djcparam.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
106 # include <dcmtk/dcmjpeg/djdecbas.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
107 # include <dcmtk/dcmjpeg/djdecext.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
108 # include <dcmtk/dcmjpeg/djdeclol.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
109 # include <dcmtk/dcmjpeg/djdecpro.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
110 # include <dcmtk/dcmjpeg/djdecsps.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
111 # include <dcmtk/dcmjpeg/djdecsv1.h>
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
112 #endif
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
113
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
114 #if DCMTK_VERSION_NUMBER <= 360
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
115 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
116 # define EXS_JPEGProcess2_4 EXS_JPEGProcess2_4TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
117 # define EXS_JPEGProcess6_8 EXS_JPEGProcess6_8TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
118 # define EXS_JPEGProcess10_12 EXS_JPEGProcess10_12TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
119 # define EXS_JPEGProcess14 EXS_JPEGProcess14TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
120 # define EXS_JPEGProcess14SV1 EXS_JPEGProcess14SV1TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
121 #endif
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 namespace Orthanc
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
125 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
126 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
127
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
128
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
129 bool DicomImageDecoder::IsPsmctRle1(DcmDataset& dataset)
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
130 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
131 DcmElement* e;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
132 char* c;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
133
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
134 // Check whether the DICOM instance contains an image encoded with
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
135 // the PMSCT_RLE1 scheme.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
136 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_COMPRESSION_TYPE), e).good() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
137 e == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
138 !e->isaString() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
139 !e->getString(c).good() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
140 c == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
141 strcmp("PMSCT_RLE1", c))
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
142 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
143 return false;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
144 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
145 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
146 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
147 return true;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
148 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
149 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
150
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
151
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
152 bool DicomImageDecoder::DecodePsmctRle1(std::string& output,
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
153 DcmDataset& dataset)
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
154 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
155 // Check whether the DICOM instance contains an image encoded with
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
156 // the PMSCT_RLE1 scheme.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
157 if (!IsPsmctRle1(dataset))
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
158 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
159 return false;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
160 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
161
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
162 // OK, this is a custom RLE encoding from Philips. Get the pixel
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
163 // data from the appropriate private DICOM tag.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
164 Uint8* pixData = NULL;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
165 DcmElement* e;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
166 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT), e).good() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
167 e == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
168 e->getUint8Array(pixData) != EC_Normal)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
169 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
170 return false;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
171 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
172
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
173 // The "unsigned" below IS VERY IMPORTANT
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
174 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
175 const size_t length = e->getLength();
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
176
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
177 /**
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
178 * The code below is an adaptation of a sample code for GDCM by
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
179 * Mathieu Malaterre (under a BSD license).
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
180 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
181 **/
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
182
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
183 // RLE pass
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
184 std::vector<uint8_t> temp;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
185 temp.reserve(length);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
186 for (size_t i = 0; i < length; i++)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
187 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
188 if (inbuffer[i] == 0xa5)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
189 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
190 temp.push_back(inbuffer[i+2]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
191 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
192 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
193 temp.push_back(inbuffer[i+2]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
194 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
195 i += 2;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
196 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
197 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
198 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
199 temp.push_back(inbuffer[i]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
200 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
201 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
202
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
203 // Delta encoding pass
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
204 uint16_t delta = 0;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
205 output.clear();
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
206 output.reserve(temp.size());
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
207 for (size_t i = 0; i < temp.size(); i++)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
208 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
209 uint16_t value;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
210
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
211 if (temp[i] == 0x5a)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
212 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
213 uint16_t v1 = temp[i + 1];
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
214 uint16_t v2 = temp[i + 2];
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
215 value = (v2 << 8) + v1;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
216 i += 2;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
217 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
218 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
219 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
220 value = delta + (int8_t) temp[i];
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
221 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
222
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
223 output.push_back(value & 0xff);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
224 output.push_back(value >> 8);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
225 delta = value;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
226 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
227
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
228 if (output.size() % 2)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
229 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
230 output.resize(output.size() - 1);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
231 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
232
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
233 return true;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
234 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
235
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
236
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
237 class DicomImageDecoder::ImageSource
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
238 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
239 private:
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
240 std::string psmct_;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
241 std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
242
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
243 public:
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
244 void Setup(DcmDataset& dataset,
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
245 unsigned int frame)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
246 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
247 psmct_.clear();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
248 slowAccessor_.reset(NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
249
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
250 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
251
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
252 DicomMap m;
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2125
diff changeset
253 Configuration::ExtractDicomSummary(m, dataset);
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
254
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
255 /**
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
256 * Create an accessor to the raw values of the DICOM image.
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
257 **/
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
258
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
259 DcmElement* e;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
260 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() &&
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
261 e != NULL)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
262 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
263 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
264 if (e->getUint8Array(pixData) == EC_Normal)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
265 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
266 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength()));
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
267 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
268 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
269 else if (DecodePsmctRle1(psmct_, dataset))
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
270 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
271 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded";
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
272 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
273 if (psmct_.size() > 0)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
274 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
275 pixData = reinterpret_cast<Uint8*>(&psmct_[0]);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
276 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
277
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
278 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size()));
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
279 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
280
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
281 if (slowAccessor_.get() == NULL)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
282 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
283 throw OrthancException(ErrorCode_BadFileFormat);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
284 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
285
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
286 slowAccessor_->SetCurrentFrame(frame);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
287 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
288
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
289 unsigned int GetWidth() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
290 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
291 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
292 return slowAccessor_->GetInformation().GetWidth();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
293 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
294
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
295 unsigned int GetHeight() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
296 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
297 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
298 return slowAccessor_->GetInformation().GetHeight();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
299 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
300
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
301 unsigned int GetChannelCount() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
302 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
303 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
304 return slowAccessor_->GetInformation().GetChannelCount();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
305 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
306
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
307 const DicomIntegerPixelAccessor& GetAccessor() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
308 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
309 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
310 return *slowAccessor_;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
311 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
312
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
313 unsigned int GetSize() const
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
314 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
315 assert(slowAccessor_.get() != NULL);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
316 return slowAccessor_->GetSize();
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
317 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
318 };
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
319
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
320
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
321 ImageAccessor* DicomImageDecoder::CreateImage(DcmDataset& dataset,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
322 bool ignorePhotometricInterpretation)
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
324 DicomMap m;
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2125
diff changeset
325 Configuration::ExtractDicomSummary(m, dataset);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
327 DicomImageInformation info(m);
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
328 PixelFormat format;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
329
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
330 if (!info.ExtractPixelFormat(format, ignorePhotometricInterpretation))
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
332 LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored()
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
333 << "bpp, " << info.GetChannelCount() << " channels, "
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
334 << (info.IsSigned() ? "signed" : "unsigned")
1206
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
335 << (info.IsPlanar() ? ", planar, " : ", non-planar, ")
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
336 << EnumerationToString(info.GetPhotometricInterpretation())
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
337 << " photometric interpretation";
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 throw OrthancException(ErrorCode_NotImplemented);
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 863
diff changeset
340
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1944
diff changeset
341 return new Image(format, info.GetWidth(), info.GetHeight(), false);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
345 template <typename PixelType>
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
346 static void CopyPixels(ImageAccessor& target,
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
347 const DicomIntegerPixelAccessor& source)
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
348 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
349 const PixelType minValue = std::numeric_limits<PixelType>::min();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
350 const PixelType maxValue = std::numeric_limits<PixelType>::max();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
351
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
352 for (unsigned int y = 0; y < source.GetInformation().GetHeight(); y++)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
353 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
354 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y));
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
355 for (unsigned int x = 0; x < source.GetInformation().GetWidth(); x++)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
356 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
357 for (unsigned int c = 0; c < source.GetInformation().GetChannelCount(); c++, pixel++)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
358 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
359 int32_t v = source.GetValue(x, y, c);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
360 if (v < static_cast<int32_t>(minValue))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
361 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
362 *pixel = minValue;
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
363 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
364 else if (v > static_cast<int32_t>(maxValue))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
365 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
366 *pixel = maxValue;
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
367 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
368 else
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
369 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
370 *pixel = static_cast<PixelType>(v);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
371 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
372 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
373 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
374 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
375 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
376
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
377
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
378 ImageAccessor* DicomImageDecoder::DecodeUncompressedImage(DcmDataset& dataset,
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
379 unsigned int frame)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
380 {
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
381 ImageSource source;
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
382 source.Setup(dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
383
858
ebc41566f742 removed unneeded check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
384
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
385 /**
858
ebc41566f742 removed unneeded check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
386 * Resize the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
387 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
388
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
389 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, false));
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
390
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
391 if (source.GetWidth() != target->GetWidth() ||
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
392 source.GetHeight() != target->GetHeight())
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
393 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
394 throw OrthancException(ErrorCode_InternalError);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
395 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
396
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
397
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
398 /**
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
399 * If the format of the DICOM buffer is natively supported, use a
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
400 * direct access to copy its values.
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
401 **/
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
402
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
403 const DicomImageInformation& info = source.GetAccessor().GetInformation();
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
404
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
405 bool fastVersionSuccess = false;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
406 PixelFormat sourceFormat;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
407 if (!info.IsPlanar() &&
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
408 info.ExtractPixelFormat(sourceFormat, false))
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
409 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
410 try
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
411 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
412 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
413 if ((frame + 1) * frameSize <= source.GetSize())
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
414 {
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
415 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(source.GetAccessor().GetPixelData());
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
416
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
417 ImageAccessor sourceImage;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
418 sourceImage.AssignReadOnly(sourceFormat,
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
419 info.GetWidth(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
420 info.GetHeight(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
421 info.GetWidth() * GetBytesPerPixel(sourceFormat),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
422 buffer + frame * frameSize);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
423
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
424 ImageProcessing::Convert(*target, sourceImage);
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
425 ImageProcessing::ShiftRight(*target, info.GetShift());
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
426 fastVersionSuccess = true;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
427 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
428 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
429 catch (OrthancException&)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
430 {
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
431 // Unsupported conversion, use the slow version
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
432 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
433 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
434
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
435 /**
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
436 * Slow version : loop over the DICOM buffer, storing its value
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
437 * into the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
438 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
439
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
440 if (!fastVersionSuccess)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
441 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
442 switch (target->GetFormat())
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
443 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
444 case PixelFormat_RGB24:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
445 case PixelFormat_RGBA32:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
446 case PixelFormat_Grayscale8:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
447 CopyPixels<uint8_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
448 break;
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
449
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
450 case PixelFormat_Grayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
451 CopyPixels<uint16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
452 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
453
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
454 case PixelFormat_SignedGrayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
455 CopyPixels<int16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
456 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
457
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
458 default:
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
459 throw OrthancException(ErrorCode_InternalError);
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
460 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
461 }
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
462
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
463 return target.release();
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
464 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
465
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
466
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
467 ImageAccessor* DicomImageDecoder::ApplyCodec(const DcmCodec& codec,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
468 const DcmCodecParameter& parameters,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
469 DcmDataset& dataset,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
470 unsigned int frame)
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
471 {
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
472 DcmPixelSequence* pixelSequence = FromDcmtkBridge::GetPixelSequence(dataset);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
473 if (pixelSequence == NULL)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
474 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
475 throw OrthancException(ErrorCode_BadFileFormat);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
476 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
477
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
478 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, true));
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 Uint32 startFragment = 0; // Default
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 OFString decompressedColorModel; // Out
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 DJ_RPLossless representationParameter;
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
483 OFCondition c = codec.decodeFrame(&representationParameter,
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
484 pixelSequence, &parameters,
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
485 &dataset, frame, startFragment, target->GetBuffer(),
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
486 target->GetSize(), decompressedColorModel);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
488 if (c.good())
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 {
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
490 return target.release();
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 }
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
492 else
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
493 {
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
494 LOG(ERROR) << "Cannot decode an image";
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
495 throw OrthancException(ErrorCode_BadFileFormat);
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
496 }
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
498
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
499
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
500 ImageAccessor* DicomImageDecoder::Decode(ParsedDicomFile& dicom,
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
501 unsigned int frame)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
502 {
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
503 DcmDataset& dataset = *dicom.GetDcmtkObject().getDataset();
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
504 E_TransferSyntax syntax = dataset.getOriginalXfer();
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
505
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
506 /**
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
507 * Deal with uncompressed, raw images.
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
508 * http://support.dcmtk.org/docs/dcxfer_8h-source.html
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
509 **/
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
510 if (syntax == EXS_Unknown ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
511 syntax == EXS_LittleEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
512 syntax == EXS_BigEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
513 syntax == EXS_LittleEndianExplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
514 syntax == EXS_BigEndianExplicit)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
515 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
516 return DecodeUncompressedImage(dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
517 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
518
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
519
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
520 #if ORTHANC_ENABLE_JPEG_LOSSLESS == 1
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
521 /**
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
522 * Deal with JPEG-LS images.
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
523 **/
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
524
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
525 if (syntax == EXS_JPEGLSLossless ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
526 syntax == EXS_JPEGLSLossy)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
527 {
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
528 DJLSCodecParameter parameters;
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
529 std::auto_ptr<DJLSDecoderBase> decoder;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
530
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
531 switch (syntax)
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
532 {
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
533 case EXS_JPEGLSLossless:
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
534 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
535 decoder.reset(new DJLSLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
536 break;
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
537
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
538 case EXS_JPEGLSLossy:
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
539 LOG(INFO) << "Decoding a JPEG-LS near-lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
540 decoder.reset(new DJLSNearLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
541 break;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
542
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
543 default:
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
544 throw OrthancException(ErrorCode_InternalError);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
545 }
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
546
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
547 return ApplyCodec(*decoder, parameters, dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
548 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
549 #endif
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
550
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
551
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
552 #if ORTHANC_ENABLE_JPEG == 1
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
553 /**
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
554 * Deal with JPEG images.
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
555 **/
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
556
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
557 if (syntax == EXS_JPEGProcess1 || // DJDecoderBaseline
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
558 syntax == EXS_JPEGProcess2_4 || // DJDecoderExtended
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
559 syntax == EXS_JPEGProcess6_8 || // DJDecoderSpectralSelection (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
560 syntax == EXS_JPEGProcess10_12 || // DJDecoderProgressive (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
561 syntax == EXS_JPEGProcess14 || // DJDecoderLossless
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
562 syntax == EXS_JPEGProcess14SV1) // DJDecoderP14SV1
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
563 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
564 // http://support.dcmtk.org/docs-snapshot/djutils_8h.html#a2a9695e5b6b0f5c45a64c7f072c1eb9d
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
565 DJCodecParameter parameters(
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
566 ECC_lossyYCbCr, // Mode for color conversion for compression, Unused for decompression
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
567 EDC_photometricInterpretation, // Perform color space conversion from YCbCr to RGB if DICOM photometric interpretation indicates YCbCr
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
568 EUC_default, // Mode for UID creation, unused for decompression
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
569 EPC_default); // Automatically determine whether color-by-plane is required from the SOP Class UID and decompressed photometric interpretation
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
570 std::auto_ptr<DJCodecDecoder> decoder;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
571
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
572 switch (syntax)
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
573 {
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
574 case EXS_JPEGProcess1:
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
575 LOG(INFO) << "Decoding a JPEG baseline (process 1) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
576 decoder.reset(new DJDecoderBaseline);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
577 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
578
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
579 case EXS_JPEGProcess2_4 :
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
580 LOG(INFO) << "Decoding a JPEG baseline (processes 2 and 4) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
581 decoder.reset(new DJDecoderExtended);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
582 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
583
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
584 case EXS_JPEGProcess6_8: // Retired
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
585 LOG(INFO) << "Decoding a JPEG spectral section, nonhierarchical (processes 6 and 8) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
586 decoder.reset(new DJDecoderSpectralSelection);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
587 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
588
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
589 case EXS_JPEGProcess10_12: // Retired
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
590 LOG(INFO) << "Decoding a JPEG full progression, nonhierarchical (processes 10 and 12) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
591 decoder.reset(new DJDecoderProgressive);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
592 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
593
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
594 case EXS_JPEGProcess14:
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
595 LOG(INFO) << "Decoding a JPEG lossless, nonhierarchical (process 14) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
596 decoder.reset(new DJDecoderLossless);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
597 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
598
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
599 case EXS_JPEGProcess14SV1:
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
600 LOG(INFO) << "Decoding a JPEG lossless, nonhierarchical, first-order prediction (process 14 selection value 1) DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
601 decoder.reset(new DJDecoderP14SV1);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
602 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
603
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
604 default:
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
605 throw OrthancException(ErrorCode_InternalError);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
606 }
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
607
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
608 return ApplyCodec(*decoder, parameters, dataset, frame);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
609 }
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
610 #endif
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
611
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
612
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
613 if (syntax == EXS_RLELossless)
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
614 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
615 LOG(INFO) << "Decoding a RLE lossless DICOM image";
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
616 DcmRLECodecParameter parameters;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
617 DcmRLECodecDecoder decoder;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
618 return ApplyCodec(decoder, parameters, dataset, frame);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
619 }
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
620
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
621
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
622 /**
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
623 * This DICOM image format is not natively supported by
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
624 * Orthanc. As a last resort, try and decode it through DCMTK by
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
625 * converting its transfer syntax to Little Endian. This will
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
626 * result in higher memory consumption. This is actually the
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
627 * second example of the following page:
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
628 * http://support.dcmtk.org/docs/mod_dcmjpeg.html#Examples
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
629 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
630
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
631 {
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
632 LOG(INFO) << "Decoding a compressed image by converting its transfer syntax to Little Endian";
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
633
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
634 std::auto_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone()));
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
635 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
636
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
637 if (converted->canWriteXfer(EXS_LittleEndianExplicit))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
638 {
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
639 return DecodeUncompressedImage(*converted, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
640 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
641 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
642
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
643 LOG(ERROR) << "Cannot decode a DICOM image with the built-in decoder";
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
644 throw OrthancException(ErrorCode_BadFileFormat);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
645 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
646
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
647
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
648 static bool IsColorImage(PixelFormat format)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
649 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
650 return (format == PixelFormat_RGB24 ||
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
651 format == PixelFormat_RGBA32);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
652 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
653
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
654
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
655 bool DicomImageDecoder::TruncateDecodedImage(std::auto_ptr<ImageAccessor>& image,
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
656 PixelFormat format,
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
657 bool allowColorConversion)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
658 {
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
659 // If specified, prevent the conversion between color and
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
660 // grayscale images
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
661 bool isSourceColor = IsColorImage(image->GetFormat());
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
662 bool isTargetColor = IsColorImage(format);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
663
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
664 if (!allowColorConversion)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
665 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
666 if (isSourceColor ^ isTargetColor)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
667 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
668 return false;
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
669 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
670 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
671
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
672 if (image->GetFormat() != format)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
673 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
674 // A conversion is required
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1944
diff changeset
675 std::auto_ptr<ImageAccessor> target(new Image(format, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
676 ImageProcessing::Convert(*target, *image);
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
677 image = target;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
678 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
679
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
680 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
681 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
682
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
683
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
684 bool DicomImageDecoder::PreviewDecodedImage(std::auto_ptr<ImageAccessor>& image)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
685 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
686 switch (image->GetFormat())
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
687 {
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
688 case PixelFormat_RGB24:
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
689 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
690 // Directly return color images without modification (RGB)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
691 return true;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
692 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
693
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
694 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
695 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
696 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
697 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
698 // Grayscale image: Stretch its dynamics to the [0,255] range
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
699 int64_t a, b;
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
700 ImageProcessing::GetMinMaxValue(a, b, *image);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
701
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
702 if (a == b)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
703 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
704 ImageProcessing::Set(*image, 0);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
705 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
706 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
707 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
708 ImageProcessing::ShiftScale(*image, static_cast<float>(-a), 255.0f / static_cast<float>(b - a));
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
709 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
710
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
711 // If the source image is not grayscale 8bpp, convert it
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
712 if (image->GetFormat() != PixelFormat_Grayscale8)
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
713 {
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1944
diff changeset
714 std::auto_ptr<ImageAccessor> target(new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
715 ImageProcessing::Convert(*target, *image);
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
716 image = target;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
717 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
718
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
719 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
720 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
721
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
722 default:
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
723 throw OrthancException(ErrorCode_NotImplemented);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
724 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
725 }
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
726
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
727
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
728 void DicomImageDecoder::ApplyExtractionMode(std::auto_ptr<ImageAccessor>& image,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
729 ImageExtractionMode mode)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
730 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
731 if (image.get() == NULL)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
732 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
733 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
734 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
735
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
736 bool ok = false;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
737
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
738 switch (mode)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
739 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
740 case ImageExtractionMode_UInt8:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
741 ok = TruncateDecodedImage(image, PixelFormat_Grayscale8, false);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
742 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
743
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
744 case ImageExtractionMode_UInt16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
745 ok = TruncateDecodedImage(image, PixelFormat_Grayscale16, false);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
746 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
747
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
748 case ImageExtractionMode_Int16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
749 ok = TruncateDecodedImage(image, PixelFormat_SignedGrayscale16, false);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
750 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
751
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
752 case ImageExtractionMode_Preview:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
753 ok = PreviewDecodedImage(image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
754 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
755
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
756 default:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
757 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
758 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
759
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
760 if (ok)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
761 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
762 assert(image.get() != NULL);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
763 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
764 else
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
765 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
766 throw OrthancException(ErrorCode_NotImplemented);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
767 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
768 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
769
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
770
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
771 void DicomImageDecoder::ExtractPngImage(std::string& result,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
772 std::auto_ptr<ImageAccessor>& image,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
773 ImageExtractionMode mode)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
774 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
775 ApplyExtractionMode(image, mode);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
776
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
777 PngWriter writer;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
778 writer.WriteToMemory(result, *image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
779 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
780
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
781
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
782 void DicomImageDecoder::ExtractJpegImage(std::string& result,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
783 std::auto_ptr<ImageAccessor>& image,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
784 ImageExtractionMode mode,
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
785 uint8_t quality)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
786 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
787 if (mode != ImageExtractionMode_UInt8 &&
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
788 mode != ImageExtractionMode_Preview)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
789 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
790 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
791 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
792
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
793 ApplyExtractionMode(image, mode);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
794
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
795 JpegWriter writer;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
796 writer.SetQuality(quality);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
797 writer.WriteToMemory(result, *image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
798 }
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 }