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 DIHSVPXT_H
00031 #define DIHSVPXT_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034
00035 #include "dcmtk/dcmimage/dicopxt.h"
00036 #include "dcmtk/dcmimgle/diinpx.h"
00037
00038
00039
00040
00041
00042
00045 template<class T1, class T2>
00046 class DiHSVPixelTemplate
00047 : public DiColorPixelTemplate<T2>
00048 {
00049
00050 public:
00051
00060 DiHSVPixelTemplate(const DiDocument *docu,
00061 const DiInputPixel *pixel,
00062 EI_Status &status,
00063 const unsigned long planeSize,
00064 const int bits)
00065 : DiColorPixelTemplate<T2>(docu, pixel, 3, status)
00066 {
00067 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00068 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), planeSize, bits);
00069 }
00070
00073 virtual ~DiHSVPixelTemplate()
00074 {
00075 }
00076
00077
00078 private:
00079
00086 void convert(const T1 *pixel,
00087 const unsigned long planeSize,
00088 const int bits)
00089 {
00090 if (Init(pixel))
00091 {
00092 register T2 *r = this->Data[0];
00093 register T2 *g = this->Data[1];
00094 register T2 *b = this->Data[2];
00095 const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00096 const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00097
00098
00099 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00100 if (this->PlanarConfiguration)
00101 {
00102
00103
00104
00105
00106
00107
00108
00109
00110 register unsigned long l;
00111 register unsigned long i = count;
00112 register const T1 *h = pixel;
00113 register const T1 *s = h + planeSize;
00114 register const T1 *v = s + planeSize;
00115 while (i != 0)
00116 {
00117
00118 for (l = planeSize; (l != 0) && (i != 0); --l, --i)
00119 {
00120 convertValue(*(r++), *(g++), *(b++), removeSign(*(h++), offset), removeSign(*(s++), offset),
00121 removeSign(*(v++), offset), maxvalue);
00122 }
00123
00124 h += 2 * planeSize;
00125 s += 2 * planeSize;
00126 v += 2 * planeSize;
00127 }
00128 }
00129 else
00130 {
00131 register const T1 *p = pixel;
00132 register T2 h;
00133 register T2 s;
00134 register T2 v;
00135 register unsigned long i;
00136 for (i = count; i != 0; --i)
00137 {
00138 h = removeSign(*(p++), offset);
00139 s = removeSign(*(p++), offset);
00140 v = removeSign(*(p++), offset);
00141 convertValue(*(r++), *(g++), *(b++), h, s, v, maxvalue);
00142 }
00143 }
00144 }
00145 }
00146
00149 void convertValue(T2 &red,
00150 T2 &green,
00151 T2 &blue,
00152 const T2 hue,
00153 const T2 saturation,
00154 const T2 value,
00155 const T2 maxvalue)
00156 {
00157
00158
00159
00160
00161 if (saturation == 0)
00162 {
00163 red = value;
00164 green = value;
00165 blue = value;
00166 }
00167 else
00168 {
00169 const double h = (OFstatic_cast(double, hue) * 6) / (OFstatic_cast(double, maxvalue) + 1);
00170 const double s = OFstatic_cast(double, saturation) / OFstatic_cast(double, maxvalue);
00171 const double v = OFstatic_cast(double, value) / OFstatic_cast(double, maxvalue);
00172 const T2 hi = OFstatic_cast(T2, h);
00173 const double hf = h - hi;
00174 const T2 p = OFstatic_cast(T2, maxvalue * v * (1 - s));
00175 const T2 q = OFstatic_cast(T2, maxvalue * v * (1 - s * hf));
00176 const T2 t = OFstatic_cast(T2, maxvalue * v * (1 - s * (1 - hf)));
00177 switch (hi)
00178 {
00179 case 0:
00180 red = value;
00181 green = t;
00182 blue = p;
00183 break;
00184 case 1:
00185 red = q;
00186 green = value;
00187 blue = p;
00188 break;
00189 case 2:
00190 red = p;
00191 green = value;
00192 blue = t;
00193 break;
00194 case 3:
00195 red = p;
00196 green = q;
00197 blue = value;
00198 break;
00199 case 4:
00200 red = t;
00201 green = p;
00202 blue = value;
00203 break;
00204 case 5:
00205 red = value;
00206 green = p;
00207 blue = q;
00208 break;
00209 default:
00210 DCMIMAGE_WARN("invalid value for 'hi' while converting HSV to RGB");
00211 }
00212 }
00213 }
00214 };
00215
00216
00217 #endif
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
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
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300