OFFIS DCMTK  Version 3.6.0
diflipt.h
1 /*
2  *
3  * Copyright (C) 1996-2011, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmimgle
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose: DicomFlipTemplate (Header)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2011-11-17 16:13:16 $
22  * CVS/RCS Revision: $Revision: 1.24 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIFLIPT_H
31 #define DIFLIPT_H
32 
33 #include "dcmtk/config/osconfig.h"
34 
35 #include "dcmtk/dcmimgle/dipixel.h"
36 #include "dcmtk/dcmimgle/ditranst.h"
37 
38 
39 /*---------------------*
40  * class declaration *
41  *---------------------*/
42 
46 template<class T>
48  : public DiTransTemplate<T>
49 {
50 
51  public:
52 
64  const Uint16 columns,
65  const Uint16 rows,
66  const Uint32 frames,
67  const int horz,
68  const int vert)
69  : DiTransTemplate<T>(0, columns, rows, columns, rows, frames)
70  {
71  if (pixel != NULL)
72  {
73  this->Planes = pixel->getPlanes();
74  if ((pixel->getCount() > 0) && (this->Planes > 0) &&
75  (pixel->getCount() == OFstatic_cast(unsigned long, columns) * OFstatic_cast(unsigned long, rows) * frames))
76  {
77  if (horz && vert)
78  flipHorzVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
79  else if (horz)
80  flipHorz(OFstatic_cast(T **, pixel->getDataArrayPtr()));
81  else if (vert)
82  flipVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
83  } else {
84  DCMIMGLE_WARN("could not flip image ... corrupted data");
85  }
86  }
87  }
88 
97  DiFlipTemplate(const int planes,
98  const Uint16 columns,
99  const Uint16 rows,
100  const Uint32 frames)
101  : DiTransTemplate<T>(planes, columns, rows, columns, rows, frames)
102  {
103  }
104 
107  virtual ~DiFlipTemplate()
108  {
109  }
110 
118  inline void flipData(const T *src[],
119  T *dest[],
120  const int horz,
121  const int vert)
122  {
123  if ((src != NULL) && (dest != NULL))
124  {
125  if (horz && vert)
126  flipHorzVert(src, dest);
127  else if (horz)
128  flipHorz(src, dest);
129  else if (vert)
130  flipVert(src, dest);
131  else
132  this->copyPixel(src, dest);
133  }
134  }
135 
136 
137  protected:
138 
144  inline void flipHorz(const T *src[],
145  T *dest[])
146  {
147  if ((src != NULL) && (dest != NULL))
148  {
149  register Uint16 x;
150  register Uint16 y;
151  register const T *p;
152  register T *q;
153  register T *r;
154  for (int j = 0; j < this->Planes; ++j)
155  {
156  p = src[j];
157  r = dest[j];
158  for (Uint32 f = this->Frames; f != 0; --f)
159  {
160  for (y = this->Src_Y; y != 0; --y)
161  {
162  q = r + this->Dest_X;
163  for (x = this->Src_X; x != 0; --x)
164  *--q = *p++;
165  r += this->Dest_X;
166  }
167  }
168  }
169  }
170  }
171 
177  inline void flipVert(const T *src[],
178  T *dest[])
179  {
180  if ((src != NULL) && (dest != NULL))
181  {
182  register Uint16 x;
183  register Uint16 y;
184  register const T *p;
185  register T *q;
186  register T *r;
187  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
188  for (int j = 0; j < this->Planes; ++j)
189  {
190  p = src[j];
191  r = dest[j];
192  for (Uint32 f = this->Frames; f != 0; --f)
193  {
194  r += count;
195  for (y = this->Src_Y; y != 0; --y)
196  {
197  q = r - this->Dest_X;
198  for (x = this->Src_X; x != 0; --x)
199  *q++ = *p++;
200  r -= this->Dest_X;
201  }
202  r += count;
203  }
204  }
205  }
206  }
207 
213  inline void flipHorzVert(const T *src[],
214  T *dest[])
215  {
216  if ((src != NULL) && (dest != NULL))
217  {
218  register unsigned long i;
219  register const T *p;
220  register T *q;
221  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
222  for (int j = 0; j < this->Planes; ++j)
223  {
224  p = src[j];
225  q = dest[j];
226  for (Uint32 f = this->Frames; f != 0; --f)
227  {
228  q += count;
229  for (i = count; i != 0; --i)
230  *--q = *p++;
231  q += count;
232  }
233  }
234  }
235  }
236 
237  private:
238 
243  inline void flipHorz(T *data[])
244  {
245  register Uint16 x;
246  register Uint16 y;
247  register T *p;
248  register T *q;
249  register T t;
250  T *r;
251  for (int j = 0; j < this->Planes; ++j)
252  {
253  r = data[j];
254  for (Uint32 f = this->Frames; f != 0; --f)
255  {
256  for (y = this->Src_Y; y != 0; --y)
257  {
258  p = r;
259  r += this->Dest_X;
260  q = r;
261  for (x = this->Src_X / 2; x != 0; --x)
262  {
263  t = *p;
264  *p++ = *--q;
265  *q = t;
266  }
267  }
268  }
269  }
270  }
271 
276  inline void flipVert(T *data[])
277  {
278  register Uint16 x;
279  register Uint16 y;
280  register T *p;
281  register T *q;
282  register T *r;
283  register T t;
284  T *s;
285  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
286  for (int j = 0; j < this->Planes; ++j)
287  {
288  s = data[j];
289  for (Uint32 f = this->Frames; f != 0; --f)
290  {
291  p = s;
292  s += count;
293  r = s;
294  for (y = this->Src_Y / 2; y != 0; --y)
295  {
296  r -= this->Dest_X;
297  q = r;
298  for (x = this->Src_X; x != 0; --x)
299  {
300  t = *p;
301  *p++ = *q;
302  *q++ = t;
303  }
304  }
305  }
306  }
307  }
308 
313  inline void flipHorzVert(T *data[])
314  {
315  register unsigned long i;
316  register T *p;
317  register T *q;
318  register T t;
319  T *s;
320  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
321  for (int j = 0; j < this->Planes; ++j)
322  {
323  s = data[j];
324  for (Uint32 f = this->Frames; f != 0; --f)
325  {
326  p = s;
327  q = s + count;
328  for (i = count / 2; i != 0; --i)
329  {
330  t = *p;
331  *p++ = *--q;
332  *q = t;
333  }
334  s += count;
335  }
336  }
337  }
338 };
339 
340 
341 #endif
342 
343 
344 /*
345  *
346  * CVS/RCS Log:
347  * $Log: diflipt.h,v $
348  * Revision 1.24 2011-11-17 16:13:16 joergr
349  * Minor fixes to keep XCode 4.2 on Mac OS X Lion (clang compiler) quiet.
350  *
351  * Revision 1.23 2010-10-14 13:16:26 joergr
352  * Updated copyright header. Added reference to COPYRIGHT file.
353  *
354  * Revision 1.22 2010-03-01 09:08:46 uli
355  * Removed some unnecessary include directives in the headers.
356  *
357  * Revision 1.21 2009-10-28 14:38:16 joergr
358  * Fixed minor issues in log output.
359  *
360  * Revision 1.20 2009-10-28 09:53:40 uli
361  * Switched to logging mechanism provided by the "new" oflog module.
362  *
363  * Revision 1.19 2006-08-15 16:30:11 meichel
364  * Updated the code in module dcmimgle to correctly compile when
365  * all standard C++ classes remain in namespace std.
366  *
367  * Revision 1.18 2005/12/08 16:47:39 meichel
368  * Changed include path schema for all DCMTK header files
369  *
370  * Revision 1.17 2005/06/15 08:25:18 joergr
371  * Fixed bug which prevented flipHorzVert() from flipping multi-frame images
372  * correctly (only the first frame was actually flipped).
373  *
374  * Revision 1.16 2004/04/21 10:00:36 meichel
375  * Minor modifications for compilation with gcc 3.4.0
376  *
377  * Revision 1.15 2004/02/06 11:07:50 joergr
378  * Distinguish more clearly between const and non-const access to pixel data.
379  *
380  * Revision 1.14 2003/12/23 15:53:22 joergr
381  * Replaced post-increment/decrement operators by pre-increment/decrement
382  * operators where appropriate (e.g. 'i++' by '++i').
383  *
384  * Revision 1.13 2003/12/08 18:55:45 joergr
385  * Adapted type casts to new-style typecast operators defined in ofcast.h.
386  * Removed leading underscore characters from preprocessor symbols (reserved
387  * symbols). Updated copyright header.
388  *
389  * Revision 1.12 2001/06/01 15:49:41 meichel
390  * Updated copyright header
391  *
392  * Revision 1.11 2000/09/12 10:04:44 joergr
393  * Corrected bug: wrong parameter for attribute search routine led to crashes
394  * when multiple pixel data attributes were contained in the dataset (e.g.
395  * IconImageSequence). Added new checking routines to avoid crashes when
396  * processing corrupted image data.
397  *
398  * Revision 1.10 2000/03/08 16:24:15 meichel
399  * Updated copyright header.
400  *
401  * Revision 1.9 2000/03/02 12:51:36 joergr
402  * Rewrote variable initialization in class contructors to avoid warnings
403  * reported on Irix.
404  *
405  * Revision 1.8 1999/09/17 12:10:55 joergr
406  * Added/changed/completed DOC++ style comments in the header files.
407  * Enhanced efficiency of some "for" loops.
408  *
409  * Revision 1.7 1999/05/03 11:09:28 joergr
410  * Minor code purifications to keep Sun CC 2.0.1 quiet.
411  *
412  * Revision 1.6 1999/04/28 14:46:54 joergr
413  * Removed debug code.
414  *
415  * Revision 1.5 1999/03/24 17:20:00 joergr
416  * Added/Modified comments and formatting.
417  *
418  * Revision 1.4 1999/02/03 17:01:16 joergr
419  * Removed some debug code.
420  *
421  * Revision 1.3 1999/01/20 14:59:05 joergr
422  * Added debug code to measure time of some routines.
423  *
424  * Revision 1.2 1998/12/16 16:27:54 joergr
425  * Added additional case to copy pixels.
426  *
427  * Revision 1.1 1998/11/27 14:57:46 joergr
428  * Added copyright message.
429  * Added methods and classes for flipping and rotating, changed for
430  * scaling and clipping.
431  *
432  *
433  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2