diff --git a/README.md b/README.md index 15d42e87..5eaa2a27 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ _The **master** branch is current development branch, build dependencies may cha * libxcb-util0-dev, * libstartup-notification0-dev, * libraw-dev, -* libfreeimage-dev, * libqt5opengl5-dev, * qtbase5-private-dev, * qtmultimedia5-dev, @@ -59,7 +58,7 @@ $ sudo apt-get build-dep image-editor ``` or ``` shell -$ sudo apt install cmake qtbase5-dev pkg-config libexif-dev libqt5svg5-dev libqt5x11extras5-dev libsqlite3-dev qttools5-dev-tools qttools5-dev libxcb-util0-dev libstartup-notification0-dev libraw-dev libfreeimage-dev libqt5opengl5-dev qtbase5-private-dev qtmultimedia5-dev x11proto-xext-dev libmtdev-dev libegl1-mesa-dev libudev-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libxrender-dev libdtkwidget-dev libdtkwidget5-bin libdtkcore5-bin libgio-qt-dev libudisks2-qt5-dev libmediainfo-dev libopencv-dev libgstreamer1.0-dev +$ sudo apt install cmake qtbase5-dev pkg-config libexif-dev libqt5svg5-dev libqt5x11extras5-dev libsqlite3-dev qttools5-dev-tools qttools5-dev libxcb-util0-dev libstartup-notification0-dev libraw-dev libqt5opengl5-dev qtbase5-private-dev qtmultimedia5-dev x11proto-xext-dev libmtdev-dev libegl1-mesa-dev libudev-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libxrender-dev libdtkwidget-dev libdtkwidget5-bin libdtkcore5-bin libgio-qt-dev libudisks2-qt5-dev libmediainfo-dev libopencv-dev libgstreamer1.0-dev ``` 2. Build: diff --git a/README.zh_CN.md b/README.zh_CN.md index 7fb9c8b0..b465b070 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -22,7 +22,6 @@ _**master**分支是当前开发分支,编译依赖可能在未更新README.md * libxcb-util0-dev, * libstartup-notification0-dev, * libraw-dev, -* libfreeimage-dev, * libqt5opengl5-dev, * qtbase5-private-dev, * qtmultimedia5-dev, @@ -59,7 +58,7 @@ $ sudo apt-get build-dep image-editor ``` 或者手动安装 ``` shell -$ sudo apt install cmake qtbase5-dev pkg-config libexif-dev libqt5svg5-dev libqt5x11extras5-dev libsqlite3-dev qttools5-dev-tools qttools5-dev libxcb-util0-dev libstartup-notification0-dev libraw-dev libfreeimage-dev libqt5opengl5-dev qtbase5-private-dev qtmultimedia5-dev x11proto-xext-dev libmtdev-dev libegl1-mesa-dev libudev-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libxrender-dev libdtkwidget-dev libdtkwidget5-bin libdtkcore5-bin libgio-qt-dev libudisks2-qt5-dev libmediainfo-dev libopencv-dev libgstreamer1.0-dev +$ sudo apt install cmake qtbase5-dev pkg-config libexif-dev libqt5svg5-dev libqt5x11extras5-dev libsqlite3-dev qttools5-dev-tools qttools5-dev libxcb-util0-dev libstartup-notification0-dev libraw-dev libqt5opengl5-dev qtbase5-private-dev qtmultimedia5-dev x11proto-xext-dev libmtdev-dev libegl1-mesa-dev libudev-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libxrender-dev libdtkwidget-dev libdtkwidget5-bin libdtkcore5-bin libgio-qt-dev libudisks2-qt5-dev libmediainfo-dev libopencv-dev libgstreamer1.0-dev ``` 2. 构建: diff --git a/debian/control b/debian/control index 04b27081..70dad7e6 100644 --- a/debian/control +++ b/debian/control @@ -15,8 +15,7 @@ Build-Depends: qttools5-dev, libxcb-util0-dev, libstartup-notification0-dev, - libraw-dev, - libfreeimage-dev, + libraw-dev, libqt5opengl5-dev, qtbase5-private-dev, qtmultimedia5-dev, diff --git a/libimageviewer/CMakeLists.txt b/libimageviewer/CMakeLists.txt index c0513115..aee43c77 100644 --- a/libimageviewer/CMakeLists.txt +++ b/libimageviewer/CMakeLists.txt @@ -45,7 +45,6 @@ include_directories(${CMAKE_INCLUDE_CURRENT_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions( -DLITE_DIV ) -add_definitions( -DUSE_UNIONIMAGE ) add_definitions( -DCMAKE_BUILD ) #库目录 @@ -92,8 +91,6 @@ set(LINK_DIR /usr/lib/) include_directories(${INC_DIR}) link_directories(${LINK_DIR}) -link_libraries(freeimage) - set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) file(GLOB TS LIST_DIRECTORIES false translations/libimageviewer*.ts) @@ -122,7 +119,7 @@ set(${TARGET_NAME} ${CMAKE_INSTALL_LIBDIR}) set_target_properties(${TARGET_NAME} PROPERTIES VERSION 0.1.0 SOVERSION 0.1) target_include_directories(${CMD_NAME} PUBLIC ${3rd_lib_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${dfm-io_lib_INCLUDE_DIRS}) -target_link_libraries(imageviewer ${3rd_lib_LIBRARIES} freeimage ${TIFF_LIBRARIES} ${dfm-io_lib_LIBRARIES} dl) +target_link_libraries(imageviewer ${3rd_lib_LIBRARIES} ${TIFF_LIBRARIES} ${dfm-io_lib_LIBRARIES} dl) include(GNUInstallDirs) configure_file(libimageviewer.pc.in ${PROJECT_BINARY_DIR}/libimageviewer.pc @ONLY) diff --git a/libimageviewer/libimageviewer.pro b/libimageviewer/libimageviewer.pro index cb6b41a5..9e6ecefb 100644 --- a/libimageviewer/libimageviewer.pro +++ b/libimageviewer/libimageviewer.pro @@ -13,9 +13,7 @@ CONFIG += c++11 link_pkgconfig PKGCONFIG += dtkwidget dtkcore DEFINES += IMAGEVIEWER_LIBRARY -LIBS += -lfreeimage DEFINES += LITE_DIV -DEFINES += USE_UNIONIMAGE # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings diff --git a/libimageviewer/quickprint/printimageloader.cpp b/libimageviewer/quickprint/printimageloader.cpp index 8fdac4d4..585797d5 100644 --- a/libimageviewer/quickprint/printimageloader.cpp +++ b/libimageviewer/quickprint/printimageloader.cpp @@ -261,13 +261,6 @@ bool PrintImageLoader::loadImageData(PrintImageData::Ptr &imagePtr) try { if (s_SingleFrame == imagePtr->frame) { - QString errorMsg; - if (!LibUnionImage_NameSpace::loadStaticImageFromFile(imagePtr->filePath, imagePtr->data, errorMsg)) { - qWarning() << QString("Load image failed: %1").arg(errorMsg); - imagePtr->state = ContentError; - return false; - } - } else { QImageReader reader(imagePtr->filePath); // jumpToImage 可能返回 false, 但数据正常读取 reader.jumpToImage(imagePtr->frame); @@ -284,7 +277,6 @@ bool PrintImageLoader::loadImageData(PrintImageData::Ptr &imagePtr) return false; } } - } catch (const std::exception &e) { // 图片读取,考虑未界定异常 qCritical() << qPrintable("Exception: load image failed!") << qPrintable(e.what()); diff --git a/libimageviewer/unionimage/baseutils.cpp b/libimageviewer/unionimage/baseutils.cpp index 4436bf74..f4a14b12 100755 --- a/libimageviewer/unionimage/baseutils.cpp +++ b/libimageviewer/unionimage/baseutils.cpp @@ -36,9 +36,6 @@ #include -#ifdef USE_UNIONIMAGE -#include "unionimage.h" -#endif DWIDGET_USE_NAMESPACE // 当前动态库使用的翻译QM翻译文件路径 @@ -53,22 +50,6 @@ const QString DATETIME_FORMAT_EXIF = "yyyy:MM:dd HH:mm:ss"; QPixmap renderSVG(const QString &filePath, const QSize &size) { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - QImage tImg(size, QImage::Format_ARGB32); - QString errMsg; - QSize realSize; -// if (!UnionImage_NameSpace::loadStaticImageFromFile(filePath, tImg, realSize, errMsg)) { -// qDebug() << errMsg; -// } - if (!LibUnionImage_NameSpace::loadStaticImageFromFile(filePath, tImg, errMsg)) { - qDebug() << errMsg; - } - QPixmap pixmap; - pixmap = QPixmap::fromImage(tImg); - - return pixmap; -#else QImageReader reader; QPixmap pixmap; @@ -84,7 +65,6 @@ QPixmap renderSVG(const QString &filePath, const QSize &size) } return pixmap; -#endif } //QString sizeToHuman(const qlonglong bytes) diff --git a/libimageviewer/unionimage/imageutils.cpp b/libimageviewer/unionimage/imageutils.cpp index 43b16fe3..9443a5dd 100755 --- a/libimageviewer/unionimage/imageutils.cpp +++ b/libimageviewer/unionimage/imageutils.cpp @@ -5,7 +5,6 @@ #include "baseutils.h" #include "imageutils.h" #include "imageutils_libexif.h" -#include "imageutils_freeimage.h" #include "snifferimageformat.h" #include "unionimage.h" #include @@ -26,6 +25,7 @@ #include #include #include +#include namespace Libutils { @@ -36,22 +36,6 @@ const QImage scaleImage(const QString &path, const QSize &size) if (!imageSupportRead(path)) { return QImage(); } - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - QImage tImg(size, QImage::Format_ARGB32); - QString errMsg; - QSize realSize; -// if (!UnionImage_NameSpace::loadStaticImageFromFile(path, tImg, realSize, errMsg)) { -// qDebug() << errMsg; -// } - if (!LibUnionImage_NameSpace::loadStaticImageFromFile(path, tImg, errMsg)) { - qDebug() << errMsg; - } - if (tImg.size() != size) { //调用加速接口失败,主动进行缩放 - tImg = tImg.scaled(size); - } - return tImg; -#else QImageReader reader(path); reader.setAutoTransform(true); if (! reader.canRead()) { @@ -86,7 +70,6 @@ const QImage scaleImage(const QString &path, const QSize &size) } } else return tImg; -#endif } const QDateTime getCreateDateTime(const QString &path) @@ -122,23 +105,8 @@ const QDateTime getCreateDateTime(const QString &path) bool imageSupportRead(const QString &path) { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - //修正论坛上提出的格式判断错误,应该采用真实格式 - //20210220真实格式来做判断 - QMap dataMap = getAllMetaData(path); - const QString suffix = dataMap.value("FileFormat"); - QStringList errorList; - errorList << "X3F"; - if (errorList.indexOf(suffix.toUpper()) != -1) { - return false; - } - return LibUnionImage_NameSpace::unionImageSupportFormat().contains(suffix.toUpper()); -#else const QString suffix = QFileInfo(path).suffix(); -//解决freeimage不支持icns if (suffix == "icns") return true; - //FIXME: file types below will cause freeimage to crash on loading, // take them here for good. QStringList errorList; errorList << "X3F"; @@ -146,28 +114,17 @@ bool imageSupportRead(const QString &path) if (errorList.indexOf(suffix.toUpper()) != -1) { return false; } - - if (freeimage::isSupportsReading(path)) - return true; - else { - return (suffix == "svg"); - } -#endif + return (suffix == "svg"); } bool imageSupportSave(const QString &path) { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - return LibUnionImage_NameSpace::canSave(path); -#else const QString suffix = QFileInfo(path).suffix(); //J2K格式暂时不支持 if (suffix.toUpper() == "J2K") { return false; } // RAW image decode is too slow, and most of these does not support saving - // RAW formats render incorrectly by freeimage const QStringList raws = QStringList() << "CR2" << "CRW" // Canon cameras << "DCR" << "KDC" // Kodak cameras @@ -190,68 +147,14 @@ bool imageSupportSave(const QString &path) if (raws.indexOf(suffix.toUpper()) != -1 || QImageReader(path).imageCount() > 1) { return false; - } else { - return freeimage::canSave(path); } -#endif + return true; } bool rotate(const QString &path, int degree) { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE QString erroMsg; return LibUnionImage_NameSpace::rotateImageFIle(degree, path, erroMsg); -#else - if (degree % 90 != 0) - return false; - - int loadFlags = 0; - int saveFlags = 0; - FREE_IMAGE_FORMAT fif = freeimage::fFormat(path); - switch (int(fif)) { - case FIF_JPEG: - loadFlags = JPEG_ACCURATE; // Load the file with the best quality, sacrificing some speed - saveFlags = JPEG_QUALITYSUPERB; // Saves with superb quality (100:1) - break; - case FIF_JP2: - // Freeimage3.17 does not support special load flags for JP2 - saveFlags = JP2_DEFAULT; // Save with a 16:1 rate - break; - case FIF_BMP: - saveFlags = BMP_DEFAULT; // Save without any compression - break; - case FIF_EXR: - saveFlags = EXR_NONE; // Save with no compression - break; - case FIF_PNG: - saveFlags = PNG_DEFAULT; // Save without ZLib compression - break; - } - - FIBITMAP *dib = freeimage::readFileToFIBITMAP(path, loadFlags); - FIBITMAP *rotated = FreeImage_Rotate(dib, -degree); - if (rotated) { - // Regenerate thumbnail if it's exits - // Image formats that currently support thumbnail saving are - // JPEG (JFIF formats), EXR, TGA and TIFF. - if (FreeImage_GetThumbnail(dib)) { - FIBITMAP *thumb = FreeImage_GetThumbnail(dib); - FIBITMAP *rotateThumb = FreeImage_Rotate(thumb, -degree); - FreeImage_SetThumbnail(rotated, rotateThumb); - FreeImage_Unload(rotateThumb); - } - } - - bool v = freeimage::writeFIBITMAPToFile(rotated, path, saveFlags); - FreeImage_Unload(dib); - FreeImage_Unload(rotated); - - // The thumbnail should regenerate by caller - removeThumbnail(path); - - return v; -#endif } /*! @@ -343,14 +246,9 @@ const QFileInfoList getImagesInfo(const QString &dir, bool recursive) int getOrientation(const QString &path) { -#ifdef USE_UNIONIMAGE return LibUnionImage_NameSpace::getOrientation(path); -#else - return freeimage::getOrientation(path); -#endif } -#ifndef USE_UNIONIMAGE const QImage loadTga(QString filePath, bool &success) { QImage img; @@ -478,7 +376,6 @@ const QImage loadTga(QString filePath, bool &success) return img; } -#endif /*! * \brief getRotatedImage @@ -491,26 +388,12 @@ const QImage getRotatedImage(const QString &path) QImage tImg; - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - QString errMsg; - QSize realSize; -// if (!UnionImage_NameSpace::loadStaticImageFromFile(path, tImg, realSize, errMsg)) { -// qDebug() << errMsg; -// } - if (!LibUnionImage_NameSpace::loadStaticImageFromFile(path, tImg, errMsg)) { - qDebug() << errMsg; - } -#else QString format = DetectImageFormat(path); if (format.isEmpty()) { QImageReader reader(path); reader.setAutoTransform(true); if (reader.canRead()) { tImg = reader.read(); - } else if (path.contains(".tga")) { - bool ret = false; - tImg = utils::image::loadTga(path, ret); } } else { QImageReader readerF(path, format.toLatin1()); @@ -524,18 +407,67 @@ const QImage getRotatedImage(const QString &path) tImg = QImage(path); } } -#endif return tImg; } +QString size2HumanT(const qlonglong bytes) +{ + qlonglong kb = 1024; + if (bytes < kb) { + return QString::number(bytes) + " B"; + } else if (bytes < kb * kb) { + QString vs = QString::number(static_cast(bytes) / kb, 'f', 1); + if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) { + return QString::number(static_cast(vs.toDouble())) + " KB"; + } else { + return vs + " KB"; + } + } else if (bytes < kb * kb * kb) { + QString vs = QString::number(static_cast(bytes) / kb / kb, 'f', 1); + if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) { + return QString::number(static_cast(vs.toDouble())) + " MB"; + } else { + return vs + " MB"; + } + } else { + //修改了当超过一个G的图片,应该用G返回,不应该返回一堆数字,bug68094 + QString vs = QString::number(static_cast(bytes) / kb / kb / kb, 'f', 1); + if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) { + return QString::number(static_cast(vs.toDouble())) + " GB"; + } else { + return vs + " GB"; + } + } +} + const QMap getAllMetaData(const QString &path) { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE - return LibUnionImage_NameSpace::getAllMetaData(path); -#else - return freeimage::getAllMetaData(path); -#endif + QMap admMap; + + //移除秒  2020/6/5 DJH + //需要转义才能读出:或者/  2020/8/21 DJH + QFileInfo info(path); + if (admMap.contains("DateTime")) { + QDateTime time = QDateTime::fromString(admMap["DateTime"], "yyyy:MM:dd hh:mm:ss"); + admMap["DateTimeOriginal"] = time.toString("yyyy/MM/dd hh:mm"); + } else { + admMap.insert("DateTimeOriginal", info.lastModified().toString("yyyy/MM/dd HH:mm")); + } + admMap.insert("DateTimeDigitized", info.lastModified().toString("yyyy/MM/dd HH:mm")); + + // // The value of width and height might incorrect + QImageReader reader(path); + int w = reader.size().width(); + + int h = reader.size().height(); + admMap.insert("Dimension", QString::number(w) + "x" + QString::number(h)); + + admMap.insert("FileName", info.fileName()); + //应该使用qfileinfo的格式 + admMap.insert("FileFormat", info.suffix()); + admMap.insert("FileSize", size2HumanT(info.size())); + + return admMap; } const QPixmap cachePixmap(const QString &path) @@ -623,7 +555,6 @@ const QPixmap getThumbnail(const QString &path, bool cacheOnly) if (QFileInfo(encodePath).exists()) { return QPixmap(encodePath); } - /*lmh0724使用USE_UNIONIMAGE*/ else if (QFileInfo(failEncodePath).exists()) { qDebug() << "Fail-thumbnail exist, won't regenerate: " ; return QPixmap(); @@ -726,7 +657,7 @@ bool thumbnailExist(const QString &path, ThumbnailType type) return false; } } -/* + static QStringList fromByteArrayList(const QByteArrayList &list) { QStringList sList; @@ -748,22 +679,20 @@ static QStringList fromByteArrayList(const QByteArrayList &list) return sList; } -*/ + QStringList supportedImageFormats() { - /*lmh0724使用USE_UNIONIMAGE*/ -#ifdef USE_UNIONIMAGE QStringList list ; for (auto str : LibUnionImage_NameSpace::unionImageSupportFormat()) { str = "*." + str; list += str; } return list; -#else - static QStringList list = fromByteArrayList(QImageReader::supportedImageFormats()); +// #else +// static QStringList list = fromByteArrayList(QImageReader::supportedImageFormats()); - return list; -#endif +// return list; +// #endif } //直接搬运文管代码 diff --git a/libimageviewer/unionimage/imageutils.h b/libimageviewer/unionimage/imageutils.h index 3bf21867..490086c9 100755 --- a/libimageviewer/unionimage/imageutils.h +++ b/libimageviewer/unionimage/imageutils.h @@ -38,9 +38,9 @@ const QFileInfoList getImagesInfo(const QString &dir, int getOrientation(const QString &path); const QImage getRotatedImage(const QString &path); -#ifndef USE_UNIONIMAGE + const QImage loadTga(QString filePath, bool &success); -#endif + bool imageSupportRead(const QString &path); bool imageSupportSave(const QString &path); diff --git a/libimageviewer/unionimage/imageutils_freeimage.h b/libimageviewer/unionimage/imageutils_freeimage.h deleted file mode 100755 index ffb53e1a..00000000 --- a/libimageviewer/unionimage/imageutils_freeimage.h +++ /dev/null @@ -1,378 +0,0 @@ -// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef USE_UNIONIMAGE -#include "baseutils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace utils { - -namespace image { - -namespace freeimage { - -FREE_IMAGE_FORMAT fFormat(const QString &path) -{ - const QByteArray ba = path.toUtf8(); - const char *pc = ba.data(); - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - fif = FreeImage_GetFileType(pc, 0); - if (fif == FIF_UNKNOWN) { - fif = FreeImage_GetFIFFromFilename(pc); - } - - return fif; -} - -const QString getFileFormat(const QString &path) -{ -#if 0 - const FREE_IMAGE_FORMAT fif = fFormat(path); - if (fif == FIF_UNKNOWN) { - return QString("UNKNOW"); - } else { - return QString(FreeImage_GetFIFMimeType(fif)); - } -#endif - //use mimedatabase get image mimetype - QFileInfo fi(path); - QString suffix = fi.suffix(); - QMimeDatabase db; - QMimeType mt = db.mimeTypeForFile(path, QMimeDatabase::MatchContent); - QMimeType mt1 = db.mimeTypeForFile(path, QMimeDatabase::MatchExtension); - if (suffix.isEmpty()) { - return mt.name(); - } else { - return mt1.name(); - } -} - -FIBITMAP *readFileToFIBITMAP(const QString &path, int flags FI_DEFAULT(0)) -{ - const FREE_IMAGE_FORMAT fif = fFormat(path); - - if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - const QByteArray ba = path.toUtf8(); - const char *pc = ba.data(); - FIBITMAP *dib = FreeImage_Load(fif, pc, flags); - return dib; - } - - return NULL; -} - - -QMap getMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) -{ - QMap mdMap; // key-data - FITAG *tag = NULL; - FIMETADATA *mdhandle = NULL; - mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); - if (mdhandle) { - do { - mdMap.insert(FreeImage_GetTagKey(tag), - FreeImage_TagToString(model, tag)); - } while (FreeImage_FindNextMetadata(mdhandle, &tag)); - - FreeImage_FindCloseMetadata(mdhandle); - } - - return mdMap; -} - -//const QDateTime getDateTime(const QString &path, bool createTime = true) -//{ -// FIBITMAP *dib = readFileToFIBITMAP(path, FIF_LOAD_NOPIXELS); -// auto datas = getMetaData(FIMD_EXIF_EXIF, dib); -// if (datas.isEmpty()) { -// QFileInfo info(path); -// if (createTime) { -// return info.created(); -// } else { -// return info.lastModified(); -// } -// } - -// if (createTime) { -// return utils::base::stringToDateTime(datas["DateTimeOriginal"]); -// } else { -// return utils::base::stringToDateTime(datas["DateTimeDigitized"]); -// } -//} - -//const QString getOrientation(const QString &path) -//{ -// FIBITMAP *dib = readFileToFIBITMAP(path, FIF_LOAD_NOPIXELS); -// auto datas = getMetaData(FIMD_EXIF_MAIN, dib); -// if (datas.isEmpty()) { -// return QString(); -// } - -// return datas["Orientation"]; -//} - -///*! -// * \brief getAllMetaData -// * This function is very fast with FIF_LOAD_NOPIXELS flag -// * \param path -// * \return -// */ -//QMap getAllMetaData(const QString &path) -//{ -// FIBITMAP *dib = readFileToFIBITMAP(path, FIF_LOAD_NOPIXELS); -// QMap admMap; -// admMap.unite(getMetaData(FIMD_EXIF_MAIN, dib)); -// admMap.unite(getMetaData(FIMD_EXIF_EXIF, dib)); -// admMap.unite(getMetaData(FIMD_EXIF_GPS, dib)); -// admMap.unite(getMetaData(FIMD_EXIF_MAKERNOTE, dib)); -// admMap.unite(getMetaData(FIMD_EXIF_INTEROP, dib)); -// admMap.unite(getMetaData(FIMD_IPTC, dib)); - -// // Basic extended data -// QFileInfo info(path); -// QImageReader reader(path); -// if (admMap.isEmpty()) { -// QDateTime emptyTime(QDate(0, 0, 0), QTime(0, 0, 0)); -// admMap.insert("DateTimeOriginal", emptyTime.toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// admMap.insert("DateTimeDigitized", info.lastModified().toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// } else { -// // ReFormat the date-time -// using namespace utils::base; -// // Exif version 0231 -// QDateTime ot = stringToDateTime(admMap.value("DateTimeOriginal")); -// QDateTime dt = stringToDateTime(admMap.value("DateTimeDigitized")); -// if (! ot.isValid()) { -// // Exif version 0221 -// ot = stringToDateTime(admMap.value("DateTime")); -// dt = ot; - -// // NO valid date information -// if (! ot.isValid()) { -// admMap.insert("DateTimeOriginal", info.created().toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// admMap.insert("DateTimeDigitized", info.lastModified().toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// } -// } -// admMap.insert("DateTimeOriginal", ot.toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// admMap.insert("DateTimeDigitized", dt.toString(QObject::tr("yyyy/MM/dd HH:mm:dd"))); -// } -// // The value of width and height might incorrect -// int w = reader.size().width(); -// w = w > 0 ? w : FreeImage_GetWidth(dib); -// int h = reader.size().height(); -// h = h > 0 ? h : FreeImage_GetHeight(dib); -// admMap.insert("Dimension", QString::number(w) + "x" + QString::number(h)); -// admMap.insert("FileName", info.fileName()); -// admMap.insert("FileFormat", getFileFormat(path)); -// admMap.insert("FileSize", utils::base::sizeToHuman(info.size())); - -// FreeImage_Unload(dib); - -// return admMap; -//} - -//FIBITMAP *makeThumbnail(const QString &path, int size) -//{ -// const QByteArray pb = path.toUtf8(); -// const char *pc = pb.data(); -// FIBITMAP *dib = NULL; -// int flags = 0; // default load flag - -// FREE_IMAGE_FORMAT fif = fFormat(path); -// if (fif == FIF_UNKNOWN) { -// return NULL; -// } - -// // for JPEG images, we can speedup the loading part -// // Using LibJPEG downsampling feature while loading the image... -// if (fif == FIF_JPEG) { -// flags = JPEG_EXIFROTATE; -// flags |= size << 16; -// // Load the dib -// dib = FreeImage_Load(fif, pc, flags); -// if (! dib) return NULL; -// } else { -// // Any cases other than the JPEG case: load the dib ... -// if (fif == FIF_RAW || fif == FIF_TIFF) { -// // ... except for RAW images, try to load the embedded JPEG preview -// // or default to RGB 24-bit ... -// flags = RAW_PREVIEW; -// dib = FreeImage_Load(fif, pc, flags); -// if (!dib) return NULL; -// } else { -// // 某些损坏的图片� �式会识别错误,freeimage在load的时候会崩溃,暂时没法解决 -// // 除了上面�� 种可能�� 速缩略图读取的方式,都返回空 -// return NULL; -// } -// } - -// // create the requested thumbnail -// FIBITMAP *thumbnail = FreeImage_MakeThumbnail(dib, size, TRUE); -// FreeImage_Unload(dib); -// return thumbnail; -//} - -//bool isSupportsReading(const QString &path) -//{ -// const FREE_IMAGE_FORMAT fif = fFormat(path); - -// return (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif); -//} - -//bool isSupportsWriting(const QString &path) -//{ -// FREE_IMAGE_FORMAT fif = fFormat(path); - -// return (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsWriting(fif); -//} - -//bool canSave(FIBITMAP *dib, const QString &path) -//{ -// FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; -// // Try to guess the file format from the file extension -// fif = FreeImage_GetFIFFromFilename(path.toUtf8().data()); -// if (fif != FIF_UNKNOWN) { -// // Check that the dib can be saved in this format -// BOOL bCanSave; -// FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); -// if (image_type == FIT_BITMAP) { -// // standard bitmap type -// // check that the plugin has sufficient writing -// // and export capabilities ... -// WORD bpp = FreeImage_GetBPP(dib); -// bCanSave = (FreeImage_FIFSupportsWriting(fif) && -// FreeImage_FIFSupportsExportBPP(fif, bpp)); -// } else { -// // special bitmap type -// // check that the plugin has sufficient export capabilities -// bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); -// } -// return bCanSave; -// } -// return false; -//} - -//bool canSave(const QString &path) -//{ -// FIBITMAP *dib = readFileToFIBITMAP(path, FIF_LOAD_NOPIXELS); -// bool v = canSave(dib, path); -// FreeImage_Unload(dib); -// return v; -//} - -//bool writeFIBITMAPToFile(FIBITMAP *dib, const QString &path, int flag = 0) -//{ -// FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; -// BOOL bSuccess = FALSE; -// const QByteArray ba = path.toUtf8(); -// const char *pc = ba.data(); -// // Try to guess the file format from the file extension -// fif = FreeImage_GetFIFFromFilename(pc); -// if (fif != FIF_UNKNOWN && canSave(dib, path)) { -// bSuccess = FreeImage_Save(fif, dib, pc, flag); -// } - -// return (bSuccess == TRUE) ? true : false; -//} - -//QImage noneQImage() -//{ -// static QImage none(0, 0, QImage::Format_Invalid); -// return none; -//} - -//bool isNoneQImage(const QImage &qi) -//{ -// return qi == noneQImage(); -//} - -//QImage FIBitmapToQImage(FIBITMAP *dib) -//{ -// if (!dib || FreeImage_GetImageType(dib) != FIT_BITMAP) -// return noneQImage(); -// int width = FreeImage_GetWidth(dib); -// int height = FreeImage_GetHeight(dib); - -// switch (FreeImage_GetBPP(dib)) { -// case 1: { -// QImage result(width, height, QImage::Format_Mono); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 1, 0, 0, 0, true -// ); -// return result; -// } -// case 4: { /* NOTE: QImage do not support 4-bit, convert it to 8-bit */ -// QImage result(width, height, QImage::Format_Indexed8); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 8, 0, 0, 0, true -// ); -// return result; -// } -// case 8: { -// QImage result(width, height, QImage::Format_Indexed8); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 8, 0, 0, 0, true -// ); -// return result; -// } -// case 16: -// if ( // 5-5-5 -// (FreeImage_GetRedMask(dib) == FI16_555_RED_MASK) && -// (FreeImage_GetGreenMask(dib) == FI16_555_GREEN_MASK) && -// (FreeImage_GetBlueMask(dib) == FI16_555_BLUE_MASK)) { -// QImage result(width, height, QImage::Format_RGB555); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 16, -// FI16_555_RED_MASK, FI16_555_GREEN_MASK, FI16_555_BLUE_MASK, -// true -// ); -// return result; -// } else { // 5-6-5 -// QImage result(width, height, QImage::Format_RGB16); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 16, -// FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK, -// true -// ); -// return result; -// } -// case 24: { -// QImage result(width, height, QImage::Format_RGB32); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 32, -// FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, -// true -// ); -// return result; -// } -// case 32: { -// QImage result(width, height, QImage::Format_ARGB32); -// FreeImage_ConvertToRawBits( -// result.scanLine(0), dib, result.bytesPerLine(), 32, -// FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, -// true -// ); -// return result; -// } -// default: -// break; -// } -// return noneQImage(); -//} - -} // namespace freeimage - -} // namespace image - -} // namespace utils - -#endif diff --git a/libimageviewer/unionimage/pluginbaseutils.cpp b/libimageviewer/unionimage/pluginbaseutils.cpp index d7310d53..3850de6e 100644 --- a/libimageviewer/unionimage/pluginbaseutils.cpp +++ b/libimageviewer/unionimage/pluginbaseutils.cpp @@ -263,8 +263,6 @@ QString mkMutiDir(const QString &path) //创建多级目录 bool imageSupportRead(const QString &path) { const QString suffix = QFileInfo(path).suffix(); - - //FIXME: file types below will cause freeimage to crash on loading, // take them here for good. QStringList errorList; errorList << "X3F"; diff --git a/libimageviewer/unionimage/unionimage.cpp b/libimageviewer/unionimage/unionimage.cpp index 7ffb2c7d..455b0d8a 100644 --- a/libimageviewer/unionimage/unionimage.cpp +++ b/libimageviewer/unionimage/unionimage.cpp @@ -3,7 +3,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "unionimage.h" -#include //#include "giflib/cmanagerattributeservice.h" #include @@ -35,184 +34,101 @@ extern "C" { const QString DATETIME_FORMAT_NORMAL = "yyyy.MM.dd"; const QString DATETIME_FORMAT_EXIF = "yyyy:MM:dd HH:mm"; -// 提供用于非线程安全函数 FreeImage_TagToString() 访问限制的锁 -Q_GLOBAL_STATIC(QMutex, g_freeImageTagToStringMutex); - namespace LibUnionImage_NameSpace { -// enum SupportFormat { -// UNKNOWN = -1, -// BMP = 0, -// ICO = 1, -// JPG = 2, -// JPE = 2, -// JPS = 2, -// JPEG = 2, -// JNG = 3, -// KOALA = 4, -// KOA = KOALA, -// LBM = 5, -// IFF = LBM, -// MNG = 6, -// PBM = 7, -// PBMRAW = 8, -// PCD = 9, -// PCX = 10, -// PGM = 11, -// PGMRAW = 12, -// PNG = 13, -// PPM = 14, -// PPMRAW = 15, -// RAS = 16, -// TGA = 17, -// TARGA = 17, -// TIFF = 18, -// WBMP = 19, -// PSD = 20, -// CUT = 21, -// XBM = 22, -// XPM = 23, -// DDS = 24, -// GIF = 25, -// FHDR = 26, -// FAXG3 = 27, -// SGI = 28, -// EXR = 29, -// J2K = 30, -// J2C = 30, -// JPC = 30, -// JP2 = 31, -// PFM = 32, -// PCT = 33, -// PIC = 33, -// PICT = 33, -// RAW = 34, -// WEBP = 35, -// JXR = 36 -// }; -//由于freeimage 不支持,而在使用过程中,将qt支持的格式也添加到hash里,所以mrw的value也为0,因此重新定义 -//fix 52612 -enum FIF_QTSUPPORT { - FIF_MRW = 37 -}; - class UnionImage_Private { - - public: UnionImage_Private() { - //FreeImage_Initialise(true); - //m_freeimage_formats["UNKNOWN"] = -1; - m_freeimage_formats["BMP"] = FIF_BMP; - m_freeimage_formats["ICO"] = FIF_ICO; - m_freeimage_formats["JPG"] = FIF_JPEG; - m_freeimage_formats["JPE"] = FIF_JPEG; - m_freeimage_formats["JPS"] = FIF_JPEG; - m_freeimage_formats["JPEG"] = FIF_JPEG; - m_freeimage_formats["JNG"] = FIF_JNG; - m_freeimage_formats["KOALA"] = FIF_KOALA; - m_freeimage_formats["KOA"] = FIF_KOALA; - m_freeimage_formats["LBM"] = FIF_LBM; - m_freeimage_formats["IFF"] = FIF_LBM; - m_freeimage_formats["MNG"] = FIF_MNG; - m_freeimage_formats["PBM"] = FIF_PBM; - m_freeimage_formats["PBMRAW"] = FIF_PBMRAW; - m_freeimage_formats["PCD"] = FIF_PCD; - m_freeimage_formats["PCX"] = FIF_PCX; - m_freeimage_formats["PGM"] = FIF_PGM; - m_freeimage_formats["PGMRAW"] = FIF_PGMRAW; - m_freeimage_formats["PNG"] = FIF_PNG; - m_freeimage_formats["PPM"] = FIF_PPM; - m_freeimage_formats["PPMRAW"] = FIF_PPMRAW; - m_freeimage_formats["RAS"] = FIF_RAS; - m_freeimage_formats["TGA"] = FIF_TARGA; - m_freeimage_formats["TARGA"] = FIF_TARGA; - m_freeimage_formats["TIFF"] = FIF_TIFF;//use qt - m_freeimage_formats["TIF"] = FIF_TIFF;//use qt - m_freeimage_formats["WBMP"] = FIF_WBMP; - m_freeimage_formats["PSD"] = FIF_PSD; - m_freeimage_formats["CUT"] = FIF_CUT; - m_freeimage_formats["XBM"] = FIF_XBM; - m_freeimage_formats["XPM"] = FIF_XPM; - m_freeimage_formats["DDS"] = FIF_DDS; - m_freeimage_formats["GIF"] = FIF_GIF; - //m_freeimage_formats["HDR"] = FIF_HDR;//FHDR covert failed - m_freeimage_formats["FAX"] = 27; - m_freeimage_formats["G3"] = 27;//FAXG3 - m_freeimage_formats["SGI"] = FIF_SGI; - m_freeimage_formats["EXR"] = FIF_EXR; - //m_freeimage_formats["J2K"] = FIF_J2K; - //m_freeimage_formats["J2C"] = FIF_J2K; - // m_freeimage_formats["JPC"] = FIF_J2K; -// m_freeimage_formats["JP2"] = FIF_JP2; - //m_freeimage_formats["PFM"] = FIF_PFM;covert failed - m_freeimage_formats["PCT"] = FIF_PICT; - m_freeimage_formats["PIC"] = FIF_PICT; - m_freeimage_formats["PICT"] = FIF_PICT; - m_freeimage_formats["PIC"] = FIF_PICT; -// m_freeimage_formats["RAW"] = FIF_RAW; - m_freeimage_formats["WEBP"] = FIF_WEBP; - m_freeimage_formats["JXR"] = FIF_JXR; - m_freeimage_formats["MRW"] = FIF_MRW; - m_movie_formats["MNG"] = FIF_MNG; - m_movie_formats["GIF"] = FIF_GIF; - m_movie_formats["WEBP"] = FIF_WEBP; /* * 由于原设计方案采用多个key对应一个value的方案,在判断可读可写的过程中是通过value去找key因此造成了多种情况而在下方变量中未将key,写完整因此补全 * */ - m_qtSupported << "BMP" << "JPG" << "JPEG" << "JPS" << "JPE" << "PNG" << "PBM" - << "PGM" << "PPM" << "PNM" << "WBMP" << "WEBP" - << "SVG" << "ICNS" << "GIF" << "MNG" << "TIF" - << "TIFF" << "BMP" << "XPM" << "DNG" - << "RAF" << "CR2" << "MEF" << "ORF" << "ICO" + m_qtSupported << "BMP" + << "JPG" + << "JPEG" + << "JPS" + << "JPE" + << "PNG" + << "PBM" + << "PGM" + << "PPM" + << "PNM" + << "WBMP" + << "WEBP" + << "SVG" + << "ICNS" + << "GIF" + << "MNG" + << "TIF" + << "TIFF" + << "BMP" + << "XPM" + << "DNG" + << "RAF" + << "CR2" + << "MEF" + << "ORF" + << "ICO" << "RAW" << "MRW" << "NEF" << "JP2" - << "HEIF" << "HEIC" << "HEJ2" - << "AVIF" << "AVIFS"; - //pic(多张图片) pcx不支持旋转 - m_canSave << "BMP" << "JPG" << "JPEG" << "JPS" << "JPE" << "PNG" - << "PGM" << "PPM" << "PNM" - << "TGA" << "XPM" << "ICO" - << "JNG" -// << "SVG" //svg不再支持旋转 -// << "JP2" -// << "PCD" -#ifndef ISSW_64 - << "WBMP" -#endif - << "RAS"; - - /* - * 修改: - * PNG保存速度Qt是FreeImage的7倍 - * FreeImage旋转BMP会导致后续读图失败 - * PGM保存速度Qt略快于FreeImage - * PBM保存速度Qt是FreeImage的20倍,且FreeImage旋转后会反色 - */ + << "HEIF" + << "HEIC" + << "HEJ2" + << "AVIF" + << "TGA" + << "PSD" + << "PXM" + << "PIC" + << "PEF" + << "XBM" + << "ARW" + << "HDR" + << "J2K" + << "ICNS" + << "AVI" + << "VIFF" + << "IFF" + << "JP2" + << "WMF" + << "CRW" + << "X3F" + << "EPS" + << "SR2" + << "AVIFS"; + m_canSave << "BMP" + << "JPG" + << "JPEG" + << "PNG" + << "PGM" + << "PPM" + << "XPM" + << "ICO" + << "ICNS"; /*<< "PGM" << "PBM"*/ - m_qtrotate << "ICNS" << "JPG" << "JPEG" << "PNG" << "BMP" ; + m_qtrotate << "BMP" + << "JPG" + << "JPEG" + << "PNG" + << "PGM" + << "PPM" + << "XPM" + << "ICO" + << "ICNS"; } ~UnionImage_Private() { - } - QMutex freeimage_mutex; QStringList m_qtSupported; - QHash m_freeimage_formats; QHash m_movie_formats; QStringList m_canSave; QStringList m_qtrotate; }; static UnionImage_Private union_image_private; - -FREE_IMAGE_FORMAT detectImageFormat_f(const QString &path); - /** * @brief noneQImage * @return QImage @@ -228,20 +144,15 @@ UNIONIMAGESHARED_EXPORT const QStringList unionImageSupportFormat() { static QStringList res; if (res.empty()) { - QStringList list = union_image_private.m_freeimage_formats.keys(); - for (const QString &i : union_image_private.m_qtSupported) { - if (!list.contains(i)) - list.append(i); - } + QStringList list = union_image_private.m_qtSupported; res.append(list); - res.append(union_image_private.m_movie_formats.keys()); } return res; } UNIONIMAGESHARED_EXPORT const QStringList supportStaticFormat() { - return (union_image_private.m_freeimage_formats.keys() << union_image_private.m_qtSupported); + return (union_image_private.m_qtSupported); } UNIONIMAGESHARED_EXPORT const QStringList supportMovieFormat() @@ -300,319 +211,18 @@ UNIONIMAGESHARED_EXPORT const QString getFileFormat(const QString &path) return suffix; } -#if 0 -/** - * @brief string2DateTime - * @param time - * @author LMH - * @return QDateTime - * string转换时间 - */ -UNIONIMAGESHARED_EXPORT QDateTime string2DateTime(const QString &time) -{ - QDateTime dt = QDateTime::fromString(time, DATETIME_FORMAT_EXIF); - if (! dt.isValid()) { - dt = QDateTime::fromString(time, DATETIME_FORMAT_NORMAL); - } - return dt; -} -#endif - -/** - * @brief getMetaData - * @param model - * @param dib - * @author LMH - * @return QMap - * 内部接口获取图片的信息 - */ -UNIONIMAGESHARED_EXPORT QMap getMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) -{ - QMap mdMap; // key-data - - if (FreeImage_GetMetadataCount(model, dib) > 0) { - FITAG *tag = nullptr; - FIMETADATA *mdhandle = nullptr; - mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); - if (mdhandle) { - do { - QString value; - // FreeImage_TagToString非线程安全,使用前加锁保护 - QMutex *mutex = g_freeImageTagToStringMutex; - if (mutex) { - mutex->lock(); - value = QString(FreeImage_TagToString(model, tag)); - mutex->unlock(); - } - - mdMap.insert(FreeImage_GetTagKey(tag), value); - } while (FreeImage_FindNextMetadata(mdhandle, &tag)); - FreeImage_FindCloseMetadata(mdhandle); - } - } - return mdMap; -} - -/** - * @brief FIBitmapToQImage - * @param dib - * @return QImage - * 由FreeImage转到QImage - */ -UNIONIMAGESHARED_EXPORT QImage FIBitmap2QImage(FIBITMAP *dib) -{ - if (!dib || FreeImage_GetImageType(dib) == FIT_UNKNOWN) - return noneQImage(); - int width = static_cast(FreeImage_GetWidth(dib)); - int height = static_cast(FreeImage_GetHeight(dib)); - int depth = static_cast(FreeImage_GetBPP(dib)); - switch (depth) { - case 1: { - QImage result(width, height, QImage::Format_Mono); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 1, 0, 0, 0, true - ); - return result; - } - case 4: { /* NOTE: QImage do not support 4-bit, convert it to 8-bit */ - QImage result(width, height, QImage::Format_Indexed8); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 8, 0, 0, 0, true - ); - return result; - } - case 8: { - QImage result(width, height, QImage::Format_Indexed8); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 8, 0, 0, 0, true - ); - return result; - } - case 16: - if ( // 5-5-5 - (FreeImage_GetRedMask(dib) == FI16_555_RED_MASK) && - (FreeImage_GetGreenMask(dib) == FI16_555_GREEN_MASK) && - (FreeImage_GetBlueMask(dib) == FI16_555_BLUE_MASK)) { - QImage result(width, height, QImage::Format_RGB555); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 16, - FI16_555_RED_MASK, FI16_555_GREEN_MASK, FI16_555_BLUE_MASK, - true - ); - return result; - } else { // 5-6-5 - QImage result(width, height, QImage::Format_RGB16); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 16, - FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK, - true - ); - return result; - } - case 24: { - QImage result(width, height, QImage::Format_RGB32); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 32, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, - true - ); - return result; - } - case 32: { - QImage result(width, height, QImage::Format_ARGB32); - FreeImage_ConvertToRawBits( - result.scanLine(0), dib, result.bytesPerLine(), 32, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, - true - ); - return result; - } - case 48: - case 64: - case 96: - //128位暂不支持 - case 128: - default: - break; - } - return noneQImage(); -} - -/** - * @brief QImgeToFIBitMap - * @param img - * @return FIBITMAP* - * 由QImage转到FreeImage - */ -#if 0 -UNIONIMAGESHARED_EXPORT FIBITMAP *QImge2FIBitMap(QImage img) -{ - if (img.isNull()) { - return nullptr; - } - int width = img.width(); - int height = img.height(); - uint depth = static_cast(img.depth()); - QImage::Format format = img.format(); - switch (format) { - //The image is invalid. - case QImage::Format_Invalid: - return nullptr; - //The image is stored using 1-bit per pixel.(MSB) - case QImage::Format_Mono: - //The image is stored using 1-bit per pixel.(LSB) - case QImage::Format_MonoLSB: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), depth, 0, 0, 0, - true); - return res; - } - /* NOTE: QImage do not support 4-bit*/ - - //可能会将彩色图转为灰度图 - //The image is stored using an 8-bit alpha only format. - case QImage::Format_Alpha8: - //The image is stored using an 8-bit grayscale format. - case QImage::Format_Grayscale8: - //The image is stored using 8-bit indexes into a colormap. - case QImage::Format_Indexed8: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), depth, 0, 0, 0, - true); - return res; - } - //The image is stored using a 16-bit RGB format (5-6-5) - case QImage::Format_RGB16: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), 16, - FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK, - true); - return res; - } - //The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero. - case QImage::Format_RGB555: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), 16, - FI16_555_RED_MASK, FI16_555_GREEN_MASK, FI16_555_BLUE_MASK, - true); - return res; - } - - //32-bit - case QImage::Format_RGB32: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), depth, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, - true); - return res; - } - case QImage::Format_ARGB32: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), depth, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, - true); - return res; - } - //24-bit - case QImage::Format_RGB666: - case QImage::Format_ARGB8555_Premultiplied: - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_ARGB6666_Premultiplied: - case QImage::Format_RGB888: { - FIBITMAP *res = FreeImage_ConvertFromRawBits( - img.scanLine(0), width, height, img.bytesPerLine(), depth, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, - true); - return res; - } - - //FreeImage is not support - //The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero. - case QImage::Format_RGB444: - case QImage::Format_ARGB4444_Premultiplied: - default: - break; - } - return nullptr; -} -#endif - -/** - * @brief readFile2FIBITMAP - * @param path - * @param flags - * @author LMH - * @return FIBITMAP - * 由QString路径转换成FIBITMAP指针 - */ -UNIONIMAGESHARED_EXPORT FIBITMAP *readFile2FIBITMAP(const QString &path, int flags FI_DEFAULT(0)) -{ - QImage image(path); - if(image.isNull()) {//判断图片是否有效 - return nullptr; - } - QByteArray b; - b.append(path); - const char *pc = b.data(); - QString().toStdString(); - const FREE_IMAGE_FORMAT fif = detectImageFormat_f(path); - if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - FIBITMAP *dib = FreeImage_Load(fif, pc, flags); - return dib; - } - return nullptr; -} - UNIONIMAGESHARED_EXPORT bool canSave(const QString &path) { QImageReader r(path); if (r.imageCount() > 1) { return false; } - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - // Try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(path.toUtf8().data()); - if (fif != FIF_UNKNOWN) { - // Check that the dib can be saved in this format - if (union_image_private.m_canSave.contains(union_image_private.m_freeimage_formats.key(fif))) { - return true; - } - } QFileInfo info(path); if (union_image_private.m_canSave.contains(info.suffix().toUpper())) return true; return false; } - - -/** - * @brief writeFIBITMAPToFile - * @param dib - * @param path - * @param flag - * @return - */ -UNIONIMAGESHARED_EXPORT bool writeFIBITMAPToFile(FIBITMAP *dib, const QString &path, int flag = 0) -{ - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - const QByteArray ba = path.toUtf8(); - const char *pc = ba.data(); - // Try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(pc); - FREE_IMAGE_FORMAT realfif = FIF_UNKNOWN; - if (fif == FIF_UNKNOWN) { - realfif = FreeImage_GetFileType(pc); - } - if (fif != FIF_UNKNOWN) { - bSuccess = FreeImage_Save(fif, dib, pc, flag); - } else if (realfif != FIF_UNKNOWN) { - bSuccess = FreeImage_Save(realfif, dib, pc, flag); - } - return bSuccess; -} - UNIONIMAGESHARED_EXPORT QString unionImageVersion() { QString ver; @@ -622,17 +232,6 @@ UNIONIMAGESHARED_EXPORT QString unionImageVersion() return ver; } - - -UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width, int height, int depth, SupportType type) -{ - Q_UNUSED(type); - FIBITMAP *dib = FreeImage_Allocate(width, height, depth); - res = FIBitmap2QImage(dib); - FreeImage_Unload(dib); - return true; -} - QString PrivateDetectImageFormat(const QString &filepath); UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage &res, QString &errorMsg, const QString &format_bar) { @@ -647,23 +246,10 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage QByteArray temp_path; temp_path.append(path.toUtf8()); - FREE_IMAGE_FORMAT f = FreeImage_GetFileType(temp_path.data()); - if (f != FIF_UNKNOWN && f != union_image_private.m_freeimage_formats[file_suffix_upper]) { - file_suffix_upper = union_image_private.m_freeimage_formats.key(f); - } - if (f == FIF_TIFF) { - file_suffix_upper = "TIFF"; - } + QString file_suffix_lower = file_suffix_upper.toLower(); - //解决欧拉版对于raw格式问题判断为PICT的问题 - bool usingQimage = false; - usingQimage = (f == FIF_RAW || f == FIF_PICT); - //如果是pct格式使用freeimage - if (f == FIF_PICT && file_info.suffix().toLower() == "pct") { - usingQimage = false; - } - if (usingQimage || union_image_private.m_qtSupported.contains(file_suffix_upper)) { + if (union_image_private.m_qtSupported.contains(file_suffix_upper)) { QImageReader reader; QImage res_qt; reader.setFileName(path); @@ -737,53 +323,14 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage return false; } return true; - } else { - if (f != FREE_IMAGE_FORMAT::FIF_UNKNOWN || union_image_private.m_freeimage_formats.contains(file_suffix_upper)) { - if (f == FREE_IMAGE_FORMAT::FIF_UNKNOWN) - f = FREE_IMAGE_FORMAT(union_image_private.m_freeimage_formats[file_suffix_upper]); - if (f == FREE_IMAGE_FORMAT::FIF_JP2 && file_info.size() > 40960000) { - errorMsg = "image load failed, format:" + union_image_private.m_freeimage_formats.key(f) + " ,path:" + temp_path; - res = QImage(); - return false; - } - FIBITMAP *dib = FreeImage_Load(f, temp_path.data()); - if (nullptr == dib) { - errorMsg = "image load failed, format:" + union_image_private.m_freeimage_formats.key(f) + " ,path:" + temp_path; - //FreeImage_Unload(dib); - res = QImage(); - return false; - } -// uint depth = FreeImage_GetBPP(dib); //just for test -// Q_UNUSED(depth); - //32位以上图片qImage不支持,强行读取和转换可能会乱码 - res = QImage(FIBitmap2QImage(dib)); - if (res.isNull()) { - errorMsg = "convert to QImage failed" + union_image_private.m_freeimage_formats.key(f) + " ,path:" + temp_path; - FreeImage_Unload(dib); - res = QImage(); - return false; - } - FreeImage_Unload(dib); - errorMsg = ""; - return true; - } - return false; } + return false; } UNIONIMAGESHARED_EXPORT QString detectImageFormat(const QString &path) { QFileInfo file_info(path); QString file_suffix_upper = file_info.suffix().toUpper(); - QByteArray temp_path; - temp_path.append(path.toUtf8()); - FREE_IMAGE_FORMAT f = FreeImage_GetFileType(temp_path.data()); - if (f != FIF_UNKNOWN && f != union_image_private.m_freeimage_formats[file_suffix_upper]) { - file_suffix_upper = union_image_private.m_freeimage_formats.key(f); - } - if (f == FIF_TIFF) { - file_suffix_upper = "TIFF"; - } QString res = file_suffix_upper; if (res.isEmpty()) { QFile file(path); @@ -865,8 +412,7 @@ UNIONIMAGESHARED_EXPORT QString detectImageFormat(const QString &path) } // Check xbm file. - if (data.indexOf("#define max_width ") > -1 && - data.indexOf("#define max_height ") > -1) { + if (data.indexOf("#define max_width ") > -1 && data.indexOf("#define max_height ") > -1) { return "XBM"; } @@ -879,114 +425,6 @@ UNIONIMAGESHARED_EXPORT QString detectImageFormat(const QString &path) return res; } -FREE_IMAGE_FORMAT detectImageFormat_f(const QString &path) -{ - QFileInfo file_info(path); - QString file_suffix_upper = file_info.suffix().toUpper(); - QByteArray temp_path; - temp_path.append(path.toUtf8()); - FREE_IMAGE_FORMAT f = FreeImage_GetFileType(temp_path.data()); - if (f != FIF_UNKNOWN && f != union_image_private.m_freeimage_formats[file_suffix_upper]) { - file_suffix_upper = union_image_private.m_freeimage_formats.key(f); - } - if (f == FIF_TIFF) { - file_suffix_upper = "TIFF"; - } - if (file_suffix_upper.isEmpty()) { - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) { - return FIF_UNKNOWN; - } - - // const QByteArray data = file.read(1024); - const QByteArray data = file.read(64); - - // Check bmp file. - if (data.startsWith("BM")) { - return FIF_BMP; - } - - // Check dds file. - if (data.startsWith("DDS")) { - return FIF_DDS; - } - - // Check gif file. - if (data.startsWith("GIF8")) { - return FIF_GIF; - } - - // Check Max OS icons file. - if (data.startsWith("icns")) { - return FIF_UNKNOWN; - } - - // Check jpeg file. - if (data.startsWith("\xff\xd8")) { - return FIF_JPEG; - } - - // Check mng file. - if (data.startsWith("\x8a\x4d\x4e\x47\x0d\x0a\x1a\x0a")) { - return FIF_MNG; - } - - // Check net pbm file (BitMap). - if (data.startsWith("P1") || data.startsWith("P4")) { - return FIF_PBM; - } - - // Check pgm file (GrayMap). - if (data.startsWith("P2") || data.startsWith("P5")) { - return FIF_PGM; - } - - // Check ppm file (PixMap). - if (data.startsWith("P3") || data.startsWith("P6")) { - return FIF_PPM; - } - - // Check png file. - if (data.startsWith("\x89PNG\x0d\x0a\x1a\x0a")) { - return FIF_PNG; - } - - // Check svg file. - if (data.indexOf(" -1) { - return FIF_UNKNOWN; - } - - // TODO(xushaohua): tga file is not supported yet. - - // Check tiff file. - if (data.startsWith("MM\x00\x2a") || data.startsWith("II\x2a\x00")) { - // big-endian, little-endian. - return FIF_TIFF; - } - - // TODO(xushaohua): Support wbmp file. - - // Check webp file. - if (data.startsWith("RIFFr\x00\x00\x00WEBPVP")) { - return FIF_WEBP; - } - - // Check xbm file. - if (data.indexOf("#define max_width ") > -1 && - data.indexOf("#define max_height ") > -1) { - return FIF_XBM; - } - - // Check xpm file. - if (data.startsWith("/* XPM */")) { - return FIF_XPM; - } - return FIF_UNKNOWN; - } - f = static_cast(union_image_private.m_freeimage_formats[file_suffix_upper]); - return f >= 0 ? f : FIF_UNKNOWN; -} - UNIONIMAGESHARED_EXPORT bool isNoneQImage(const QImage &qi) { return (qi == noneQImage()); @@ -1014,30 +452,30 @@ QImage adjustImageToRealPosition(const QImage &image, int orientation) QImage result = image; switch (orientation) { - case 1: //不做操作 + case 1: //不做操作 default: break; - case 2: //水平翻转 + case 2: //水平翻转 result = result.mirrored(true, false); break; - case 3: //180度翻转 + case 3: //180度翻转 rotateImage(180, result); break; - case 4: //垂直翻转 + case 4: //垂直翻转 result = result.mirrored(false, true); break; - case 5: //顺时针90度+水平翻转 + case 5: //顺时针90度+水平翻转 rotateImage(90, result); result = result.mirrored(true, false); break; - case 6: //顺时针90度 + case 6: //顺时针90度 rotateImage(90, result); break; - case 7: //顺时针90度+垂直翻转 + case 7: //顺时针90度+垂直翻转 rotateImage(90, result); result = result.mirrored(false, true); break; - case 8: //逆时针90度 + case 8: //逆时针90度 rotateImage(-90, result); break; }; @@ -1084,7 +522,6 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt return true; } else if (union_image_private.m_qtrotate.contains(format)) { //由于Qt内部不会去读图片的EXIF信息来判断当前的图像矩阵的真实位置,同时回写数据的时候会丢失全部的EXIF数据 - //因此在这里需要额外基于FreeImage来读取相关的数据,确保图片能旋转到合理的位置 int orientation = getOrientation(path); QImage image_copy(path); image_copy = adjustImageToRealPosition(image_copy, orientation); @@ -1101,45 +538,7 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt erroMsg = "rotate by qt failed"; return false; } - FIBITMAP *dib = readFile2FIBITMAP(path); - if (nullptr == dib) { - erroMsg = "unsupported format"; - FreeImage_Unload(dib); - return false; - } - FIBITMAP *rotateRes = FreeImage_Rotate(dib, -angel); - if (rotateRes) { - // Regenerate thumbnail if it's exits - // Image formats that currently support thumbnail saving are - // JPEG (JFIF formats), EXR, TGA and TIFF. - if (FreeImage_GetThumbnail(dib)) { - FIBITMAP *thumb = FreeImage_GetThumbnail(dib); - FIBITMAP *rotateThumb = FreeImage_Rotate(thumb, -angel); - - FreeImage_SetThumbnail(rotateRes, rotateThumb); - FreeImage_Unload(rotateThumb); - } - } - QByteArray temp_path; - temp_path.append(path); - FREE_IMAGE_FORMAT f = FREE_IMAGE_FORMAT(union_image_private.m_freeimage_formats[QFileInfo(path).suffix().toUpper()]); - if (f == FREE_IMAGE_FORMAT::FIF_UNKNOWN) { - erroMsg = "rotate image format error"; - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - return false; - } - ; - if (!writeFIBITMAPToFile(rotateRes, path)) { - erroMsg = "rotate image save failed, unknown format"; - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - return false; - } - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - erroMsg = ""; - return true; + return false; } UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, const QString &path, QString &erroMsg) @@ -1149,8 +548,10 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, co return false; } QImage image_copy; - if (img.isNull()) return false; - else image_copy = img; + if (img.isNull()) + return false; + else + image_copy = img; QString format = detectImageFormat(path); if (format == "SVG") { @@ -1188,56 +589,12 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, co return true; } } - FIBITMAP *dib = readFile2FIBITMAP(path); - if (nullptr == dib) { - erroMsg = "unsupported format"; - FreeImage_Unload(dib); - return false; - } - FIBITMAP *rotateRes = FreeImage_Rotate(dib, -angel); - if (rotateRes) { - // Regenerate thumbnail if it's exits - // Image formats that currently support thumbnail saving are - // JPEG (JFIF formats), EXR, TGA and TIFF. - if (FreeImage_GetThumbnail(dib)) { - FIBITMAP *thumb = FreeImage_GetThumbnail(dib); - FIBITMAP *rotateThumb = FreeImage_Rotate(thumb, -angel); - FreeImage_SetThumbnail(rotateRes, rotateThumb); - FreeImage_Unload(rotateThumb); - } - } - QByteArray temp_path; - temp_path.append(path); - FREE_IMAGE_FORMAT f = FREE_IMAGE_FORMAT(union_image_private.m_freeimage_formats[QFileInfo(path).suffix().toUpper()]); - if (f == FREE_IMAGE_FORMAT::FIF_UNKNOWN) { - erroMsg = "rotate image format error"; - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - return false; - } - img = FIBitmap2QImage(rotateRes); - if (!writeFIBITMAPToFile(rotateRes, path)) { - erroMsg = "rotate image save failed, unknown format"; - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - return false; - } - FreeImage_Unload(dib); - FreeImage_Unload(rotateRes); - erroMsg = ""; - return true; + return false; } UNIONIMAGESHARED_EXPORT QMap getAllMetaData(const QString &path) { - FIBITMAP *dib = readFile2FIBITMAP(path, FIF_LOAD_NOPIXELS); QMap admMap; - admMap.unite(getMetaData(FIMD_EXIF_MAIN, dib)); - admMap.unite(getMetaData(FIMD_EXIF_EXIF, dib)); - admMap.unite(getMetaData(FIMD_EXIF_GPS, dib)); - admMap.unite(getMetaData(FIMD_EXIF_MAKERNOTE, dib)); - admMap.unite(getMetaData(FIMD_EXIF_INTEROP, dib)); - admMap.unite(getMetaData(FIMD_IPTC, dib)); //移除秒  2020/6/5 DJH //需要转义才能读出:或者/  2020/8/21 DJH QFileInfo info(path); @@ -1245,243 +602,45 @@ UNIONIMAGESHARED_EXPORT QMap getAllMetaData(const QString &pat QDateTime time = QDateTime::fromString(admMap["DateTime"], "yyyy:MM:dd hh:mm:ss"); admMap["DateTimeOriginal"] = time.toString("yyyy/MM/dd hh:mm"); } else { - admMap.insert("DateTimeOriginal", info.lastModified().toString("yyyy/MM/dd HH:mm")); + admMap.insert("DateTimeOriginal", info.lastModified().toString("yyyy/MM/dd HH:mm")); } - admMap.insert("DateTimeDigitized", info.lastModified().toString("yyyy/MM/dd HH:mm")); -// if (admMap.isEmpty()) { -// QDateTime emptyTime(QDate(0, 0, 0), QTime(0, 0)); -// admMap.insert("DateTimeOriginal", emptyTime.toString("yyyy/MM/dd HH:mm")); -// admMap.insert("DateTimeDigitized", info.lastModified().toString("yyyy/MM/dd HH:mm")); -// } - /* else { - QString qsdto = admMap.value("DateTimeOriginal"); - QString qsdtd = admMap.value("DateTimeDigitized"); - QDateTime ot = QDateTime::fromString(qsdto, "yyyy/MM/dd HH:mm"); - QDateTime dt = QDateTime::fromString(qsdtd, "yyyy/MM/dd HH:mm"); - if (! ot.isValid()) { - // Exif version 0221 - QString qsdt = admMap.value("DateTime"); - ot = QDateTime::fromString(qsdt, "yyyy/MM/dd HH:mm"); - dt = ot; - - // NO valid date information - if (! ot.isValid()) { - // admMap.insert("DateTimeOriginal", info.created().toString("yyyy/MM/dd HH:mm:dd")); - admMap.insert("DateTimeOriginal", info.birthTime().toString("yyyy/MM/dd HH:mm")); - admMap.insert("DateTimeDigitized", info.lastModified().toString("yyyy/MM/dd HH:mm")); - } else { - admMap.insert("DateTimeOriginal", ot.toString("yyyy/MM/dd HH:mm")); - admMap.insert("DateTimeDigitized", dt.toString("yyyy/MM/dd HH:mm")); - } - } - }*/ + admMap.insert("DateTimeDigitized", info.lastModified().toString("yyyy/MM/dd HH:mm")); -// // The value of width and height might incorrect + // // The value of width and height might incorrect QImageReader reader(path); int w = reader.size().width(); - w = w > 0 ? w : static_cast(FreeImage_GetWidth(dib)); int h = reader.size().height(); - h = h > 0 ? h : static_cast(FreeImage_GetHeight(dib)); admMap.insert("Dimension", QString::number(w) + "x" + QString::number(h)); admMap.insert("FileName", info.fileName()); //应该使用qfileinfo的格式 admMap.insert("FileFormat", getFileFormat(path)); admMap.insert("FileSize", size2Human(info.size())); - FreeImage_Unload(dib); - return admMap; } UNIONIMAGESHARED_EXPORT bool isImageSupportRotate(const QString &path) { - return canSave(path) ; -} - -#if 0 -UNIONIMAGESHARED_EXPORT bool isSupportsReading(const QString &path) -{ - const FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(path.toUtf8().data()); - return (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif); + return canSave(path); } -UNIONIMAGESHARED_EXPORT bool isSupportsWriting(const QString &path) -{ - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(path.toUtf8().data()); - return (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsWriting(fif); -} -#endif - UNIONIMAGESHARED_EXPORT int getOrientation(const QString &path) { - int result = 1; //1代表不做操作,维持原样 - - FIBITMAP *dib = readFile2FIBITMAP(path, FIF_LOAD_NOPIXELS); - - //有时候会存在tag为野指针的情况,根据FreeImage的demo,需要加这个进行预判断 - if (FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib) == 0) { - FreeImage_Unload(dib); - return result; - } - - FITAG *tag = nullptr; - FIMETADATA *mdhandle = nullptr; - mdhandle = FreeImage_FindFirstMetadata(FIMD_EXIF_MAIN, dib, &tag); - if (mdhandle) { - do { - if (std::strcmp(FreeImage_GetTagKey(tag), "Orientation") == 0) { - result = *static_cast(FreeImage_GetTagValue(tag)); - break; - } - } while (FreeImage_FindNextMetadata(mdhandle, &tag)); - FreeImage_FindCloseMetadata(mdhandle); - } - - FreeImage_Unload(dib); + int result = 1; //1代表不做操作,维持原样 return result; } - -#if 0 -bool getThumbnail(QImage &res, const QString &path) -{ - FIBITMAP *dib = readFile2FIBITMAP(path); - res = FIBitmap2QImage(FreeImage_GetThumbnail(dib)); - FreeImage_Unload(dib); - return true; -} -#endif - -#if 0 -class UnionMovieImagePrivate : public QObject -{ -protected: - explicit UnionMovieImagePrivate(UnionMovieImage *parent): q_ptr(parent) - { - Q_UNUSED(padding); - } - ~UnionMovieImagePrivate() - { -// CManagerAttributeService::getInstance()->setCouldRun(false); -// CManagerAttributeService::getInstance()->GifFreeFile(); - } - - - void setPathAndBegin(const QString &path) - { - Q_UNUSED(path) -// CManagerAttributeService::getInstance()->setfilePathWithSignalPlay(path); -// QObject::connect(CManagerAttributeService::getInstance(), &CManagerAttributeService::emitImageSignal, this, [ = ](QImage image, bool isFirst) { -// Q_UNUSED(isFirst); -// res = image; -// }); - } - - int getCurrent() - { - return currentIndex; - } - - void reset() - { -// CManagerAttributeService::getInstance()->setCouldRun(false); -// CManagerAttributeService::getInstance()->GifFreeFile(); - - delete r; - r = nullptr; - errMsg = ""; - res = QImage(); - currentFormat = FIF_UNKNOWN; - currentIndex = 0; - frames = 0; - } - - void setIndex(int i) - { - currentIndex = i; - } -private: - UnionMovieImage *const q_ptr; - Q_DECLARE_PUBLIC(UnionMovieImage) - QImageReader *r = nullptr; - QString errMsg = ""; - QImage res; - FREE_IMAGE_FORMAT currentFormat = FIF_UNKNOWN; - int currentIndex = 0; - int frames = 0; - char padding[4]; -}; - -UnionMovieImage::UnionMovieImage(): d_ptr(new UnionMovieImagePrivate(this)) -{ - -} - -UnionMovieImage::~UnionMovieImage() -{ - Q_D(UnionMovieImage); - delete d; -} - -void UnionMovieImage::setFileName(const QString &path) +UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width, int height, int depth, SupportType type) { - Q_D(UnionMovieImage); - d->reset(); - QString errMsg; - QFileInfo file_info(path); - QString file_suffix_upper = file_info.suffix().toUpper(); - QByteArray temp_path; - temp_path.append(path.toUtf8()); - FREE_IMAGE_FORMAT f = FreeImage_GetFileType(temp_path.data()); - if (!union_image_private.m_movie_formats.contains(file_suffix_upper) || !union_image_private.m_movie_formats.values().contains(f)) { - errMsg = "static Image"; + Q_UNUSED(type); + if (depth == 8) { + res = QImage(width, height, QImage::Format_RGB888); + } else if (depth == 16) { + res = QImage(width, height, QImage::Format_RGB16); } else { - switch (f) { - case FIF_GIF: { - d->setPathAndBegin(path); - d->currentFormat = FIF_GIF; - } - break; - case FIF_WEBP: - case FIF_MNG: { - d->r = new QImageReader; - d->r->setFileName(path); - if (d->r->canRead()) { - d->currentFormat = FIF_MNG; - d->frames = d->r->imageCount(); - } - } - break; - default: - break; - } - } -} - -QImage UnionMovieImage::next() -{ - Q_D(UnionMovieImage); - switch (d->currentFormat) { - case FIF_GIF: { - return d->res; - } - case FIF_WEBP: - case FIF_MNG: { - int temp = d->currentIndex; - d->setIndex(temp + 1); - if (temp + 1 >= d->frames) { - d->setIndex(0); - } - d->res = d->r->read(); - d->r->jumpToNextImage(); - break; + res = QImage(width, height, QImage::Format_RGB32); } - default: - break; - } - return d->res; + return true; } -#endif - imageViewerSpace::ImageType getImageType(const QString &imagepath) { imageViewerSpace::ImageType type = imageViewerSpace::ImageType::ImageTypeBlank; @@ -1622,8 +781,7 @@ QString PrivateDetectImageFormat(const QString &filepath) } // Check xbm file. - if (data.indexOf("#define max_width ") > -1 && - data.indexOf("#define max_height ") > -1) { + if (data.indexOf("#define max_width ") > -1 && data.indexOf("#define max_height ") > -1) { return "xbm"; } @@ -1635,6 +793,3 @@ QString PrivateDetectImageFormat(const QString &filepath) } }; - - - diff --git a/libimageviewer/unionimage/unionimage.h b/libimageviewer/unionimage/unionimage.h index c7479df8..36e14a01 100644 --- a/libimageviewer/unionimage/unionimage.h +++ b/libimageviewer/unionimage/unionimage.h @@ -193,37 +193,6 @@ UNIONIMAGESHARED_EXPORT imageViewerSpace::ImageType getImageType(const QString & */ UNIONIMAGESHARED_EXPORT imageViewerSpace::PathType getPathType(const QString &imagepath); -QT_BEGIN_NAMESPACE - -class UnionMovieImagePrivate; -/** - * @brief The UnionDynamicImage class - * @author DJH - * 用来读取动态图片,使用下标来获取动图的每一帧 - */ -class UNIONIMAGESHARED_EXPORT UnionMovieImage -{ -public: - explicit UnionMovieImage(); - ~UnionMovieImage(); - - void setFileName(const QString &path); - - /** - * @brief next - * @return QImage - * 返回下一帧,该函数可以循环调用 - */ - QImage next(); - -private: - UnionMovieImagePrivate *const d_ptr; - Q_DECLARE_PRIVATE(UnionMovieImage) - Q_DISABLE_COPY(UnionMovieImage) -}; - -QT_END_NAMESPACE - }; diff --git a/libimageviewer/unionimage/unionimage.pri b/libimageviewer/unionimage/unionimage.pri index bac27786..cef69eaf 100755 --- a/libimageviewer/unionimage/unionimage.pri +++ b/libimageviewer/unionimage/unionimage.pri @@ -1,6 +1,5 @@ HEADERS += \ $$PWD/baseutils.h \ - $$PWD/imageutils_freeimage.h \ $$PWD/imageutils_libexif.h \ $$PWD/imageutils.h \ $$PWD/imgoperate.h \ diff --git a/libimageviewer/widgets/printhelper.cpp b/libimageviewer/widgets/printhelper.cpp index c2f35c40..49f92d7a 100755 --- a/libimageviewer/widgets/printhelper.cpp +++ b/libimageviewer/widgets/printhelper.cpp @@ -18,11 +18,10 @@ #include #include -#ifdef USE_UNIONIMAGE #include "printhelper.h" #include "unionimage/unionimage.h" -#endif +#include PrintHelper *PrintHelper::m_Printer = nullptr; PrintHelper *PrintHelper::getIntance() @@ -65,7 +64,7 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent) } else { // QImage不应该多次赋值,所以换到这里来,修复style问题 QImage img; - LibUnionImage_NameSpace::loadStaticImageFromFile(path, img, errMsg); + LibUnionImage_NameSpace::loadStaticImageFromFile(path, img, errMsg); if (!img.isNull()) { m_re->appendImage(img); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5ec06f9..61bb4cef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,8 +7,6 @@ ADD_COMPILE_OPTIONS(-fno-access-control) #"option"用来定义宏,"ON"表示打开,"OFF"表示关闭 option (LITE_DIV "Use tutorial provided math implementation" ON) add_definitions( -DLITE_DIV ) -option (USE_UNIONIMAGE "Use UNIONIMAGE" ON) -add_definitions( -DUSE_UNIONIMAGE ) option (USE_TEST "Use TESTS" ON) add_definitions( -DUSE_TEST ) @@ -84,7 +82,6 @@ pkg_check_modules(3rd_lib REQUIRED gsettings-qt gstreamer-1.0 libmediainfo -# freeimage ) ## translations @@ -137,7 +134,6 @@ target_link_libraries( # gio-unix-2.0 gio-qt udisks2-qt5 - freeimage pthread gtest ) diff --git a/tests/test_aimodelservice.cpp b/tests/test_aimodelservice.cpp index b3460f03..d539dde5 100644 --- a/tests/test_aimodelservice.cpp +++ b/tests/test_aimodelservice.cpp @@ -8,93 +8,93 @@ #include "service/aimodelservice.h" #include "service/aimodelservice_p.h" -class TestAIModelService : public testing::Test -{ -public: - TestAIModelService() = default; - ~TestAIModelService() = default; - -protected: - static AIModelService *ins; -}; - -AIModelService *TestAIModelService::ins = AIModelService::instance(); - -TEST_F(TestAIModelService, TemporaryFile_Contains_Pass) -{ - ins->dptr->enhanceCache.clear(); - EnhancePtr ptr(new EnhanceInfo("source", "output", "model")); - ins->dptr->enhanceCache.insert("output", ptr); - - EXPECT_FALSE(ins->isTemporaryFile("source")); - EXPECT_TRUE(ins->isTemporaryFile("output")); - EXPECT_EQ(QString("source"), ins->sourceFilePath("output")); - - ins->dptr->enhanceCache.clear(); -} - -TEST_F(TestAIModelService, ImageProcessing_ErrorFile_Failed) -{ - ModelPtr mptr(new ModelInfo); - mptr->modelID = 0; - mptr->model = "model"; - ins->dptr->mapModelInfo.insert(mptr->modelID, mptr); - - QString outfile = ins->imageProcessing("source", mptr->modelID, QImage()); - // 等待处理结束,涉及条件变量等待! - ins->dptr->enhanceWatcher.waitForFinished(); - - auto enhancePtr = ins->dptr->enhanceWatcher.result(); - EXPECT_EQ(enhancePtr->source, QString("source")); - EXPECT_EQ(enhancePtr->output, outfile); - - EXPECT_FALSE(QFile::exists(outfile)); - EXPECT_FALSE(ins->dptr->enhanceCache.isEmpty()); -} - -TEST_F(TestAIModelService, OnDBusEnhanceEnd_NotExist_Failed) -{ - QString source; - QString output; - AIModelService::State state; - auto conn = - QObject::connect(ins, &AIModelService::enhanceEnd, [&](const QString &src, const QString &out, AIModelService::State s) { - source = src; - output = out; - state = s; - }); - - ins->dptr->enhanceCache.clear(); - ins->onDBusEnhanceEnd("output", 0); - EXPECT_TRUE(source.isEmpty()); - - EnhancePtr ptr(new EnhanceInfo("source", "output", "model")); - ptr->state.store(AIModelService::LoadSucc); - ins->dptr->enhanceCache.insert("output", ptr); - ins->onDBusEnhanceEnd("output", 0); - EXPECT_EQ(AIModelService::LoadFailed, ptr->state.loadAcquire()); - - EXPECT_EQ(source, QString("source")); - EXPECT_EQ(output, QString("output")); - EXPECT_EQ(state, ptr->state.loadAcquire()); - - QObject::disconnect(conn); -} - -TEST_F(TestAIModelService, CheckConvertFile_NewImage_Pass) -{ - ins->dptr->convertCache.clear(); - QImage nullImage; - QString tmpImage = ins->checkConvertFile("localtest.png", nullImage); - EXPECT_TRUE(tmpImage.isEmpty()); - - QImage contentImage(20, 20, QImage::Format_ARGB32); - contentImage.fill(Qt::red); - tmpImage = ins->checkConvertFile("localtest.png", contentImage); - EXPECT_FALSE(tmpImage.isEmpty()); - EXPECT_TRUE(QFile::exists(tmpImage)); - EXPECT_TRUE(ins->dptr->convertCache.contains("localtest.png")); - EXPECT_EQ(tmpImage, ins->dptr->convertCache.value("localtest.png")); - - ins->dptr->convertCache.clear(); -} +//class TestAIModelService : public testing::Test +//{ +//public: +// TestAIModelService() = default; +// ~TestAIModelService() = default; + +//protected: +// static AIModelService *ins; +//}; + +//AIModelService *TestAIModelService::ins = AIModelService::instance(); + +//TEST_F(TestAIModelService, TemporaryFile_Contains_Pass) +//{ +// ins->dptr->enhanceCache.clear(); +// EnhancePtr ptr(new EnhanceInfo("source", "output", "model")); +// ins->dptr->enhanceCache.insert("output", ptr); + +// EXPECT_FALSE(ins->isTemporaryFile("source")); +// EXPECT_TRUE(ins->isTemporaryFile("output")); +// EXPECT_EQ(QString("source"), ins->sourceFilePath("output")); + +// ins->dptr->enhanceCache.clear(); +//} + +//TEST_F(TestAIModelService, ImageProcessing_ErrorFile_Failed) +//{ +// ModelPtr mptr(new ModelInfo); +// mptr->modelID = 0; +// mptr->model = "model"; +// ins->dptr->mapModelInfo.insert(mptr->modelID, mptr); + +// QString outfile = ins->imageProcessing("source", mptr->modelID, QImage()); +// // 等待处理结束,涉及条件变量等待! +// ins->dptr->enhanceWatcher.waitForFinished(); + +// auto enhancePtr = ins->dptr->enhanceWatcher.result(); +// EXPECT_EQ(enhancePtr->source, QString("source")); +// EXPECT_EQ(enhancePtr->output, outfile); + +// EXPECT_FALSE(QFile::exists(outfile)); +// EXPECT_FALSE(ins->dptr->enhanceCache.isEmpty()); +//} + +//TEST_F(TestAIModelService, OnDBusEnhanceEnd_NotExist_Failed) +//{ +// QString source; +// QString output; +// AIModelService::State state; +// auto conn = +// QObject::connect(ins, &AIModelService::enhanceEnd, [&](const QString &src, const QString &out, AIModelService::State s) { +// source = src; +// output = out; +// state = s; +// }); + +// ins->dptr->enhanceCache.clear(); +// ins->onDBusEnhanceEnd("output", 0); +// EXPECT_TRUE(source.isEmpty()); + +// EnhancePtr ptr(new EnhanceInfo("source", "output", "model")); +// ptr->state.store(AIModelService::LoadSucc); +// ins->dptr->enhanceCache.insert("output", ptr); +// ins->onDBusEnhanceEnd("output", 0); +// EXPECT_EQ(AIModelService::LoadFailed, ptr->state.loadAcquire()); + +// EXPECT_EQ(source, QString("source")); +// EXPECT_EQ(output, QString("output")); +// EXPECT_EQ(state, ptr->state.loadAcquire()); + +// QObject::disconnect(conn); +//} + +//TEST_F(TestAIModelService, CheckConvertFile_NewImage_Pass) +//{ +// ins->dptr->convertCache.clear(); +// QImage nullImage; +// QString tmpImage = ins->checkConvertFile("localtest.png", nullImage); +// EXPECT_TRUE(tmpImage.isEmpty()); + +// QImage contentImage(20, 20, QImage::Format_ARGB32); +// contentImage.fill(Qt::red); +// tmpImage = ins->checkConvertFile("localtest.png", contentImage); +// EXPECT_FALSE(tmpImage.isEmpty()); +// EXPECT_TRUE(QFile::exists(tmpImage)); +// EXPECT_TRUE(ins->dptr->convertCache.contains("localtest.png")); +// EXPECT_EQ(tmpImage, ins->dptr->convertCache.value("localtest.png")); + +// ins->dptr->convertCache.clear(); +//}