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 DIYF2PXT_H
00031 #define DIYF2PXT_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 DiYBR422PixelTemplate
00047 : public DiColorPixelTemplate<T2>
00048 {
00049
00050 public:
00051
00060 DiYBR422PixelTemplate(const DiDocument *docu,
00061 const DiInputPixel *pixel,
00062 EI_Status &status,
00063 const int bits,
00064 const OFBool rgb)
00065 : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00066 {
00067 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00068 {
00069 if (this->PlanarConfiguration)
00070 {
00071 status = EIS_InvalidValue;
00072 DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")");
00073 }
00074 else
00075 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits, rgb);
00076 }
00077 }
00078
00081 virtual ~DiYBR422PixelTemplate()
00082 {
00083 }
00084
00085
00086 private:
00087
00094 void convert(const T1 *pixel,
00095 const int bits,
00096 const OFBool rgb)
00097 {
00098 if (Init(pixel))
00099 {
00100 const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00101 register unsigned long i;
00102 register const T1 *p = pixel;
00103 register T2 *r = this->Data[0];
00104 register T2 *g = this->Data[1];
00105 register T2 *b = this->Data[2];
00106 register T2 y1;
00107 register T2 y2;
00108 register T2 cb;
00109 register T2 cr;
00110
00111
00112 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00113 if (rgb)
00114 {
00115 const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00116 for (i = count / 2; i != 0; --i)
00117 {
00118 y1 = removeSign(*(p++), offset);
00119 y2 = removeSign(*(p++), offset);
00120 cb = removeSign(*(p++), offset);
00121 cr = removeSign(*(p++), offset);
00122 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00123 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00124 }
00125 } else {
00126 for (i = count / 2; i != 0; --i)
00127 {
00128 y1 = removeSign(*(p++), offset);
00129 y2 = removeSign(*(p++), offset);
00130 cb = removeSign(*(p++), offset);
00131 cr = removeSign(*(p++), offset);
00132 *(r++) = y1;
00133 *(g++) = cb;
00134 *(b++) = cr;
00135 *(r++) = y2;
00136 *(g++) = cb;
00137 *(b++) = cr;
00138 }
00139 }
00140 }
00141 }
00142
00145 inline void convertValue(T2 &red,
00146 T2 &green,
00147 T2 &blue,
00148 const T2 y,
00149 const T2 cb,
00150 const T2 cr,
00151 const T2 maxvalue)
00152 {
00153 double dr = OFstatic_cast(double, y) + 1.4020 * OFstatic_cast(double, cr) - 0.7010 * OFstatic_cast(double, maxvalue);
00154 double dg = OFstatic_cast(double, y) - 0.3441 * OFstatic_cast(double, cb) - 0.7141 * OFstatic_cast(double, cr) + 0.5291 * OFstatic_cast(double, maxvalue);
00155 double db = OFstatic_cast(double, y) + 1.7720 * OFstatic_cast(double, cb) - 0.8859 * OFstatic_cast(double, maxvalue);
00156 red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00157 green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00158 blue = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00159 }
00160 };
00161
00162
00163 #endif
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
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