Skip to content
Snippets Groups Projects
Commit 590fba85 authored by Shawn Waldon's avatar Shawn Waldon
Browse files

MRCReader: assume file is little endian unless marked othewise

Some MRC file writers don't follow the standard and fail to fill in the
endianness field.  So unless the file is marked as big endian, assume it is
little endian.
parent d2013691
No related merge requests found
......@@ -226,9 +226,11 @@ int vtkMRCReader::RequestInformation(vtkInformation* vtkNotUsed(request),
return 0;
}
this->Internals->stream->read((char*)&this->Internals->header, sizeof(mrc_file_header));
if (this->Internals->header.stamp[0] == 'D')
// Officially, the next character should be 'A', but this appears to vary
// between implementations, so I only test the first one
if (this->Internals->header.stamp[0] != ((char)17))
// This is what the big-endian MRC files are supposed to look like. I don't have one to
// test with though. However, if it does not look like that, assume it is little endian.
// There are some non-conformant programs that don't correctly fill in this field, and
// assuming little endian is safer.
{
vtkByteSwap::Swap4LERange(&this->Internals->header,24);
vtkByteSwap::Swap2LERange(&this->Internals->header.creatid,1);
......@@ -388,7 +390,13 @@ void vtkMRCReader::ExecuteDataWithInformation(vtkDataObject *vtkNotUsed(output),
inOffsets[1] = this->Internals->header.nx * numComponents;
inOffsets[2] = this->Internals->header.ny * this->Internals->header.nx
* numComponents;
bool fileIsLittleEndian = (this->Internals->header.stamp[0] == 'D');
// This is what the big-endian MRC files are supposed to look like. I don't have one to
// test with though. However, if it does not look like that, assume it is little endian.
// There are some non-conformant programs that don't correctly fill in this field, and
// assuming little endian is safer.
bool fileIsLittleEndian = (this->Internals->header.stamp[0] != ((char)17));
ByteSwapFunction byteSwapFunction = getByteSwapFunction(vtkType,fileIsLittleEndian);
switch (vtkType)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment