From 3c1aa602571d9f6b4fc8e501f9c11dc13d9582b1 Mon Sep 17 00:00:00 2001 From: Liu Zheng Date: Thu, 17 Oct 2024 16:21:05 +0800 Subject: [PATCH] feat: rmove freeimage lib rmove freeimage lib Log: rmove freeimage lib Task: https://pms.uniontech.com/task-view-365161.html --- README.md | 3 +- README.zh_CN.md | 3 +- debian/control | 2 +- libimageviewer/CMakeLists.txt | 6 +- libimageviewer/libimageviewer.pro | 2 +- .../quickprint/printimageloader.cpp | 3 +- libimageviewer/unionimage/imageutils.cpp | 165 ++++--- .../unionimage/imageutils_freeimage.h | 2 +- libimageviewer/unionimage/unionimage.cpp | 432 ++++++++++++++---- libimageviewer/widgets/printhelper.cpp | 6 +- 10 files changed, 473 insertions(+), 151 deletions(-) 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..12c7b4fc 100644 --- a/debian/control +++ b/debian/control @@ -16,7 +16,7 @@ Build-Depends: libxcb-util0-dev, libstartup-notification0-dev, libraw-dev, - libfreeimage-dev, +# libfreeimage-dev, libqt5opengl5-dev, qtbase5-private-dev, qtmultimedia5-dev, diff --git a/libimageviewer/CMakeLists.txt b/libimageviewer/CMakeLists.txt index c0513115..1d4d8b03 100644 --- a/libimageviewer/CMakeLists.txt +++ b/libimageviewer/CMakeLists.txt @@ -45,7 +45,7 @@ include_directories(${CMAKE_INCLUDE_CURRENT_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions( -DLITE_DIV ) -add_definitions( -DUSE_UNIONIMAGE ) +#add_definitions( -DUSE_UNIONIMAGE ) add_definitions( -DCMAKE_BUILD ) #库目录 @@ -92,7 +92,7 @@ set(LINK_DIR /usr/lib/) include_directories(${INC_DIR}) link_directories(${LINK_DIR}) -link_libraries(freeimage) +# link_libraries(freeimage) set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) @@ -122,7 +122,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..58ff000f 100644 --- a/libimageviewer/libimageviewer.pro +++ b/libimageviewer/libimageviewer.pro @@ -13,7 +13,7 @@ CONFIG += c++11 link_pkgconfig PKGCONFIG += dtkwidget dtkcore DEFINES += IMAGEVIEWER_LIBRARY -LIBS += -lfreeimage +#LIBS += -lfreeimage DEFINES += LITE_DIV DEFINES += USE_UNIONIMAGE diff --git a/libimageviewer/quickprint/printimageloader.cpp b/libimageviewer/quickprint/printimageloader.cpp index 8fdac4d4..f8bebc8e 100644 --- a/libimageviewer/quickprint/printimageloader.cpp +++ b/libimageviewer/quickprint/printimageloader.cpp @@ -261,6 +261,7 @@ bool PrintImageLoader::loadImageData(PrintImageData::Ptr &imagePtr) try { if (s_SingleFrame == imagePtr->frame) { +#ifdef DUSE_UNIONIMAGE QString errorMsg; if (!LibUnionImage_NameSpace::loadStaticImageFromFile(imagePtr->filePath, imagePtr->data, errorMsg)) { qWarning() << QString("Load image failed: %1").arg(errorMsg); @@ -268,6 +269,7 @@ bool PrintImageLoader::loadImageData(PrintImageData::Ptr &imagePtr) return false; } } else { +#endif QImageReader reader(imagePtr->filePath); // jumpToImage 可能返回 false, 但数据正常读取 reader.jumpToImage(imagePtr->frame); @@ -284,7 +286,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/imageutils.cpp b/libimageviewer/unionimage/imageutils.cpp index 43b16fe3..5eea36c5 100755 --- a/libimageviewer/unionimage/imageutils.cpp +++ b/libimageviewer/unionimage/imageutils.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace Libutils { @@ -146,12 +147,8 @@ bool imageSupportRead(const QString &path) if (errorList.indexOf(suffix.toUpper()) != -1) { return false; } + return (suffix == "svg"); - if (freeimage::isSupportsReading(path)) - return true; - else { - return (suffix == "svg"); - } #endif } @@ -190,9 +187,8 @@ bool imageSupportSave(const QString &path) if (raws.indexOf(suffix.toUpper()) != -1 || QImageReader(path).imageCount() > 1) { return false; - } else { - return freeimage::canSave(path); } + return true; #endif } @@ -206,51 +202,51 @@ bool rotate(const QString &path, int degree) 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; - } + // 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); - 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; + return false; #endif } @@ -346,7 +342,7 @@ int getOrientation(const QString &path) #ifdef USE_UNIONIMAGE return LibUnionImage_NameSpace::getOrientation(path); #else - return freeimage::getOrientation(path); + return 1; #endif } @@ -508,9 +504,6 @@ const QImage getRotatedImage(const QString &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()); @@ -528,13 +521,69 @@ const QImage getRotatedImage(const QString &path) 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); + + 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; #endif } @@ -726,7 +775,7 @@ bool thumbnailExist(const QString &path, ThumbnailType type) return false; } } -/* + static QStringList fromByteArrayList(const QByteArrayList &list) { QStringList sList; @@ -748,7 +797,7 @@ static QStringList fromByteArrayList(const QByteArrayList &list) return sList; } -*/ + QStringList supportedImageFormats() { /*lmh0724使用USE_UNIONIMAGE*/ diff --git a/libimageviewer/unionimage/imageutils_freeimage.h b/libimageviewer/unionimage/imageutils_freeimage.h index ffb53e1a..5e9563dd 100755 --- a/libimageviewer/unionimage/imageutils_freeimage.h +++ b/libimageviewer/unionimage/imageutils_freeimage.h @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#ifndef USE_UNIONIMAGE +#ifdef USE_UNIONIMAGE #include "baseutils.h" #include #include diff --git a/libimageviewer/unionimage/unionimage.cpp b/libimageviewer/unionimage/unionimage.cpp index 7ffb2c7d..60e61e67 100644 --- a/libimageviewer/unionimage/unionimage.cpp +++ b/libimageviewer/unionimage/unionimage.cpp @@ -3,7 +3,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "unionimage.h" -#include +#ifdef DUSE_UNIONIMAGE +# include +#endif //#include "giflib/cmanagerattributeservice.h" #include @@ -104,80 +106,127 @@ 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; +//FreeImage_Initialise(true); +//m_freeimage_formats["UNKNOWN"] = -1; +#ifdef DUSE_UNIONIMAGE + 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["FAX"] = 27; + m_freeimage_formats["G3"] = 27; //FAXG3 + m_freeimage_formats["SGI"] = FIF_SGI; + m_freeimage_formats["EXR"] = FIF_EXR; + 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["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; +#endif /* * 由于原设计方案采用多个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"; + << "HEIF" + << "HEIC" + << "HEJ2" + << "AVIF" + << "TGA" + << "PSD" + << "PXM" + << "PIC" + << "PEF" + << "XBM" + << "ARW" + << "HDR" + << "J2K" + << "ICNS" + << "AVI" + << "VIFF" + << "IFF" + << "JP2" + << "WMF" + << "CRW" + << "X3F" + << "EPS" + << "SR2" + << "AVIFS"; //pic(多张图片) pcx不支持旋转 - m_canSave << "BMP" << "JPG" << "JPEG" << "JPS" << "JPE" << "PNG" - << "PGM" << "PPM" << "PNM" - << "TGA" << "XPM" << "ICO" + m_canSave << "BMP" + << "JPG" + << "JPEG" + << "JPS" + << "JPE" + << "PNG" + << "PGM" + << "PPM" + << "PNM" + << "TGA" + << "XPM" + << "ICO" << "JNG" // << "SVG" //svg不再支持旋转 // << "JP2" @@ -210,9 +259,9 @@ class UnionImage_Private }; static UnionImage_Private union_image_private; - +#ifdef DUSE_UNIONIMAGE FREE_IMAGE_FORMAT detectImageFormat_f(const QString &path); - +#endif /** * @brief noneQImage * @return QImage @@ -326,6 +375,7 @@ UNIONIMAGESHARED_EXPORT QDateTime string2DateTime(const QString &time) * @return QMap * 内部接口获取图片的信息 */ +#ifdef DUSE_UNIONIMAGE UNIONIMAGESHARED_EXPORT QMap getMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) { QMap mdMap; // key-data @@ -437,7 +487,7 @@ UNIONIMAGESHARED_EXPORT QImage FIBitmap2QImage(FIBITMAP *dib) } return noneQImage(); } - +#endif /** * @brief QImgeToFIBitMap * @param img @@ -536,7 +586,7 @@ UNIONIMAGESHARED_EXPORT FIBITMAP *QImge2FIBitMap(QImage img) return nullptr; } #endif - +#ifdef DUSE_UNIONIMAGE /** * @brief readFile2FIBITMAP * @param path @@ -612,6 +662,20 @@ UNIONIMAGESHARED_EXPORT bool writeFIBITMAPToFile(FIBITMAP *dib, const QString &p } return bSuccess; } +#else +UNIONIMAGESHARED_EXPORT bool canSave(const QString &path) +{ + QImageReader r(path); + if (r.imageCount() > 1) { + return false; + } + QFileInfo info(path); + if (union_image_private.m_canSave.contains(info.suffix().toUpper())) + return true; + return false; +} + +#endif UNIONIMAGESHARED_EXPORT QString unionImageVersion() { @@ -621,9 +685,7 @@ UNIONIMAGESHARED_EXPORT QString unionImageVersion() ver.append("\n"); return ver; } - - - +#ifdef DUSE_UNIONIMAGE UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width, int height, int depth, SupportType type) { Q_UNUSED(type); @@ -632,7 +694,8 @@ UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width, int height, i FreeImage_Unload(dib); return true; } - +#endif +#ifdef DUSE_UNIONIMAGE QString PrivateDetectImageFormat(const QString &filepath); UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage &res, QString &errorMsg, const QString &format_bar) { @@ -986,7 +1049,200 @@ FREE_IMAGE_FORMAT detectImageFormat_f(const QString &path) f = static_cast(union_image_private.m_freeimage_formats[file_suffix_upper]); return f >= 0 ? f : FIF_UNKNOWN; } +#else +QString PrivateDetectImageFormat(const QString &filepath); +UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage &res, QString &errorMsg, const QString &format_bar) +{ + QFileInfo file_info(path); + if (file_info.size() == 0) { + res = QImage(); + errorMsg = "error file!"; + return false; + } + QMap dataMap = getAllMetaData(path); + QString file_suffix_upper = dataMap.value("FileFormat").toUpper(); + + QByteArray temp_path; + temp_path.append(path.toUtf8()); + + QString file_suffix_lower = file_suffix_upper.toLower(); + + if (union_image_private.m_qtSupported.contains(file_suffix_upper)) { + QImageReader reader; + QImage res_qt; + reader.setFileName(path); + if (format_bar.isEmpty()) { + reader.setFormat(file_suffix_lower.toLatin1()); + } else { + reader.setFormat(format_bar.toLatin1()); + } + reader.setAutoTransform(true); + if (reader.imageCount() > 0 || file_suffix_upper != "ICNS") { + res_qt = reader.read(); + if (res_qt.isNull()) { + //try old loading method + QString format = PrivateDetectImageFormat(path); + QImageReader readerF(path, format.toLatin1()); + QImage try_res; + readerF.setAutoTransform(true); + if (readerF.canRead()) { + try_res = readerF.read(); + } else { + errorMsg = "can't read image:" + readerF.errorString() + format; + try_res = QImage(path); + } + + // 单独处理TIF格式情况 + if (try_res.isNull() && (file_suffix_upper == "TIF" || file_suffix_upper == "TIFF")) { + // 读取失败,tif需要单独处理,尝试通过转换函数处理 + QFileInfo imageFile(path); + QString cacheFile = Libutils::image::getCacheImagePath() + QDir::separator() + imageFile.fileName(); + // 判断是否存在缓存图片数据 + if (Libutils::image::checkCacheImage(imageFile.fileName())) { + try_res = QImage(cacheFile); + } else { + // 由于多线程调用,可能同时访问文件,使用临时文件处理,防止部分线程读取未转码完成的图片文件 + QString tempFile = Libutils::image::getCacheImagePath() + QDir::separator() + + QUuid::createUuid().toString() + imageFile.fileName(); + qDebug() << "convert" << imageFile.absoluteFilePath() << cacheFile << tempFile; + + // 转换图像编码格式 + int nRet = convertOldStyleImage(imageFile.absoluteFilePath().toUtf8().data(), tempFile.toUtf8().data()); + // 转换成功标识 + static const int s_nFlagSucc = 0; + if (s_nFlagSucc == nRet) { + if (QFile::exists(tempFile)) { + try_res = QImage(tempFile); + + // 判断缓存文件是否已存在,保存缓存数据 + if (QFile::exists(cacheFile)) { + QFile::remove(tempFile); + } else { + QFile::rename(tempFile, cacheFile); + } + } + } + } + } + + if (try_res.isNull()) { + errorMsg = "load image by qt failed, use format:" + reader.format() + " ,path:" + path; + res = QImage(); + return false; + } + errorMsg = "use old method to load QImage"; + res = try_res; + return true; + } + errorMsg = "use QImage"; + res = res_qt; + } else { + res = QImage(); + return false; + } + return true; + } + return false; +} + +UNIONIMAGESHARED_EXPORT QString detectImageFormat(const QString &path) +{ + QFileInfo file_info(path); + QString file_suffix_upper = file_info.suffix().toUpper(); + QString res = file_suffix_upper; + if (res.isEmpty()) { + QFile file(path); + if (!file.open(QIODevice::ReadOnly)) { + return ""; + } + + // const QByteArray data = file.read(1024); + const QByteArray data = file.read(64); + + // Check bmp file. + if (data.startsWith("BM")) { + return "BMP"; + } + + // Check dds file. + if (data.startsWith("DDS")) { + return "DDS"; + } + + // Check gif file. + if (data.startsWith("GIF8")) { + return "GIF"; + } + + // Check Max OS icons file. + if (data.startsWith("icns")) { + return "ICNS"; + } + + // Check jpeg file. + if (data.startsWith("\xff\xd8")) { + return "JPG"; + } + + // Check mng file. + if (data.startsWith("\x8a\x4d\x4e\x47\x0d\x0a\x1a\x0a")) { + return "MNG"; + } + + // Check net pbm file (BitMap). + if (data.startsWith("P1") || data.startsWith("P4")) { + return "PBM"; + } + + // Check pgm file (GrayMap). + if (data.startsWith("P2") || data.startsWith("P5")) { + return "PGM"; + } + // Check ppm file (PixMap). + if (data.startsWith("P3") || data.startsWith("P6")) { + return "PPM"; + } + + // Check png file. + if (data.startsWith("\x89PNG\x0d\x0a\x1a\x0a")) { + return "PNG"; + } + + // Check svg file. + if (data.indexOf(" -1) { + return "SVG"; + } + + // 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 "TIFF"; + } + + // TODO(xushaohua): Support wbmp file. + + // Check webp file. + if (data.startsWith("RIFFr\x00\x00\x00WEBPVP")) { + return "WEBP"; + } + + // Check xbm file. + if (data.indexOf("#define max_width ") > -1 && data.indexOf("#define max_height ") > -1) { + return "XBM"; + } + + // Check xpm file. + if (data.startsWith("/* XPM */")) { + return "XPM"; + } + return ""; + } + return res; +} +#endif UNIONIMAGESHARED_EXPORT bool isNoneQImage(const QImage &qi) { return (qi == noneQImage()); @@ -1101,6 +1357,7 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt erroMsg = "rotate by qt failed"; return false; } +#ifdef DUSE_UNIONIMAGE FIBITMAP *dib = readFile2FIBITMAP(path); if (nullptr == dib) { erroMsg = "unsupported format"; @@ -1129,7 +1386,6 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt FreeImage_Unload(rotateRes); return false; } - ; if (!writeFIBITMAPToFile(rotateRes, path)) { erroMsg = "rotate image save failed, unknown format"; FreeImage_Unload(dib); @@ -1140,6 +1396,9 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt FreeImage_Unload(rotateRes); erroMsg = ""; return true; +#else + return false; +#endif } UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, const QString &path, QString &erroMsg) @@ -1188,6 +1447,7 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, co return true; } } +#ifdef DUSE_UNIONIMAGE FIBITMAP *dib = readFile2FIBITMAP(path); if (nullptr == dib) { erroMsg = "unsupported format"; @@ -1226,18 +1486,24 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIleWithImage(int angel, QImage &img, co FreeImage_Unload(rotateRes); erroMsg = ""; return true; +#else + return false; +#endif } UNIONIMAGESHARED_EXPORT QMap getAllMetaData(const QString &path) { - FIBITMAP *dib = readFile2FIBITMAP(path, FIF_LOAD_NOPIXELS); QMap admMap; +#ifdef DUSE_UNIONIMAGE + FIBITMAP *dib = readFile2FIBITMAP(path, FIF_LOAD_NOPIXELS); + 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)); +#endif //移除秒  2020/6/5 DJH //需要转义才能读出:或者/  2020/8/21 DJH QFileInfo info(path); @@ -1279,17 +1545,20 @@ UNIONIMAGESHARED_EXPORT QMap getAllMetaData(const QString &pat // // 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(); +#ifdef DUSE_UNIONIMAGE + w = w > 0 ? w : static_cast(FreeImage_GetWidth(dib)); h = h > 0 ? h : static_cast(FreeImage_GetHeight(dib)); +#endif 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())); +#ifdef DUSE_UNIONIMAGE FreeImage_Unload(dib); - +#endif return admMap; } @@ -1314,8 +1583,8 @@ UNIONIMAGESHARED_EXPORT bool isSupportsWriting(const QString &path) UNIONIMAGESHARED_EXPORT int getOrientation(const QString &path) { - int result = 1; //1代表不做操作,维持原样 - + int result = 1; //1代表不做操作,维持原样 +#ifdef DUSE_UNIONIMAGE FIBITMAP *dib = readFile2FIBITMAP(path, FIF_LOAD_NOPIXELS); //有时候会存在tag为野指针的情况,根据FreeImage的demo,需要加这个进行预判断 @@ -1338,6 +1607,7 @@ UNIONIMAGESHARED_EXPORT int getOrientation(const QString &path) } FreeImage_Unload(dib); +#endif return result; } diff --git a/libimageviewer/widgets/printhelper.cpp b/libimageviewer/widgets/printhelper.cpp index c2f35c40..a76e8336 100755 --- a/libimageviewer/widgets/printhelper.cpp +++ b/libimageviewer/widgets/printhelper.cpp @@ -22,7 +22,7 @@ #include "printhelper.h" #include "unionimage/unionimage.h" #endif - +#include PrintHelper *PrintHelper::m_Printer = nullptr; PrintHelper *PrintHelper::getIntance() @@ -64,8 +64,12 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent) } } else { // QImage不应该多次赋值,所以换到这里来,修复style问题 +#ifdef USE_UNIONIMAGE QImage img; LibUnionImage_NameSpace::loadStaticImageFromFile(path, img, errMsg); +#else + QImage img(path); +#endif if (!img.isNull()) { m_re->appendImage(img); }