/usr/include/ossim/base/ossimEndian.h is in libossim-dev 1.7.21-4.
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | //******************************************************************
//
// License: See top level LICENSE.txt file.
//
// Author: Garrett Potts
//
// Description: This file contains the interface to the
// endian byte swap
//
//***********************************
// $ID$
#ifndef ossimEndian_HEADER
#define ossimEndian_HEADER
// for OSSIM_LITTLE_ENDIAN AND BIG_ENDIAN
#include <ossim/base/ossimConstants.h>
class OSSIMDLLEXPORT ossimEndian
{
public:
ossimEndian();
/*!
* Swap bytes methods that work on a single pixel.
*/
void swap(ossim_int16 &data) const;
void swap(ossim_uint16 &data) const;
void swap(ossim_int32 &data) const;
void swap(ossim_uint32 &data) const;
void swap(ossim_uint64 &data) const;
void swap(ossim_sint64 &data) const;
void swap(ossim_float32 &data) const;
void swap(ossim_float64 &data) const;
/*!
* Swap bytes methods that work on arrays of pixels.
*
* @note size is number of pixels, not number of bytes.
*/
void swap(ossimScalarType scalar, void* data, ossim_uint32 size) const;
// only here to allow template based swaps to compile correctly
//
void swap(ossim_sint8* data, ossim_uint32 size)const;
void swap(ossim_uint8* data, ossim_uint32 size)const;
void swap(ossim_int16* data, ossim_uint32 size) const;
void swap(ossim_uint16* data, ossim_uint32 size) const;
void swap(ossim_int32* data, ossim_uint32 size) const;
void swap(ossim_uint32* data, ossim_uint32 size) const;
//#ifdef HAS_LONG_LONG
void swap(ossim_int64* data, ossim_uint32 size) const;
void swap(ossim_uint64* data, ossim_uint32 size) const;
//#endif
void swap(ossim_float32* data, ossim_uint32 size) const;
void swap(ossim_float64* data, ossim_uint32 size) const;
void swapTwoBytes(void* data, ossim_uint32 size) const;
void swapFourBytes(void* data, ossim_uint32 size) const;
void swapEightBytes(void* data, ossim_uint32 size) const;
ossimByteOrder getSystemEndianType() const;
private:
// Holds the Endian of the architecture that you are running on.
ossimByteOrder theSystemEndianType;
void swapTwoBytes(void *data) const;
void swapFourBytes(void *data) const;
void swapEightBytes(void *data) const;
void swapPrivate(ossim_uint8 *c1,
ossim_uint8 *c2) const;
};
inline ossimByteOrder ossimEndian::getSystemEndianType() const
{
return theSystemEndianType;
}
inline void ossimEndian::swap(ossim_sint8* /* data */,
ossim_uint32 /* size */ )const
{
//intentionally left blank
}
inline void ossimEndian::swap(ossim_uint8* /* data */,
ossim_uint32 /* size */ )const
{
//intentionally left blank
}
inline void ossimEndian::swap(ossim_int16 &data) const
{
swapTwoBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_uint16 &data) const
{
swapTwoBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_int32 &data) const
{
swapFourBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_uint32 &data) const
{
swapFourBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_uint64 &data) const
{
swapEightBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_sint64 &data) const
{
swapEightBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_float32 &data) const
{
swapFourBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swap(ossim_float64 &data) const
{
swapEightBytes(reinterpret_cast<void*>(&data));
}
inline void ossimEndian::swapTwoBytes(void *data) const
{
unsigned char *c = reinterpret_cast<unsigned char*>(data);
swapPrivate(&c[0], &c[1]);
}
inline void ossimEndian::swapFourBytes(void* data) const
{
unsigned char *c = reinterpret_cast<unsigned char*>(data);
swapPrivate(&c[0], &c[3]);
swapPrivate(&c[1], &c[2]);
}
inline void ossimEndian::swapEightBytes(void* data) const
{
unsigned char *c = reinterpret_cast<unsigned char*>(data);
swapPrivate(&c[0], &c[7]);
swapPrivate(&c[1], &c[6]);
swapPrivate(&c[2], &c[5]);
swapPrivate(&c[3], &c[4]);
}
inline void ossimEndian::swapPrivate(ossim_uint8 *c1,
ossim_uint8 *c2) const
{
ossim_uint8 temp_c = *c1;
*c1 = *c2;
*c2 = temp_c;
}
inline void ossimEndian::swap(ossimScalarType scalar,
void* data, ossim_uint32 size) const
{
switch (scalar)
{
case OSSIM_USHORT16:
case OSSIM_SSHORT16:
case OSSIM_USHORT11:
swapTwoBytes(data, size);
return;
case OSSIM_FLOAT:
case OSSIM_NORMALIZED_FLOAT:
swapFourBytes(data, size);
return;
case OSSIM_DOUBLE:
case OSSIM_NORMALIZED_DOUBLE:
swapEightBytes(data, size);
break;
default:
return;
}
}
inline void ossimEndian::swap(ossim_int16* data, ossim_uint32 size) const
{
swapTwoBytes(data, size);
}
inline void ossimEndian::swap(ossim_uint16* data, ossim_uint32 size) const
{
swapTwoBytes(data, size);
}
inline void ossimEndian::swap(ossim_int32* data, ossim_uint32 size) const
{
swapFourBytes(data, size);
}
inline void ossimEndian::swap(ossim_uint32* data, ossim_uint32 size) const
{
swapFourBytes(data, size);
}
#ifdef HAS_LONG_LONG
inline void ossimEndian::swap(ossim_int64* data, ossim_uint32 size) const
{
swapEightBytes(data, size);
}
inline void ossimEndian::swap(ossim_uint64* data, ossim_uint32 size) const
{
swapEightBytes(data, size);
}
#endif /* End of #ifdef HAS_LONG_LONG */
inline void ossimEndian::swap(ossim_float32* data, ossim_uint32 size) const
{
swapFourBytes(data, size);
}
inline void ossimEndian::swap(ossim_float64* data, ossim_uint32 size) const
{
swapEightBytes(data, size);
}
inline void ossimEndian::swapTwoBytes(void* data, ossim_uint32 size) const
{
ossim_uint16* buf = reinterpret_cast<ossim_uint16*>(data);
for (ossim_uint32 i=0; i<size; ++i)
{
buf[i] = ((buf[i] & 0x00ff) << 8) | ((buf[i] & 0xff00) >> 8);
}
}
inline void ossimEndian::swapFourBytes(void* data, ossim_uint32 size) const
{
ossim_uint32* buf = reinterpret_cast<ossim_uint32*>(data);
for (ossim_uint32 i=0; i<size; ++i)
{
buf[i]
= ( ((buf[i] & 0xff000000) >> 24)
| ((buf[i] & 0x00ff0000) >> 8)
| ((buf[i] & 0x0000ff00) << 8)
| ((buf[i] & 0x000000ff) << 24));
}
}
inline void ossimEndian::swapEightBytes(void* data, ossim_uint32 size) const
{
#ifdef HAS_LONG_LONG
uint64* buf = reinterpret_cast<ossim_uint64*>(data);
for (uint32 i=0; i<size; ++i)
{
buf[i]
= ( ((buf[i] & 0xff00000000000000ull) >> 56)
| ((buf[i] & 0x00ff000000000000ull) >> 40)
| ((buf[i] & 0x0000ff0000000000ull) >> 24)
| ((buf[i] & 0x000000ff00000000ull) >> 8)
| ((buf[i] & 0x00000000ff000000ull) << 8)
| ((buf[i] & 0x0000000000ff0000ull) << 24)
| ((buf[i] & 0x000000000000ff00ull) << 40)
| ((buf[i] & 0x00000000000000ffull) << 56));
}
#else
ossim_float64* buf = reinterpret_cast<ossim_float64*>(data);
for (ossim_uint32 i=0; i<size; ++i)
{
swapEightBytes(buf+i);
}
#endif
}
#endif /* End of #ifndef ossimEndian_HEADER */
|