int64_t DICOMImageFrame::rawABGRFrameBytes()

in src/dcmFilePyramidSource.cpp [72:99]


int64_t DICOMImageFrame::rawABGRFrameBytes(uint8_t *rawMemory,
int64_t memorySize) {
  // DICOM frame data in native format is jpeg encoded.
  // uncompress and return # of bytes read.
  // return 0 if error occures.
  const uint64_t width = frameWidth();
  const uint64_t height = frameHeight();
  const uint64_t flags = CIF_UsePartialAccessToPixelData;
  const uint64_t frameCount = 1;
  const uint64_t bufferSize = size_;
  std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(bufferSize);
  int read_index = pyramidSource_->getNextDicomDatasetReaderIndex();
  DICOMDatasetReader *datasetReader =
                                pyramidSource_->dicomDatasetReader(read_index);
  {
    boost::lock_guard<boost::mutex> guard(*datasetReader->datasetMutex());
    DicomImage img(datasetReader->dataset(),
                  pyramidSource_->transferSyntax(), flags,
                  static_cast<uint64_t>(frameNumber_), frameCount);
    if (!img.getOutputData(buffer.get(), bufferSize)) {
      return 0;
    }
  }
  cv::Mat bgr(height, width, CV_8UC3, buffer.get());
  cv::Mat bgra(height, width, CV_8UC4, rawMemory);
  cv::cvtColor(bgr, bgra, cv::COLOR_BGR2BGRA);
  return width * height * 4;
}