00001 /* 00002 * 00003 * Copyright (C) 1996-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmimgle 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: DicomFlipTemplate (Header) 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:26 $ 00022 * CVS/RCS Revision: $Revision: 1.23 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 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 * class declaration * 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 * CVS/RCS Log: 00347 * $Log: diflipt.h,v $ 00348 * Revision 1.23 2010-10-14 13:16:26 joergr 00349 * Updated copyright header. Added reference to COPYRIGHT file. 00350 * 00351 * Revision 1.22 2010-03-01 09:08:46 uli 00352 * Removed some unnecessary include directives in the headers. 00353 * 00354 * Revision 1.21 2009-10-28 14:38:16 joergr 00355 * Fixed minor issues in log output. 00356 * 00357 * Revision 1.20 2009-10-28 09:53:40 uli 00358 * Switched to logging mechanism provided by the "new" oflog module. 00359 * 00360 * Revision 1.19 2006-08-15 16:30:11 meichel 00361 * Updated the code in module dcmimgle to correctly compile when 00362 * all standard C++ classes remain in namespace std. 00363 * 00364 * Revision 1.18 2005/12/08 16:47:39 meichel 00365 * Changed include path schema for all DCMTK header files 00366 * 00367 * Revision 1.17 2005/06/15 08:25:18 joergr 00368 * Fixed bug which prevented flipHorzVert() from flipping multi-frame images 00369 * correctly (only the first frame was actually flipped). 00370 * 00371 * Revision 1.16 2004/04/21 10:00:36 meichel 00372 * Minor modifications for compilation with gcc 3.4.0 00373 * 00374 * Revision 1.15 2004/02/06 11:07:50 joergr 00375 * Distinguish more clearly between const and non-const access to pixel data. 00376 * 00377 * Revision 1.14 2003/12/23 15:53:22 joergr 00378 * Replaced post-increment/decrement operators by pre-increment/decrement 00379 * operators where appropriate (e.g. 'i++' by '++i'). 00380 * 00381 * Revision 1.13 2003/12/08 18:55:45 joergr 00382 * Adapted type casts to new-style typecast operators defined in ofcast.h. 00383 * Removed leading underscore characters from preprocessor symbols (reserved 00384 * symbols). Updated copyright header. 00385 * 00386 * Revision 1.12 2001/06/01 15:49:41 meichel 00387 * Updated copyright header 00388 * 00389 * Revision 1.11 2000/09/12 10:04:44 joergr 00390 * Corrected bug: wrong parameter for attribute search routine led to crashes 00391 * when multiple pixel data attributes were contained in the dataset (e.g. 00392 * IconImageSequence). Added new checking routines to avoid crashes when 00393 * processing corrupted image data. 00394 * 00395 * Revision 1.10 2000/03/08 16:24:15 meichel 00396 * Updated copyright header. 00397 * 00398 * Revision 1.9 2000/03/02 12:51:36 joergr 00399 * Rewrote variable initialization in class contructors to avoid warnings 00400 * reported on Irix. 00401 * 00402 * Revision 1.8 1999/09/17 12:10:55 joergr 00403 * Added/changed/completed DOC++ style comments in the header files. 00404 * Enhanced efficiency of some "for" loops. 00405 * 00406 * Revision 1.7 1999/05/03 11:09:28 joergr 00407 * Minor code purifications to keep Sun CC 2.0.1 quiet. 00408 * 00409 * Revision 1.6 1999/04/28 14:46:54 joergr 00410 * Removed debug code. 00411 * 00412 * Revision 1.5 1999/03/24 17:20:00 joergr 00413 * Added/Modified comments and formatting. 00414 * 00415 * Revision 1.4 1999/02/03 17:01:16 joergr 00416 * Removed some debug code. 00417 * 00418 * Revision 1.3 1999/01/20 14:59:05 joergr 00419 * Added debug code to measure time of some routines. 00420 * 00421 * Revision 1.2 1998/12/16 16:27:54 joergr 00422 * Added additional case to copy pixels. 00423 * 00424 * Revision 1.1 1998/11/27 14:57:46 joergr 00425 * Added copyright message. 00426 * Added methods and classes for flipping and rotating, changed for 00427 * scaling and clipping. 00428 * 00429 * 00430 */