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 DIFLIPT_H
00031 #define DIFLIPT_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034
00035 #include "dcmtk/dcmimgle/dipixel.h"
00036 #include "dcmtk/dcmimgle/ditranst.h"
00037
00038
00039
00040
00041
00042
00046 template<class T>
00047 class DiFlipTemplate
00048 : public DiTransTemplate<T>
00049 {
00050
00051 public:
00052
00063 DiFlipTemplate(DiPixel *pixel,
00064 const Uint16 columns,
00065 const Uint16 rows,
00066 const Uint32 frames,
00067 const int horz,
00068 const int vert)
00069 : DiTransTemplate<T>(0, columns, rows, columns, rows, frames)
00070 {
00071 if (pixel != NULL)
00072 {
00073 this->Planes = pixel->getPlanes();
00074 if ((pixel->getCount() > 0) && (this->Planes > 0) &&
00075 (pixel->getCount() == OFstatic_cast(unsigned long, columns) * OFstatic_cast(unsigned long, rows) * frames))
00076 {
00077 if (horz && vert)
00078 flipHorzVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00079 else if (horz)
00080 flipHorz(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00081 else if (vert)
00082 flipVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00083 } else {
00084 DCMIMGLE_WARN("could not flip image ... corrupted data");
00085 }
00086 }
00087 }
00088
00097 DiFlipTemplate(const int planes,
00098 const Uint16 columns,
00099 const Uint16 rows,
00100 const Uint32 frames)
00101 : DiTransTemplate<T>(planes, columns, rows, columns, rows, frames)
00102 {
00103 }
00104
00107 virtual ~DiFlipTemplate()
00108 {
00109 }
00110
00118 inline void flipData(const T *src[],
00119 T *dest[],
00120 const int horz,
00121 const int vert)
00122 {
00123 if ((src != NULL) && (dest != NULL))
00124 {
00125 if (horz && vert)
00126 flipHorzVert(src, dest);
00127 else if (horz)
00128 flipHorz(src, dest);
00129 else if (vert)
00130 flipVert(src, dest);
00131 else
00132 copyPixel(src, dest);
00133 }
00134 }
00135
00136
00137 protected:
00138
00144 inline void flipHorz(const T *src[],
00145 T *dest[])
00146 {
00147 if ((src != NULL) && (dest != NULL))
00148 {
00149 register Uint16 x;
00150 register Uint16 y;
00151 register const T *p;
00152 register T *q;
00153 register T *r;
00154 for (int j = 0; j < this->Planes; ++j)
00155 {
00156 p = src[j];
00157 r = dest[j];
00158 for (Uint32 f = this->Frames; f != 0; --f)
00159 {
00160 for (y = this->Src_Y; y != 0; --y)
00161 {
00162 q = r + this->Dest_X;
00163 for (x = this->Src_X; x != 0; --x)
00164 *--q = *p++;
00165 r += this->Dest_X;
00166 }
00167 }
00168 }
00169 }
00170 }
00171
00177 inline void flipVert(const T *src[],
00178 T *dest[])
00179 {
00180 if ((src != NULL) && (dest != NULL))
00181 {
00182 register Uint16 x;
00183 register Uint16 y;
00184 register const T *p;
00185 register T *q;
00186 register T *r;
00187 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00188 for (int j = 0; j < this->Planes; ++j)
00189 {
00190 p = src[j];
00191 r = dest[j];
00192 for (Uint32 f = this->Frames; f != 0; --f)
00193 {
00194 r += count;
00195 for (y = this->Src_Y; y != 0; --y)
00196 {
00197 q = r - this->Dest_X;
00198 for (x = this->Src_X; x != 0; --x)
00199 *q++ = *p++;
00200 r -= this->Dest_X;
00201 }
00202 r += count;
00203 }
00204 }
00205 }
00206 }
00207
00213 inline void flipHorzVert(const T *src[],
00214 T *dest[])
00215 {
00216 if ((src != NULL) && (dest != NULL))
00217 {
00218 register unsigned long i;
00219 register const T *p;
00220 register T *q;
00221 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00222 for (int j = 0; j < this->Planes; ++j)
00223 {
00224 p = src[j];
00225 q = dest[j];
00226 for (Uint32 f = this->Frames; f != 0; --f)
00227 {
00228 q += count;
00229 for (i = count; i != 0; --i)
00230 *--q = *p++;
00231 q += count;
00232 }
00233 }
00234 }
00235 }
00236
00237 private:
00238
00243 inline void flipHorz(T *data[])
00244 {
00245 register Uint16 x;
00246 register Uint16 y;
00247 register T *p;
00248 register T *q;
00249 register T t;
00250 T *r;
00251 for (int j = 0; j < this->Planes; ++j)
00252 {
00253 r = data[j];
00254 for (Uint32 f = this->Frames; f != 0; --f)
00255 {
00256 for (y = this->Src_Y; y != 0; --y)
00257 {
00258 p = r;
00259 r += this->Dest_X;
00260 q = r;
00261 for (x = this->Src_X / 2; x != 0; --x)
00262 {
00263 t = *p;
00264 *p++ = *--q;
00265 *q = t;
00266 }
00267 }
00268 }
00269 }
00270 }
00271
00276 inline void flipVert(T *data[])
00277 {
00278 register Uint16 x;
00279 register Uint16 y;
00280 register T *p;
00281 register T *q;
00282 register T *r;
00283 register T t;
00284 T *s;
00285 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00286 for (int j = 0; j < this->Planes; ++j)
00287 {
00288 s = data[j];
00289 for (Uint32 f = this->Frames; f != 0; --f)
00290 {
00291 p = s;
00292 s += count;
00293 r = s;
00294 for (y = this->Src_Y / 2; y != 0; --y)
00295 {
00296 r -= this->Dest_X;
00297 q = r;
00298 for (x = this->Src_X; x != 0; --x)
00299 {
00300 t = *p;
00301 *p++ = *q;
00302 *q++ = t;
00303 }
00304 }
00305 }
00306 }
00307 }
00308
00313 inline void flipHorzVert(T *data[])
00314 {
00315 register unsigned long i;
00316 register T *p;
00317 register T *q;
00318 register T t;
00319 T *s;
00320 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00321 for (int j = 0; j < this->Planes; ++j)
00322 {
00323 s = data[j];
00324 for (Uint32 f = this->Frames; f != 0; --f)
00325 {
00326 p = s;
00327 q = s + count;
00328 for (i = count / 2; i != 0; --i)
00329 {
00330 t = *p;
00331 *p++ = *--q;
00332 *q = t;
00333 }
00334 s += count;
00335 }
00336 }
00337 }
00338 };
00339
00340
00341 #endif
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430