MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / initializeType

Method initializeType

multiresolutionimageinterface/LIFImage.cpp:80–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80bool LIFImage::initializeType(const std::string& imagePath) {
81 cleanup();
82 if (!core::fileExists(imagePath)) {
83 return false;
84 }
85 std::ifstream lif;
86 lif.open(imagePath.c_str(), std::ios::in | std::ios::binary);
87 if (lif.good()) {
88 _fileName = imagePath;
89 // First check file size
90 lif.seekg(0, std::ifstream::end);
91 _fileSize = lif.tellg();
92 lif.seekg(0);
93
94 // Buffers to hold int and long
95 char* memblock = new char[4];
96 char* memblockLong = new char[8];
97
98 char checkOne;
99 lif.read(&checkOne,1);
100 lif.seekg(2, std::ios::cur);
101 char checkTwo;
102 lif.read(&checkTwo,1);
103 if (checkOne != LIF_MAGIC_BYTE && checkTwo != LIF_MAGIC_BYTE) {
104 return false;
105 }
106
107 lif.seekg(4, std::ios::cur);
108 lif.read(&checkTwo,1);
109 if (checkTwo != LIF_MEMORY_BYTE) {
110 return false;
111 }
112
113 // Reading and cleaning up XML
114 lif.read(memblock,4);
115 int nc = *reinterpret_cast<int*>(memblock);
116 char* rawXml = new char[nc*2];
117 char* editedXml = new char[nc*2];
118 lif.read(rawXml, nc*2);
119 int index = 0;
120 for (int i =0; i < nc*2; ++i) {
121 if(rawXml[i]) {
122 editedXml[index] = rawXml[i];
123 ++index;
124 }
125 }
126 if (index < nc*2) {
127 editedXml[index] = '\0';
128 }
129 std::string xml(editedXml);
130
131 // Read the image offsets
132 while (lif.tellg() < _fileSize) {
133 lif.read(memblock,4);
134 int magicByte = *reinterpret_cast<int*>(memblock);
135 if (magicByte != LIF_MAGIC_BYTE) {
136 return false;
137 }

Callers

nothing calls this directly

Calls 5

fileExistsFunction · 0.85
openMethod · 0.80
emptyMethod · 0.80
loadMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected