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 DIROTAT_H
00031 #define DIROTAT_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/ofstd/ofcast.h"
00035
00036 #include "dcmtk/dcmimgle/dipixel.h"
00037 #include "dcmtk/dcmimgle/ditranst.h"
00038
00039
00040
00041
00042
00043
00047 template<class T>
00048 class DiRotateTemplate
00049 : public DiTransTemplate<T>
00050 {
00051
00052 public:
00053
00065 DiRotateTemplate(DiPixel *pixel,
00066 const Uint16 src_cols,
00067 const Uint16 src_rows,
00068 const Uint16 dest_cols,
00069 const Uint16 dest_rows,
00070 const Uint32 frames,
00071 const int degree)
00072 : DiTransTemplate<T>(0, src_cols, src_rows, dest_cols, dest_rows, frames)
00073 {
00074 if (pixel != NULL)
00075 {
00076 this->Planes = pixel->getPlanes();
00077 if ((pixel->getCount() > 0) && (this->Planes > 0) &&
00078 (pixel->getCount() == OFstatic_cast(unsigned long, src_cols) * OFstatic_cast(unsigned long, src_rows) * frames))
00079 {
00080 if (degree == 90)
00081 rotateRight(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00082 else if (degree == 180)
00083 rotateTopDown(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00084 else if (degree == 270)
00085 rotateLeft(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00086 } else {
00087 DCMIMGLE_WARN("could not rotate image ... corrupted data");
00088 }
00089 }
00090 }
00091
00102 DiRotateTemplate(const int planes,
00103 const Uint16 src_cols,
00104 const Uint16 src_rows,
00105 const Uint16 dest_cols,
00106 const Uint16 dest_rows,
00107 const Uint32 frames)
00108 : DiTransTemplate<T>(planes, src_cols, src_rows, dest_cols, dest_rows, frames)
00109 {
00110 }
00111
00114 virtual ~DiRotateTemplate()
00115 {
00116 }
00117
00124 inline void rotateData(const T *src[],
00125 T *dest[],
00126 const int degree)
00127 {
00128 if (degree == 90)
00129 rotateRight(src, dest);
00130 else if (degree == 180)
00131 rotateTopDown(src, dest);
00132 else if (degree == 270)
00133 rotateLeft(src, dest);
00134 else
00135 copyPixel(src, dest);
00136 }
00137
00138
00139 protected:
00140
00146 inline void rotateLeft(const T *src[],
00147 T *dest[])
00148 {
00149 if ((src != NULL) && (dest != NULL))
00150 {
00151 register Uint16 x;
00152 register Uint16 y;
00153 register const T *p;
00154 register T *q;
00155 register T *r;
00156 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00157 for (int j = 0; j < this->Planes; ++j)
00158 {
00159 p = src[j];
00160 r = dest[j];
00161 for (unsigned long f = this->Frames; f != 0; --f)
00162 {
00163 r += count;
00164 for (x = this->Dest_X; x != 0; --x)
00165 {
00166 q = r - x;
00167 for (y = this->Dest_Y; y != 0; --y)
00168 {
00169 *q = *p++;
00170 q -= this->Dest_X;
00171 }
00172 }
00173 }
00174 }
00175 }
00176 }
00177
00183 inline void rotateRight(const T *src[],
00184 T *dest[])
00185 {
00186 if ((src != NULL) && (dest != NULL))
00187 {
00188 register Uint16 x;
00189 register Uint16 y;
00190 register const T *p;
00191 register T *q;
00192 register T *r;
00193 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00194 for (int j = 0; j < this->Planes; ++j)
00195 {
00196 p = src[j];
00197 r = dest[j];
00198 for (unsigned long f = this->Frames; f != 0; --f)
00199 {
00200 for (x = this->Dest_X; x != 0; --x)
00201 {
00202 q = r + x - 1;
00203 for (y = this->Dest_Y; y != 0; --y)
00204 {
00205 *q = *p++;
00206 q += this->Dest_X;
00207 }
00208 }
00209 r += count;
00210 }
00211 }
00212 }
00213 }
00214
00220 inline void rotateTopDown(const T *src[],
00221 T *dest[])
00222 {
00223 if ((src != NULL) && (dest != NULL))
00224 {
00225 register unsigned long i;
00226 register const T *p;
00227 register T *q;
00228 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00229 for (int j = 0; j < this->Planes; ++j)
00230 {
00231 p = src[j];
00232 q = dest[j];
00233 for (unsigned long f = this->Frames; f != 0; --f)
00234 {
00235 q += count;
00236 for (i = count; i != 0; --i)
00237 *--q = *p++;
00238 q += count;
00239 }
00240 }
00241 }
00242 }
00243
00244 private:
00245
00250 inline void rotateLeft(T *data[])
00251 {
00252 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00253 T *temp = new T[count];
00254 if (temp != NULL)
00255 {
00256 register Uint16 x;
00257 register Uint16 y;
00258 register const T *p;
00259 register T *q;
00260 register T *r;
00261 for (int j = 0; j < this->Planes; ++j)
00262 {
00263 r = data[j];
00264 for (unsigned long f = this->Frames; f != 0; --f)
00265 {
00266 OFBitmanipTemplate<T>::copyMem(OFstatic_cast(const T *, r), temp, count);
00267 p = temp;
00268 r += count;
00269 for (x = this->Dest_X; x != 0; --x)
00270 {
00271 q = r - x;
00272 for (y = this->Dest_Y; y != 0; --y)
00273 {
00274 *q = *p++;
00275 q -= this->Dest_X;
00276 }
00277 }
00278 }
00279 }
00280 delete[] temp;
00281 }
00282 }
00283
00288 inline void rotateRight(T *data[])
00289 {
00290 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00291 T *temp = new T[count];
00292 if (temp != NULL)
00293 {
00294 register Uint16 x;
00295 register Uint16 y;
00296 register const T *p;
00297 register T *q;
00298 register T *r;
00299 for (int j = 0; j < this->Planes; ++j)
00300 {
00301 r = data[j];
00302 for (unsigned long f = this->Frames; f != 0; --f)
00303 {
00304 OFBitmanipTemplate<T>::copyMem(OFstatic_cast(const T *, r), temp, count);
00305 p = temp;
00306 for (x = this->Dest_X; x != 0; --x)
00307 {
00308 q = r + x - 1;
00309 for (y = this->Dest_Y; y != 0; --y)
00310 {
00311 *q = *p++;
00312 q += this->Dest_X;
00313 }
00314 }
00315 r += count;
00316 }
00317 }
00318 delete[] temp;
00319 }
00320 }
00321
00326 inline void rotateTopDown(T *data[])
00327 {
00328 register unsigned long i;
00329 register T *p;
00330 register T *q;
00331 register T t;
00332 T *s;
00333 const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00334 for (int j = 0; j < this->Planes; ++j)
00335 {
00336 s = data[j];
00337 for (unsigned long f = this->Frames; f != 0; --f)
00338 {
00339 p = s;
00340 q = s + count;
00341 for (i = count / 2; i != 0; --i)
00342 {
00343 t = *p;
00344 *p++ = *--q;
00345 *q = t;
00346 }
00347 s += count;
00348 }
00349 }
00350 }
00351 };
00352
00353
00354 #endif
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
00431
00432
00433
00434
00435
00436
00437
00438
00439