fw4spl
ImageRGBLookupReader.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwDcmtkIO/config.hpp"
10 
11 #include <fwMedData/DicomSeries.hpp>
12 
13 #include <dcmtk/config/osconfig.h>
14 #include <dcmtk/dcmdata/dcdeftag.h>
15 #include <dcmtk/dcmdata/dcfilefo.h>
16 #include <dcmtk/dcmimgle/dcmimage.h>
17 #include <dcmtk/dcmnet/diutil.h>
18 
19 namespace fwDcmtkIO
20 {
21 namespace reader
22 {
23 namespace rgblookup
24 {
25 
30 class FWDCMTKIO_CLASS_API ImageRGBLookupReader
31 {
32 public:
33  typedef ::fwMedData::DicomSeries::DicomContainerType DicomContainerType;
34 
49  template< typename T, typename U >
50  static void fillImageBuffer(unsigned int rows, unsigned int columns,
51  unsigned int depth,
52  DicomContainerType& instances,
53  void* destination, const T* redLookup,
54  const T* greenLookup,
55  const T* blueLookup)
56  {
57  U* tempoBuffer = ::fwDcmtkIO::reader::main::ImageReader::createTemporaryBuffer<U>(
58  rows, columns, depth, instances);
59 
60  T* arrayBuffer = static_cast< T* >(destination);
61  unsigned short x, y, z;
62  unsigned int frameSize = columns * rows;
63  x = y = z = 0;
64  for (x = 0; x < columns; ++x)
65  {
66  for (y = 0; y < rows; ++y)
67  {
68  unsigned int yshift = x * rows;
69 
70  for (z = 0; z < depth; ++z)
71  {
72  unsigned int position = y + yshift + z * frameSize;
73  U value = tempoBuffer[position];
74 
75  arrayBuffer[position*3] = static_cast< T >((redLookup[value]/(double)0xffff)*256);
76  arrayBuffer[position*3+1] = static_cast< T >((greenLookup[value]/(double)0xffff)*256);
77  arrayBuffer[position*3+2] = static_cast< T >((blueLookup[value]/(double)0xffff)*256);
78  }
79  }
80  }
81  delete tempoBuffer;
82  }
83 };
84 
85 } //rgblookup
86 } //reader
87 } //fwDcmtkIO
fwDcmtkIO contains classes used to pull Dicom images from a pacs using dcmtk library.
Definition: Codec.hpp:12
static void fillImageBuffer(unsigned int rows, unsigned int columns, unsigned int depth, DicomContainerType &instances, void *destination, const T *redLookup, const T *greenLookup, const T *blueLookup)
Fill the buffer of an image The template T is used to determine color format The template U is used t...
This class is used to read the buffer of a DICOM image in DIRECT mode when a pixel lookup must be per...