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

MRC file format bug and compatibility fixes. #4019

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Modules/IO/MRC/include/itkMRCHeaderObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class ITKIOMRC_EXPORT MRCHeaderObject : public LightObject
float zorg;

char cmap[4]; /**< Contains "MAP " */
char stamp[4]; /**< First byte has 17 for big- or 68 for
little-endian */
char stamp[4]; /**< First two bytes have 17 and 17 for big-endian or
68 and 68 for little-endian */
float rms;

// ALL HEADERS:
Expand Down
49 changes: 0 additions & 49 deletions Modules/IO/MRC/src/itkMRCHeaderObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,55 +110,6 @@ MRCHeaderObject::SetHeader(const Header * buffer)
this->m_ExtendedHeader = nullptr;
this->m_ExtendedFeiHeader = nullptr;

SizeValueType extendedHeaderBytes = 0;
if (this->m_Header.nreal & 1)
{
extendedHeaderBytes += 2;
}
if (this->m_Header.nreal & 2)
{
extendedHeaderBytes += 6;
}
if (this->m_Header.nreal & 4)
{
extendedHeaderBytes += 3;
}
if (this->m_Header.nreal & 8)
{
extendedHeaderBytes += 2;
}
if (this->m_Header.nreal & 16)
{
extendedHeaderBytes += 2;
}
if (this->m_Header.nreal & 32)
{
extendedHeaderBytes += 4;
}
if (this->m_Header.nreal & 64)
{
extendedHeaderBytes += 2;
}
if (this->m_Header.nreal & 128)
{
extendedHeaderBytes += 4;
}
if (this->m_Header.nreal & 256)
{
extendedHeaderBytes += 2;
}
if (this->m_Header.nreal & 512)
{
extendedHeaderBytes += 4;
}
if (this->m_Header.nreal & 1024)
{
extendedHeaderBytes += 2;
}
// TODO: all the above to set extendedHeaderBytes, yet extendedHeaderBytes is unused!
itkWarningMacro(<< "extendedHeaderBytes is: " << extendedHeaderBytes
<< "If you see this log please contact https://github.com/InsightSoftwareConsortium/ITK/pull/2778");
dzenanz marked this conversation as resolved.
Show resolved Hide resolved

this->m_ExtendedHeaderSize = this->m_Header.next;

// check to make sure the data makes sense
Expand Down
20 changes: 6 additions & 14 deletions Modules/IO/MRC/src/itkMRCImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,10 @@ MRCImageIO::ReadImageInformation()
}
}

if (header.xlen == 0.0f && header.ylen == 0.0f && header.zlen == 0.0f)
{
// if the spacing was not set in the header then this is the
// default
m_Spacing[0] = 1.0;
m_Spacing[1] = 1.0;
m_Spacing[2] = 1.0;
}
else
{
m_Spacing[0] = header.xlen / static_cast<float>(header.mx);
m_Spacing[1] = header.ylen / static_cast<float>(header.my);
m_Spacing[2] = header.zlen / static_cast<float>(header.mz);
}
// if the spacing was not set in the header then 1.0 is the default
m_Spacing[0] = header.xlen != 0.0f ? header.xlen / static_cast<float>(header.mx) : 1.0;
m_Spacing[1] = header.ylen != 0.0f ? header.ylen / static_cast<float>(header.my) : 1.0;
m_Spacing[2] = header.zlen != 0.0f ? header.zlen / static_cast<float>(header.mz) : 1.0;

// copy the origin
m_Origin[0] = header.xorg;
Expand Down Expand Up @@ -368,10 +358,12 @@ MRCImageIO::UpdateHeaderFromImageIO()
if (ByteSwapper<void *>::SystemIsBigEndian())
{
header.stamp[0] = 17;
header.stamp[1] = 17;
}
else
{
header.stamp[0] = 68;
header.stamp[1] = 68;
}

header.alpha = 90;
Expand Down
8 changes: 8 additions & 0 deletions Modules/IO/MRC/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ itk_add_test(NAME itkMRCImageIOTest2c
DATA{${ITK_DATA_ROOT}/Input/RGBTestImageLZW.tif}
${ITK_TEST_OUTPUT_DIR}/itkMRCImageIOTest2c.mrc
38a2dcfc08812e04b1528f15ca3d2ab7)
itk_add_test(NAME itkMRCImageIOTest2d
COMMAND ITKIOMRCTestDriver
--compare-MD5 ${ITK_TEST_OUTPUT_DIR}/itkMRCImageIOTest2d.mrc
96093c8573ce2b4f197f0b0bfcc574bf
itkMRCImageIOTest2
DATA{Input/tilt_uint8.mrc}
${ITK_TEST_OUTPUT_DIR}/itkMRCImageIOTest2d.mrc
96093c8573ce2b4f197f0b0bfcc574bf)
1 change: 1 addition & 0 deletions Modules/IO/MRC/test/Input/tilt_uint8.mrc.sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
332985f125b8584b9ba158faef6294cd2f2a9e8d9fb5b7f05a74b08089b2d4e13465c1c483e42b6c4263dac9af19542a8bd5ff33dc627507ba60c976a3cb5b0a
3 changes: 3 additions & 0 deletions Modules/IO/MRC/test/itkMRCImageIOTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "itkMetaDataObject.h"
#include "itkTestingHashImageFilter.h"


static_assert(sizeof(itk::MRCHeaderObject::Header) == 1024, " Ill defined MRC Header struct");

namespace
{

Expand Down