Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding raw I/O capabilities for non integral types and signed integers. #1084

Merged
merged 10 commits into from
Dec 24, 2015
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
the camera center).
(Bertrand Kerautret [#1070](https://github.com/DGtal-team/DGtal/pull/1070))

- Adding raw I/O capabilities for non integral types and signed integers.
(Roland Denis [#1084](https://github.com/DGtal-team/DGtal/pull/1084))

## Bug Fixes

Expand Down
2 changes: 0 additions & 2 deletions src/DGtal/io/readers/RawReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ namespace DGtal
typedef typename TImageContainer::Domain::Vector Vector;
typedef TFunctor Functor;

BOOST_STATIC_ASSERT( (ImageContainer::Domain::dimension == 2) || (ImageContainer::Domain::dimension == 3) );

/**
* Method to import a Raw into an instance of the
* template parameter ImageContainer.
Expand Down
6 changes: 4 additions & 2 deletions src/DGtal/io/readers/RawReader.ih
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


//////////////////////////////////////////////////////////////////////////////
#include <cstddef>
#include <cstdlib>
//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -116,7 +117,8 @@ FILE*
DGtal::raw_reader_read_word( FILE* fin, Word& aValue )
{
aValue = 0;
for (unsigned size = 0; size < sizeof( Word ); ++size)
aValue |= getc(fin) << (8 * size);
for ( std::size_t i = 0; i < sizeof( Word ); ++i )
reinterpret_cast<unsigned char*>(&aValue)[i] = getc(fin);

return fin;
}
6 changes: 4 additions & 2 deletions src/DGtal/io/writers/RawWriter.ih
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


//////////////////////////////////////////////////////////////////////////////
#include <cstddef>
#include <cstdlib>
#include <fstream>
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -101,8 +102,9 @@ template <typename Word>
std::ostream&
DGtal::raw_writer_write_word(std::ostream& outs, Word value)
{
for (unsigned size = sizeof(Word); size; --size, value >>= 8)
outs.put(static_cast<unsigned char>(value & 0xFF));
for ( std::size_t i = 0; i < sizeof(Word); ++i )
outs.put( reinterpret_cast<unsigned char*>(&value)[i] );

return outs;
}

Loading