/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qlinuxfbscreen.h"
#include <QtPlatformSupport/private/qfbcursor_p.h>
#include <QtPlatformSupport/private/qfbwindow_p.h>
#include <QtCore/QRegularExpression>
#include <QtGui/QPainter>
#include <private/qcore_unix_p.h> // overrides QT_OPEN
#include <qimage.h>
#include <qdebug.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <linux/kd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <limits.h>
#include <signal.h>
#include <linux/fb.h>
QT_BEGIN_NAMESPACE
static int openFramebufferDevice(const QString &dev)
{
int fd = -1;
if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0)
fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR);
if (fd == -1) {
if (access(dev.toLatin1().constData(), R_OK) == 0)
fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY);
}
return fd;
}
static int determineDepth(const fb_var_screeninfo &vinfo)
{
int depth = vinfo.bits_per_pixel;
if (depth== 24) {
depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
if (depth <= 0)
depth = 24; // reset if color component lengths are not reported
} else if (depth == 16) {
depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
if (depth <= 0)
depth = 16;
}
return depth;
}
static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &userGeometry)
{
int xoff = vinfo.xoffset;
int yoff = vinfo.yoffset;
int w, h;
if (userGeometry.isValid()) {
w = userGeometry.width();
h = userGeometry.height();
if ((uint)w > vinfo.xres)
w = vinfo.xres;
if ((uint)h > vinfo.yres)
h = vinfo.yres;
int xxoff = userGeometry.x(), yyoff = userGeometry.y();
if (xxoff != 0 || yyoff != 0) {
if (xxoff < 0 || xxoff + w > (int)(vinfo.xres))
xxoff = vinfo.xres - w;
if (yyoff < 0 || yyoff + h > (int)(vinfo.yres))
yyoff = vinfo.yres - h;
xoff += xxoff;
yoff += yyoff;
} else {
xoff += (vinfo.xres - w)/2;
yoff += (vinfo.yres - h)/2;
}
} else {
w = vinfo.xres;
h = vinfo.yres;
}
if (w == 0 || h == 0) {
qWarning("Unable to find screen geometry, using 320x240");
w = 320;
h = 240;
}
return QRect(xoff, yoff, w, h);
}
static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res)
{
int mmWidth = mmSize.width(), mmHeight = mmSize.height();
if (mmWidth <= 0 && mmHeight <= 0) {
if (vinfo.width != 0 && vinfo.height != 0
&& vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) {
mmWidth = vinfo.width;
mmHeight = vinfo.height;
} else {
const int dpi = 100;
mmWidth = qRound(res.width() * 25.4 / dpi);
mmHeight = qRound(res.height() * 25.4 / dpi);
}
} else if (mmWidth > 0 && mmHeight <= 0) {
mmHeight = res.height() * mmWidth/res.width();
} else if (mmHeight > 0 && mmWidth <= 0) {
mmWidth = res.width() * mmHeight/res.height();
}
return QSize(mmWidth, mmHeight);
}
static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth)
{
const fb_bitfield rgba[4] = { info.red, info.green,
info.blue, info.transp };
QImage::Format format = QImage::Format_Invalid;
switch (depth) {
case 32: {
const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
{0, 8, 0}, {24, 8, 0}};
const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
{16, 8, 0}, {24, 8, 0}};
if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_ARGB32;
} else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB32;
} else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB32;
// pixeltype = BGRPixel;
}
break;
}
case 24: {
const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0},
{0, 8, 0}, {0, 0, 0}};
const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0},
{16, 8, 0}, {0, 0, 0}};
if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB888;
} else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB888;
// pixeltype = BGRPixel;
}
break;
}
case 18: {
const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0},
{0, 6, 0}, {0, 0, 0}};
if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0)
format = QImage::Format_RGB666;
break;
}
case 16: {
const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0},
{0, 5, 0}, {0, 0, 0}};
const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0},
{11, 5, 0}, {0, 0, 0}};
if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB16;
} else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB16;
// pixeltype = BGRPixel;
}
break;
}
case 15: {
const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0},
{0, 5, 0}, {15, 1, 0}};
const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0},
{10, 5, 0}, {15, 1, 0}};
if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB555;
} else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) {
format = QImage::Format_RGB555;
// pixeltype = BGRPixel;
}
break;
}
case 12: {
const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0},
{0, 4, 0}, {0, 0, 0}};
if (memcmp(rgba, rg
Qt5.X的linuxfb平台源码补丁包
5星 · 超过95%的资源 需积分: 42 163 浏览量
2018-05-17
16:13:29
上传
评论
收藏 6KB ZIP 举报
immortal018
- 粉丝: 3
- 资源: 2
最新资源
- 基于C实现的N阶数字正方形 ;N阶数字三角形;N阶数字递减三角形;乘法表
- 基于分水岭算法的图像分割的python源码(课程设计).zip
- 基于Java 实现的二进制十进制之间的相互转换
- Pytorch实现基于卷积神经网络的面部表情识别项目源码+数据集+全部资料(毕业设计).zip
- Pytorch实现基于深度学习卷积神经网络的面部表情识别项目源码+面部表情数据集(人脸面部表情识别项目).zip
- 淘金小游戏助手.apk
- 基于卷积神经网络的人脸面部表情识别项目源码+面部表情数据集+训练好的模型(人脸面部表情识别项目).zip
- 深度学习基于卷积神经网络的人脸面部表情识别项目源码+面部表情数据集+训练好的模型(人脸面部表情识别项目).zip
- 4f76dd1f4d0bea09663e536fd2297540.txt
- React项目基于JavaScript实现的全球新闻发布管理系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈