------------------------------------------------------------------------------ This function reads in one data of data. templated to handle different data types.
| 215 | // This function reads in one data of data. |
| 216 | // templated to handle different data types. |
| 217 | bool vtkHDRReader::HDRReaderUpdateSlice(float* outPtr, int* outExt) |
| 218 | { |
| 219 | vtkResourceStream* stream = this->GetStream(); |
| 220 | vtkNew<vtkFileResourceStream> fileStream; |
| 221 | if (!stream) |
| 222 | { |
| 223 | if (!fileStream->Open(this->InternalFileName)) |
| 224 | { |
| 225 | vtkErrorMacro("Could not open file " << this->InternalFileName); |
| 226 | return false; |
| 227 | } |
| 228 | stream = fileStream; |
| 229 | } |
| 230 | |
| 231 | // Ignore header |
| 232 | stream->Seek(this->HeaderSize, vtkResourceStream::SeekDirection::Begin); |
| 233 | |
| 234 | // Even if we have a smaller extent, the RLE encoding forces us to read all the line width |
| 235 | const int width = this->GetWidth(); |
| 236 | |
| 237 | const int extentWidth = outExt[1] - outExt[0] + 1; |
| 238 | |
| 239 | // We read only lines that we need (depending on outExt[2] and outExt[3]); |
| 240 | int nbLinesLeft = outExt[3] - outExt[2] + 1; |
| 241 | const int totalNbLines = nbLinesLeft; |
| 242 | |
| 243 | float* outPtr2 = outPtr; |
| 244 | // decrPtr is the number of byte needed to go to the previous line |
| 245 | int decrPtr = 0; |
| 246 | if (this->FileLowerLeft) |
| 247 | { |
| 248 | // Start at the end of outPtr and go up |
| 249 | outPtr2 = outPtr + (nbLinesLeft - 1) * extentWidth * 3; |
| 250 | decrPtr = 2 * extentWidth * 3; |
| 251 | } |
| 252 | |
| 253 | if ((width < 8) || (width > 0x7fff)) |
| 254 | { |
| 255 | // File not run length encoded |
| 256 | this->ReadAllFileNoRLE(stream, outPtr2, decrPtr, outExt); |
| 257 | this->CloseFile(); |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | // We need to skip some lines |
| 262 | int nbSkipLines = outExt[2]; |
| 263 | |
| 264 | // Store the position in case of a non RLE encoded file |
| 265 | vtkTypeInt64 afterHeader = stream->Tell(); |
| 266 | |
| 267 | // rgbe will hold the value of each channels |
| 268 | unsigned char rgbe[4]; |
| 269 | // lineBuffer will contain data read from the file |
| 270 | // 4 uchar for each pixel of a line |
| 271 | std::vector<unsigned char> lineBuffer(width * 4); |
| 272 | while (nbLinesLeft > 0) |
| 273 | { |
| 274 | stream->Read(rgbe, sizeof(unsigned char) * 4); |
no test coverage detected