@@ -249,7 +249,7 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
249
249
// No data.
250
250
continue ;
251
251
}
252
- else
252
+ else if ( arraySize < numDyes )
253
253
{
254
254
// Indexed array, where we have [n] # of real entries,
255
255
// then 254 one-byte index entries referencing those [n] entries.
@@ -287,11 +287,13 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
287
287
if ( type == StainingTemplateArrayType . Indexed )
288
288
{
289
289
var nArray = new List < Half [ ] > ( ) ;
290
- for ( int i = 0 ; i < numDyes ; i ++ )
290
+ // The first entry in the list is an 0xFF byte that we skip
291
+ // Since that would leave us with one less value than we need, as dummy value is added for the last dye
292
+ for ( int i = 1 ; i < numDyes + 1 ; i ++ )
291
293
{
292
294
try
293
295
{
294
- var index = data [ indexStart + i ] ;
296
+ var index = ( i == numDyes ) ? 255 : data [ indexStart + i ] ;
295
297
if ( index == 255 || index == 0 )
296
298
{
297
299
if ( x < 3 )
@@ -402,7 +404,7 @@ public StainingTemplateFile(byte[] data, EStainingTemplate templateType)
402
404
offset += oldFormat ? 2 : 4 ;
403
405
}
404
406
405
- const int _headerEntrySize = 8 ;
407
+ int _headerEntrySize = oldFormat ? 4 : 8 ;
406
408
var endOfHeader = ( 8 + ( _headerEntrySize * entryCount ) ) ;
407
409
408
410
for ( int i = 0 ; i < entryCount ; i ++ )
0 commit comments