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 DIYP2PXT_H
00035
#define DIYP2PXT_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 DiYBRPart422PixelTemplate
00052 :
public DiColorPixelTemplate<T2>
00053 {
00054
00055
public:
00056
00064 DiYBRPart422PixelTemplate(
const DiDocument *docu,
00065
const DiInputPixel *pixel,
00066 EI_Status &status,
00067
const int bits)
00068 :
DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00069 {
00070
if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00071 {
00072
if (this->PlanarConfiguration)
00073 {
00074 status = EIS_InvalidValue;
00075
if (
DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors))
00076 {
00077 ofConsole.lockCerr() <<
"ERROR: invalid value for 'PlanarConfiguration' ("
00078 << this->PlanarConfiguration <<
") ! " << endl;
00079 ofConsole.unlockCerr();
00080 }
00081 }
00082
else
00083
convert(OFstatic_cast(
const T1 *, pixel->
getData()) + pixel->
getPixelStart(), bits);
00084 }
00085 }
00086
00089 virtual ~DiYBRPart422PixelTemplate()
00090 {
00091 }
00092
00093
00094
private:
00095
00101 void convert(
const T1 *pixel,
00102
const int bits)
00103 {
00104
if (
Init(pixel))
00105 {
00106
register T2 *r = this->Data[0];
00107
register T2 *g = this->Data[1];
00108
register T2 *b = this->Data[2];
00109
register unsigned long i;
00110
const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00111
const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00112
00113
00114
const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00115
00116
register const T1 *p = pixel;
00117
register T2 y1;
00118
register T2 y2;
00119
register T2 cb;
00120
register T2 cr;
00121
for (i = count / 2; i != 0; --i)
00122 {
00123 y1 = removeSign(*(p++), offset);
00124 y2 = removeSign(*(p++), offset);
00125 cb = removeSign(*(p++), offset);
00126 cr = removeSign(*(p++), offset);
00127
convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00128
convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00129 }
00130 }
00131 }
00132
00135 inline void convertValue(T2 &red,
00136 T2 &green,
00137 T2 &blue,
00138
const T2 y,
00139
const T2 cb,
00140
const T2 cr,
00141
const T2 maxvalue)
00142 {
00143
double dr = 1.1631 * OFstatic_cast(
double, y) + 1.5969 * OFstatic_cast(
double, cr) - 0.8713 * OFstatic_cast(
double, maxvalue);
00144
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);
00145
double db = 1.1631 * OFstatic_cast(
double, y) + 2.0177 * OFstatic_cast(
double, cb) - 1.0820 * OFstatic_cast(
double, maxvalue);
00146 red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(
double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00147 green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(
double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00148 blue = (db < 0.0) ? 0 : (db > OFstatic_cast(
double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00149 }
00150 };
00151
00152
00153
#endif
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