00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef DIQTCTAB_H
00031 #define DIQTCTAB_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/ofstd/oftypes.h"
00035 #include "dcmtk/ofstd/ofcond.h"
00036 #include "dcmtk/dcmimage/diqtpix.h"
00037 #include "dcmtk/dcmimage/diqthash.h"
00038 #include "dcmtk/ofstd/ofstring.h"
00039
00040
00041 class DicomImage;
00042 class DcmItem;
00043
00044
00048 class DcmQuantColorTable
00049 {
00050 public:
00051
00053 DcmQuantColorTable();
00054
00056 ~DcmQuantColorTable();
00057
00059 void clear();
00060
00064 inline unsigned long getColors() const
00065 {
00066 return numColors;
00067 }
00068
00073 void setDescriptionString(OFString& str) const;
00074
00084 OFCondition computeHistogram(DicomImage& image, unsigned long maxcolors);
00085
00090 inline unsigned long getMaxVal() const
00091 {
00092 return maxval;
00093 }
00094
00099 inline const DcmQuantPixel& getPixel(unsigned long idx) const
00100 {
00101 #ifdef DEBUG
00102 assert(array && idx < numColors);
00103 #endif
00104 return *(array[idx]);
00105 }
00106
00111 inline DcmQuantComponent getRed(unsigned long idx) const
00112 {
00113 #ifdef DEBUG
00114 assert(array && idx < numColors);
00115 #endif
00116 return array[idx]->getRed();
00117 }
00118
00123 inline DcmQuantComponent getGreen(unsigned long idx) const
00124 {
00125 #ifdef DEBUG
00126 assert(array && idx < numColors);
00127 #endif
00128 return array[idx]->getGreen();
00129 }
00130
00135 inline DcmQuantComponent getBlue(unsigned long idx) const
00136 {
00137 #ifdef DEBUG
00138 assert(array && idx < numColors);
00139 #endif
00140 return array[idx]->getBlue();
00141 }
00142
00158 OFCondition medianCut(
00159 DcmQuantColorTable& histogram,
00160 unsigned long sum,
00161 unsigned long theMaxval,
00162 unsigned long numberOfColors,
00163 DcmLargestDimensionType largeType,
00164 DcmRepresentativeColorType repType);
00165
00170 inline int computeIndex(const DcmQuantPixel& px) const
00171 {
00172 int result = -1;
00173 register int r2, g2, b2;
00174 register long newdist;
00175 register int r1 = OFstatic_cast(int, px.getRed());
00176 register int g1 = OFstatic_cast(int, px.getGreen());
00177 register int b1 = OFstatic_cast(int, px.getBlue());
00178 register long dist = 2000000000;
00179 for (unsigned long i = 0; i < numColors; ++i)
00180 {
00181 r2 = r1 - OFstatic_cast(int, array[i]->getRed());
00182 g2 = g1 - OFstatic_cast(int, array[i]->getGreen());
00183 b2 = b1 - OFstatic_cast(int, array[i]->getBlue());
00184 newdist = r2*r2 + g2*g2 + b2*b2;
00185 if (newdist < dist)
00186 {
00187 result = OFstatic_cast(int, i);
00188 dist = newdist;
00189 if (dist < array[i]->getValue()) i=numColors;
00190 }
00191 }
00192 return result;
00193 }
00194
00204 OFCondition write(
00205 DcmItem& target,
00206 OFBool writeAsOW,
00207 OFBool write16BitEntries);
00208
00209
00210 private:
00211
00218 void computeClusters();
00219
00221 DcmQuantColorTable(const DcmQuantColorTable& src);
00222
00224 DcmQuantColorTable& operator=(const DcmQuantColorTable& src);
00225
00227 DcmQuantHistogramItemPointer *array;
00228
00230 unsigned long numColors;
00231
00235 unsigned long maxval;
00236
00237 };
00238
00239 #endif
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270