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 DIFLIPT_H
00035
#define DIFLIPT_H
00036
00037
#include "osconfig.h"
00038
#include "dctypes.h"
00039
#include "ofcast.h"
00040
00041
#include "dipixel.h"
00042
#include "ditranst.h"
00043
00044
00045
00046
00047
00048
00052
template<
class T>
00053 class DiFlipTemplate
00054 :
public DiTransTemplate<T>
00055 {
00056
00057
public:
00058
00069 DiFlipTemplate(
DiPixel *pixel,
00070
const Uint16 columns,
00071
const Uint16 rows,
00072
const Uint32 frames,
00073
const int horz,
00074
const int vert)
00075 :
DiTransTemplate<T>(0, columns, rows, columns, rows, frames)
00076 {
00077
if (pixel != NULL)
00078 {
00079 this->Planes = pixel->
getPlanes();
00080
if ((pixel->
getCount() > 0) && (this->Planes > 0) &&
00081 (pixel->
getCount() == OFstatic_cast(
unsigned long, columns) * OFstatic_cast(
unsigned long, rows) * frames))
00082 {
00083
if (horz && vert)
00084
flipHorzVert(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00085
else if (horz)
00086
flipHorz(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00087
else if (vert)
00088
flipVert(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00089 }
else {
00090
if (
DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00091 {
00092 ofConsole.lockCerr() <<
"WARNING: could not flip image ... corrupted data." << endl;
00093 ofConsole.unlockCerr();
00094 }
00095 }
00096 }
00097 }
00098
00107 DiFlipTemplate(
const int planes,
00108
const Uint16 columns,
00109
const Uint16 rows,
00110
const Uint32 frames)
00111 :
DiTransTemplate<T>(planes, columns, rows, columns, rows, frames)
00112 {
00113 }
00114
00117 virtual ~DiFlipTemplate()
00118 {
00119 }
00120
00128 inline void flipData(
const T *src[],
00129 T *dest[],
00130
const int horz,
00131
const int vert)
00132 {
00133
if ((src != NULL) && (dest != NULL))
00134 {
00135
if (horz && vert)
00136
flipHorzVert(src, dest);
00137
else if (horz)
00138
flipHorz(src, dest);
00139
else if (vert)
00140
flipVert(src, dest);
00141
else
00142
copyPixel(src, dest);
00143 }
00144 }
00145
00146
00147
protected:
00148
00154 inline void flipHorz(
const T *src[],
00155 T *dest[])
00156 {
00157
if ((src != NULL) && (dest != NULL))
00158 {
00159
register Uint16 x;
00160
register Uint16 y;
00161
register const T *p;
00162
register T *q;
00163
register T *r;
00164
for (
int j = 0; j < this->Planes; ++j)
00165 {
00166 p = src[j];
00167 r = dest[j];
00168
for (Uint32 f = this->Frames; f != 0; --f)
00169 {
00170
for (y = this->Src_Y; y != 0; --y)
00171 {
00172 q = r + this->Dest_X;
00173
for (x = this->Src_X; x != 0; --x)
00174 *--q = *p++;
00175 r += this->Dest_X;
00176 }
00177 }
00178 }
00179 }
00180 }
00181
00187 inline void flipVert(
const T *src[],
00188 T *dest[])
00189 {
00190
if ((src != NULL) && (dest != NULL))
00191 {
00192
register Uint16 x;
00193
register Uint16 y;
00194
register const T *p;
00195
register T *q;
00196
register T *r;
00197
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00198
for (
int j = 0; j < this->Planes; ++j)
00199 {
00200 p = src[j];
00201 r = dest[j];
00202
for (Uint32 f = this->Frames; f != 0; --f)
00203 {
00204 r += count;
00205
for (y = this->Src_Y; y != 0; --y)
00206 {
00207 q = r - this->Dest_X;
00208
for (x = this->Src_X; x != 0; --x)
00209 *q++ = *p++;
00210 r -= this->Dest_X;
00211 }
00212 r += count;
00213 }
00214 }
00215 }
00216 }
00217
00223 inline void flipHorzVert(
const T *src[],
00224 T *dest[])
00225 {
00226
if ((src != NULL) && (dest != NULL))
00227 {
00228
register unsigned long i;
00229
register const T *p;
00230
register T *q;
00231
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00232
for (
int j = 0; j < this->Planes; ++j)
00233 {
00234 p = src[j];
00235 q = dest[j];
00236
for (Uint32 f = this->Frames; f != 0; --f)
00237 {
00238 q += count;
00239
for (i = count; i != 0; --i)
00240 *--q = *p++;
00241 q += count;
00242 }
00243 }
00244 }
00245 }
00246
00247
private:
00248
00253 inline void flipHorz(T *data[])
00254 {
00255
register Uint16 x;
00256
register Uint16 y;
00257
register T *p;
00258
register T *q;
00259
register T t;
00260 T *r;
00261
for (
int j = 0; j < this->Planes; ++j)
00262 {
00263 r = data[j];
00264
for (Uint32 f = this->Frames; f != 0; --f)
00265 {
00266
for (y = this->Src_Y; y != 0; --y)
00267 {
00268 p = r;
00269 r += this->Dest_X;
00270 q = r;
00271
for (x = this->Src_X / 2; x != 0; --x)
00272 {
00273 t = *p;
00274 *p++ = *--q;
00275 *q = t;
00276 }
00277 }
00278 }
00279 }
00280 }
00281
00286 inline void flipVert(T *data[])
00287 {
00288
register Uint16 x;
00289
register Uint16 y;
00290
register T *p;
00291
register T *q;
00292
register T *r;
00293
register T t;
00294 T *s;
00295
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00296
for (
int j = 0; j < this->Planes; ++j)
00297 {
00298 s = data[j];
00299
for (Uint32 f = this->Frames; f != 0; --f)
00300 {
00301 p = s;
00302 s += count;
00303 r = s;
00304
for (y = this->Src_Y / 2; y != 0; --y)
00305 {
00306 r -= this->Dest_X;
00307 q = r;
00308
for (x = this->Src_X; x != 0; --x)
00309 {
00310 t = *p;
00311 *p++ = *q;
00312 *q++ = t;
00313 }
00314 }
00315 }
00316 }
00317 }
00318
00323 inline void flipHorzVert(T *data[])
00324 {
00325
register unsigned long i;
00326
register T *p;
00327
register T *q;
00328
register T t;
00329 T *s;
00330
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00331
for (
int j = 0; j < this->Planes; ++j)
00332 {
00333 s = data[j];
00334
for (Uint32 f = this->Frames; f != 0; --f)
00335 {
00336 p = s;
00337 q = s + count;
00338
for (i = count / 2; i != 0; --i)
00339 {
00340 t = *p;
00341 *p++ = *--q;
00342 *q = t;
00343 }
00344 }
00345 }
00346 }
00347 };
00348
00349
00350
#endif
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