<commit_before>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkStreamingImageIOBase.h"

#include "itksys/SystemTools.hxx"

namespace itk
{
StreamingImageIOBase::StreamingImageIOBase():
  ImageIOBase()
{}

void StreamingImageIOBase::PrintSelf(std::ostream & os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);
}

bool StreamingImageIOBase
::StreamReadBufferAsBinary(std::istream & file, void *_buffer)
{
  itkDebugMacro(<< "StreamingReadBufferAsBinary called");

  char *buffer = static_cast< char * >( _buffer );
  // Offset into file
  std::streampos dataPos = this->GetDataPosition();

  std::streamsize sizeOfRegion = static_cast< std::streamsize >( m_IORegion.GetNumberOfPixels() )
                                 * this->GetPixelSize();

  // compute the number of continuous bytes to be read
  std::streamsize sizeOfChunk = 1;
  unsigned int    movingDirection = 0;
  do
    {
    sizeOfChunk *= m_IORegion.GetSize(movingDirection);
    ++movingDirection;
    }
  while ( movingDirection < m_IORegion.GetImageDimension()
          && m_IORegion.GetSize(movingDirection - 1) == this->GetDimensions(movingDirection - 1) );
  sizeOfChunk *= this->GetPixelSize();

  ImageIORegion::IndexType currentIndex = m_IORegion.GetIndex();

  while ( m_IORegion.IsInside(currentIndex) )
    {
    // calculate the position to seek to in the file
    std::streampos seekPos = 0;
    SizeValueType  subDimensionQuantity = 1;
    for ( unsigned int i = 0; i < m_IORegion.GetImageDimension(); ++i )
      {
      seekPos = seekPos + static_cast< std::streamoff >( subDimensionQuantity
                                                         * this->GetPixelSize()
                                                         * currentIndex[i] );
      subDimensionQuantity *= this->GetDimensions(i);
      }

    itkDebugMacro(
      << "Reading " << sizeOfChunk << " of " << sizeOfRegion << " bytes for " << m_FileName << " at " << dataPos<commit_msg>COMP:  Protected Debug variable compiler warn<commit_after>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkStreamingImageIOBase.h"

#include "itksys/SystemTools.hxx"

namespace itk
{
StreamingImageIOBase::StreamingImageIOBase():
  ImageIOBase()
{}

void StreamingImageIOBase::PrintSelf(std::ostream & os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);
}

bool StreamingImageIOBase
::StreamReadBufferAsBinary(std::istream & file, void *_buffer)
{
  itkDebugMacro(<< "StreamingReadBufferAsBinary called");

  char *buffer = static_cast< char * >( _buffer );
  // Offset into file
  std::streampos dataPos = this->GetDataPosition();

  itkDebugStatement(
  const std::streamsize sizeOfRegion = static_cast< std::streamsize >( m_IORegion.GetNumberOfPixels() )
                                 * this->GetPixelSize();
  );

  // compute the number of continuous bytes to be read
  std::streamsize sizeOfChunk = 1;
  unsigned int    movingDirection = 0;
  do
    {
    sizeOfChunk *= m_IORegion.GetSize(movingDirection);
    ++movingDirection;
    }
  while ( movingDirection < m_IORegion.GetImageDimension()
          && m_IORegion.GetSize(movingDirection - 1) == this->GetDimensions(movingDirection - 1) );
  sizeOfChunk *= this->GetPixelSize();

  ImageIORegion::IndexType currentIndex = m_IORegion.GetIndex();

  while ( m_IORegion.IsInside(currentIndex) )
    {
    // calculate the position to seek to in the file
    std::streampos seekPos = 0;
    SizeValueType  subDimensionQuantity = 1;
    for ( unsigned int i = 0; i < m_IORegion.GetImageDimension(); ++i )
      {
      seekPos = seekPos + static_cast< std::streamoff >( subDimensionQuantity
                                                         * this->GetPixelSize()
                                                         * currentIndex[i] );
      subDimensionQuantity *= this->GetDimensions(i);
      }

    itkDebugMacro(
      << "Reading " << sizeOfChunk << " of " << sizeOfRegion << " bytes for " << m_FileName << " at " << dataPos
{'fraction_non_alphanumeric': 0.15167095115681234, 'fraction_numerical': 0.004039662137348513, 'mean_word_length': 3.3093354430379747, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4313781', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1479, 'n_words': 408}