dcmimage/include/dcmtk/dcmimage/diqtcmap.h

00001 /*
00002  *
00003  *  Copyright (C) 2002-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:  Marco Eichelberg
00017  *
00018  *  Purpose: class DcmQuantColorMapping
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:16:29 $
00022  *  CVS/RCS Revision: $Revision: 1.5 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef DIQTCMAP_H
00031 #define DIQTCMAP_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/dcmimage/diqttype.h"  /* for DcmQuantComponent */
00035 #include "dcmtk/dcmimgle/dcmimage.h"  /* gcc 3.4 needs this */
00036 #include "dcmtk/dcmimage/diqtstab.h"  /* gcc 3.4 needs this */
00037 #include "dcmtk/dcmimage/diqtpix.h"   /* gcc 3.4 needs this */
00038 #include "dcmtk/dcmimage/diqthash.h"  /* gcc 3.4 needs this */
00039 #include "dcmtk/dcmimage/diqtctab.h"  /* gcc 3.4 needs this */
00040 
00041 class DicomImage;
00042 class DcmQuantColorHashTable;
00043 class DcmQuantColorTable;
00044 class DcmQuantPixel;
00045 class DcmQuantScaleTable;
00046 
00047 
00054 template <class T1, class T2>
00055 class DcmQuantColorMapping
00056 {
00057 public:
00058 
00076   static void create(
00077     DicomImage& sourceImage,
00078     unsigned long frameNumber,
00079     unsigned long maxval,
00080     DcmQuantColorHashTable& cht,
00081     DcmQuantColorTable& colormap,
00082     T1& fs,
00083     T2 *tp)
00084   {
00085     unsigned long cols = sourceImage.getWidth();
00086     unsigned long rows = sourceImage.getHeight();
00087     const int bits = sizeof(DcmQuantComponent)*8;
00088     DcmQuantPixel px;
00089     long limitcol;
00090     long col; // must be signed!
00091     long maxval_l = OFstatic_cast(long, maxval);
00092     register int ind;
00093     const DcmQuantComponent *currentpixel;
00094     register DcmQuantComponent cr, cg, cb;
00095 
00096     // create scale table
00097     DcmQuantScaleTable scaletable;
00098     scaletable.createTable(OFstatic_cast(DcmQuantComponent, -1), maxval);
00099 
00100     const void *data = sourceImage.getOutputData(bits, frameNumber, 0);
00101     if (data)
00102     {
00103       const DcmQuantComponent *cp = OFstatic_cast(const DcmQuantComponent *, data);
00104       for (unsigned long row = 0; row < rows; ++row)
00105       {
00106         fs.startRow(col, limitcol);
00107         do
00108         {
00109             currentpixel = cp + col + col + col;
00110             cr = *currentpixel++;
00111             cg = *currentpixel++;
00112             cb = *currentpixel;
00113             px.scale(cr, cg, cb, scaletable);
00114 
00115             fs.adjust(px, col, maxval_l);
00116 
00117             // Check hash table to see if we have already matched this color.
00118             ind = cht.lookup(px);
00119             if (ind < 0)
00120             {
00121               ind = colormap.computeIndex(px);
00122               cht.add(px, ind);
00123             }
00124 
00125             fs.propagate(px, colormap.getPixel(ind), col);
00126             tp[col] = OFstatic_cast(T2, ind);
00127             fs.nextCol(col);
00128         } while ( col != limitcol );
00129         fs.finishRow();
00130         cp += (cols * 3); // advance source pointer by one row
00131         tp += cols;  // advance target pointer by one row
00132       } // for all rows
00133     } // if (data)
00134   }
00135 };
00136 
00137 
00138 #endif
00139 
00140 
00141 /*
00142  * CVS/RCS Log:
00143  * $Log: diqtcmap.h,v $
00144  * Revision 1.5  2010-10-14 13:16:29  joergr
00145  * Updated copyright header. Added reference to COPYRIGHT file.
00146  *
00147  * Revision 1.4  2005/12/08 16:01:44  meichel
00148  * Changed include path schema for all DCMTK header files
00149  *
00150  * Revision 1.3  2004/04/21 10:00:31  meichel
00151  * Minor modifications for compilation with gcc 3.4.0
00152  *
00153  * Revision 1.2  2003/12/23 12:14:38  joergr
00154  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00155  * Updated copyright header.
00156  *
00157  * Revision 1.1  2002/01/25 13:32:04  meichel
00158  * Initial release of new color quantization classes and
00159  *   the dcmquant tool in module dcmimage.
00160  *
00161  *
00162  */


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