OFFIS DCMTK  Version 3.6.0
diqtcmap.h
1 /*
2  *
3  * Copyright (C) 2002-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: Marco Eichelberg
17  *
18  * Purpose: class DcmQuantColorMapping
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:16:29 $
22  * CVS/RCS Revision: $Revision: 1.5 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIQTCMAP_H
31 #define DIQTCMAP_H
32 
33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/dcmimage/diqttype.h" /* for DcmQuantComponent */
35 #include "dcmtk/dcmimgle/dcmimage.h" /* gcc 3.4 needs this */
36 #include "dcmtk/dcmimage/diqtstab.h" /* gcc 3.4 needs this */
37 #include "dcmtk/dcmimage/diqtpix.h" /* gcc 3.4 needs this */
38 #include "dcmtk/dcmimage/diqthash.h" /* gcc 3.4 needs this */
39 #include "dcmtk/dcmimage/diqtctab.h" /* gcc 3.4 needs this */
40 
41 class DicomImage;
43 class DcmQuantColorTable;
44 class DcmQuantPixel;
45 class DcmQuantScaleTable;
46 
47 
54 template <class T1, class T2>
56 {
57 public:
58 
76  static void create(
77  DicomImage& sourceImage,
78  unsigned long frameNumber,
79  unsigned long maxval,
81  DcmQuantColorTable& colormap,
82  T1& fs,
83  T2 *tp)
84  {
85  unsigned long cols = sourceImage.getWidth();
86  unsigned long rows = sourceImage.getHeight();
87  const int bits = sizeof(DcmQuantComponent)*8;
88  DcmQuantPixel px;
89  long limitcol;
90  long col; // must be signed!
91  long maxval_l = OFstatic_cast(long, maxval);
92  register int ind;
93  const DcmQuantComponent *currentpixel;
94  register DcmQuantComponent cr, cg, cb;
95 
96  // create scale table
97  DcmQuantScaleTable scaletable;
98  scaletable.createTable(OFstatic_cast(DcmQuantComponent, -1), maxval);
99 
100  const void *data = sourceImage.getOutputData(bits, frameNumber, 0);
101  if (data)
102  {
103  const DcmQuantComponent *cp = OFstatic_cast(const DcmQuantComponent *, data);
104  for (unsigned long row = 0; row < rows; ++row)
105  {
106  fs.startRow(col, limitcol);
107  do
108  {
109  currentpixel = cp + col + col + col;
110  cr = *currentpixel++;
111  cg = *currentpixel++;
112  cb = *currentpixel;
113  px.scale(cr, cg, cb, scaletable);
114 
115  fs.adjust(px, col, maxval_l);
116 
117  // Check hash table to see if we have already matched this color.
118  ind = cht.lookup(px);
119  if (ind < 0)
120  {
121  ind = colormap.computeIndex(px);
122  cht.add(px, ind);
123  }
124 
125  fs.propagate(px, colormap.getPixel(ind), col);
126  tp[col] = OFstatic_cast(T2, ind);
127  fs.nextCol(col);
128  } while ( col != limitcol );
129  fs.finishRow();
130  cp += (cols * 3); // advance source pointer by one row
131  tp += cols; // advance target pointer by one row
132  } // for all rows
133  } // if (data)
134  }
135 };
136 
137 
138 #endif
139 
140 
141 /*
142  * CVS/RCS Log:
143  * $Log: diqtcmap.h,v $
144  * Revision 1.5 2010-10-14 13:16:29 joergr
145  * Updated copyright header. Added reference to COPYRIGHT file.
146  *
147  * Revision 1.4 2005/12/08 16:01:44 meichel
148  * Changed include path schema for all DCMTK header files
149  *
150  * Revision 1.3 2004/04/21 10:00:31 meichel
151  * Minor modifications for compilation with gcc 3.4.0
152  *
153  * Revision 1.2 2003/12/23 12:14:38 joergr
154  * Adapted type casts to new-style typecast operators defined in ofcast.h.
155  * Updated copyright header.
156  *
157  * Revision 1.1 2002/01/25 13:32:04 meichel
158  * Initial release of new color quantization classes and
159  * the dcmquant tool in module dcmimage.
160  *
161  *
162  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2