1 /*
2  *
3  *  Copyright (C) 1996-2016, 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: DicomColorMonochromeTemplate (Header)
19  *
20  */
21 
22 
23 #ifndef DICOMOT_H
24 #define DICOMOT_H
25 
26 #include "dcmtk/config/osconfig.h"
27 
28 #include "dcmtk/dcmimgle/dimopxt.h"
29 #include "dcmtk/dcmimage/dicopx.h"
30 
31 
32 /*---------------------*
33  *  class declaration  *
34  *---------------------*/
35 
36 /** Template class to convert color image to monochrome images.
37  *  (on pixel data level)
38  */
39 template<class T>
40 class DiColorMonoTemplate
41   : public DiMonoPixelTemplate<T>
42 {
43 
44  public:
45 
46     /** constructor
47      *
48      ** @param  pixel     intermediate representation of color pixel data
49      *  @param  modality  pointer to object managing modality transform
50      *  @param  red       coefficient of red pixel component
51      *  @param  green     coefficient of green pixel component
52      *  @param  blue      coefficient of blue pixel component
53      */
DiColorMonoTemplate(const DiColorPixel * pixel,DiMonoModality * modality,const double red,const double green,const double blue)54     DiColorMonoTemplate(const DiColorPixel *pixel,
55                         DiMonoModality *modality,
56                         const double red,
57                         const double green,
58                         const double blue)
59       : DiMonoPixelTemplate<T>(pixel, modality)
60     {
61         if ((pixel != NULL) && (pixel->getCount() > 0))
62         {
63             convert(OFstatic_cast(const T **, OFconst_cast(void *, pixel->getData())), red, green, blue);
64             this->determineMinMax();
65         }
66     }
67 
68     /** destructor
69      */
~DiColorMonoTemplate()70     virtual ~DiColorMonoTemplate()
71     {
72     }
73 
74 
75  private:
76 
77     /** convert color pixel data to monochrome format
78      *
79      ** @param  pixel  intermediate representation of color pixel data
80      *  @param  red    coefficient of red pixel component
81      *  @param  green  coefficient of green pixel component
82      *  @param  blue   coefficient of blue pixel component
83      */
convert(const T * pixel[3],const double red,const double green,const double blue)84     void convert(const T *pixel[3],
85                  const double red,
86                  const double green,
87                  const double blue)
88     {
89         if (pixel != NULL)
90         {
91             this->Data = new T[this->Count];
92             if (this->Data != NULL)
93             {
94                 const T *r = pixel[0];
95                 const T *g = pixel[1];
96                 const T *b = pixel[2];
97                 T *q = this->Data;
98                 unsigned long i;
99                 for (i = this->Count; i != 0; i--)
100                 {
101                     *(q++) = OFstatic_cast(T, OFstatic_cast(double, *(r++)) * red +
102                                               OFstatic_cast(double, *(g++)) * green +
103                                               OFstatic_cast(double, *(b++)) * blue);
104                 }
105             }
106         }
107     }
108 };
109 
110 
111 #endif
112