Skip to content
Snippets Groups Projects
Commit bbe1c73d authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

#30274: mirroring local camera frames

parent 2f4419c5
No related branches found
No related tags found
No related merge requests found
......@@ -210,6 +210,45 @@ void VideoFrame::clear()
memset(frame_->data[2], 0, frame_->linesize[2]*frame_->height/2);
}
int VideoFrame::mirror() {
if (frame_->format != PIX_FMT_YUV420P) {
ERROR("Unsupported pixel format");
return -1;
}
uint8_t *data;
ssize_t stride;
// Y
stride = frame_->linesize[0];
data = frame_->data[0];
for (int i = 0; i < frame_->height; i++) {
for (int j=0,k=stride-1; j < stride/2; j++, k--)
std::swap(data[j], data[k]);
data += stride;
}
// U
stride = frame_->linesize[1];
data = frame_->data[1];
for (int i = 0; i < frame_->height / 2; i++) {
for (int j=0,k=stride-1; j < stride/2; j++, k--)
std::swap(data[j], data[k]);
data += stride;
}
// V
stride = frame_->linesize[2];
data = frame_->data[2];
for (int i = 0; i < frame_->height / 2; i++) {
for (int j=0,k=stride-1; j < stride/2; j++, k--)
std::swap(data[j], data[k]);
data += stride;
}
return 0;
}
void VideoFrame::test()
{
memset(frame_->data[0], 0xaa, frame_->linesize[0]*frame_->height/2);
......
......@@ -204,6 +204,7 @@ public:
int blit(VideoFrame& src, int xoff, int yoff);
void copy(VideoFrame &src);
void clear();
int mirror();
void test();
private:
......
......@@ -132,7 +132,8 @@ int VideoCamera::interruptCb(void *data)
bool VideoCamera::captureFrame()
{
int ret = decoder_->decode(getNewFrame());
VideoFrame& frame = getNewFrame();
int ret = decoder_->decode(frame);
if (ret <= 0) {
if (ret < 0)
......@@ -140,6 +141,7 @@ bool VideoCamera::captureFrame()
return false;
}
frame.mirror();
publishFrame();
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment