annotate OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp @ 4138:1a26daefc3fe

DicomImageInformation::USEFUL_TAG_LENGTH
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Aug 2020 17:56:10 +0200
parents 6774605d4341
children dbd74fa2f446
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3525
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
23 #include "../../PrecompiledHeaders.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomImageDecoder.h"
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
26 #include "../ParsedDicomFile.h"
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
27
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
28
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
29 /*=========================================================================
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
30
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
31 This file is based on portions of the following project
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
32 (cf. function "DecodePsmctRle1()"):
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
33
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
34 Program: GDCM (Grassroots DICOM). A DICOM library
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
35 Module: http://gdcm.sourceforge.net/Copyright.html
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
36
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
37 Copyright (c) 2006-2011 Mathieu Malaterre
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
38 Copyright (c) 1993-2005 CREATIS
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
39 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
40 All rights reserved.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
41
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
42 Redistribution and use in source and binary forms, with or without
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
43 modification, are permitted provided that the following conditions are met:
846
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 * Redistributions of source code must retain the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
46 this list of conditions and the following disclaimer.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
47
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
48 * Redistributions in binary form must reproduce the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
49 this list of conditions and the following disclaimer in the documentation
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 and/or other materials provided with the distribution.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
51
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
52 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
53 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
54 endorse or promote products derived from this software without specific
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
55 prior written permission.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
56
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
57 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
58 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
59 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
60 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
61 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
63 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
64 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
65 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
66 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
67
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
68 =========================================================================*/
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
69
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
70
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
71 #include "../../Logging.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
72 #include "../../OrthancException.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
73 #include "../../Images/Image.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
74 #include "../../Images/ImageProcessing.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
75 #include "../../DicomFormat/DicomIntegerPixelAccessor.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 #include "../ToDcmtkBridge.h"
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
77 #include "../FromDcmtkBridge.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
79 #if ORTHANC_ENABLE_PNG == 1
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
80 # include "../../Images/PngWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
81 #endif
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
82
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
83 #if ORTHANC_ENABLE_JPEG == 1
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
84 # include "../../Images/JpegWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
85 #endif
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
86 #include "../../Images/PamWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
87
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
88 #include <boost/lexical_cast.hpp>
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
89
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
90 #include <dcmtk/dcmdata/dcdeftag.h>
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
91 #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
92 #include <dcmtk/dcmdata/dcrlecp.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
93 #include <dcmtk/dcmdata/dcrlerp.h>
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
94
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
95 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
96 # include <dcmtk/dcmjpeg/djrplol.h>
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
97 # include <dcmtk/dcmjpls/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
98 # include <dcmtk/dcmjpls/djcparam.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
99 # include <dcmtk/dcmjpls/djrparam.h>
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 #endif
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
102 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
103 # include <dcmtk/dcmjpeg/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
104 # include <dcmtk/dcmjpeg/djcparam.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
105 # include <dcmtk/dcmjpeg/djdecbas.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
106 # include <dcmtk/dcmjpeg/djdecext.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
107 # include <dcmtk/dcmjpeg/djdeclol.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
108 # include <dcmtk/dcmjpeg/djdecpro.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
109 # include <dcmtk/dcmjpeg/djdecsps.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
110 # include <dcmtk/dcmjpeg/djdecsv1.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
111 # include <dcmtk/dcmjpeg/djrploss.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_;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
241 std::unique_ptr<DicomIntegerPixelAccessor> slowAccessor_;
942
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;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
253 std::set<DicomTag> ignoreTagLength;
4138
1a26daefc3fe DicomImageInformation::USEFUL_TAG_LENGTH
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
254 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::USEFUL_TAG_LENGTH, ignoreTagLength);
942
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 /**
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
257 * 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
258 **/
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
259
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
260 DcmElement* e;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
261 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
262 e != NULL)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
263 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
264 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
265 if (e->getUint8Array(pixData) == EC_Normal)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
266 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
267 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength()));
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 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
270 else if (DecodePsmctRle1(psmct_, dataset))
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
271 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
272 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded";
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
273 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
274 if (psmct_.size() > 0)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
275 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
276 pixData = reinterpret_cast<Uint8*>(&psmct_[0]);
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
279 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size()));
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
282 if (slowAccessor_.get() == NULL)
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
283 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
284 throw OrthancException(ErrorCode_BadFileFormat);
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
287 slowAccessor_->SetCurrentFrame(frame);
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
290 unsigned int GetWidth() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
291 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
292 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
293 return slowAccessor_->GetInformation().GetWidth();
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
296 unsigned int GetHeight() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
297 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
298 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
299 return slowAccessor_->GetInformation().GetHeight();
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
302 unsigned int GetChannelCount() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
303 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
304 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
305 return slowAccessor_->GetInformation().GetChannelCount();
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
308 const DicomIntegerPixelAccessor& GetAccessor() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
309 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
310 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
311 return *slowAccessor_;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
312 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
313
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
314 unsigned int GetSize() const
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
315 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
316 assert(slowAccessor_.get() != NULL);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
317 return slowAccessor_->GetSize();
942
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
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
321
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
322 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
323 bool ignorePhotometricInterpretation)
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
325 DicomMap m;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
326 std::set<DicomTag> ignoreTagLength;
4138
1a26daefc3fe DicomImageInformation::USEFUL_TAG_LENGTH
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
327 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::USEFUL_TAG_LENGTH, ignoreTagLength);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
329 DicomImageInformation info(m);
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
330 PixelFormat format;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
331
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
332 if (!info.ExtractPixelFormat(format, ignorePhotometricInterpretation))
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
334 LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored()
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
335 << "bpp, " << info.GetChannelCount() << " channels, "
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
336 << (info.IsSigned() ? "signed" : "unsigned")
1206
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
337 << (info.IsPlanar() ? ", planar, " : ", non-planar, ")
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
338 << EnumerationToString(info.GetPhotometricInterpretation())
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
339 << " photometric interpretation";
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 throw OrthancException(ErrorCode_NotImplemented);
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 863
diff changeset
342
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1944
diff changeset
343 return new Image(format, info.GetWidth(), info.GetHeight(), false);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
347 template <typename PixelType>
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
348 static void CopyPixels(ImageAccessor& target,
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
349 const DicomIntegerPixelAccessor& source)
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
350 {
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
351 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
352 // dealing with float or double (which is not the case so far)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
353 const PixelType minValue = std::numeric_limits<PixelType>::min();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
354 const PixelType maxValue = std::numeric_limits<PixelType>::max();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
355
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
356 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
357 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
358 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y));
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
359 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
360 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
361 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
362 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
363 int32_t v = source.GetValue(x, y, c);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
364 if (v < static_cast<int32_t>(minValue))
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 = minValue;
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 if (v > static_cast<int32_t>(maxValue))
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 = maxValue;
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 else
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 *pixel = static_cast<PixelType>(v);
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 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
378 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
379 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
380
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
381
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
382 static ImageAccessor* DecodeLookupTable(std::unique_ptr<ImageAccessor>& target,
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
383 const DicomImageInformation& info,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
384 DcmDataset& dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
385 const uint8_t* pixelData,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
386 unsigned long pixelLength)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
387 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
388 LOG(INFO) << "Decoding a lookup table";
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
389
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
390 OFString r, g, b;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
391 PixelFormat format;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
392 const uint16_t* lutRed = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
393 const uint16_t* lutGreen = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
394 const uint16_t* lutBlue = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
395 unsigned long rc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
396 unsigned long gc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
397 unsigned long bc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
398
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
399 if (pixelData == NULL &&
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
400 !dataset.findAndGetUint8Array(DCM_PixelData, pixelData, &pixelLength).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
401 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
402 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
403 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
404
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
405 if (info.IsPlanar() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
406 info.GetNumberOfFrames() != 1 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
407 !info.ExtractPixelFormat(format, false) ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
408 !dataset.findAndGetOFStringArray(DCM_BluePaletteColorLookupTableDescriptor, b).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
409 !dataset.findAndGetOFStringArray(DCM_GreenPaletteColorLookupTableDescriptor, g).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
410 !dataset.findAndGetOFStringArray(DCM_RedPaletteColorLookupTableDescriptor, r).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
411 !dataset.findAndGetUint16Array(DCM_BluePaletteColorLookupTableData, lutBlue, &bc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
412 !dataset.findAndGetUint16Array(DCM_GreenPaletteColorLookupTableData, lutGreen, &gc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
413 !dataset.findAndGetUint16Array(DCM_RedPaletteColorLookupTableData, lutRed, &rc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
414 r != g ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
415 r != b ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
416 g != b ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
417 lutRed == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
418 lutGreen == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
419 lutBlue == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
420 pixelData == NULL)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
421 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
422 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
423 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
424
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
425 switch (format)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
426 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
427 case PixelFormat_RGB24:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
428 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
429 if (r != "256\\0\\16" ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
430 rc != 256 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
431 gc != 256 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
432 bc != 256 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
433 pixelLength != target->GetWidth() * target->GetHeight())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
434 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
435 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
436 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
437
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
438 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
439
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
440 for (unsigned int y = 0; y < target->GetHeight(); y++)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
441 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
442 uint8_t* p = reinterpret_cast<uint8_t*>(target->GetRow(y));
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
443
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
444 for (unsigned int x = 0; x < target->GetWidth(); x++)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
445 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
446 p[0] = lutRed[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
447 p[1] = lutGreen[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
448 p[2] = lutBlue[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
449 source++;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
450 p += 3;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
451 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
452 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
453
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
454 return target.release();
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
455 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
456
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
457 case PixelFormat_RGB48:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
458 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
459 if (r != "0\\0\\16" ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
460 rc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
461 gc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
462 bc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
463 pixelLength != 2 * target->GetWidth() * target->GetHeight())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
464 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
465 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
466 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
467
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
468 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
469
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
470 for (unsigned int y = 0; y < target->GetHeight(); y++)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
471 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
472 uint16_t* p = reinterpret_cast<uint16_t*>(target->GetRow(y));
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
473
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
474 for (unsigned int x = 0; x < target->GetWidth(); x++)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
475 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
476 p[0] = lutRed[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
477 p[1] = lutGreen[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
478 p[2] = lutBlue[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
479 source++;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
480 p += 3;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
481 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
482 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
483
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
484 return target.release();
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
485 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
486
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
487 default:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
488 break;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
489 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
490
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
491 throw OrthancException(ErrorCode_InternalError);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
492 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
493
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
494
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
495 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
496 unsigned int frame)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
497 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
498 /**
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
499 * Create the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
500 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
501
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
502 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, false));
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
503
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
504 ImageSource source;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
505 source.Setup(dataset, frame);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
506
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
507 if (source.GetWidth() != target->GetWidth() ||
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
508 source.GetHeight() != target->GetHeight())
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
509 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
510 throw OrthancException(ErrorCode_InternalError);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
511 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
512
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
513
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
514 /**
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
515 * Deal with lookup tables
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
516 **/
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
517
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
518 const DicomImageInformation& info = source.GetAccessor().GetInformation();
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
519
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
520 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
521 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
522 return DecodeLookupTable(target, info, dataset, NULL, 0);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
523 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
524
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
525
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
526 /**
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
527 * 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
528 * direct access to copy its values.
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
529 **/
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
530
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
531 bool fastVersionSuccess = false;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
532 PixelFormat sourceFormat;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
533 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
534 info.ExtractPixelFormat(sourceFormat, false))
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
535 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
536 try
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
537 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
538 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
539 if ((frame + 1) * frameSize <= source.GetSize())
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
540 {
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
541 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
542
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
543 ImageAccessor sourceImage;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
544 sourceImage.AssignReadOnly(sourceFormat,
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
545 info.GetWidth(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
546 info.GetHeight(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
547 info.GetWidth() * GetBytesPerPixel(sourceFormat),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
548 buffer + frame * frameSize);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
549
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
550 ImageProcessing::Convert(*target, sourceImage);
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
551 ImageProcessing::ShiftRight(*target, info.GetShift());
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
552 fastVersionSuccess = true;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
553 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
554 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
555 catch (OrthancException&)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
556 {
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
557 // Unsupported conversion, use the slow version
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
558 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
559 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
560
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
561 /**
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
562 * Slow version : loop over the DICOM buffer, storing its value
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
563 * into the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
564 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
565
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
566 if (!fastVersionSuccess)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
567 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
568 switch (target->GetFormat())
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
569 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
570 case PixelFormat_RGB24:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
571 case PixelFormat_RGBA32:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
572 case PixelFormat_Grayscale8:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
573 CopyPixels<uint8_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
574 break;
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
575
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
576 case PixelFormat_Grayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
577 CopyPixels<uint16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
578 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
579
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
580 case PixelFormat_SignedGrayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
581 CopyPixels<int16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
582 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
583
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
584 default:
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
585 throw OrthancException(ErrorCode_InternalError);
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
586 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
587 }
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
588
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
589 return target.release();
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
590 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
591
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
592
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
593 ImageAccessor* DicomImageDecoder::ApplyCodec
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
594 (const DcmCodec& codec,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
595 const DcmCodecParameter& parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
596 const DcmRepresentationParameter& representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
597 DcmDataset& dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
598 unsigned int frame)
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
599 {
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
600 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
601 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
602 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
603 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
604 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
605
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
606 DicomMap m;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
607 std::set<DicomTag> ignoreTagLength;
4138
1a26daefc3fe DicomImageInformation::USEFUL_TAG_LENGTH
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
608 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::USEFUL_TAG_LENGTH, ignoreTagLength);
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
609 DicomImageInformation info(m);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
610
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
611 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, true));
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 Uint32 startFragment = 0; // Default
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 OFString decompressedColorModel; // Out
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
615
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
616 OFCondition c;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
617
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
618 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette &&
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
619 info.GetChannelCount() == 1)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
620 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
621 std::string uncompressed;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
622 uncompressed.resize(info.GetWidth() * info.GetHeight() * info.GetBytesPerValue());
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
624 if (uncompressed.size() == 0 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
625 !codec.decodeFrame(&representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
626 pixelSequence, &parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
627 &dataset, frame, startFragment, &uncompressed[0],
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
628 uncompressed.size(), decompressedColorModel).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
629 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
630 throw OrthancException(ErrorCode_BadFileFormat,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
631 "Cannot decode a palette image");
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
632 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
633
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
634 return DecodeLookupTable(target, info, dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
635 reinterpret_cast<const uint8_t*>(uncompressed.c_str()),
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
636 uncompressed.size());
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 }
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
638 else
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
639 {
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
640 if (!codec.decodeFrame(&representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
641 pixelSequence, &parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
642 &dataset, frame, startFragment, target->GetBuffer(),
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
643 target->GetSize(), decompressedColorModel).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
644 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
645 throw OrthancException(ErrorCode_BadFileFormat,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
646 "Cannot decode a non-palette image");
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
647 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
648
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
649 return target.release();
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
650 }
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
652
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
653
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
654 ImageAccessor* DicomImageDecoder::Decode(ParsedDicomFile& dicom,
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
655 unsigned int frame)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
656 {
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
657 if (dicom.GetDcmtkObject().getDataset() == NULL)
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
658 {
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
659 throw OrthancException(ErrorCode_InternalError);
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
660 }
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
661 else
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
662 {
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
663 return Decode(*dicom.GetDcmtkObject().getDataset(), frame);
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
664 }
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
665 }
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
666
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
667
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
668 ImageAccessor* DicomImageDecoder::Decode(DcmDataset& dataset,
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
669 unsigned int frame)
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
670 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
671 E_TransferSyntax syntax = dataset.getCurrentXfer();
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
672
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
673 /**
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
674 * Deal with uncompressed, raw images.
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
675 * http://support.dcmtk.org/docs/dcxfer_8h-source.html
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
676 **/
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
677 if (syntax == EXS_Unknown ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
678 syntax == EXS_LittleEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
679 syntax == EXS_BigEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
680 syntax == EXS_LittleEndianExplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
681 syntax == EXS_BigEndianExplicit)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
682 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
683 return DecodeUncompressedImage(dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
684 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
685
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
686
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
687 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
688 /**
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
689 * Deal with JPEG-LS images.
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
690 **/
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
691
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
692 if (syntax == EXS_JPEGLSLossless ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
693 syntax == EXS_JPEGLSLossy)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
694 {
2430
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
695 // The (2, OFTrue) are the default parameters as found in DCMTK 3.6.2
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
696 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
697 DJLSRepresentationParameter representationParameter(2, OFTrue);
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
698
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
699 DJLSCodecParameter parameters;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
700 std::unique_ptr<DJLSDecoderBase> decoder;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
701
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
702 switch (syntax)
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
703 {
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
704 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
705 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
706 decoder.reset(new DJLSLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
707 break;
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
708
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
709 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
710 LOG(INFO) << "Decoding a JPEG-LS near-lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
711 decoder.reset(new DJLSNearLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
712 break;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
713
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
714 default:
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
715 throw OrthancException(ErrorCode_InternalError);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
716 }
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
717
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
718 return ApplyCodec(*decoder, parameters, representationParameter, dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
719 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
720 #endif
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
721
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
722
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
723 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
724 /**
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
725 * 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
726 **/
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
727
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
728 if (syntax == EXS_JPEGProcess1 || // DJDecoderBaseline
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
729 syntax == EXS_JPEGProcess2_4 || // DJDecoderExtended
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
730 syntax == EXS_JPEGProcess6_8 || // DJDecoderSpectralSelection (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
731 syntax == EXS_JPEGProcess10_12 || // DJDecoderProgressive (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
732 syntax == EXS_JPEGProcess14 || // DJDecoderLossless
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
733 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
734 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
735 // 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
736 DJCodecParameter parameters(
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
737 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
738 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
739 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
740 EPC_default); // Automatically determine whether color-by-plane is required from the SOP Class UID and decompressed photometric interpretation
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
741 DJ_RPLossy representationParameter;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
742 std::unique_ptr<DJCodecDecoder> decoder;
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
743
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
744 switch (syntax)
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
745 {
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
746 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
747 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
748 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
749 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
750
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
751 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
752 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
753 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
754 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
755
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
756 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
757 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
758 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
759 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
760
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
761 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
762 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
763 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
764 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
765
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
766 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
767 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
768 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
769 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
770
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
771 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
772 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
773 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
774 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
775
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
776 default:
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
777 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
778 }
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
779
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
780 return ApplyCodec(*decoder, parameters, representationParameter, dataset, frame);
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
781 }
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
782 #endif
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
783
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
784
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
785 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
786 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
787 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
788 DcmRLECodecParameter parameters;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
789 DcmRLECodecDecoder decoder;
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
790 DcmRLERepresentationParameter representationParameter;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
791 return ApplyCodec(decoder, parameters, representationParameter, dataset, frame);
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
792 }
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
793
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
794
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
795 /**
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
796 * 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
797 * 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
798 * 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
799 * 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
800 * second example of the following page:
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
801 * 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
802 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
803
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
804 {
3932
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
805 LOG(INFO) << "Trying to decode a compressed image by transcoding it to Little Endian Explicit";
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
806
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
807 std::unique_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone()));
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
808 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
809
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
810 if (converted->canWriteXfer(EXS_LittleEndianExplicit))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
811 {
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
812 return DecodeUncompressedImage(*converted, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
813 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
814 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
815
3932
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
816 DicomTransferSyntax s;
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
817 if (FromDcmtkBridge::LookupOrthancTransferSyntax(s, dataset.getCurrentXfer()))
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
818 {
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
819 throw OrthancException(ErrorCode_NotImplemented,
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
820 "The built-in DCMTK decoder cannot decode some DICOM instance "
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
821 "whose transfer syntax is: " + std::string(GetTransferSyntaxUid(s)));
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
822 }
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
823 else
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
824 {
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
825 throw OrthancException(ErrorCode_NotImplemented,
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
826 "The built-in DCMTK decoder cannot decode some DICOM instance");
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
827 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
828 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
829
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
830
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
831 static bool IsColorImage(PixelFormat format)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
832 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
833 return (format == PixelFormat_RGB24 ||
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
834 format == PixelFormat_RGBA32);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
835 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
836
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
837
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
838 bool DicomImageDecoder::TruncateDecodedImage(std::unique_ptr<ImageAccessor>& image,
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
839 PixelFormat format,
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
840 bool allowColorConversion)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
841 {
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
842 // If specified, prevent the conversion between color and
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
843 // grayscale images
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
844 bool isSourceColor = IsColorImage(image->GetFormat());
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
845 bool isTargetColor = IsColorImage(format);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
846
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
847 if (!allowColorConversion)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
848 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
849 if (isSourceColor ^ isTargetColor)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
850 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
851 return false;
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
852 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
853 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
854
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
855 if (image->GetFormat() != format)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
856 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
857 // A conversion is required
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
858 std::unique_ptr<ImageAccessor> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
859 (new Image(format, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
860 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
861
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
862 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
863 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
864 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
865 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
866 #endif
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
867 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
868
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
869 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
870 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
871
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
872
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
873 bool DicomImageDecoder::PreviewDecodedImage(std::unique_ptr<ImageAccessor>& image)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
874 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
875 switch (image->GetFormat())
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
876 {
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
877 case PixelFormat_RGB24:
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
878 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
879 // Directly return color images without modification (RGB)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
880 return true;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
881 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
882
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
883 case PixelFormat_RGB48:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
884 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
885 std::unique_ptr<ImageAccessor> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
886 (new Image(PixelFormat_RGB24, image->GetWidth(), image->GetHeight(), false));
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
887 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
888
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
889 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
890 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
891 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
892 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
893 #endif
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
894
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
895 return true;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
896 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
897
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
898 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
899 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
900 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
901 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
902 // 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
903 int64_t a, b;
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
904 ImageProcessing::GetMinMaxIntegerValue(a, b, *image);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
905
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
906 if (a == b)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
907 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
908 ImageProcessing::Set(*image, 0);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
909 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
910 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
911 {
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
912 ImageProcessing::ShiftScale(*image, static_cast<float>(-a),
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
913 255.0f / static_cast<float>(b - a),
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
914 true /* TODO - Consider using "false" to speed up */);
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
915 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
916
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
917 // If the source image is not grayscale 8bpp, convert it
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
918 if (image->GetFormat() != PixelFormat_Grayscale8)
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
919 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
920 std::unique_ptr<ImageAccessor> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
921 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
922 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
923
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
924 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
925 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
926 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
927 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
928 #endif
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
929 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
930
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
931 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
932 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
933
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
934 default:
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
935 throw OrthancException(ErrorCode_NotImplemented);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
936 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
937 }
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
938
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
939
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
940 void DicomImageDecoder::ApplyExtractionMode(std::unique_ptr<ImageAccessor>& image,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
941 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
942 bool invert)
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
943 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
944 if (image.get() == NULL)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
945 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
946 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
947 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
948
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
949 bool ok = false;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
950
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
951 switch (mode)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
952 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
953 case ImageExtractionMode_UInt8:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
954 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
955 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
956
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
957 case ImageExtractionMode_UInt16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
958 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
959 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
960
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
961 case ImageExtractionMode_Int16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
962 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
963 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
964
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
965 case ImageExtractionMode_Preview:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
966 ok = PreviewDecodedImage(image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
967 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
968
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
969 default:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
970 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
971 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
972
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
973 if (ok)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
974 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
975 assert(image.get() != NULL);
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
976
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
977 if (invert)
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
978 {
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
979 Orthanc::ImageProcessing::Invert(*image);
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
980 }
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
981 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
982 else
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
983 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
984 throw OrthancException(ErrorCode_NotImplemented);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
985 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
986 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
987
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
988
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
989 void DicomImageDecoder::ExtractPamImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
990 std::unique_ptr<ImageAccessor>& image,
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
991 ImageExtractionMode mode,
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
992 bool invert)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
993 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
994 ApplyExtractionMode(image, mode, invert);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
995
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
996 PamWriter writer;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
997 writer.WriteToMemory(result, *image);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
998 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
999
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1000 #if ORTHANC_ENABLE_PNG == 1
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1001 void DicomImageDecoder::ExtractPngImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1002 std::unique_ptr<ImageAccessor>& image,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1003 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1004 bool invert)
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1005 {
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1006 ApplyExtractionMode(image, mode, invert);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1007
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1008 PngWriter writer;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1009 writer.WriteToMemory(result, *image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1010 }
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1011 #endif
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1012
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1013
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1014 #if ORTHANC_ENABLE_JPEG == 1
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1015 void DicomImageDecoder::ExtractJpegImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1016 std::unique_ptr<ImageAccessor>& image,
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1017 ImageExtractionMode mode,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1018 bool invert,
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1019 uint8_t quality)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1020 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1021 if (mode != ImageExtractionMode_UInt8 &&
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1022 mode != ImageExtractionMode_Preview)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1023 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1024 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1025 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1026
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1027 ApplyExtractionMode(image, mode, invert);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1028
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1029 JpegWriter writer;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1030 writer.SetQuality(quality);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1031 writer.WriteToMemory(result, *image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1032 }
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1033 #endif
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 }