MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteFileHeader

Method WriteFileHeader

IO/Image/vtkTIFFWriter.cxx:123–270  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

121
122//------------------------------------------------------------------------------
123void vtkTIFFWriter::WriteFileHeader(ostream*, vtkImageData* data, int wExt[6])
124{
125 vtkDataArray* scalarArray = this->GetInputArrayToProcess(0, this->GetInput());
126
127 int dims[3];
128 data->GetDimensions(dims);
129 int scomponents = scalarArray->GetNumberOfComponents();
130 int stype = scalarArray->GetDataType();
131 uint32_t rowsperstrip = (uint32_t)-1;
132
133 int bps;
134 switch (stype)
135 {
136 case VTK_CHAR:
137 case VTK_SIGNED_CHAR:
138 case VTK_UNSIGNED_CHAR:
139 bps = 8;
140 break;
141 case VTK_SHORT:
142 case VTK_UNSIGNED_SHORT:
143 bps = 16;
144 break;
145 case VTK_FLOAT:
146 bps = 32;
147 break;
148 default:
149 vtkErrorMacro(<< "Unsupported data type: " << vtkImageScalarTypeNameMacro(stype));
150 this->SetErrorCode(vtkErrorCode::FileFormatError);
151 return;
152 }
153
154 int predictor;
155
156 // Find the width/height of the images
157 this->Width = wExt[1] - wExt[0] + 1;
158 this->Height = wExt[3] - wExt[2] + 1;
159 // Check if we need to write an image stack (pages > 2).
160 this->Pages = wExt[5] - wExt[4] + 1;
161
162 // Check the resolution too, assume we store it in metric (as in reader).
163 this->XResolution = 10.0 / data->GetSpacing()[0];
164 this->YResolution = 10.0 / data->GetSpacing()[1];
165
166 std::stringstream writeMode;
167 writeMode << "w";
168 vtkTypeInt64 len =
169 static_cast<vtkTypeInt64>(this->Width) * this->Height * this->Pages * scomponents * (bps / 8);
170 if (len > VTK_INT_MAX)
171 {
172 // Large image detected, use BigTIFF mode
173 writeMode << "8";
174 }
175#if defined(_WIN32)
176 std::wstring widepath = vtksys::Encoding::ToWide(this->InternalFileName);
177 TIFF* tif = TIFFOpenW(widepath.c_str(), writeMode.str().c_str());
178#else
179 TIFF* tif = TIFFOpen(this->InternalFileName, writeMode.str().c_str());
180#endif

Callers 1

vtkTIFFWriter.cxxFile · 0.45

Calls 14

TIFFSetFieldFunction · 0.85
TIFFDefaultStripSizeFunction · 0.85
TIFFOpenWFunction · 0.50
TIFFOpenFunction · 0.50
GetInputMethod · 0.45
GetDimensionsMethod · 0.45
GetNumberOfComponentsMethod · 0.45
GetDataTypeMethod · 0.45
GetSpacingMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected