Skip to content

Commit

Permalink
GDCM 2020-02-13 (5f191ecb)
Browse files Browse the repository at this point in the history
Code extracted from:

    http://git.code.sf.net/p/gdcm/gdcm.git

at commit 5f191ecb3024a5d979bca1cad0c8883561a4112d (release).

Change-Id: I2ff01ce4be29addbcf7c6e1d8b5fd9f9cd71b3e3
  • Loading branch information
GDCM Upstream authored and dzenanz committed Feb 13, 2020
1 parent b49b0b8 commit efd187a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx
Expand Up @@ -538,14 +538,22 @@ bool ImageCodec::DoOverlayCleanup(std::istream &is, std::ostream &os)
else // Pixel are unsigned
{
#if 1
uint16_t c;
while( is.read((char*)&c,2) )
// On Windows, is.read and os.write are expensive operations.
// If we called it for each value then conversion would be extremely slow.
// Therefore we read/mask/write 1000 values at once.
const unsigned int bufferSize = 1000;
std::vector<uint16_t> buffer(bufferSize);
while (is)
{
c = (uint16_t)(
(c >> (PF.GetBitsStored() - PF.GetHighBit() - 1)) & pmask);
os.write((char*)&c, 2 );
}
//os.rdbuf( is.rdbuf() );
is.read((char *)&buffer[0], bufferSize * sizeof(uint16_t));
std::streamsize bytesRead = is.gcount();
std::vector<uint16_t>::iterator validBufferEnd = buffer.begin() + bytesRead / sizeof(uint16_t);
for (std::vector<uint16_t>::iterator it = buffer.begin(); it != validBufferEnd; ++it)
{
*it = ((*it >> (PF.GetBitsStored() - PF.GetHighBit() - 1)) & pmask);
}
os.write((char *)&buffer[0], bytesRead);
};
#else
//std::ostreambuf_iterator<char> end_of_stream_iterator;
//std::ostreambuf_iterator<char> out_iter(os.rdbuf());
Expand Down

0 comments on commit efd187a

Please sign in to comment.