1 /*
2  *
3  *  Copyright (C) 1996-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:  dcmimage
15  *
16  *  Author:  Joerg Riesmeier
17  *
18  *  Purpose: DiARGBImage (Source) - UNTESTED !!!
19  *
20  */
21 
22 
23 #include "dcmtk/config/osconfig.h"
24 
25 #include "dcmtk/dcmdata/dctypes.h"
26 #include "dcmtk/dcmdata/dcdeftag.h"
27 
28 #include "dcmtk/dcmimage/diargimg.h"
29 #include "dcmtk/dcmimage/diargpxt.h"
30 #include "dcmtk/dcmimage/diqttype.h"
31 #include "dcmtk/dcmimage/dilogger.h"
32 #include "dcmtk/dcmimgle/diluptab.h"
33 #include "dcmtk/dcmimgle/diinpx.h"
34 #include "dcmtk/dcmimgle/didocu.h"
35 
36 
37 /*----------------*
38  *  constructors  *
39  *----------------*/
40 
DiARGBImage(const DiDocument * docu,const EI_Status status)41 DiARGBImage::DiARGBImage(const DiDocument *docu,
42                          const EI_Status status)
43   : DiColorImage(docu, status, 4),
44     Palette()  // initializes the three color palettes to NULL
45 {
46     if ((Document != NULL) && (InputData != NULL) && (ImageStatus == EIS_Normal))
47     {
48         if (BitsStored <= MAX_TABLE_ENTRY_SIZE)                         // color depth <= 16
49         {
50             const EL_BitsPerTableEntry descMode = (Document->getFlags() & CIF_CheckLutBitDepth) ? ELM_CheckValue : ELM_UseValue;
51             Palette[0] = new DiLookupTable(Document, DCM_RedPaletteColorLookupTableDescriptor,
52                 DCM_RedPaletteColorLookupTableData, DCM_UndefinedTagKey, descMode, &ImageStatus);
53             Palette[1] = new DiLookupTable(Document, DCM_GreenPaletteColorLookupTableDescriptor,
54                 DCM_GreenPaletteColorLookupTableData, DCM_UndefinedTagKey, descMode, &ImageStatus);
55             Palette[2] = new DiLookupTable(Document, DCM_BluePaletteColorLookupTableDescriptor,
56                 DCM_BluePaletteColorLookupTableData, DCM_UndefinedTagKey, descMode, &ImageStatus);
57             if ((ImageStatus == EIS_Normal) && (Palette[0] != NULL) && (Palette[1] != NULL) && (Palette[2] != NULL))
58             {
59                 BitsPerSample = BitsStored;
60                 for (int jj = 0; jj < 3; jj++)                          // determine maximum bit count
61                 {
62                     if (Palette[jj]->getBits() > OFstatic_cast(Uint16, BitsPerSample))
63                         BitsPerSample = Palette[jj]->getBits();
64                 }
65                 Init();                                                 // create intermediate representation
66             }
67         }
68         else                                                            // color depth > 16
69         {
70             ImageStatus = EIS_InvalidValue;
71             DCMIMAGE_ERROR("invalid value for 'BitsStored' (" << BitsStored << ") "
72                 << "... exceeds maximum palette entry size of " << MAX_TABLE_ENTRY_SIZE << " bits");
73         }
74     }
75 }
76 
77 
78 /*--------------*
79  *  destructor  *
80  *--------------*/
81 
~DiARGBImage()82 DiARGBImage::~DiARGBImage()
83 {
84     delete Palette[0];
85     delete Palette[1];
86     delete Palette[2];
87 }
88 
89 
90 /*********************************************************************/
91 
92 
Init()93 void DiARGBImage::Init()
94 {
95     /* number of pixels per plane */
96     const unsigned long planeSize = OFstatic_cast(unsigned long, Columns) * OFstatic_cast(unsigned long, Rows);
97     switch (InputData->getRepresentation())
98     {
99         case EPR_Uint8:
100             if (BitsPerSample <= 8)
101                 InterData = new DiARGBPixelTemplate<Uint8, Uint32, Uint8>(Document, InputData, Palette, ImageStatus,
102                     planeSize, BitsStored);
103             else
104                 InterData = new DiARGBPixelTemplate<Uint8, Uint32, Uint16>(Document, InputData, Palette, ImageStatus,
105                     planeSize, BitsStored);
106             break;
107         case EPR_Sint8:
108             if (BitsPerSample <= 8)
109                 InterData = new DiARGBPixelTemplate<Sint8, Sint32, Uint8>(Document, InputData, Palette, ImageStatus,
110                     planeSize, BitsStored);
111             else
112                 InterData = new DiARGBPixelTemplate<Sint8, Sint32, Uint16>(Document, InputData, Palette, ImageStatus,
113                     planeSize, BitsStored);
114             break;
115         case EPR_Uint16:
116             if (BitsPerSample <= 8)
117                 InterData = new DiARGBPixelTemplate<Uint16, Uint32, Uint8>(Document, InputData, Palette, ImageStatus,
118                     planeSize, BitsStored);
119             else
120                 InterData = new DiARGBPixelTemplate<Uint16, Uint32, Uint16>(Document, InputData, Palette, ImageStatus,
121                     planeSize, BitsStored);
122             break;
123         case EPR_Sint16:
124             if (BitsPerSample <= 8)
125                 InterData = new DiARGBPixelTemplate<Sint16, Sint32, Uint8>(Document, InputData, Palette, ImageStatus,
126                     planeSize, BitsStored);
127             else
128                 InterData = new DiARGBPixelTemplate<Sint16, Sint32, Uint16>(Document, InputData, Palette, ImageStatus,
129                     planeSize, BitsStored);
130             break;
131         default:
132             DCMIMAGE_WARN("invalid value for inter-representation");
133     }
134     deleteInputData();                          // input data is no longer needed
135     checkInterData();
136 }
137 
138 
139 /*********************************************************************/
140 
141 
processNextFrames(const unsigned long fcount)142 int DiARGBImage::processNextFrames(const unsigned long fcount)
143 {
144     if (DiImage::processNextFrames(fcount))
145     {
146         delete InterData;
147         InterData = NULL;
148         Init();
149         return (ImageStatus == EIS_Normal);
150     }
151     return 0;
152 }
153