annotate OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp @ 5649:4a2bfda999c6

todo
author Alain Mazy <am@orthanc.team>
date Mon, 03 Jun 2024 14:30:30 +0200
parents f7adfb22e20e
children 078b724dcbf8
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5283
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * 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
10 * 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
11 * 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
12 * the License, or (at your option) any later version.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * Lesser General Public License for more details.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
25 #include "../../PrecompiledHeaders.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "DicomImageDecoder.h"
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
28 #include "../ParsedDicomFile.h"
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
29
846
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 /*=========================================================================
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
32
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
33 This file is based on portions of the following project
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
34 (cf. function "DecodePsmctRle1()"):
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
35
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
36 Program: GDCM (Grassroots DICOM). A DICOM library
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
37 Module: http://gdcm.sourceforge.net/Copyright.html
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
38
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
39 Copyright (c) 2006-2011 Mathieu Malaterre
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
40 Copyright (c) 1993-2005 CREATIS
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
41 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
42 All rights reserved.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
43
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
44 Redistribution and use in source and binary forms, with or without
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
45 modification, are permitted provided that the following conditions are met:
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
46
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
47 * Redistributions of source code must retain the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
48 this list of conditions and the following disclaimer.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
49
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
50 * Redistributions in binary form must reproduce the above copyright notice,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
51 this list of conditions and the following disclaimer in the documentation
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
52 and/or other materials provided with the distribution.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
53
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
54 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
55 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
56 endorse or promote products derived from this software without specific
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
57 prior written permission.
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
58
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
59 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
60 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
61 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
62 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
63 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
64 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
65 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
66 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
67 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
68 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
69
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
70 =========================================================================*/
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
71
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
72
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
73 #include "../../Logging.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
74 #include "../../OrthancException.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
75 #include "../../Images/Image.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
76 #include "../../Images/ImageProcessing.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
77 #include "../../DicomFormat/DicomIntegerPixelAccessor.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #include "../ToDcmtkBridge.h"
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
79 #include "../FromDcmtkBridge.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
81 #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
82 # include "../../Images/PngWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
83 #endif
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
84
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
85 #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
86 # include "../../Images/JpegWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
87 #endif
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
88 #include "../../Images/PamWriter.h"
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
89
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
90 #include <boost/lexical_cast.hpp>
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
91
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
92 #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
93 #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
94 #include <dcmtk/dcmdata/dcrlecp.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
95 #include <dcmtk/dcmdata/dcrlerp.h>
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
96 #include <dcmtk/dcmdata/dcswap.h>
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
97
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
98 #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
99 # include <dcmtk/dcmjpeg/djrplol.h>
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
100 # include <dcmtk/dcmjpls/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
101 # include <dcmtk/dcmjpls/djcparam.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
102 # include <dcmtk/dcmjpls/djrparam.h>
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #endif
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
105 #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
106 # include <dcmtk/dcmjpeg/djcodecd.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
107 # include <dcmtk/dcmjpeg/djcparam.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
108 # include <dcmtk/dcmjpeg/djdecbas.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
109 # include <dcmtk/dcmjpeg/djdecext.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
110 # include <dcmtk/dcmjpeg/djdeclol.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
111 # include <dcmtk/dcmjpeg/djdecpro.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
112 # include <dcmtk/dcmjpeg/djdecsps.h>
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
113 # include <dcmtk/dcmjpeg/djdecsv1.h>
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
114 # 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
115 #endif
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
116
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
117 #if DCMTK_VERSION_NUMBER <= 360
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
118 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
119 # 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
120 # 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
121 # 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
122 # define EXS_JPEGProcess14 EXS_JPEGProcess14TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
123 # define EXS_JPEGProcess14SV1 EXS_JPEGProcess14SV1TransferSyntax
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
124 #endif
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 namespace Orthanc
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
128 static const Endianness ENDIANNESS = Toolbox::DetectEndianness();
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
129 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
130 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
131
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
132
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
133 bool DicomImageDecoder::IsPsmctRle1(DcmDataset& dataset)
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
134 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
135 DcmElement* e;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
136 char* c;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
137
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
138 // Check whether the DICOM instance contains an image encoded with
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
139 // the PMSCT_RLE1 scheme.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
140 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_COMPRESSION_TYPE), e).good() ||
4184
dbd74fa2f446 Enable the access to raw frames in Philips ELSCINT1 proprietary compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4138
diff changeset
141 !dataset.tagExistsWithValue(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT)) || // New in Orthanc 1.7.4
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
142 e == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
143 !e->isaString() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
144 !e->getString(c).good() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
145 c == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
146 strcmp("PMSCT_RLE1", c))
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
147 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
148 return false;
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 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
151 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
152 return true;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
153 }
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
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
156
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
157 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
158 DcmDataset& dataset)
846
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
159 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
160 // Check whether the DICOM instance contains an image encoded with
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
161 // the PMSCT_RLE1 scheme.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
162 if (!IsPsmctRle1(dataset))
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
163 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
164 return false;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
165 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
166
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
167 // OK, this is a custom RLE encoding from Philips. Get the pixel
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
168 // data from the appropriate private DICOM tag.
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
169 Uint8* pixData = NULL;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
170 DcmElement* e;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
171 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT), e).good() ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
172 e == NULL ||
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
173 e->getUint8Array(pixData) != EC_Normal)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
174 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
175 return false;
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 "unsigned" below IS VERY IMPORTANT
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
179 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
180 const size_t length = e->getLength();
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 * 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
184 * Mathieu Malaterre (under a BSD license).
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
185 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
186 **/
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 // RLE pass
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
189 std::vector<uint8_t> temp;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
190 temp.reserve(length);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
191 for (size_t i = 0; i < length; i++)
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 if (inbuffer[i] == 0xa5)
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 temp.push_back(inbuffer[i+2]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
196 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
197 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
198 temp.push_back(inbuffer[i+2]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
199 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
200 i += 2;
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 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
203 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
204 temp.push_back(inbuffer[i]);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
205 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
206 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
207
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
208 // Delta encoding pass
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
209 uint16_t delta = 0;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
210 output.clear();
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
211 output.reserve(temp.size());
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
212 for (size_t i = 0; i < temp.size(); i++)
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
213 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
214 uint16_t value;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
215
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
216 if (temp[i] == 0x5a)
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 uint16_t v1 = temp[i + 1];
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
219 uint16_t v2 = temp[i + 2];
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
220 value = (v2 << 8) + v1;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
221 i += 2;
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 else
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
224 {
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
225 value = delta + (int8_t) temp[i];
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 output.push_back(value & 0xff);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
229 output.push_back(value >> 8);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
230 delta = value;
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 if (output.size() % 2)
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 output.resize(output.size() - 1);
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
236 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
237
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
238 return true;
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
239 }
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
240
715ab7674993 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 845
diff changeset
241
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
242 class DicomImageDecoder::ImageSource
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
243 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
244 private:
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
245 std::string psmct_;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
246 std::unique_ptr<DicomIntegerPixelAccessor> slowAccessor_;
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
247
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
248 public:
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
249 void Setup(DcmDataset& dataset,
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
250 unsigned int frame)
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 psmct_.clear();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
253 slowAccessor_.reset(NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
254
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
255 // 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
256
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
257 DicomMap m;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
258 std::set<DicomTag> ignoreTagLength;
4312
6d49e3b6ff77 fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
259 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength);
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
260
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
261 /**
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
262 * 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
263 **/
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
264
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
265 DcmElement* e;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
266 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
267 e != NULL)
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 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
270 if (e->getUint8Array(pixData) == EC_Normal)
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 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength()));
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
273 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
274 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
275 else if (DecodePsmctRle1(psmct_, dataset))
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
276 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
277 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded";
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
278 Uint8* pixData = NULL;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
279 if (psmct_.size() > 0)
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 pixData = reinterpret_cast<Uint8*>(&psmct_[0]);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
282 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
283
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
284 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size()));
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 if (slowAccessor_.get() == NULL)
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 throw OrthancException(ErrorCode_BadFileFormat);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
290 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
291
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
292 slowAccessor_->SetCurrentFrame(frame);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
293 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
294
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
295 unsigned int GetWidth() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
296 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
297 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
298 return slowAccessor_->GetInformation().GetWidth();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
299 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
300
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
301 unsigned int GetHeight() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
302 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
303 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
304 return slowAccessor_->GetInformation().GetHeight();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
305 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
306
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
307 unsigned int GetChannelCount() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
308 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
309 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
310 return slowAccessor_->GetInformation().GetChannelCount();
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
311 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
312
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
313 const DicomIntegerPixelAccessor& GetAccessor() const
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
314 {
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
315 assert(slowAccessor_.get() != NULL);
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
316 return *slowAccessor_;
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
317 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
318
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
319 unsigned int GetSize() const
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
320 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
321 assert(slowAccessor_.get() != NULL);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
322 return slowAccessor_->GetSize();
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
323 }
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
324 };
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
325
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
326
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
327 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
328 bool ignorePhotometricInterpretation)
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
330 DicomMap m;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
331 std::set<DicomTag> ignoreTagLength;
4312
6d49e3b6ff77 fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
332 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength);
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 DicomImageInformation info(m);
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
335 PixelFormat format;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
336
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
337 if (!info.ExtractPixelFormat(format, ignorePhotometricInterpretation))
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
339 LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored()
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
340 << "bpp, " << info.GetChannelCount() << " channels, "
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
341 << (info.IsSigned() ? "signed" : "unsigned")
1206
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
342 << (info.IsPlanar() ? ", planar, " : ", non-planar, ")
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
343 << EnumerationToString(info.GetPhotometricInterpretation())
f5b0207967bc Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
344 << " photometric interpretation";
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 throw OrthancException(ErrorCode_NotImplemented);
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 863
diff changeset
347
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1944
diff changeset
348 return new Image(format, info.GetWidth(), info.GetHeight(), false);
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
352 template <typename PixelType>
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
353 static void CopyPixels(ImageAccessor& target,
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
354 const DicomIntegerPixelAccessor& source)
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
355 {
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
356 // 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
357 // 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
358 const PixelType minValue = std::numeric_limits<PixelType>::min();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
359 const PixelType maxValue = std::numeric_limits<PixelType>::max();
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
360
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
361 const unsigned int height = source.GetInformation().GetHeight();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
362 const unsigned int width = source.GetInformation().GetWidth();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
363 const unsigned int channels = source.GetInformation().GetChannelCount();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
364
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
365 for (unsigned int y = 0; y < height; y++)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
366 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
367 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y));
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
368 for (unsigned int x = 0; x < width; x++)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
369 {
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
370 for (unsigned int c = 0; c < channels; c++, pixel++)
847
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 int32_t v = source.GetValue(x, y, c);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
373 if (v < static_cast<int32_t>(minValue))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
374 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
375 *pixel = minValue;
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 else if (v > static_cast<int32_t>(maxValue))
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 *pixel = maxValue;
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 else
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
382 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
383 *pixel = static_cast<PixelType>(v);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
384 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
385 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
386 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
387 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
388 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
389
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
390
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
391 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
392 const DicomImageInformation& info,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
393 DcmDataset& dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
394 const uint8_t* pixelData,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
395 unsigned long pixelLength)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
396 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
397 LOG(INFO) << "Decoding a lookup table";
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 OFString r, g, b;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
400 PixelFormat format;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
401 const uint16_t* lutRed = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
402 const uint16_t* lutGreen = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
403 const uint16_t* lutBlue = NULL;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
404 unsigned long rc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
405 unsigned long gc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
406 unsigned long bc = 0;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
407
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
408 if (pixelData == NULL &&
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
409 !dataset.findAndGetUint8Array(DCM_PixelData, pixelData, &pixelLength).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
410 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
411 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
412 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
413
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
414 if (info.IsPlanar() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
415 info.GetNumberOfFrames() != 1 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
416 !info.ExtractPixelFormat(format, false) ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
417 !dataset.findAndGetOFStringArray(DCM_BluePaletteColorLookupTableDescriptor, b).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
418 !dataset.findAndGetOFStringArray(DCM_GreenPaletteColorLookupTableDescriptor, g).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
419 !dataset.findAndGetOFStringArray(DCM_RedPaletteColorLookupTableDescriptor, r).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
420 !dataset.findAndGetUint16Array(DCM_BluePaletteColorLookupTableData, lutBlue, &bc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
421 !dataset.findAndGetUint16Array(DCM_GreenPaletteColorLookupTableData, lutGreen, &gc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
422 !dataset.findAndGetUint16Array(DCM_RedPaletteColorLookupTableData, lutRed, &rc).good() ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
423 r != g ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
424 r != b ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
425 g != b ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
426 lutRed == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
427 lutGreen == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
428 lutBlue == NULL ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
429 pixelData == NULL)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
430 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
431 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
432 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
433
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
434 switch (format)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
435 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
436 case PixelFormat_RGB24:
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 if (r != "256\\0\\16" ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
439 rc != 256 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
440 gc != 256 ||
4975
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
441 bc != 256)
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
442 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
443 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
444 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
445
4975
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
446 if (pixelLength != target->GetWidth() * target->GetHeight())
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
447 {
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
448 DcmElement *elem;
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
449 Uint16 bitsAllocated = 0;
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
450
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
451 if (!dataset.findAndGetUint16(DCM_BitsAllocated, bitsAllocated).good())
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
452 {
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
453 throw OrthancException(ErrorCode_NotImplemented);
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
454 }
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
455
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
456 if (!dataset.findAndGetElement(DCM_PixelData, elem).good())
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
457 {
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
458 throw OrthancException(ErrorCode_NotImplemented);
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
459 }
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
460
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
461 // In implicit VR files, pixelLength is expressed in words (OW) although pixels can actually be 8 bits
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
462 // -> pixelLength is wrong by a factor of two and the image can still be decoded!
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
463 // seen in some Philips ClearVue 650 images (using 8 bits LUT)
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
464 if (!(elem->getVR() == EVR_OW && bitsAllocated == 8 && (2*pixelLength == target->GetWidth() * target->GetHeight())))
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
465 {
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
466 throw OrthancException(ErrorCode_NotImplemented);
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
467 }
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
468 }
5e7404f23fa8 Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents: 4902
diff changeset
469
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
470 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData);
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
471 const unsigned int width = target->GetWidth();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
472 const unsigned int height = target->GetHeight();
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
473
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
474 for (unsigned int y = 0; y < height; y++)
2423
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 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
477
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
478 for (unsigned int x = 0; x < width; x++)
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
479 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
480 p[0] = lutRed[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
481 p[1] = lutGreen[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
482 p[2] = lutBlue[*source] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
483 source++;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
484 p += 3;
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
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
488 return target.release();
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 case PixelFormat_RGB48:
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 if (r != "0\\0\\16" ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
494 rc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
495 gc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
496 bc != 65536 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
497 pixelLength != 2 * target->GetWidth() * target->GetHeight())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
498 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
499 throw OrthancException(ErrorCode_NotImplemented);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
500 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
501
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
502 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData);
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
503 const unsigned int width = target->GetWidth();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
504 const unsigned int height = target->GetHeight();
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
505
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
506 for (unsigned int y = 0; y < height; y++)
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
507 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
508 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
509
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
510 for (unsigned int x = 0; x < width; x++)
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
511 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
512 p[0] = lutRed[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
513 p[1] = lutGreen[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
514 p[2] = lutBlue[*source];
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
515 source++;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
516 p += 3;
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 }
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 return target.release();
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
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
523 default:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
524 break;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
525 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
526
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
527 throw OrthancException(ErrorCode_InternalError);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
528 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
529
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
530
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
531 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
532 unsigned int frame)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
533 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
534 /**
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
535 * Create the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
536 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
537
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
538 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
539
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
540 ImageSource source;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
541 source.Setup(dataset, frame);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
542
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
543 if (source.GetWidth() != target->GetWidth() ||
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
544 source.GetHeight() != target->GetHeight())
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
545 {
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
546 throw OrthancException(ErrorCode_InternalError);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
547 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
548
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
549
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
550 /**
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
551 * Deal with lookup tables
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
552 **/
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
553
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
554 const DicomImageInformation& info = source.GetAccessor().GetInformation();
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
555
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
556 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
557 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
558 return DecodeLookupTable(target, info, dataset, NULL, 0);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
559 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
560
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
561
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
562 /**
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
563 * 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
564 * direct access to copy its values.
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
565 **/
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
566
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
567 bool fastVersionSuccess = false;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
568 PixelFormat sourceFormat;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
569 if (!info.IsPlanar() &&
4902
df86d2505df8 Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
570 info.GetBitsStored() != 1 && // Black-and-white image, notably DICOM SEG (new in Orthanc 1.10.0)
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
571 info.ExtractPixelFormat(sourceFormat, false))
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
572 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
573 try
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
574 {
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
575 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
576 if ((frame + 1) * frameSize <= source.GetSize())
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
577 {
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
578 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
579
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
580 ImageAccessor sourceImage;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
581 sourceImage.AssignReadOnly(sourceFormat,
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
582 info.GetWidth(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
583 info.GetHeight(),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
584 info.GetWidth() * GetBytesPerPixel(sourceFormat),
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
585 buffer + frame * frameSize);
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
586
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
587 switch (ENDIANNESS)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
588 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
589 case Endianness_Little:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
590 ImageProcessing::Convert(*target, sourceImage);
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
591 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
592
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
593 case Endianness_Big:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
594 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
595 // We cannot do byte swapping directly on the constant DcmDataset
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
596 std::unique_ptr<ImageAccessor> copy(Image::Clone(sourceImage));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
597 ImageProcessing::SwapEndianness(*copy);
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
598 ImageProcessing::Convert(*target, *copy);
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
599 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
600 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
601
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
602 default:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
603 throw OrthancException(ErrorCode_InternalError);
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
604 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
605
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
606 ImageProcessing::ShiftRight(*target, info.GetShift());
1190
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
607 fastVersionSuccess = true;
851a55d183c9 fix issue 22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
608 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
609 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
610 catch (OrthancException&)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
611 {
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
612 // Unsupported conversion, use the slow version
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
613 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
614 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
615
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
616 /**
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
617 * Slow version : loop over the DICOM buffer, storing its value
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
618 * into the target image.
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
619 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
620
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
621 if (!fastVersionSuccess)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
622 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
623 switch (target->GetFormat())
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
624 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
625 case PixelFormat_RGB24:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
626 case PixelFormat_RGBA32:
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
627 case PixelFormat_Grayscale8:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
628 CopyPixels<uint8_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
629 break;
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 859
diff changeset
630
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
631 case PixelFormat_Grayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
632 CopyPixels<uint16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
633 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
634
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
635 case PixelFormat_SignedGrayscale16:
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
636 CopyPixels<int16_t>(*target, source.GetAccessor());
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
637 break;
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
638
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
639 default:
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
640 throw OrthancException(ErrorCode_InternalError);
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
641 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
642 }
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
643
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
644 return target.release();
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
645 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
646
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
647
5129
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
648 static ImageAccessor* DecodePlanarConfiguration(const ImageAccessor& source)
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
649 {
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
650 /**
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
651 * This function will interleave the RGB channels, if the source
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
652 * DICOM image has the "Planar Configuration" (0028,0006) tag that
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
653 * equals 1. This process was not applied to images using the RLE
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
654 * codec, which led to the following issue:
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
655 * https://groups.google.com/g/orthanc-users/c/CSVWfRasSR0/m/y1XDRXVnAgAJ
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
656 **/
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
657
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
658 const unsigned int height = source.GetHeight();
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
659 const unsigned int width = source.GetWidth();
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
660 const size_t size = static_cast<size_t>(height) * static_cast<size_t>(width);
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
661
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
662 if (source.GetFormat() != PixelFormat_RGB24 ||
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
663 3 * width != source.GetPitch())
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
664 {
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
665 throw OrthancException(ErrorCode_NotImplemented);
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
666 }
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
667
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
668 std::unique_ptr<ImageAccessor> target(new Image(PixelFormat_RGB24, width, height, false));
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
669
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
670 const uint8_t* red = reinterpret_cast<const uint8_t*>(source.GetConstBuffer());
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
671 const uint8_t* green = red + size;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
672 const uint8_t* blue = red + 2 * size;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
673
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
674 for (unsigned int y = 0; y < height; y++)
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
675 {
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
676 uint8_t* interleaved = reinterpret_cast<uint8_t*>(target->GetRow(y));
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
677 for (unsigned int x = 0; x < width; x++)
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
678 {
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
679 interleaved[0] = *red;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
680 interleaved[1] = *green;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
681 interleaved[2] = *blue;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
682 interleaved += 3;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
683 red++;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
684 green++;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
685 blue++;
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
686 }
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
687 }
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
688
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
689 return target.release();
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
690 }
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
691
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
692
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
693 ImageAccessor* DicomImageDecoder::ApplyCodec
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
694 (const DcmCodec& codec,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
695 const DcmCodecParameter& parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
696 const DcmRepresentationParameter& representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
697 DcmDataset& dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
698 unsigned int frame)
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
699 {
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
700 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
701 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
702 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
703 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
704 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
705
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
706 DicomMap m;
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
707 std::set<DicomTag> ignoreTagLength;
4312
6d49e3b6ff77 fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
708 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength);
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
709 DicomImageInformation info(m);
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
710
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
711 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, true));
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 Uint32 startFragment = 0; // Default
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 OFString decompressedColorModel; // Out
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
715
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
716 OFCondition c;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
717
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
718 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette &&
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
719 info.GetChannelCount() == 1)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
720 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
721 std::string uncompressed;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
722 uncompressed.resize(info.GetWidth() * info.GetHeight() * info.GetBytesPerValue());
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
724 if (uncompressed.size() == 0 ||
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
725 !codec.decodeFrame(&representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
726 pixelSequence, &parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
727 &dataset, frame, startFragment, &uncompressed[0],
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
728 uncompressed.size(), decompressedColorModel).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
729 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
730 throw OrthancException(ErrorCode_BadFileFormat,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
731 "Cannot decode a palette image");
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
732 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
733
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
734 return DecodeLookupTable(target, info, dataset,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
735 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
736 uncompressed.size());
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 }
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
738 else
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
739 {
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
740 if (!codec.decodeFrame(&representationParameter,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
741 pixelSequence, &parameters,
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
742 &dataset, frame, startFragment, target->GetBuffer(),
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
743 target->GetSize(), decompressedColorModel).good())
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
744 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
745 throw OrthancException(ErrorCode_BadFileFormat,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
746 "Cannot decode a non-palette image");
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
747 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
748
5283
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
749 std::string colorModel = Orthanc::Toolbox::StripSpaces(decompressedColorModel.c_str());
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
750
5129
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
751 if (target->GetFormat() == PixelFormat_RGB24 &&
5283
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
752 (colorModel == "RGB" || colorModel == "YBR_FULL") &&
5129
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
753 info.IsPlanar())
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
754 {
5283
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
755 std::unique_ptr<ImageAccessor> output(DecodePlanarConfiguration(*target));
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
756
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
757 if (colorModel == "YBR_FULL")
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
758 {
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
759 ImageProcessing::ConvertJpegYCbCrToRgb(*output);
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
760 }
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
761
57c0fba5e5c7 fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
762 return output.release();
5129
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
763 }
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
764 else
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
765 {
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
766 return target.release();
16138d6d568d fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4975
diff changeset
767 }
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
768 }
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
770
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
771
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
772 static void UndoBigEndianSwapping(ImageAccessor& decoded)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
773 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
774 if (ENDIANNESS == Endianness_Big &&
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
775 decoded.GetFormat() == PixelFormat_Grayscale8)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
776 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
777 /**
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
778 * Undo the call to "swapIfNecessary()" that is done in
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
779 * "dcmjpeg/libsrc/djcodecd.cc" and "dcmjpls/libsrc/djcodecd.cc"
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
780 * if "jpeg->bytesPerSample() == 1", presumably because DCMTK
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
781 * plans for DICOM-to-DICOM conversion
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
782 **/
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
783 if (decoded.GetPitch() % 2 == 0)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
784 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
785 swapBytes(decoded.GetBuffer(), decoded.GetPitch() * decoded.GetHeight(), sizeof(uint16_t));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
786 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
787 else
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
788 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
789 throw OrthancException(ErrorCode_InternalError, "Cannot swap the bytes of an image that has an odd width");
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
790 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
791 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
792 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
793
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
794
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
795 ImageAccessor* DicomImageDecoder::Decode(DcmDataset& dataset,
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
796 unsigned int frame)
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
797 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
798 E_TransferSyntax syntax = dataset.getCurrentXfer();
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
799
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
800 /**
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
801 * Deal with uncompressed, raw images.
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
802 * http://support.dcmtk.org/docs/dcxfer_8h-source.html
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
803 **/
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
804 if (syntax == EXS_Unknown ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
805 syntax == EXS_LittleEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
806 syntax == EXS_BigEndianImplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
807 syntax == EXS_LittleEndianExplicit ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
808 syntax == EXS_BigEndianExplicit)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
809 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
810 return DecodeUncompressedImage(dataset, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
811 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
812
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
813
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
814 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
815 /**
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
816 * Deal with JPEG-LS images.
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
817 **/
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
818
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
819 if (syntax == EXS_JPEGLSLossless ||
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
820 syntax == EXS_JPEGLSLossy)
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
821 {
2430
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
822 // 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
823 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
824 DJLSRepresentationParameter representationParameter(2, OFTrue);
a6fab385b89e fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
825
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
826 DJLSCodecParameter parameters;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
827 std::unique_ptr<DJLSDecoderBase> decoder;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
828
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
829 switch (syntax)
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
830 {
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
831 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
832 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
833 decoder.reset(new DJLSLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
834 break;
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
835
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
836 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
837 LOG(INFO) << "Decoding a JPEG-LS near-lossless DICOM image";
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
838 decoder.reset(new DJLSNearLosslessDecoder);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
839 break;
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
840
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
841 default:
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
842 throw OrthancException(ErrorCode_InternalError);
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
843 }
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
844
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
845 std::unique_ptr<ImageAccessor> result(ApplyCodec(*decoder, parameters, representationParameter, dataset, frame));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
846 UndoBigEndianSwapping(*result); // New in Orthanc 1.9.1 to decode on big-endian architectures
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
847 return result.release();
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
848 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
849 #endif
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
850
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
851
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
852 #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
853 /**
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
854 * 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
855 **/
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
856
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
857 if (syntax == EXS_JPEGProcess1 || // DJDecoderBaseline
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
858 syntax == EXS_JPEGProcess2_4 || // DJDecoderExtended
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
859 syntax == EXS_JPEGProcess6_8 || // DJDecoderSpectralSelection (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
860 syntax == EXS_JPEGProcess10_12 || // DJDecoderProgressive (retired)
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
861 syntax == EXS_JPEGProcess14 || // DJDecoderLossless
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
862 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
863 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
864 // 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
865 DJCodecParameter parameters(
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
866 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
867 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
868 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
869 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
870 DJ_RPLossy representationParameter;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
871 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
872
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
873 switch (syntax)
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
874 {
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
875 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
876 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
877 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
878 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
879
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
880 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
881 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
882 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
883 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
884
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
885 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
886 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
887 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
888 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
889
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
890 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
891 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
892 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
893 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
894
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
895 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
896 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
897 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
898 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
899
1944
1a5e070a21c3 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
900 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
901 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
902 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
903 break;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
904
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
905 default:
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
906 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
907 }
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
908
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
909 std::unique_ptr<ImageAccessor> result(ApplyCodec(*decoder, parameters, representationParameter, dataset, frame));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
910 UndoBigEndianSwapping(*result); // New in Orthanc 1.9.1 to decode on big-endian architectures
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
911 return result.release();
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
912 }
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
913 #endif
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 851
diff changeset
914
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
915
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
916 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
917 {
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
918 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
919 DcmRLECodecParameter parameters;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1904
diff changeset
920 DcmRLECodecDecoder decoder;
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
921 DcmRLERepresentationParameter representationParameter;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
922 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
923 }
1904
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
924
4be8accf8768 clarifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
925
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
926 /**
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
927 * 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
928 * 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
929 * 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
930 * 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
931 * second example of the following page:
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
932 * 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
933 **/
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
934
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
935 {
3932
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
936 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
937
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
938 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
939 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
940
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
941 if (converted->canWriteXfer(EXS_LittleEndianExplicit))
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
942 {
1903
554ec8422ec5 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
943 return DecodeUncompressedImage(*converted, frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
944 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
945 }
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
946
3932
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
947 DicomTransferSyntax s;
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
948 if (FromDcmtkBridge::LookupOrthancTransferSyntax(s, dataset.getCurrentXfer()))
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
949 {
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
950 throw OrthancException(ErrorCode_NotImplemented,
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
951 "The built-in DCMTK decoder cannot decode some DICOM instance "
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
952 "whose transfer syntax is: " + std::string(GetTransferSyntaxUid(s)));
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
953 }
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
954 else
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
955 {
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
956 throw OrthancException(ErrorCode_NotImplemented,
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
957 "The built-in DCMTK decoder cannot decode some DICOM instance");
bf46e10de8ae clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3883
diff changeset
958 }
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
959 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
960
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
961
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
962 static bool IsColorImage(PixelFormat format)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
963 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
964 return (format == PixelFormat_RGB24 ||
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
965 format == PixelFormat_RGBA32);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
966 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
967
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
968
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
969 bool DicomImageDecoder::TruncateDecodedImage(std::unique_ptr<ImageAccessor>& image,
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
970 PixelFormat format,
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
971 bool allowColorConversion)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
972 {
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
973 // If specified, prevent the conversion between color and
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
974 // grayscale images
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
975 bool isSourceColor = IsColorImage(image->GetFormat());
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
976 bool isTargetColor = IsColorImage(format);
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
977
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
978 if (!allowColorConversion)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
979 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
980 if (isSourceColor ^ isTargetColor)
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
981 {
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
982 return false;
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
983 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
984 }
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
985
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
986 if (image->GetFormat() != format)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
987 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
988 // A conversion is required
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
989 std::unique_ptr<ImageAccessor> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
990 (new Image(format, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
991 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
992
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
993 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
994 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
995 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
996 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
997 #endif
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
998 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
999
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1000 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1001 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1002
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1003
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1004 bool DicomImageDecoder::PreviewDecodedImage(std::unique_ptr<ImageAccessor>& image)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1005 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1006 switch (image->GetFormat())
861
a546b05a43da fix PngWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 860
diff changeset
1007 {
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1008 case PixelFormat_RGB24:
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1009 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1010 // Directly return color images without modification (RGB)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1011 return true;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1012 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1013
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1014 case PixelFormat_RGB48:
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1015 {
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> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1017 (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
1018 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1019
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1020 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1021 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1022 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1023 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1024 #endif
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1025
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1026 return true;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1027 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1028
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1029 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1030 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1031 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1032 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1033 // 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
1034 int64_t a, b;
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1035 ImageProcessing::GetMinMaxIntegerValue(a, b, *image);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1036
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1037 if (a == b)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1038 {
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1039 ImageProcessing::Set(*image, 0);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1040 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1041 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1042 {
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1043 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
1044 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
1045 true /* TODO - Consider using "false" to speed up */);
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1046 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1047
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1048 // If the source image is not grayscale 8bpp, convert it
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1049 if (image->GetFormat() != PixelFormat_Grayscale8)
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1050 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1051 std::unique_ptr<ImageAccessor> target
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1052 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false));
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1053 ImageProcessing::Convert(*target, *image);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1054
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1055 #if __cplusplus < 201103L
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1056 image.reset(target.release());
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1057 #else
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1058 image = std::move(target);
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1059 #endif
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1060 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1061
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1062 return true;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1063 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 861
diff changeset
1064
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1065 default:
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1066 throw OrthancException(ErrorCode_NotImplemented);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1067 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 858
diff changeset
1068 }
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1069
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1070
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1071 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
1072 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1073 bool invert)
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1074 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1075 if (image.get() == NULL)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1076 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1077 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1078 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1079
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1080 bool ok = false;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1081
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1082 switch (mode)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1083 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1084 case ImageExtractionMode_UInt8:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1085 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
1086 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1087
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1088 case ImageExtractionMode_UInt16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1089 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
1090 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1091
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1092 case ImageExtractionMode_Int16:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1093 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
1094 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1095
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1096 case ImageExtractionMode_Preview:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1097 ok = PreviewDecodedImage(image);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1098 break;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1099
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1100 default:
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1101 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1102 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1103
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1104 if (ok)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1105 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1106 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
1107
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1108 if (invert)
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1109 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1110 ImageProcessing::Invert(*image);
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1111 }
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1112 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1113 else
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1114 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1115 throw OrthancException(ErrorCode_NotImplemented);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1116 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1117 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1118
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1119
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1120 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
1121 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
1122 ImageExtractionMode mode,
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1123 bool invert)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1124 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1125 ApplyExtractionMode(image, mode, invert);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1126
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1127 PamWriter writer;
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1128 IImageWriter::WriteToMemory(writer, result, *image);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1129 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2488
diff changeset
1130
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1131 #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
1132 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
1133 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
1134 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1135 bool invert)
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1136 {
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1137 ApplyExtractionMode(image, mode, invert);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1138
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1139 PngWriter writer;
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1140 IImageWriter::WriteToMemory(writer, result, *image);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1141 }
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1142 #endif
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1143
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1144
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1145 #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
1146 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
1147 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
1148 ImageExtractionMode mode,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1149 bool invert,
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1150 uint8_t quality)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1151 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1152 if (mode != ImageExtractionMode_UInt8 &&
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1153 mode != ImageExtractionMode_Preview)
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1154 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1155 throw OrthancException(ErrorCode_ParameterOutOfRange);
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1156 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1157
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1158 ApplyExtractionMode(image, mode, invert);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1159
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1160 JpegWriter writer;
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1161 writer.SetQuality(quality);
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1162 IImageWriter::WriteToMemory(writer, result, *image);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1163 }
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1164 #endif
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1165
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1166
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1167 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1168 ImageAccessor *DicomImageDecoder::Decode(ParsedDicomFile& dataset,
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1169 unsigned int frame)
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1170 {
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1171 return Decode(*dataset.GetDcmtkObject().getDataset(), frame);
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1172 }
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
1173 #endif
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 }