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
00031
00032
00033
00034
#ifndef DIQTCTAB_H
00035
#define DIQTCTAB_H
00036
00037
#include "osconfig.h"
00038
#include "oftypes.h"
00039
#include "ofcond.h"
00040
#include "diqtpix.h"
00041
#include "diqthash.h"
00042
#include "ofstring.h"
00043
00044
00045
class DicomImage;
00046
class DcmItem;
00047
00048
00052 class DcmQuantColorTable
00053 {
00054
public:
00055
00057
DcmQuantColorTable();
00058
00060
~DcmQuantColorTable();
00061
00063
void clear();
00064
00068 inline unsigned long getColors()
const
00069
{
00070
return numColors;
00071 }
00072
00077
void setDescriptionString(
OFString& str)
const;
00078
00088
OFCondition computeHistogram(
DicomImage& image,
unsigned long maxcolors);
00089
00094 inline unsigned long getMaxVal()
const
00095
{
00096
return maxval;
00097 }
00098
00103 inline const DcmQuantPixel&
getPixel(
unsigned long idx)
const
00104
{
00105
#ifdef DEBUG
00106
assert(
array && idx <
numColors);
00107
#endif
00108
return *(
array[idx]);
00109 }
00110
00115 inline DcmQuantComponent
getRed(
unsigned long idx)
const
00116
{
00117
#ifdef DEBUG
00118
assert(
array && idx <
numColors);
00119
#endif
00120
return array[idx]->
getRed();
00121 }
00122
00127 inline DcmQuantComponent
getGreen(
unsigned long idx)
const
00128
{
00129
#ifdef DEBUG
00130
assert(
array && idx <
numColors);
00131
#endif
00132
return array[idx]->
getGreen();
00133 }
00134
00139 inline DcmQuantComponent
getBlue(
unsigned long idx)
const
00140
{
00141
#ifdef DEBUG
00142
assert(
array && idx <
numColors);
00143
#endif
00144
return array[idx]->
getBlue();
00145 }
00146
00162
OFCondition medianCut(
00163
DcmQuantColorTable& histogram,
00164
unsigned long sum,
00165
unsigned long theMaxval,
00166
unsigned long numberOfColors,
00167 DcmLargestDimensionType largeType,
00168 DcmRepresentativeColorType repType);
00169
00174 inline int computeIndex(
const DcmQuantPixel& px)
const
00175
{
00176
int result = -1;
00177
register int r2, g2, b2;
00178
register long newdist;
00179
register int r1 = OFstatic_cast(
int, px.
getRed());
00180
register int g1 = OFstatic_cast(
int, px.
getGreen());
00181
register int b1 = OFstatic_cast(
int, px.
getBlue());
00182
register long dist = 2000000000;
00183
for (
unsigned long i = 0; i <
numColors; ++i)
00184 {
00185 r2 = r1 - OFstatic_cast(
int,
array[i]->
getRed());
00186 g2 = g1 - OFstatic_cast(
int,
array[i]->
getGreen());
00187 b2 = b1 - OFstatic_cast(
int,
array[i]->
getBlue());
00188 newdist = r2*r2 + g2*g2 + b2*b2;
00189
if (newdist < dist)
00190 {
00191 result = OFstatic_cast(
int, i);
00192 dist = newdist;
00193
if (dist <
array[i]->
getValue()) i=numColors;
00194 }
00195 }
00196
return result;
00197 }
00198
00208
OFCondition write(
00209
DcmItem& target,
00210 OFBool writeAsOW,
00211 OFBool write16BitEntries);
00212
00213
00214
private:
00215
00222
void computeClusters();
00223
00225
DcmQuantColorTable(
const DcmQuantColorTable& src);
00226
00228
DcmQuantColorTable&
operator=(
const DcmQuantColorTable& src);
00229
00231 DcmQuantHistogramItemPointer *
array;
00232
00234 unsigned long numColors;
00235
00239 unsigned long maxval;
00240
00241 };
00242
00243
#endif
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