做开发的时候,需要在lcd制定区域播放视频,播放器是gstreamer,用到了overlaysink组件,但是这个组件会吧视频之外的区域渲染黑,此时板式显示不出来。后来经过研究,用color_key可以完美解决这个问题。下面直接上代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "ui_mainwindow.h"
#include <QDebug>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/mxcfb.h>
#include <sys/mman.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/mxcfb.h>
#include <sys/mman.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
struct mxcfb_gbl_alpha gbl_alpha;
struct mxcfb_color_key key;
int ret;
QMainWindow(parent),
ui(new Ui::MainWindow)
{
struct mxcfb_gbl_alpha gbl_alpha;
struct mxcfb_color_key key;
int ret;
ui->setupUi(this);
setCursor(QCursor(Qt::BlankCursor));
QWidget *widget;
widget = new QWidget(this);
widget->setGeometry(0, 0, 800, 600);
widget = new QWidget(this);
widget->setGeometry(0, 0, 800, 600);
QPalette palette;
palette.setColor(QPalette::Background, QColor(0,0,0));
widget->setPalette(palette);
widget->setAutoFillBackground(true);
widget->show();
palette.setColor(QPalette::Background, QColor(0,0,0));
widget->setPalette(palette);
widget->setAutoFillBackground(true);
widget->show();
int fd;
if ((fd = open("/dev/fb0", O_RDWR, 0)) < 0) {
fprintf(stderr, "Unable to open %s\n", "/dev/fb0");
}
if ((fd = open("/dev/fb0", O_RDWR, 0)) < 0) {
fprintf(stderr, "Unable to open %s\n", "/dev/fb0");
}
gbl_alpha.enable = 1;
gbl_alpha.alpha = 255; // BG opaque
gbl_alpha.alpha = 255; // BG opaque
ret = ioctl(fd, MXCFB_SET_GBL_ALPHA, &gbl_alpha);
if (ret)
qDebug() << "set Global Alpha error";
if (ret)
qDebug() << "set Global Alpha error";
key.enable = 1;
key.color_key = 0x00000000; // Black
ret = ioctl(fd, MXCFB_SET_CLR_KEY, &key);
if (ret)
qDebug() << "set Color key error";
//std::close(fd);
}
MainWindow::~MainWindow()
{
delete ui;
}
{
delete ui;
}
此时,板式可以随意显示,板式中的黑色会被视频透出来。