| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#ifndef UNIONIMAGE_H |
| 22 |
#define UNIONIMAGE_H |
| 23 |
|
| 24 |
#include <QtCore/qglobal.h> |
| 25 |
|
| 26 |
#if defined(UNIONIMAGE_LIBRARY) |
| 27 |
# define UNIONIMAGESHARED_EXPORT Q_DECL_EXPORT |
| 28 |
#else |
| 29 |
# define UNIONIMAGESHARED_EXPORT Q_DECL_IMPORT |
| 30 |
#endif |
| 31 |
|
| 32 |
#include <QHash> |
| 33 |
#include <QString> |
| 34 |
#include <QByteArray> |
| 35 |
#include <QImage> |
| 36 |
#include <QFileInfo> |
| 37 |
#include <QStringList> |
| 38 |
#include <QMap> |
| 39 |
|
| 40 |
namespace UnionImage_NameSpace { |
| 41 |
|
| 42 |
enum SupportType { |
| 43 |
UNKNOWNTYPE = 0, // unknown type |
| 44 |
BITMAP = 1, // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit |
| 45 |
UINT16 = 2, // array of unsigned short : unsigned 16-bit |
| 46 |
INT16 = 3, // array of short : signed 16-bit |
| 47 |
UINT32 = 4, // array of unsigned long : unsigned 32-bit |
| 48 |
INT32 = 5, // array of long : signed 32-bit |
| 49 |
FLOAT = 6, // array of float : 32-bit IEEE floating point |
| 50 |
DOUBLE = 7, // array of double : 64-bit IEEE floating point |
| 51 |
COMPLEX = 8, // array of FICOMPLEX : 2 x 64-bit IEEE floating point |
| 52 |
RGB16 = 9, // 48-bit RGB image : 3 x 16-bit |
| 53 |
RGBA16 = 10, // 64-bit RGBA image : 4 x 16-bit |
| 54 |
RGBF = 11, // 96-bit RGB float image : 3 x 32-bit IEEE floating point |
| 55 |
RGBAF = 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point |
| 56 |
}; |
| 57 |
|
| 58 |
/** |
| 59 |
* @brief UnionImageVersion |
| 60 |
* @return 版本信息 |
| 61 |
*/ |
| 62 |
UNIONIMAGESHARED_EXPORT QString unionImageVersion(); |
| 63 |
|
| 64 |
/** |
| 65 |
* @brief UnionImageSupporFormat |
| 66 |
* @return const QStringList |
| 67 |
* @author DJH |
| 68 |
* 返回UnionImage支持的所有格式 |
| 69 |
* StaticFormat返回支持的静态图片 |
| 70 |
* DynamicFormat返回支持的动态图片 |
| 71 |
*/ |
| 72 |
UNIONIMAGESHARED_EXPORT const QStringList unionImageSupportFormat(); |
| 73 |
UNIONIMAGESHARED_EXPORT const QStringList supportStaticFormat(); |
| 74 |
UNIONIMAGESHARED_EXPORT const QStringList supportMovieFormat(); |
| 75 |
|
| 76 |
|
| 77 |
UNIONIMAGESHARED_EXPORT bool isDynamicFormat(); |
| 78 |
/** |
| 79 |
* @brief CreatNewImage |
| 80 |
* @param[out] res |
| 81 |
* @param[in] width |
| 82 |
* @param[in] height |
| 83 |
* @param[in] depth |
| 84 |
* @param[in] type |
| 85 |
* @return bool |
| 86 |
* @author DJH |
| 87 |
* 创建一个可以自定义深度和颜色空间的图片 |
| 88 |
*/ |
| 89 |
UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width = 0, int height = 0, int depth = 0, SupportType type = UNKNOWNTYPE); |
| 90 |
|
| 91 |
/** |
| 92 |
* @brief LoadImageFromFile |
| 93 |
* @param[in] path |
| 94 |
* @param[out] res |
| 95 |
* @param[out] errorMsg |
| 96 |
* @return bool |
| 97 |
* @author DJH |
| 98 |
* 从文件载入图片 |
| 99 |
* 载入成功返回true,图片数据返回到res |
| 100 |
* 载入失败返回false,如果需要可以读取errorMsg返回错误信息 |
| 101 |
* 载入动态图片时,只会返回动态图片的第一帧,如果需要动图请使用UnionDynamicImage |
| 102 |
*/ |
| 103 |
UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage &res, QString &errorMsg, const QString &format_bar = ""); |
| 104 |
|
| 105 |
/** |
| 106 |
* @brief detectImageFormat |
| 107 |
* @param path |
| 108 |
* @return QString |
| 109 |
* 返回图片的真格式 |
| 110 |
*/ |
| 111 |
UNIONIMAGESHARED_EXPORT QString detectImageFormat(const QString &path); |
| 112 |
|
| 113 |
/** |
| 114 |
* @brief isNoneQImage |
| 115 |
* @param[in] qi |
| 116 |
* @return bool |
| 117 |
* @author DJH |
| 118 |
* 判断是否为空图 |
| 119 |
*/ |
| 120 |
UNIONIMAGESHARED_EXPORT bool isNoneQImage(const QImage &qi); |
| 121 |
|
| 122 |
/** |
| 123 |
* @brief rotateImage |
| 124 |
* @param[in] angel |
| 125 |
* @param[out] image |
| 126 |
* @return bool |
| 127 |
* @author DJH |
| 128 |
* 在内存中旋转图片 |
| 129 |
*/ |
| 130 |
UNIONIMAGESHARED_EXPORT bool rotateImage(int angel, QImage &image); |
| 131 |
|
| 132 |
/** |
| 133 |
* @brief rotateImageFile |
| 134 |
* @param[in] angel |
| 135 |
* @param[in] path |
| 136 |
* @param[out] erroMsg |
| 137 |
* @return bool |
| 138 |
* @author DJH |
| 139 |
* 旋转图片文件,旋转成功返回true,失败返回false |
| 140 |
* 当不需要获取旋转图片的结果或者只有文件地址时调用该函数 |
| 141 |
* 失败时会将错误信息写入erroMsg |
| 142 |
*/ |
| 143 |
UNIONIMAGESHARED_EXPORT bool rotateImageFile(int angel, const QString &path, QString &erroMsg); |
| 144 |
|
| 145 |
/** |
| 146 |
* @brief rotateImageFile |
| 147 |
* @param[in] angel |
| 148 |
* @param[in][out] img |
| 149 |
* @param[in] path |
| 150 |
* @param[out] erroMsg |
| 151 |
* @return bool |
| 152 |
* @author DJH |
| 153 |
* 旋转图片文件,旋转成功返回true,失败返回false |
| 154 |
* 旋转成功会同时旋转img |
| 155 |
* 图片为空则不会旋转返回失败,失败时会将错误信息写入erroMsg |
| 156 |
*/ |
| 157 |
UNIONIMAGESHARED_EXPORT bool rotateImageFileWithImage(int angel, QImage &img, const QString &path, QString &erroMsg); |
| 158 |
|
| 159 |
/** |
| 160 |
* @brief getAllMetaData |
| 161 |
* @param path |
| 162 |
* @author LMH |
| 163 |
* @return QMap<QString, QString> |
| 164 |
* 获取图片的所有数据,包括创建时间、修改时间、大小等 |
| 165 |
*/ |
| 166 |
UNIONIMAGESHARED_EXPORT QMap<QString, QString> getAllMetaData(const QString &path); |
| 167 |
|
| 168 |
/** |
| 169 |
* @brief isImageSupportRotate |
| 170 |
* @param path |
| 171 |
* @author LMH |
| 172 |
* @return bool |
| 173 |
* 图片是否可以旋转 |
| 174 |
*/ |
| 175 |
UNIONIMAGESHARED_EXPORT bool isImageSupportRotate(const QString &path); |
| 176 |
|
| 177 |
/** |
| 178 |
* @brief canSave |
| 179 |
* @param path |
| 180 |
* @author LMH |
| 181 |
* @return bool |
| 182 |
* 图片是否可以保存 |
| 183 |
*/ |
| 184 |
UNIONIMAGESHARED_EXPORT bool canSave(const QString &path); |
| 185 |
|
| 186 |
UNIONIMAGESHARED_EXPORT bool isSupportReading(const QString &path); |
| 187 |
|
| 188 |
UNIONIMAGESHARED_EXPORT bool isSupportWritting(const QString &path); |
| 189 |
|
| 190 |
/** |
| 191 |
* @brief getOrientation |
| 192 |
* @param path |
| 193 |
* @author LMH |
| 194 |
* @return QString |
| 195 |
* 获得图片的数据 |
| 196 |
*/ |
| 197 |
UNIONIMAGESHARED_EXPORT const QString getOrientation(const QString &path); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
QT_BEGIN_NAMESPACE |
| 202 |
|
| 203 |
class UnionMovieImagePrivate; |
| 204 |
/** |
| 205 |
* @brief The UnionDynamicImage class |
| 206 |
* @author DJH |
| 207 |
* 用来读取动态图片,使用下标来获取动图的每一帧 |
| 208 |
*/ |
| 209 |
class UNIONIMAGESHARED_EXPORT UnionMovieImage |
| 210 |
{ |
| 211 |
public: |
| 212 |
explicit UnionMovieImage(); |
| 213 |
~UnionMovieImage(); |
| 214 |
|
| 215 |
void setFileName(const QString &path); |
| 216 |
|
| 217 |
/** |
| 218 |
* @brief next |
| 219 |
* @return QImage |
| 220 |
* 返回下一帧 |
| 221 |
*/ |
| 222 |
QImage next(); |
| 223 |
|
| 224 |
private: |
| 225 |
UnionMovieImagePrivate *const d_ptr; |
| 226 |
Q_DECLARE_PRIVATE(UnionMovieImage) |
| 227 |
Q_DISABLE_COPY(UnionMovieImage) |
| 228 |
}; |
| 229 |
|
| 230 |
QT_END_NAMESPACE |
| 231 |
|
| 232 |
}; |
| 233 |
|
| 234 |
|
| 235 |
#endif // UNIONIMAGE_H |