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 DIYP2PXT_H
00031 #define DIYP2PXT_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 DiYBRPart422PixelTemplate
00047 : public DiColorPixelTemplate<T2>
00048 {
00049
00050 public:
00051
00059 DiYBRPart422PixelTemplate(const DiDocument *docu,
00060 const DiInputPixel *pixel,
00061 EI_Status &status,
00062 const int bits)
00063 : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00064 {
00065 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00066 {
00067 if (this->PlanarConfiguration)
00068 {
00069 status = EIS_InvalidValue;
00070 DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")");
00071 }
00072 else
00073 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits);
00074 }
00075 }
00076
00079 virtual ~DiYBRPart422PixelTemplate()
00080 {
00081 }
00082
00083
00084 private:
00085
00091 void convert(const T1 *pixel,
00092 const int bits)
00093 {
00094 if (Init(pixel))
00095 {
00096 register T2 *r = this->Data[0];
00097 register T2 *g = this->Data[1];
00098 register T2 *b = this->Data[2];
00099 register unsigned long i;
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
00106 register const T1 *p = pixel;
00107 register T2 y1;
00108 register T2 y2;
00109 register T2 cb;
00110 register T2 cr;
00111 for (i = count / 2; i != 0; --i)
00112 {
00113 y1 = removeSign(*(p++), offset);
00114 y2 = removeSign(*(p++), offset);
00115 cb = removeSign(*(p++), offset);
00116 cr = removeSign(*(p++), offset);
00117 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00118 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00119 }
00120 }
00121 }
00122
00125 inline void convertValue(T2 &red,
00126 T2 &green,
00127 T2 &blue,
00128 const T2 y,
00129 const T2 cb,
00130 const T2 cr,
00131 const T2 maxvalue)
00132 {
00133 double dr = 1.1631 * OFstatic_cast(double, y) + 1.5969 * OFstatic_cast(double, cr) - 0.8713 * OFstatic_cast(double, maxvalue);
00134 double dg = 1.1631 * OFstatic_cast(double, y) - 0.3913 * OFstatic_cast(double, cb) - 0.8121 * OFstatic_cast(double, cr) + 0.5290 * OFstatic_cast(double, maxvalue);
00135 double db = 1.1631 * OFstatic_cast(double, y) + 2.0177 * OFstatic_cast(double, cb) - 1.0820 * OFstatic_cast(double, maxvalue);
00136 red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00137 green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00138 blue = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00139 }
00140 };
00141
00142
00143 #endif
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225