void DICOMFileFrameRegionReader::copyRegionFromFrames()

in src/dicom_file_region_reader.cpp [124:164]


void DICOMFileFrameRegionReader::copyRegionFromFrames(
int64_t imageOffsetX, int64_t imageOffsetY, const uint32_t * const frameBytes,
int64_t fx, int64_t fy, int64_t copyWidth, int64_t copyHeight,
uint32_t *memory, int64_t memoryWidth, int64_t mx, int64_t my) const {
    // Copies a memory region from a frame memory to memory buffer.
    //
    // Args:
    //   imageOffsetX : global upper left coordinate in image
    //   imageOffsetY : global upper left coordinate in image
    //   frameBytes: frame pixel memory
    //   fx : upper left coordinate of frame
    //   fy : upper left coordinate of frame
    //   copyWidth : width to copy from frame
    //   copyHeight : height to copy frome frame
    //   memory : pixel memory to copy frame data to.
    //   memoryWidth : total width of memory block.
    //   mx : upper left coordinate in memory to read from
    //   my : upper left coordinate in memory to read from

    const int64_t endMX = mx + copyWidth;  // end position to copy to
    int64_t myOffset = my * memoryWidth;   // y offset to start writing to
    int64_t frameOffset = fy * frameWidth_;  // y offset to read from.
    int64_t imageY = imageOffsetY;         // global position in image
    for (int64_t row = 0; row < copyHeight; ++row) {
      int64_t frameCursor = fx + frameOffset;  // frame memory read index
      for (int64_t column = mx; column < endMX; ++column) {
          int64_t imageX = column + imageOffsetX;
          if (imageX >= imageWidth_ ||   // if frame memory is nullptr or
              imageY >= imageHeight_ ||  // outside of image bounds
              frameBytes == nullptr) {  // set copied pixel memory ARGB to 0
            memory[column + myOffset] = 0;
          } else {   // otherwise copy memory
            memory[column + myOffset] = frameBytes[frameCursor];
          }
          frameCursor += 1;  // increment frame read index
      }
      myOffset += memoryWidth;  // increment row offsets
      frameOffset += frameWidth_;
      imageY  += 1;
    }
}