Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
fix the czi reader
Browse files Browse the repository at this point in the history
  • Loading branch information
takashi310 committed Jun 3, 2021
1 parent 507a436 commit d4206ae
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions fluorender/FluoRender/Formats/czi_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void CZIReader::Preprocess()
unsigned char *data = (unsigned char *)(lockinfo.ptrData);
cout << "first: " << (int)data[0] << endl;
cout << "last: " << (int)data[lockinfo.size - 1] << endl;
bitmap->Unlock();
}

return true;
Expand Down Expand Up @@ -337,6 +338,8 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)
case libCZI::DimensionIndex::T:
planeCoord.Set(idx, t+m_time_min);
break;
case libCZI::DimensionIndex::S:
break;
default:
planeCoord.Set(idx, start);
break;
Expand All @@ -347,12 +350,29 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)

int slice_max = m_slice_min + m_slice_num;
size_t slice_size = (unsigned long long)m_x_size * (unsigned long long)m_y_size;
size_t pitchY = m_x_size;
for (size_t i = m_slice_min; i < slice_max; i++)
{
planeCoord.Set(libCZI::DimensionIndex::Z, i);
auto multiTileComposit = accessor->Get(libCZI::PixelType::Gray8, slice_bd, &planeCoord, nullptr);
auto lockinfo = multiTileComposit->Lock();
memcpy(val + i * slice_size, lockinfo.ptrDataRoi, lockinfo.size < slice_size ? lockinfo.size : slice_size);
if (pitchY == lockinfo.stride)
memcpy((unsigned char *)val + i * slice_size, lockinfo.ptrDataRoi, lockinfo.size < slice_size ? lockinfo.size : slice_size);
else
{
size_t src_offset = 0;
size_t dst_offset = 0;
unsigned char *src = (unsigned char *)lockinfo.ptrDataRoi;
unsigned char *dst = (unsigned char *)val + i * slice_size;
while (src_offset < lockinfo.size && dst_offset < slice_size)
{
memcpy(dst + dst_offset, src + src_offset,
(src_offset + pitchY <= lockinfo.size) ? (dst_offset + pitchY <= slice_size ? pitchY : slice_size - dst_offset) : lockinfo.size - src_offset);
src_offset += lockinfo.stride;
dst_offset += pitchY;
}
}
multiTileComposit->Unlock();
}

//create nrrd
Expand Down Expand Up @@ -393,6 +413,8 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)
case libCZI::DimensionIndex::T:
planeCoord.Set(idx, t+m_time_min);
break;
case libCZI::DimensionIndex::S:
break;
default:
planeCoord.Set(idx, start);
break;
Expand All @@ -403,12 +425,29 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)

int slice_max = m_slice_min + m_slice_num;
size_t slice_size = (unsigned long long)m_x_size * (unsigned long long)m_y_size * 2ULL;
size_t pitchY = m_x_size * 2ULL;
for (size_t i = m_slice_min; i < slice_max; i++)
{
planeCoord.Set(libCZI::DimensionIndex::Z, i);
auto multiTileComposit = accessor->Get(libCZI::PixelType::Gray16, slice_bd, &planeCoord, nullptr);
auto lockinfo = multiTileComposit->Lock();
memcpy((unsigned char *)val + i * slice_size, lockinfo.ptrDataRoi, lockinfo.size < slice_size ? lockinfo.size : slice_size);
if (pitchY == lockinfo.stride)
memcpy((unsigned char *)val + i * slice_size, lockinfo.ptrDataRoi, lockinfo.size < slice_size ? lockinfo.size : slice_size);
else
{
size_t src_offset = 0;
size_t dst_offset = 0;
unsigned char *src = (unsigned char *)lockinfo.ptrDataRoi;
unsigned char *dst = (unsigned char *)val + i * slice_size;
while (src_offset < lockinfo.size && dst_offset < slice_size)
{
memcpy(dst + dst_offset, src + src_offset,
(src_offset + pitchY <= lockinfo.size) ? (dst_offset + pitchY <= slice_size ? pitchY : slice_size - dst_offset) : lockinfo.size - src_offset);
src_offset += lockinfo.stride;
dst_offset += pitchY;
}
}
multiTileComposit->Unlock();
}

//create nrrd
Expand Down

0 comments on commit d4206ae

Please sign in to comment.