diyp2pxt.h

00001 /*
00002  *
00003  *  Copyright (C) 1998-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmimage
00019  *
00020  *  Author:  Joerg Riesmeier
00021  *
00022  *  Purpose: DicomYBRPart422PixelTemplate (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:02:05 $
00026  *  CVS/RCS Revision: $Revision: 1.17 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIYP2PXT_H
00035 #define DIYP2PXT_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 
00039 #include "dcmtk/ofstd/ofconsol.h"    /* for ofConsole */
00040 #include "dcmtk/dcmimage/dicopxt.h"
00041 #include "dcmtk/dcmimgle/diinpx.h"  /* gcc 3.4 needs this */
00042 
00043 
00044 /*---------------------*
00045  *  class declaration  *
00046  *---------------------*/
00047 
00050 template<class T1, class T2>
00051 class DiYBRPart422PixelTemplate
00052   : public DiColorPixelTemplate<T2>
00053 {
00054 
00055  public:
00056 
00064     DiYBRPart422PixelTemplate(const DiDocument *docu,
00065                               const DiInputPixel *pixel,
00066                               EI_Status &status,
00067                               const int bits)
00068       : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00069     {
00070         if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00071         {
00072             if (this->PlanarConfiguration)
00073             {
00074                 status = EIS_InvalidValue;
00075                 if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors))
00076                 {
00077                     ofConsole.lockCerr() << "ERROR: invalid value for 'PlanarConfiguration' ("
00078                                          << this->PlanarConfiguration << ") ! " << endl;
00079                     ofConsole.unlockCerr();
00080                 }
00081             }
00082             else
00083                 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits);
00084         }
00085     }
00086 
00089     virtual ~DiYBRPart422PixelTemplate()
00090     {
00091     }
00092 
00093 
00094  private:
00095 
00101     void convert(const T1 *pixel,
00102                  const int bits)
00103     {
00104         if (Init(pixel))
00105         {
00106             register T2 *r = this->Data[0];
00107             register T2 *g = this->Data[1];
00108             register T2 *b = this->Data[2];
00109             register unsigned long i;
00110             const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00111             const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00112             // use the number of input pixels derived from the length of the 'PixelData'
00113             // attribute), but not more than the size of the intermediate buffer
00114             const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00115 
00116             register const T1 *p = pixel;
00117             register T2 y1;
00118             register T2 y2;
00119             register T2 cb;
00120             register T2 cr;
00121             for (i = count / 2; i != 0; --i)
00122             {
00123                 y1 = removeSign(*(p++), offset);
00124                 y2 = removeSign(*(p++), offset);
00125                 cb = removeSign(*(p++), offset);
00126                 cr = removeSign(*(p++), offset);
00127                 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00128                 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00129             }
00130         }
00131     }
00132 
00135     inline void convertValue(T2 &red,
00136                              T2 &green,
00137                              T2 &blue,
00138                              const T2 y,
00139                              const T2 cb,
00140                              const T2 cr,
00141                              const T2 maxvalue)
00142     {
00143         double dr = 1.1631 * OFstatic_cast(double, y) + 1.5969 * OFstatic_cast(double, cr) - 0.8713 * OFstatic_cast(double, maxvalue);
00144         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);
00145         double db = 1.1631 * OFstatic_cast(double, y) + 2.0177 * OFstatic_cast(double, cb) - 1.0820 * OFstatic_cast(double, maxvalue);
00146         red   = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00147         green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00148         blue  = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00149     }
00150 };
00151 
00152 
00153 #endif
00154 
00155 
00156 /*
00157  *
00158  * CVS/RCS Log:
00159  * $Log: diyp2pxt.h,v $
00160  * Revision 1.17  2005/12/08 16:02:05  meichel
00161  * Changed include path schema for all DCMTK header files
00162  *
00163  * Revision 1.16  2004/04/21 10:00:31  meichel
00164  * Minor modifications for compilation with gcc 3.4.0
00165  *
00166  * Revision 1.15  2003/12/23 12:35:00  joergr
00167  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00168  * Removed leading underscore characters from preprocessor symbols (reserved
00169  * symbols). Updated copyright header. Added missing API documentation.
00170  * Replaced post-increment/decrement operators by pre-increment/decrement
00171  * operators where appropriate (e.g. 'i++' by '++i').
00172  *
00173  * Revision 1.14  2002/06/26 16:21:01  joergr
00174  * Enhanced handling of corrupted pixel data and/or length.
00175  *
00176  * Revision 1.13  2001/11/09 16:47:03  joergr
00177  * Removed 'inline' specifier from certain methods.
00178  *
00179  * Revision 1.12  2001/06/01 15:49:33  meichel
00180  * Updated copyright header
00181  *
00182  * Revision 1.11  2000/04/28 12:39:33  joergr
00183  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
00184  *
00185  * Revision 1.10  2000/04/27 13:15:16  joergr
00186  * Dcmimage library code now consistently uses ofConsole for error output.
00187  *
00188  * Revision 1.9  2000/03/08 16:21:55  meichel
00189  * Updated copyright header.
00190  *
00191  * Revision 1.8  2000/03/03 14:07:53  meichel
00192  * Implemented library support for redirecting error messages into memory
00193  *   instead of printing them to stdout/stderr for GUI applications.
00194  *
00195  * Revision 1.7  1999/09/17 14:03:47  joergr
00196  * Enhanced efficiency of some "for" loops.
00197  *
00198  * Revision 1.6  1999/04/28 12:45:22  joergr
00199  * Introduced new scheme for the debug level variable: now each level can be
00200  * set separately (there is no "include" relationship).
00201  *
00202  * Revision 1.5  1999/02/03 16:55:30  joergr
00203  * Moved global functions maxval() and determineRepresentation() to class
00204  * DicomImageClass (as static methods).
00205  *
00206  * Revision 1.4  1999/01/20 14:48:13  joergr
00207  * Replaced invocation of getCount() by member variable Count where possible.
00208  *
00209  * Revision 1.3  1998/11/27 14:22:55  joergr
00210  * Introduced global debug level for dcmimage module to control error output.
00211  *
00212  * Revision 1.2  1998/05/11 14:53:34  joergr
00213  * Added CVS/RCS header to each file.
00214  *
00215  *
00216  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5