This file is indexed.

/usr/include/gdcm-2.6/gdcmByteSwap.txx is in libgdcm2-dev 2.6.3-3ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#ifndef GDCMBYTESWAP_TXX
#define GDCMBYTESWAP_TXX

#include "gdcmByteSwap.h"
#include <iostream>

#include <stdlib.h> // abort

namespace gdcm
{

/*
  template (class T)
{
void bswap(inout T i)
{
byte* p = cast(byte*)&i;
for (int b = 0; b < T.size/2; ++b)
instance swap(byte).swap(p[b], p[T.size-1-b]);
}
}
*/


// Machine definitions
#ifdef GDCM_WORDS_BIGENDIAN
template <class T>
bool ByteSwap<T>::SystemIsBigEndian() { return true; }
template <class T>
bool ByteSwap<T>::SystemIsLittleEndian() { return false; }
#else
template <class T>
bool ByteSwap<T>::SystemIsBigEndian() { return false; }
template <class T>
bool ByteSwap<T>::SystemIsLittleEndian() { return true; }
#endif

template <class T>
void ByteSwap<T>::Swap(T &p)
{
#ifdef GDCM_WORDS_BIGENDIAN
    ByteSwap<T>::SwapFromSwapCodeIntoSystem(p, SwapCode::LittleEndian);
#else
    ByteSwap<T>::SwapFromSwapCodeIntoSystem(p, SwapCode::BigEndian);
#endif
}

// Swaps the bytes so they agree with the processor order
template <class T>
void ByteSwap<T>::SwapFromSwapCodeIntoSystem(T &a, SwapCode const &swapcode)
{
  //std::cerr << "sizeof(T)= " << sizeof(T) << " " << (int)a << std::endl;
  switch(sizeof(T))
    {
  case 1:
    break;
  case 2:
    Swap4(a, swapcode);
    break;
  case 4:
    Swap8(a, swapcode);
    break;
  default:
    std::cerr << "Impossible" << std::endl;
    abort();
    }
}

template <class T>
void ByteSwap<T>::SwapRange(T *p, unsigned int num)
{
  for(unsigned int i=0; i<num; i++)
    {
    ByteSwap<T>::Swap(p[i]);
    }
}

template <class T>
void ByteSwap<T>::SwapRangeFromSwapCodeIntoSystem(T *p, SwapCode const &sc,
  std::streamoff num)
{
  for( std::streamoff i=0; i<num; i++)
    {
    ByteSwap<T>::SwapFromSwapCodeIntoSystem(p[i], sc);
    }
}

// Private:
//

template<class T>
void Swap4(T &a, SwapCode const &swapcode)
{
#ifndef GDCM_WORDS_BIGENDIAN
  if ( swapcode == 4321 || swapcode == 2143 )
    a = (T)(( a << 8 ) | ( a >> 8 ));
#else
  if ( swapcode == 1234 || swapcode == 3412 )
    a = ( a << 8 ) | ( a >> 8 );
  // On big endian as long as the SwapCode is Unknown let's pretend we were
  // on a LittleEndian system (might introduce overhead on those system).
  else if ( swapcode == SwapCode::Unknown )
    a = ( a << 8 ) | ( a >> 8 );
#endif
}

//note: according to http://www.parashift.com/c++-faq-lite/templates.html#faq-35.8
//the inlining of the template class means that the specialization doesn't cause linker errors
template<class T>
inline void Swap8(T &a, SwapCode const &swapcode)
{
  switch (swapcode)
    {
  case SwapCode::Unknown:
#ifdef GDCM_WORDS_BIGENDIAN
    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 1234 :
#ifdef GDCM_WORDS_BIGENDIAN
    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 4321 :
#ifndef GDCM_WORDS_BIGENDIAN
    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 3412 :
    a= ((a<<16) | (a>>16)  );
    break;
  case 2143 :
    a= (((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) );
    break;
  default :
    std::cerr << "Unexpected swap code:" << swapcode;
    }
}

template <>
inline void Swap8<uint16_t>(uint16_t &a, SwapCode const &swapcode)
{
  switch (swapcode)
    {
  case SwapCode::Unknown:
#ifdef GDCM_WORDS_BIGENDIAN
    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 1234 :
#ifdef GDCM_WORDS_BIGENDIAN
    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 4321 :
#ifndef GDCM_WORDS_BIGENDIAN
//    probably not really useful since the lowest 0x0000 are what's used in unsigned shorts
//    a= (( a<<24) | ((a<<8)  & 0x00ff0000) | ((a>>8) & 0x0000ff00) | (a>>24) );
#endif
    break;
  case 3412 :
    //a= ((a<<16) | (a>>16)  );//do nothing, a = a
    break;
  case 2143 :
    a= (uint16_t)(((a<< 8) & 0xff00) | ((a>>8) & 0x00ff) );
    break;
  default :
    std::cerr << "Unexpected swap code:" << swapcode;
    }
}


} // end namespace gdcm

#endif // GDCMBYTESWAP_TXX