This file is indexed.

/usr/src/WrapITK/Tcl/itkTkImageViewer2D.cxx is in libinsighttoolkit3-dev 3.20.1+git20120521-6build1.

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
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkTkImageViewer2D.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "itkTkImageViewer2D.h"

#include <tk.h>

namespace itk
{

TkImageViewer2D::TkImageViewer2D()
{
  m_Interpreter = 0;
  
  // Setup the internal pipeline.
  m_FlipFilter = FlipFilter::New();
  FlipFilter::FlipAxesArrayType axes;
  axes[0] = false;
  axes[1] = true;
  m_FlipFilter->SetFlipAxes(axes);
  m_RescaleFilter = RescaleFilter::New();
  m_RescaleFilter->SetInput(m_FlipFilter->GetOutput());
  m_RescaleFilter->SetOutputMinimum(0);
  m_RescaleFilter->SetOutputMaximum(255);
}

TkImageViewer2D::~TkImageViewer2D()
{
}

//----------------------------------------------------------------------------
void TkImageViewer2D::SetInterpreter(Tcl_Interp* interp)
{
  m_Interpreter = interp;
}

//----------------------------------------------------------------------------
Tcl_Interp* TkImageViewer2D::GetInterpreter() const
{
  return m_Interpreter;
}

//----------------------------------------------------------------------------
void TkImageViewer2D::SetImageName(const char* name)
{
  m_ImageName = name;
}

//----------------------------------------------------------------------------
const char* TkImageViewer2D::GetImageName() const
{
  return m_ImageName.c_str();
}

//----------------------------------------------------------------------------
void TkImageViewer2D::SetCanvasName(const char* name)
{
  m_CanvasName = name;
}

//----------------------------------------------------------------------------
const char* TkImageViewer2D::GetCanvasName() const
{
  return m_CanvasName.c_str();
}

//----------------------------------------------------------------------------
void TkImageViewer2D::SetInput(InputImageType* image)
{
  this->Superclass::SetNthInput(0, image);
}

//----------------------------------------------------------------------------
TkImageViewer2D::InputImageType* TkImageViewer2D::GetInput()
{
  DataObject* input = this->Superclass::GetInput(0);
  return dynamic_cast<InputImageType*>(input);
}

//----------------------------------------------------------------------------
void TkImageViewer2D::Draw()
{
  // Make sure we have an input image.
  InputImageType* input = this->GetInput();
  if(!input) { return; }
  
  // Connect our input to the internal pipeline.
  m_FlipFilter->SetInput(input);
  
  // Bring the image up to date.
  RescaleFilter::OutputImageType* image = m_RescaleFilter->GetOutput();
  image->UpdateOutputInformation();
  image->SetRequestedRegion(image->GetLargestPossibleRegion());
  image->Update();
  
  // Get the size of the image.
  itk::Size<2> size = image->GetLargestPossibleRegion().GetSize();
  int width = static_cast<int>(size[0]);
  int height = static_cast<int>(size[1]);
  
  // Setup the size 
  Tk_PhotoHandle photo =
    Tk_FindPhoto(m_Interpreter, const_cast<char*>(m_ImageName.c_str()));
  Tk_PhotoSetSize(photo, width, height);
  
  OStringStream command;
  command << m_CanvasName.c_str() << " configure -scrollregion \"1 1 "
          << width << " " << height << "\"";
  std::string cmdstr = command.str();
  char* cmd = new char[cmdstr.length()+1];
  strcpy(cmd, cmdstr.c_str());
  Tcl_GlobalEval(m_Interpreter, cmd);
  delete [] cmd;
  
  // Copy the image data to the Tk photo.
  unsigned char* buffer =
    reinterpret_cast<unsigned char*>(image->GetBufferPointer());
  
  Tk_PhotoImageBlock block;
  block.pixelPtr = buffer;
  block.width = width;
  block.height = height;
  block.pitch = width;
  block.pixelSize = 1;
  block.offset[0] = 0;
  block.offset[1] = 0;
  block.offset[2] = 0;
  block.offset[3] = 0;
#if (TK_MAJOR_VERSION == 8) && (TK_MINOR_VERSION < 4)
  Tk_PhotoPutBlock(photo, &block, 0, 0, size[0], size[1]);
#else
  Tk_PhotoPutBlock(photo, &block, 0, 0, size[0], size[1],
                   TK_PHOTO_COMPOSITE_SET);
#endif
}

} // namespace itk