Commit 96614853 authored by Tristan Matthews's avatar Tristan Matthews

video: refactor blit() code

parent 4e868771
...@@ -158,38 +158,20 @@ int VideoFrame::blit(VideoFrame &src, int xoff, int yoff) ...@@ -158,38 +158,20 @@ int VideoFrame::blit(VideoFrame &src, int xoff, int yoff)
return -1; return -1;
} }
uint8_t *src_data, *dst_data; auto copy_plane = [&] (unsigned idx) {
ssize_t dst_stride; const unsigned divisor = idx == 0 ? 1 : 2;
ssize_t dst_stride = frame_->linesize[idx];
// Y uint8_t *src_data = src_frame->data[idx];
dst_stride = frame_->linesize[0]; uint8_t *dst_data = frame_->data[idx] + yoff / divisor * dst_stride + xoff / divisor;
src_data = src_frame->data[0]; for (unsigned i = 0; i < src_frame->height / divisor; i++) {
dst_data = frame_->data[0] + yoff * dst_stride + xoff; memcpy(dst_data, src_data, src_frame->linesize[idx]);
for (int i = 0; i < src_frame->height; i++) { src_data += src_frame->linesize[idx];
memcpy(dst_data, src_data, src_frame->linesize[0]); dst_data += dst_stride;
src_data += src_frame->linesize[0]; }
dst_data += dst_stride; };
}
for (unsigned plane = 0; plane < 3; ++plane)
// U copy_plane(plane);
dst_stride = frame_->linesize[1];
src_data = src_frame->data[1];
dst_data = frame_->data[1] + yoff / 2 * dst_stride + xoff / 2;
for (int i = 0; i < src_frame->height / 2; i++) {
memcpy(dst_data, src_data, src_frame->linesize[1]);
src_data += src_frame->linesize[1];
dst_data += dst_stride;
}
// V
dst_stride = frame_->linesize[2];
src_data = src_frame->data[2];
dst_data = frame_->data[2] + yoff / 2 * dst_stride + xoff / 2;
for (int i = 0; i < src_frame->height / 2; i++) {
memcpy(dst_data, src_data, src_frame->linesize[2]);
src_data += src_frame->linesize[2];
dst_data += dst_stride;
}
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment