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

Method PixelDataCallback

Utilities/DICOMParser/DICOMAppHelper.cxx:808–923  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

806}
807
808void DICOMAppHelper::PixelDataCallback(
809 DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* data, quadbyte len)
810{
811 int numPixels = this->Dimensions[0] * this->Dimensions[1] * this->GetNumberOfComponents();
812 numPixels = std::min(len, numPixels);
813 numPixels = std::max(numPixels, 0);
814
815#ifdef DEBUG_DICOM_APP_HELPER
816 std::cout << "numPixels : " << numPixels << std::endl;
817#endif
818
819 int ptrIncr = int(this->BitsAllocated / 8.0);
820
821 unsigned short* ushortInputData = reinterpret_cast<unsigned short*>(data);
822 unsigned char* ucharInputData = data;
823 short* shortInputData = reinterpret_cast<short*>(data);
824
825 float* floatOutputData; // = nullptr;
826
827 bool isFloat = this->RescaledImageDataIsFloat();
828
829 if (isFloat)
830 {
831#ifdef DEBUG_DICOM_APP_HELPER
832 std::cout << "Slope and offset are not integer valued : ";
833 std::cout << this->RescaleSlope << ", " << this->RescaleOffset << std::endl;
834#endif
835 delete[] (static_cast<char*>(this->ImageData));
836 this->ImageData = new float[numPixels];
837 floatOutputData = static_cast<float*>(this->ImageData);
838
839 this->ImageDataType = DICOMParser::VR_FL;
840 unsigned long uNumPixels = static_cast<unsigned long>(numPixels);
841 this->ImageDataLengthInBytes = uNumPixels * sizeof(float);
842 float newFloatPixel;
843
844 if (ptrIncr == 1)
845 {
846 for (int i = 0; i < numPixels; i++)
847 {
848 newFloatPixel = float(static_cast<double>(this->RescaleSlope) * ucharInputData[i] +
849 static_cast<double>(this->RescaleOffset));
850 floatOutputData[i] = newFloatPixel;
851 }
852#ifdef DEBUG_DICOM_APP_HELPER
853 std::cout << "Did rescale, offset to float from char." << std::endl;
854 std::cout << numPixels << " pixels." << std::endl;
855#endif
856 }
857 else if (ptrIncr == 2)
858 {
859 for (int i = 0; i < numPixels; i++)
860 {
861 newFloatPixel = float(static_cast<double>(this->RescaleSlope) * ushortInputData[i] +
862 static_cast<double>(this->RescaleOffset));
863 floatOutputData[i] = newFloatPixel;
864 }
865#ifdef DEBUG_DICOM_APP_HELPER

Callers

nothing calls this directly

Calls 4

minFunction · 0.50
maxFunction · 0.50
GetNumberOfComponentsMethod · 0.45

Tested by

no test coverage detected