| 83 | } |
| 84 | |
| 85 | void vtkBMPWriter::WriteFile(ostream* file, vtkImageData* data, int extent[6], int wExtent[6]) |
| 86 | { |
| 87 | int idx1, idx2; |
| 88 | int rowLength, rowAdder, i; // in bytes |
| 89 | unsigned char* ptr; |
| 90 | int bpp; |
| 91 | unsigned long count = 0; |
| 92 | unsigned long target; |
| 93 | float progress = this->Progress; |
| 94 | float area; |
| 95 | |
| 96 | bpp = data->GetNumberOfScalarComponents(); |
| 97 | |
| 98 | // Make sure we actually have data. |
| 99 | if (!data->GetPointData()->GetScalars()) |
| 100 | { |
| 101 | vtkErrorMacro(<< "Could not get data from input."); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | // take into consideration the scalar type |
| 106 | if (data->GetScalarType() != VTK_UNSIGNED_CHAR) |
| 107 | { |
| 108 | vtkErrorMacro("BMPWriter only accepts unsigned char scalars!"); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | // Row length of x axis |
| 113 | rowLength = extent[1] - extent[0] + 1; |
| 114 | rowAdder = (4 - ((extent[1] - extent[0] + 1) * 3) % 4) % 4; |
| 115 | |
| 116 | area = ((extent[5] - extent[4] + 1) * (extent[3] - extent[2] + 1) * (extent[1] - extent[0] + 1)) / |
| 117 | ((wExtent[5] - wExtent[4] + 1) * (wExtent[3] - wExtent[2] + 1) * (wExtent[1] - wExtent[0] + 1)); |
| 118 | |
| 119 | target = |
| 120 | (unsigned long)((extent[5] - extent[4] + 1) * (extent[3] - extent[2] + 1) / (50.0 * area)); |
| 121 | target++; |
| 122 | |
| 123 | for (idx2 = extent[4]; idx2 <= extent[5]; ++idx2) |
| 124 | { |
| 125 | for (idx1 = extent[2]; idx1 <= extent[3]; idx1++) |
| 126 | { |
| 127 | if (!(count % target)) |
| 128 | { |
| 129 | this->UpdateProgress(progress + count / (50.0 * target)); |
| 130 | } |
| 131 | count++; |
| 132 | ptr = (unsigned char*)data->GetScalarPointer(extent[0], idx1, idx2); |
| 133 | if (bpp == 1) |
| 134 | { |
| 135 | for (i = 0; i < rowLength; i++) |
| 136 | { |
| 137 | file->put(ptr[i]); |
| 138 | file->put(ptr[i]); |
| 139 | file->put(ptr[i]); |
| 140 | } |
| 141 | } |
| 142 | if (bpp == 2) |
no test coverage detected