1 /*
2 *
3 * Copyright (C) 1998-2010, OFFIS e.V.
4 * All rights reserved. See COPYRIGHT file for details.
5 *
6 * This software and supporting documentation were developed by
7 *
8 * OFFIS e.V.
9 * R&D Division Health
10 * Escherweg 2
11 * D-26121 Oldenburg, Germany
12 *
13 *
14 * Module: dcmpstat
15 *
16 * Author: Marco Eichelberg
17 *
18 * Purpose:
19 * classes: DVPSPresentationLUT
20 *
21 */
22
23 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
24 #include "dcmtk/ofstd/ofstring.h"
25 #include "dcmtk/dcmpstat/dvpspl.h"
26 #include "dcmtk/dcmimgle/dcmimage.h" /* for class DiLookupTable, DicomImage */
27 #include "dcmtk/dcmpstat/dvpsdef.h" /* for constants and macros */
28 #include "dcmtk/dcmnet/dimse.h"
29
30 /* --------------- class DVPSPresentationLUT --------------- */
31
compareDiLookupTable(DiLookupTable * lut)32 OFBool DVPSPresentationLUT::compareDiLookupTable(DiLookupTable *lut)
33 {
34 if ((presentationLUT == DVPSP_table) && lut
35 && (0 == lut->compareLUT(presentationLUTData, presentationLUTDescriptor))) return OFTrue;
36 return OFFalse;
37 }
38
createDiLookupTable()39 DiLookupTable *DVPSPresentationLUT::createDiLookupTable()
40 {
41 DiLookupTable *result = NULL;
42 if (presentationLUT == DVPSP_table) result = new DiLookupTable(presentationLUTData, presentationLUTDescriptor);
43 return result;
44 }
45
invert()46 OFCondition DVPSPresentationLUT::invert()
47 {
48 OFCondition status = EC_Normal;
49 switch (presentationLUT)
50 {
51 case DVPSP_identity:
52 presentationLUT = DVPSP_inverse;
53 break;
54 case DVPSP_inverse:
55 presentationLUT = DVPSP_identity;
56 break;
57 case DVPSP_table:
58 status = EC_IllegalCall;
59 if (haveTable())
60 {
61 DiLookupTable *lut = new DiLookupTable(presentationLUTData, presentationLUTDescriptor);
62 if (lut && (lut->mirrorTable(0x2))) status = EC_Normal; // flag = 0x2: mirror only original LUT data
63 delete lut;
64 }
65 break;
66 case DVPSP_lin_od:
67 status = EC_IllegalCall;
68 break;
69
70 }
71 return status;
72 }
73
activate(DicomImage * image,OFBool printLUT)74 OFBool DVPSPresentationLUT::activate(DicomImage *image, OFBool printLUT)
75 {
76 if (image==NULL) return OFFalse;
77
78 int result=0;
79 switch (presentationLUT)
80 {
81 case DVPSP_identity:
82 if (printLUT)
83 {
84 // in DICOM print, IDENTITY should not invert a MONOCHROME1 image
85 result = image->setPresentationLutShape(ESP_Default);
86 }
87 else
88 {
89 result = image->setPresentationLutShape(ESP_Identity);
90 }
91 if (!result)
92 DCMPSTAT_WARN("unable to set identity presentation LUT shape, ignoring.");
93 break;
94 case DVPSP_inverse:
95 if (!printLUT)
96 result = image->setPresentationLutShape(ESP_Inverse);
97 if (!result)
98 DCMPSTAT_WARN("unable to set inverse presentation LUT shape, ignoring.");
99 break;
100 case DVPSP_lin_od:
101 result = image->setPresentationLutShape(ESP_LinOD);
102 if (!result)
103 DCMPSTAT_WARN("unable to set linear optical density presentation LUT shape, ignoring.");
104 break;
105 case DVPSP_table:
106 if (printLUT)
107 result = image->setVoiLut(presentationLUTData, presentationLUTDescriptor, &presentationLUTExplanation);
108 else
109 result = image->setPresentationLut(presentationLUTData, presentationLUTDescriptor, &presentationLUTExplanation);
110 if (!result)
111 DCMPSTAT_WARN("unable to set presentation LUT, ignoring.");
112 break;
113 }
114 if (result) return OFTrue; else return OFFalse;
115 }
116
activateInverseLUT(DicomImage * image)117 OFBool DVPSPresentationLUT::activateInverseLUT(DicomImage *image)
118 {
119 int result = 0;
120 if ((image != NULL) && (presentationLUT == DVPSP_table))
121 {
122 result = image->setInversePresentationLut(presentationLUTData, presentationLUTDescriptor);
123 if (!result)
124 DCMPSTAT_WARN("unable to set inverse presentation LUT, ignoring.");
125 }
126 if (result) return OFTrue; else return OFFalse;
127 }
128
isInverse()129 OFBool DVPSPresentationLUT::isInverse()
130 {
131 OFBool result = OFFalse;
132 switch (presentationLUT)
133 {
134 case DVPSP_identity:
135 case DVPSP_lin_od:
136 break;
137 case DVPSP_inverse:
138 result = OFTrue;
139 break;
140 case DVPSP_table:
141 if ((presentationLUTDescriptor.getVM()==3)&&(presentationLUTData.getLength() > 0))
142 {
143 DiLookupTable *lut = new DiLookupTable(presentationLUTData, presentationLUTDescriptor);
144 if (lut && (lut->getFirstValue() > lut->getLastValue())) result = OFTrue;
145 delete lut;
146 }
147 break;
148 }
149 return result;
150 }
151