This file is indexed.

/usr/include/ITK-4.9/itkVideoFileReader.hxx is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*=========================================================================
 *
 *  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.
 *
 *=========================================================================*/

#ifndef itkVideoFileReader_hxx
#define itkVideoFileReader_hxx

#include "itkConvertPixelBuffer.h"

#include "itkVideoFileReader.h"

namespace itk
{

//-CONSTRUCTOR DESTRUCTOR PRINT------------------------------------------------

//
// Constructor
//
template< typename TOutputVideoStream >
VideoFileReader< TOutputVideoStream >
::VideoFileReader()
{
  // Initialize members
  m_FileName = "";
  m_VideoIO = ITK_NULLPTR;
  m_PixelConversionNeeded = false;
  m_IFrameSafe = true;

  // TemporalProcessObject inherited members
  this->SetUnitOutputNumberOfFrames(1);
  this->SetFrameSkipPerOutput(1);
  this->SetInputStencilCurrentFrameIndex(0);
}


//
// Destructor
//
template< typename TOutputVideoStream >
VideoFileReader< TOutputVideoStream >
::~VideoFileReader()
{}


//
// PrintSelf
//
template< typename TOutputVideoStream >
void
VideoFileReader< TOutputVideoStream >
::PrintSelf(std::ostream &os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);

  os << indent << "FileName: " << m_FileName << std::endl;
  if (m_VideoIO)
    {
    os << indent << "VideoIO:" << std::endl;
    m_VideoIO->Print(os, indent.GetNextIndent());
    }
}

//-PUBLIC METHODS--------------------------------------------------------------

//
// GenerateOutputInformation
//
template< typename TOutputVideoStream >
void
VideoFileReader< TOutputVideoStream >
::UpdateOutputInformation()
{
  //
  // Use the VideoIOFactory to generate a VideoIOBase if needed
  //
  if (m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }

  //
  // Check that the desired dimension mateches that read from the file
  //
  if (m_VideoIO->GetNumberOfDimensions() != FrameDimension)
    {
    itkExceptionMacro(<< "Output dimension doesn't match dimension of read "
                      << "data. Expected " << FrameDimension << " but the IO "
                      << "method has " << m_VideoIO->GetNumberOfDimensions()
                      << ".");
    }

  //
  // Set up the largest possible temporal region for the output
  //
  TemporalRegion largestPossibleTemporalRegion;
  largestPossibleTemporalRegion.SetFrameStart(0);
  if (m_IFrameSafe)
    {
    largestPossibleTemporalRegion.SetFrameDuration(m_VideoIO->GetLastIFrame()+1);
    }
  else
    {
    largestPossibleTemporalRegion.SetFrameDuration(m_VideoIO->GetFrameTotal());
    }
  this->GetOutput()->SetLargestPossibleTemporalRegion(largestPossibleTemporalRegion);

  //
  // Set up the information for the output frames
  //

  // Set up largest possible spatial region
  RegionType region;
  SizeType size;
  IndexType start;
  PointType origin;
  SpacingType spacing;
  DirectionType direction;
  for (unsigned int i = 0; i < FrameDimension; ++i)
    {
    size[i] = m_VideoIO->GetDimensions(i);
    origin[i] = m_VideoIO->GetOrigin(i);
    spacing[i] = m_VideoIO->GetSpacing(i);
    std::vector< double > directionInI = m_VideoIO->GetDirection(i);
    for (unsigned int j = 0; j < FrameDimension; ++j)
      {
      direction[j][i] = directionInI[j];
      }
    }
  start.Fill(0);
  region.SetSize(size);
  region.SetIndex(start);

  VideoStreamPointer output = this->GetOutput();

  output->SetAllLargestPossibleSpatialRegions(region);
  output->SetAllBufferedSpatialRegions(region);
  output->SetAllRequestedSpatialRegions(region);

  output->SetAllFramesSpacing(spacing);
  output->SetAllFramesOrigin(origin);
  output->SetAllFramesDirection(direction);
}

//
// GetCurrentPositionFrame
//
template< typename TOutputVideoStream >
typename VideoFileReader<TOutputVideoStream>::FrameOffsetType
VideoFileReader< TOutputVideoStream >
::GetCurrentPositionFrame()
{
  if(m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }
  return m_VideoIO->GetCurrentFrame();
}


//
// GetCurrentPositionRatio
//
template< typename TOutputVideoStream >
typename VideoFileReader<TOutputVideoStream>::TemporalRatioType
VideoFileReader< TOutputVideoStream >
::GetCurrentPositionRatio()
{
  if(m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }
  return m_VideoIO->GetRatio();
}


//
// GetCurrentPositionMSec
//
template< typename TOutputVideoStream >
typename VideoFileReader<TOutputVideoStream>::TemporalRatioType
VideoFileReader< TOutputVideoStream >
::GetCurrentPositionMSec()
{
  if(m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }
  return m_VideoIO->GetPositionInMSec();
}


//
// GetNumberOfFrames
//
template< typename TOutputVideoStream >
typename VideoFileReader<TOutputVideoStream>::FrameOffsetType
VideoFileReader< TOutputVideoStream >
::GetNumberOfFrames()
{
  if(m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }
  return m_VideoIO->GetFrameTotal();
}


//
// GetFramesPerSecond
//
template< typename TOutputVideoStream >
typename VideoFileReader<TOutputVideoStream>::TemporalRatioType
VideoFileReader< TOutputVideoStream >
::GetFramesPerSecond()
{
  if(m_VideoIO.IsNull())
    {
    this->InitializeVideoIO();
    }
  return m_VideoIO->GetFramesPerSecond();
}


//-PROTECTED METHODS-----------------------------------------------------------

//
// InitializeVideoIO
//
template< typename TOutputVideoStream >
void
VideoFileReader< TOutputVideoStream >
::InitializeVideoIO()
{
  m_VideoIO = itk::VideoIOFactory::CreateVideoIO(
                                itk::VideoIOFactory::ReadFileMode,
                                m_FileName.c_str());
  m_VideoIO->SetFileName(m_FileName.c_str());
  m_VideoIO->ReadImageInformation();

  // Make sure the input video has the same number of dimensions as the desired
  // output
  //
  // Note: This may be changed with the implementation of the Image
  //       Interpretation Layer
  if (m_VideoIO->GetNumberOfDimensions() != FrameType::ImageDimension)
    {
    itkExceptionMacro("Cannot convert " << m_VideoIO->GetNumberOfDimensions() << "D "
      "image set to " << FrameType::ImageDimension << "D");
    }

  // See if a buffer conversion is needed
  ImageIOBase::IOComponentType ioType = ImageIOBase
    ::MapPixelType< typename ConvertPixelTraits::ComponentType >::CType;
  if ( m_VideoIO->GetComponentType() != ioType ||
       m_VideoIO->GetNumberOfComponents() != ConvertPixelTraits::GetNumberOfComponents() )
    {
    // the pixel types don't match so a type conversion needs to be
    // performed
    itkDebugMacro( << "Buffer conversion required from: "
                   << m_VideoIO->GetComponentTypeAsString(m_VideoIO->GetComponentType())
                   << " to: "
                   << m_VideoIO->GetComponentTypeAsString(ioType)
                   << " ConvertPixelTraits::NumComponents "
                   << ConvertPixelTraits::GetNumberOfComponents()
                   << " m_VideoIO->NumComponents "
                   << m_VideoIO->GetNumberOfComponents() );
    m_PixelConversionNeeded = true;
    }
  else
    {
    m_PixelConversionNeeded = false;
    }
}


//
// TemporalStreamingGenerateData
//
template< typename TOutputVideoStream >
void
VideoFileReader< TOutputVideoStream >
::TemporalStreamingGenerateData()
{
  // Allocate the output frames
  this->AllocateOutputs();

  // Get the frame number for the frame we're reading
  typename VideoStreamType::Pointer output;
  typename VideoStreamType::TemporalRegionType requestedTemporalRegion;
  output = this->GetOutput();
  requestedTemporalRegion = output->GetRequestedTemporalRegion();
  FrameOffsetType frameNum = requestedTemporalRegion.GetFrameStart();

  // Figure out if we need to skip frames
  FrameOffsetType currentIOFrame = m_VideoIO->GetCurrentFrame();
  if (frameNum != currentIOFrame)
    {
    m_VideoIO->SetNextFrameToRead(frameNum);
    }

  // Read a single frame
  if (this->m_PixelConversionNeeded)
    {
    // Set up temporary buffer for reading
    size_t bufferSize = m_VideoIO->GetImageSizeInBytes();
    char* loadBuffer = new char[bufferSize];

    // Read into a temporary buffer
    this->m_VideoIO->Read(static_cast<void*>(loadBuffer));

    // Convert the buffer into the output buffer location
    this->DoConvertBuffer(static_cast<void*>(loadBuffer), frameNum);
    delete[] loadBuffer;
    }
  else
    {
    FrameType* frame = this->GetOutput()->GetFrame(frameNum);
    m_VideoIO->Read(reinterpret_cast<void*>(frame->GetBufferPointer()));
    }

  // Mark ourselves modified
  this->Modified();
}


//
// DoConvertBuffer (much borrowed from itkImageFileReader)
//
template< typename TOutputVideoStream >
void
VideoFileReader< TOutputVideoStream >::
DoConvertBuffer(void* inputData, FrameOffsetType frameNumber)
{
  PixelType* outputData =
    this->GetOutput()->GetFrame(frameNumber)->GetPixelContainer()->GetBufferPointer();
  unsigned int numberOfPixels =
    this->GetOutput()->GetFrame(frameNumber)->GetPixelContainer()->Size();
  bool isVectorImage(strcmp(this->GetOutput()->GetFrame(frameNumber)->GetNameOfClass(),
                            "VectorImage") == 0);
#define ITK_CONVERT_BUFFER_IF_BLOCK(_CType,type)                        \
  else if(m_VideoIO->GetComponentType() == _CType)                      \
    {                                                                   \
    if (isVectorImage)                                                  \
      {                                                                 \
      ConvertPixelBuffer<type,                                          \
                         PixelType,                                     \
                         ConvertPixelTraits                             \
                         >                                              \
        ::ConvertVectorImage(static_cast< type * >( inputData ),        \
                             m_VideoIO->GetNumberOfComponents(),        \
                             outputData,                                \
                             numberOfPixels);                           \
      }                                                                 \
    else                                                                \
      {                                                                 \
      ConvertPixelBuffer<type,                                          \
                         PixelType,                                     \
                         ConvertPixelTraits                             \
                         >                                              \
        ::Convert(static_cast< type * >( inputData ),                   \
                  m_VideoIO->GetNumberOfComponents(),                   \
                  outputData,                                           \
                  numberOfPixels);                                      \
      }                                                                 \
    }

  if(0) {}
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::UCHAR,unsigned char)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::CHAR,char)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::USHORT,unsigned short)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::SHORT,short)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::UINT,unsigned int)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::INT,int)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::ULONG,unsigned long)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::LONG,long)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::FLOAT,float)
  ITK_CONVERT_BUFFER_IF_BLOCK(ImageIOBase::DOUBLE,double)
  else
    {
#define TYPENAME_VideoFileReader(x)                                     \
    m_VideoIO->GetComponentTypeAsString                 \
      (ImageIOBase::MapPixelType<x>::CType)

    ExceptionObject e(__FILE__, __LINE__);
    std::ostringstream       msg;
    msg << "Couldn't convert component type: "
        << std::endl << "    "
        << m_VideoIO->GetComponentTypeAsString( m_VideoIO->GetComponentType() )
        << std::endl << "to one of: "
        << std::endl << "    " << TYPENAME_VideoFileReader( unsigned char )
        << std::endl << "    " << TYPENAME_VideoFileReader( char )
        << std::endl << "    " << TYPENAME_VideoFileReader( unsigned short )
        << std::endl << "    " << TYPENAME_VideoFileReader( short )
        << std::endl << "    " << TYPENAME_VideoFileReader( unsigned int )
        << std::endl << "    " << TYPENAME_VideoFileReader( int )
        << std::endl << "    " << TYPENAME_VideoFileReader( FrameOffsetType )
        << std::endl << "    " << TYPENAME_VideoFileReader( long )
        << std::endl << "    " << TYPENAME_VideoFileReader( float )
        << std::endl << "    " << TYPENAME_VideoFileReader( double )
        << std::endl;
    e.SetDescription( msg.str().c_str() );
    e.SetLocation(ITK_LOCATION);
    throw e;
    return;
    }
#undef ITK_CONVERT_BUFFER_IF_BLOCK

}

} // end namespace itk

#endif