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 DIYF2PXT_H
00035 #define DIYF2PXT_H
00036
00037 #include "dcmtk/config/osconfig.h"
00038
00039 #include "dcmtk/ofstd/ofconsol.h"
00040 #include "dcmtk/dcmimage/dicopxt.h"
00041 #include "dcmtk/dcmimgle/diinpx.h"
00042
00043
00044
00045
00046
00047
00050 template<class T1, class T2>
00051 class DiYBR422PixelTemplate
00052 : public DiColorPixelTemplate<T2>
00053 {
00054
00055 public:
00056
00065 DiYBR422PixelTemplate(const DiDocument *docu,
00066 const DiInputPixel *pixel,
00067 EI_Status &status,
00068 const int bits,
00069 const OFBool rgb)
00070 : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00071 {
00072 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00073 {
00074 if (this->PlanarConfiguration)
00075 {
00076 status = EIS_InvalidValue;
00077 if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors))
00078 {
00079 ofConsole.lockCerr() << "ERROR: invalid value for 'PlanarConfiguration' ("
00080 << this->PlanarConfiguration << ") ! " << endl;
00081 ofConsole.unlockCerr();
00082 }
00083 }
00084 else
00085 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits, rgb);
00086 }
00087 }
00088
00091 virtual ~DiYBR422PixelTemplate()
00092 {
00093 }
00094
00095
00096 private:
00097
00104 void convert(const T1 *pixel,
00105 const int bits,
00106 const OFBool rgb)
00107 {
00108 if (Init(pixel))
00109 {
00110 const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00111 register unsigned long i;
00112 register const T1 *p = pixel;
00113 register T2 *r = this->Data[0];
00114 register T2 *g = this->Data[1];
00115 register T2 *b = this->Data[2];
00116 register T2 y1;
00117 register T2 y2;
00118 register T2 cb;
00119 register T2 cr;
00120
00121
00122 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00123 if (rgb)
00124 {
00125 const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
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 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00133 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00134 }
00135 } else {
00136 for (i = count / 2; i != 0; --i)
00137 {
00138 y1 = removeSign(*(p++), offset);
00139 y2 = removeSign(*(p++), offset);
00140 cb = removeSign(*(p++), offset);
00141 cr = removeSign(*(p++), offset);
00142 *(r++) = y1;
00143 *(g++) = cb;
00144 *(b++) = cr;
00145 *(r++) = y2;
00146 *(g++) = cb;
00147 *(b++) = cr;
00148 }
00149 }
00150 }
00151 }
00152
00155 inline void convertValue(T2 &red,
00156 T2 &green,
00157 T2 &blue,
00158 const T2 y,
00159 const T2 cb,
00160 const T2 cr,
00161 const T2 maxvalue)
00162 {
00163 double dr = OFstatic_cast(double, y) + 1.4020 * OFstatic_cast(double, cr) - 0.7010 * OFstatic_cast(double, maxvalue);
00164 double dg = OFstatic_cast(double, y) - 0.3441 * OFstatic_cast(double, cb) - 0.7141 * OFstatic_cast(double, cr) + 0.5291 * OFstatic_cast(double, maxvalue);
00165 double db = OFstatic_cast(double, y) + 1.7720 * OFstatic_cast(double, cb) - 0.8859 * OFstatic_cast(double, maxvalue);
00166 red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00167 green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00168 blue = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00169 }
00170 };
00171
00172
00173 #endif
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