int64_t ImageFileFrame::rawABGRFrameBytes()

in src/imageFilePyramidSource.cpp [31:55]


int64_t ImageFileFrame::rawABGRFrameBytes(uint8_t *rawMemory,
int64_t memorySize) {
  const uint64_t locX = locationX();
  const uint64_t locY = locationY();
  const uint64_t fWidth = frameWidth();
  const uint64_t fHeight = frameHeight();
  cv::Mat *wholeImage = pyramidSource_->image();
  uint64_t width = std::min(wholeImage->cols - locX, fWidth);
  uint64_t height = std::min(wholeImage->rows - locY, fHeight);
  cv::Mat patch(*wholeImage,
                cv::Range(locY, locY + height),
                cv::Range(locX, locX + width));
  uint64_t padright = std::max(static_cast<uint64_t>(0), fWidth - width);
  uint64_t padbottom = std::max(static_cast<uint64_t>(0), fHeight - height);
  cv::Mat bgraMemory(fHeight, fWidth, CV_8UC4, rawMemory);
  if (padright > 0 || padbottom > 0) {
    cv::Mat paddedPatch(fHeight, fWidth, patch.depth());
    cv::copyMakeBorder(patch, paddedPatch, 0, padbottom, 0, padright,
                       cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
    cv::cvtColor(paddedPatch, bgraMemory, cv::COLOR_RGB2BGRA);
  } else {
    cv::cvtColor(patch, bgraMemory, cv::COLOR_RGB2BGRA);
  }
  return memorySize;
}