dcmimage/include/dcmtk/dcmimage/diyp2pxt.h

00001 /*
00002  *
00003  *  Copyright (C) 1998-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:  dcmimage
00015  *
00016  *  Author:  Joerg Riesmeier
00017  *
00018  *  Purpose: DicomYBRPart422PixelTemplate (Header)
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:16:30 $
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 DIYP2PXT_H
00031 #define DIYP2PXT_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 
00035 #include "dcmtk/dcmimage/dicopxt.h"
00036 #include "dcmtk/dcmimgle/diinpx.h"  /* gcc 3.4 needs this */
00037 
00038 
00039 /*---------------------*
00040  *  class declaration  *
00041  *---------------------*/
00042 
00045 template<class T1, class T2>
00046 class DiYBRPart422PixelTemplate
00047   : public DiColorPixelTemplate<T2>
00048 {
00049 
00050  public:
00051 
00059     DiYBRPart422PixelTemplate(const DiDocument *docu,
00060                               const DiInputPixel *pixel,
00061                               EI_Status &status,
00062                               const int bits)
00063       : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00064     {
00065         if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00066         {
00067             if (this->PlanarConfiguration)
00068             {
00069                 status = EIS_InvalidValue;
00070                 DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")");
00071             }
00072             else
00073                 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits);
00074         }
00075     }
00076 
00079     virtual ~DiYBRPart422PixelTemplate()
00080     {
00081     }
00082 
00083 
00084  private:
00085 
00091     void convert(const T1 *pixel,
00092                  const int bits)
00093     {
00094         if (Init(pixel))
00095         {
00096             register T2 *r = this->Data[0];
00097             register T2 *g = this->Data[1];
00098             register T2 *b = this->Data[2];
00099             register unsigned long i;
00100             const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00101             const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00102             // use the number of input pixels derived from the length of the 'PixelData'
00103             // attribute), but not more than the size of the intermediate buffer
00104             const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00105 
00106             register const T1 *p = pixel;
00107             register T2 y1;
00108             register T2 y2;
00109             register T2 cb;
00110             register T2 cr;
00111             for (i = count / 2; i != 0; --i)
00112             {
00113                 y1 = removeSign(*(p++), offset);
00114                 y2 = removeSign(*(p++), offset);
00115                 cb = removeSign(*(p++), offset);
00116                 cr = removeSign(*(p++), offset);
00117                 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00118                 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00119             }
00120         }
00121     }
00122 
00125     inline void convertValue(T2 &red,
00126                              T2 &green,
00127                              T2 &blue,
00128                              const T2 y,
00129                              const T2 cb,
00130                              const T2 cr,
00131                              const T2 maxvalue)
00132     {
00133         double dr = 1.1631 * OFstatic_cast(double, y) + 1.5969 * OFstatic_cast(double, cr) - 0.8713 * OFstatic_cast(double, maxvalue);
00134         double dg = 1.1631 * OFstatic_cast(double, y) - 0.3913 * OFstatic_cast(double, cb) - 0.8121 * OFstatic_cast(double, cr) + 0.5290 * OFstatic_cast(double, maxvalue);
00135         double db = 1.1631 * OFstatic_cast(double, y) + 2.0177 * OFstatic_cast(double, cb) - 1.0820 * OFstatic_cast(double, maxvalue);
00136         red   = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00137         green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00138         blue  = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00139     }
00140 };
00141 
00142 
00143 #endif
00144 
00145 
00146 /*
00147  *
00148  * CVS/RCS Log:
00149  * $Log: diyp2pxt.h,v $
00150  * Revision 1.23  2010-10-14 13:16:30  joergr
00151  * Updated copyright header. Added reference to COPYRIGHT file.
00152  *
00153  * Revision 1.22  2010-03-01 09:08:46  uli
00154  * Removed some unnecessary include directives in the headers.
00155  *
00156  * Revision 1.21  2009-11-25 14:31:21  joergr
00157  * Removed inclusion of header file "ofconsol.h".
00158  *
00159  * Revision 1.20  2009-10-14 10:25:14  joergr
00160  * Fixed minor issues in log output. Also updated copyright date (if required).
00161  *
00162  * Revision 1.19  2009-10-13 14:08:33  uli
00163  * Switched to logging mechanism provided by the "new" oflog module
00164  *
00165  * Revision 1.18  2006-08-15 16:35:01  meichel
00166  * Updated the code in module dcmimage to correctly compile when
00167  *   all standard C++ classes remain in namespace std.
00168  *
00169  * Revision 1.17  2005/12/08 16:02:05  meichel
00170  * Changed include path schema for all DCMTK header files
00171  *
00172  * Revision 1.16  2004/04/21 10:00:31  meichel
00173  * Minor modifications for compilation with gcc 3.4.0
00174  *
00175  * Revision 1.15  2003/12/23 12:35:00  joergr
00176  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00177  * Removed leading underscore characters from preprocessor symbols (reserved
00178  * symbols). Updated copyright header. Added missing API documentation.
00179  * Replaced post-increment/decrement operators by pre-increment/decrement
00180  * operators where appropriate (e.g. 'i++' by '++i').
00181  *
00182  * Revision 1.14  2002/06/26 16:21:01  joergr
00183  * Enhanced handling of corrupted pixel data and/or length.
00184  *
00185  * Revision 1.13  2001/11/09 16:47:03  joergr
00186  * Removed 'inline' specifier from certain methods.
00187  *
00188  * Revision 1.12  2001/06/01 15:49:33  meichel
00189  * Updated copyright header
00190  *
00191  * Revision 1.11  2000/04/28 12:39:33  joergr
00192  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
00193  *
00194  * Revision 1.10  2000/04/27 13:15:16  joergr
00195  * Dcmimage library code now consistently uses ofConsole for error output.
00196  *
00197  * Revision 1.9  2000/03/08 16:21:55  meichel
00198  * Updated copyright header.
00199  *
00200  * Revision 1.8  2000/03/03 14:07:53  meichel
00201  * Implemented library support for redirecting error messages into memory
00202  *   instead of printing them to stdout/stderr for GUI applications.
00203  *
00204  * Revision 1.7  1999/09/17 14:03:47  joergr
00205  * Enhanced efficiency of some "for" loops.
00206  *
00207  * Revision 1.6  1999/04/28 12:45:22  joergr
00208  * Introduced new scheme for the debug level variable: now each level can be
00209  * set separately (there is no "include" relationship).
00210  *
00211  * Revision 1.5  1999/02/03 16:55:30  joergr
00212  * Moved global functions maxval() and determineRepresentation() to class
00213  * DicomImageClass (as static methods).
00214  *
00215  * Revision 1.4  1999/01/20 14:48:13  joergr
00216  * Replaced invocation of getCount() by member variable Count where possible.
00217  *
00218  * Revision 1.3  1998/11/27 14:22:55  joergr
00219  * Introduced global debug level for dcmimage module to control error output.
00220  *
00221  * Revision 1.2  1998/05/11 14:53:34  joergr
00222  * Added CVS/RCS header to each file.
00223  *
00224  *
00225  */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1