core/vil/vil_stream_write.cxx
Go to the documentation of this file.
00001 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00002 #pragma implementation
00003 #endif
00004 //:
00005 // \file
00006 // \author fsm
00007 //
00008 // \verbatim
00009 //  Modifications
00010 //   23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
00011 // \endverbatim
00012 
00013 #include "vil_stream_write.h"
00014 #include <vil/vil_stream.h>
00015 #include <vxl_config.h>
00016 
00017 void vil_stream_write_big_endian_uint_16(vil_stream *s, vxl_uint_16 w)
00018 {
00019   vxl_uint_8 bytes[2];
00020   bytes[0] = vxl_uint_8(w >> 8);
00021   bytes[1] = vxl_uint_8(w & 0xff);
00022   s->write(bytes, sizeof bytes);
00023 }
00024 
00025 void vil_stream_write_little_endian_uint_16(vil_stream *s, vxl_uint_16 w)
00026 {
00027   vxl_uint_8 bytes[2];
00028   bytes[0] = vxl_uint_8(w & 0xff);
00029   bytes[1] = vxl_uint_8(w >> 8);
00030   s->write(bytes, sizeof bytes);
00031 }
00032 
00033 void vil_stream_write_big_endian_uint_32(vil_stream *s, vxl_uint_32 w)
00034 {
00035   vxl_byte bytes[4];
00036   bytes[0] = w >> 24;
00037   bytes[1] = w >> 16;
00038   bytes[2] = w >> 8;
00039   bytes[3] = w >> 0;
00040   s->write(bytes, sizeof bytes);
00041 }
00042 
00043 void vil_stream_write_little_endian_uint_32(vil_stream *s, vxl_uint_32 w)
00044 {
00045   vxl_byte bytes[4];
00046   bytes[0] = w >> 0;
00047   bytes[1] = w >> 8;
00048   bytes[2] = w >> 16;
00049   bytes[3] = w >> 24;
00050   s->write(bytes, sizeof bytes);
00051 }
00052 
00053 #if VXL_HAS_INT_64
00054 
00055 void vil_stream_write_big_endian_uint_64(vil_stream *s, vxl_uint_64 w)
00056 {
00057   vxl_byte bytes[8];
00058   bytes[0] = static_cast<vxl_byte>(w >> 56);
00059   bytes[1] = static_cast<vxl_byte>(w >> 48);
00060   bytes[2] = static_cast<vxl_byte>(w >> 40);
00061   bytes[3] = static_cast<vxl_byte>(w >> 32);
00062   bytes[4] = static_cast<vxl_byte>(w >> 24);
00063   bytes[5] = static_cast<vxl_byte>(w >> 16);
00064   bytes[6] = static_cast<vxl_byte>(w >> 8);
00065   bytes[7] = static_cast<vxl_byte>(w >> 0);
00066   s->write(bytes, sizeof bytes);
00067 }
00068 
00069 void vil_stream_write_little_endian_uint_64(vil_stream *s, vxl_uint_64 w)
00070 {
00071   vxl_byte bytes[8];
00072   bytes[0] = static_cast<vxl_byte>(w >> 0);
00073   bytes[1] = static_cast<vxl_byte>(w >> 8);
00074   bytes[2] = static_cast<vxl_byte>(w >> 16);
00075   bytes[3] = static_cast<vxl_byte>(w >> 24);
00076   bytes[4] = static_cast<vxl_byte>(w >> 32);
00077   bytes[5] = static_cast<vxl_byte>(w >> 40);
00078   bytes[6] = static_cast<vxl_byte>(w >> 48);
00079   bytes[7] = static_cast<vxl_byte>(w >> 56);
00080   s->write(bytes, sizeof bytes);
00081 }
00082 
00083 #endif // VXL_HAS_INT_64