diqtcmap.h

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


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