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 DIHSVPXT_H
00035
#define DIHSVPXT_H
00036
00037
#include "osconfig.h"
00038
00039
#include "ofconsol.h"
00040
#include "dicopxt.h"
00041
#include "diinpx.h"
00042
00043
00044
00045
00046
00047
00050
template<
class T1,
class T2>
00051 class DiHSVPixelTemplate
00052 :
public DiColorPixelTemplate<T2>
00053 {
00054
00055
public:
00056
00065 DiHSVPixelTemplate(
const DiDocument *docu,
00066
const DiInputPixel *pixel,
00067 EI_Status &status,
00068
const unsigned long planeSize,
00069
const int bits)
00070 :
DiColorPixelTemplate<T2>(docu, pixel, 3, status)
00071 {
00072
if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00073
convert(OFstatic_cast(
const T1 *, pixel->
getData()) + pixel->
getPixelStart(), planeSize, bits);
00074 }
00075
00078 virtual ~DiHSVPixelTemplate()
00079 {
00080 }
00081
00082
00083
private:
00084
00091 void convert(
const T1 *pixel,
00092
const unsigned long planeSize,
00093
const int bits)
00094 {
00095
if (
Init(pixel))
00096 {
00097
register T2 *r = this->Data[0];
00098
register T2 *g = this->Data[1];
00099
register T2 *b = this->Data[2];
00100
const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00101
const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00102
00103
00104
const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00105
if (this->PlanarConfiguration)
00106 {
00107
00108
00109
00110
00111
00112
00113
00114
00115
register unsigned long l;
00116
register unsigned long i = count;
00117
register const T1 *h = pixel;
00118
register const T1 *s = h + planeSize;
00119
register const T1 *v = s + planeSize;
00120
while (i != 0)
00121 {
00122
00123
for (l = planeSize; (l != 0) && (i != 0); --l, --i)
00124 {
00125
convertValue(*(r++), *(g++), *(b++), removeSign(*(h++), offset), removeSign(*(s++), offset),
00126 removeSign(*(v++), offset), maxvalue);
00127 }
00128
00129 h += 2 * planeSize;
00130 s += 2 * planeSize;
00131 v += 2 * planeSize;
00132 }
00133 }
00134
else
00135 {
00136
register const T1 *p = pixel;
00137
register T2 h;
00138
register T2 s;
00139
register T2 v;
00140
register unsigned long i;
00141
for (i = count; i != 0; --i)
00142 {
00143 h = removeSign(*(p++), offset);
00144 s = removeSign(*(p++), offset);
00145 v = removeSign(*(p++), offset);
00146
convertValue(*(r++), *(g++), *(b++), h, s, v, maxvalue);
00147 }
00148 }
00149 }
00150 }
00151
00154 void convertValue(T2 &red,
00155 T2 &green,
00156 T2 &blue,
00157
const T2 hue,
00158
const T2 saturation,
00159
const T2 value,
00160
const T2 maxvalue)
00161 {
00162
00163
00164
00165
00166
if (saturation == 0)
00167 {
00168 red = value;
00169 green = value;
00170 blue = value;
00171 }
00172
else
00173 {
00174
const double h = (OFstatic_cast(
double, hue) * 6) / (OFstatic_cast(
double, maxvalue) + 1);
00175
const double s = OFstatic_cast(
double, saturation) / OFstatic_cast(
double, maxvalue);
00176
const double v = OFstatic_cast(
double, value) / OFstatic_cast(
double, maxvalue);
00177
const T2 hi = OFstatic_cast(T2, h);
00178
const double hf = h - hi;
00179
const T2 p = OFstatic_cast(T2, maxvalue * v * (1 - s));
00180
const T2 q = OFstatic_cast(T2, maxvalue * v * (1 - s * hf));
00181
const T2 t = OFstatic_cast(T2, maxvalue * v * (1 - s * (1 - hf)));
00182
switch (hi)
00183 {
00184
case 0:
00185 red = value;
00186 green = t;
00187 blue = p;
00188
break;
00189
case 1:
00190 red = q;
00191 green = value;
00192 blue = p;
00193
break;
00194
case 2:
00195 red = p;
00196 green = value;
00197 blue = t;
00198
break;
00199
case 3:
00200 red = p;
00201 green = q;
00202 blue = value;
00203
break;
00204
case 4:
00205 red = t;
00206 green = p;
00207 blue = value;
00208
break;
00209
case 5:
00210 red = value;
00211 green = p;
00212 blue = q;
00213
break;
00214
default:
00215
if (
DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00216 {
00217 ofConsole.lockCerr() <<
"WARNING: invalid value for 'hi' while converting HSV to RGB !" << endl;
00218 ofConsole.unlockCerr();
00219 }
00220 }
00221 }
00222 }
00223 };
00224
00225
00226
#endif
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