dcmimage/include/dcmtk/dcmimage/diyf2pxt.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: DicomYBR422PixelTemplate (Header)
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:16:30 $
00022  *  CVS/RCS Revision: $Revision: 1.25 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef DIYF2PXT_H
00031 #define DIYF2PXT_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 DiYBR422PixelTemplate
00047   : public DiColorPixelTemplate<T2>
00048 {
00049 
00050  public:
00051 
00060     DiYBR422PixelTemplate(const DiDocument *docu,
00061                           const DiInputPixel *pixel,
00062                           EI_Status &status,
00063                           const int bits,
00064                           const OFBool rgb)
00065       : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
00066     {
00067         if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
00068         {
00069             if (this->PlanarConfiguration)
00070             {
00071                 status = EIS_InvalidValue;
00072                 DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")");
00073             }
00074             else
00075                 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits, rgb);
00076         }
00077     }
00078 
00081     virtual ~DiYBR422PixelTemplate()
00082     {
00083     }
00084 
00085 
00086  private:
00087 
00094     void convert(const T1 *pixel,
00095                  const int bits,
00096                  const OFBool rgb)
00097     {
00098         if (Init(pixel))
00099         {
00100             const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
00101             register unsigned long i;
00102             register const T1 *p = pixel;
00103             register T2 *r = this->Data[0];
00104             register T2 *g = this->Data[1];
00105             register T2 *b = this->Data[2];
00106             register T2 y1;
00107             register T2 y2;
00108             register T2 cb;
00109             register T2 cr;
00110             // use the number of input pixels derived from the length of the 'PixelData'
00111             // attribute), but not more than the size of the intermediate buffer
00112             const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
00113             if (rgb)    /* convert to RGB model */
00114             {
00115                 const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
00116                 for (i = count / 2; i != 0; --i)
00117                 {
00118                     y1 = removeSign(*(p++), offset);
00119                     y2 = removeSign(*(p++), offset);
00120                     cb = removeSign(*(p++), offset);
00121                     cr = removeSign(*(p++), offset);
00122                     convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
00123                     convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
00124                 }
00125             } else {    /* retain YCbCr model: YCbCr_422_full -> YCbCr_full */
00126                 for (i = count / 2; i != 0; --i)
00127                 {
00128                     y1 = removeSign(*(p++), offset);
00129                     y2 = removeSign(*(p++), offset);
00130                     cb = removeSign(*(p++), offset);
00131                     cr = removeSign(*(p++), offset);
00132                     *(r++) = y1;
00133                     *(g++) = cb;
00134                     *(b++) = cr;
00135                     *(r++) = y2;
00136                     *(g++) = cb;
00137                     *(b++) = cr;
00138                 }
00139             }
00140         }
00141     }
00142 
00145     inline void convertValue(T2 &red,
00146                              T2 &green,
00147                              T2 &blue,
00148                              const T2 y,
00149                              const T2 cb,
00150                              const T2 cr,
00151                              const T2 maxvalue)
00152     {
00153         double dr = OFstatic_cast(double, y) + 1.4020 * OFstatic_cast(double, cr) - 0.7010 * OFstatic_cast(double, maxvalue);
00154         double dg = OFstatic_cast(double, y) - 0.3441 * OFstatic_cast(double, cb) - 0.7141 * OFstatic_cast(double, cr) + 0.5291 * OFstatic_cast(double, maxvalue);
00155         double db = OFstatic_cast(double, y) + 1.7720 * OFstatic_cast(double, cb) - 0.8859 * OFstatic_cast(double, maxvalue);
00156         red   = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
00157         green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
00158         blue  = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
00159     }
00160 };
00161 
00162 
00163 #endif
00164 
00165 
00166 /*
00167  *
00168  * CVS/RCS Log:
00169  * $Log: diyf2pxt.h,v $
00170  * Revision 1.25  2010-10-14 13:16:30  joergr
00171  * Updated copyright header. Added reference to COPYRIGHT file.
00172  *
00173  * Revision 1.24  2010-03-01 09:08:46  uli
00174  * Removed some unnecessary include directives in the headers.
00175  *
00176  * Revision 1.23  2009-11-25 14:31:21  joergr
00177  * Removed inclusion of header file "ofconsol.h".
00178  *
00179  * Revision 1.22  2009-10-14 10:25:14  joergr
00180  * Fixed minor issues in log output. Also updated copyright date (if required).
00181  *
00182  * Revision 1.21  2009-10-13 14:08:33  uli
00183  * Switched to logging mechanism provided by the "new" oflog module
00184  *
00185  * Revision 1.20  2006-08-15 16:35:01  meichel
00186  * Updated the code in module dcmimage to correctly compile when
00187  *   all standard C++ classes remain in namespace std.
00188  *
00189  * Revision 1.19  2005/12/08 16:02:03  meichel
00190  * Changed include path schema for all DCMTK header files
00191  *
00192  * Revision 1.18  2004/04/21 10:00:31  meichel
00193  * Minor modifications for compilation with gcc 3.4.0
00194  *
00195  * Revision 1.17  2003/12/23 12:33:01  joergr
00196  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00197  * Removed leading underscore characters from preprocessor symbols (reserved
00198  * symbols). Updated copyright header. Added missing API documentation.
00199  * Replaced post-increment/decrement operators by pre-increment/decrement
00200  * operators where appropriate (e.g. 'i++' by '++i').
00201  *
00202  * Revision 1.16  2002/06/26 16:20:53  joergr
00203  * Enhanced handling of corrupted pixel data and/or length.
00204  *
00205  * Revision 1.15  2002/05/24 09:53:06  joergr
00206  * Added missing #include "ofconsol.h".
00207  *
00208  * Revision 1.14  2001/11/09 16:47:03  joergr
00209  * Removed 'inline' specifier from certain methods.
00210  *
00211  * Revision 1.13  2001/09/28 13:55:41  joergr
00212  * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr
00213  * color models to RGB.
00214  *
00215  * Revision 1.12  2001/06/01 15:49:33  meichel
00216  * Updated copyright header
00217  *
00218  * Revision 1.11  2000/04/28 12:39:33  joergr
00219  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
00220  *
00221  * Revision 1.10  2000/04/27 13:15:16  joergr
00222  * Dcmimage library code now consistently uses ofConsole for error output.
00223  *
00224  * Revision 1.9  2000/03/08 16:21:54  meichel
00225  * Updated copyright header.
00226  *
00227  * Revision 1.8  2000/03/03 14:07:52  meichel
00228  * Implemented library support for redirecting error messages into memory
00229  *   instead of printing them to stdout/stderr for GUI applications.
00230  *
00231  * Revision 1.7  1999/09/17 14:03:47  joergr
00232  * Enhanced efficiency of some "for" loops.
00233  *
00234  * Revision 1.6  1999/04/28 12:45:21  joergr
00235  * Introduced new scheme for the debug level variable: now each level can be
00236  * set separately (there is no "include" relationship).
00237  *
00238  * Revision 1.5  1999/02/03 16:55:29  joergr
00239  * Moved global functions maxval() and determineRepresentation() to class
00240  * DicomImageClass (as static methods).
00241  *
00242  * Revision 1.4  1999/01/20 14:48:01  joergr
00243  * Replaced invocation of getCount() by member variable Count where possible.
00244  *
00245  * Revision 1.3  1998/11/27 14:21:48  joergr
00246  * Added copyright message.
00247  * Introduced global debug level for dcmimage module to control error output.
00248  *
00249  * Revision 1.2  1998/05/11 14:53:33  joergr
00250  * Added CVS/RCS header to each file.
00251  *
00252  *
00253  */


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