| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkScalarToRGBPixelFunctor.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:47 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
DEF |
#ifndef _itkScalarToRGBPixelFunctor_txx |
| 18 |
DEF |
#define _itkScalarToRGBPixelFunctor_txx |
| 19 |
|
|
| 20 |
|
#include "itkScalarToRGBPixelFunctor.h" |
| 21 |
|
|
| 22 |
|
namespace itk { |
| 23 |
|
|
| 24 |
|
namespace Functor { |
| 25 |
|
|
| 26 |
|
template <class TScalar> |
| 27 |
|
ScalarToRGBPixelFunctor<TScalar> |
| 28 |
|
::ScalarToRGBPixelFunctor() |
| 29 |
|
{ |
| 30 |
|
m_Index[0] = m_Index[1] = m_Index[2] = 0; |
| 31 |
|
const ::size_t l = sizeof(ScalarType); |
| 32 |
|
for (unsigned int i = 0; i < l && i < 3; ++i) |
| 33 |
|
{ m_Index[i] = i; } |
| 34 |
|
|
| 35 |
|
m_IsBigEndian = true; |
| 36 |
|
#ifndef ITK_WORDS_BIGENDIAN |
| 37 |
|
m_IsBigEndian = false; |
| 38 |
|
#endif |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
template <class TScalar> |
| 43 |
|
typename ScalarToRGBPixelFunctor<TScalar>::RGBPixelType |
| 44 |
|
ScalarToRGBPixelFunctor<TScalar> |
| 45 |
|
::operator()( const TScalar & v) const |
| 46 |
|
{ |
| 47 |
|
unsigned int i; |
| 48 |
|
int j; |
| 49 |
|
|
| 50 |
|
TScalar buf = v; |
| 51 |
|
unsigned char *bytes = (unsigned char *)(&buf); |
| 52 |
|
|
| 53 |
|
RGBPixelType ans; |
| 54 |
|
if (this->m_IsBigEndian == true) |
| 55 |
|
{ // swap bytes |
| 56 |
|
TScalar tmp; |
| 57 |
SEM |
for (j = sizeof(TScalar) - 1, i = 0; j >=0 ; j--, i++) |
| 58 |
|
{ ((unsigned char *)(&tmp))[i] = bytes[j]; } |
| 59 |
|
buf = tmp; |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
ans[0] = static_cast<RGBComponentType>( bytes[m_Index[0]] * 3 ); |
| 63 |
LEN |
ans[1] = static_cast<RGBComponentType>( (bytes[m_Index[0]] + bytes[m_Index[1]]) * 5 ); |
| 64 |
LEN |
ans[2] = static_cast<RGBComponentType>( (bytes[m_Index[0]] + bytes[m_Index[2]]) ); |
| 65 |
|
|
| 66 |
|
return ans; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
} // end namespace Functor |
| 74 |
|
|
| 75 |
|
} // end namespace itk |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
#endif |
| 79 |
|
|