Skip to content

Commit

Permalink
feat: rmove freeimage lib
Browse files Browse the repository at this point in the history
rmove freeimage lib

Log: rmove freeimage lib

Task: https://pms.uniontech.com/task-view-365161.html
  • Loading branch information
lzwind committed Oct 17, 2024
1 parent 4372724 commit 3c1aa60
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 151 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ _**master**分支是当前开发分支,编译依赖可能在未更新README.md
* libxcb-util0-dev,
* libstartup-notification0-dev,
* libraw-dev,
* libfreeimage-dev,
* libqt5opengl5-dev,
* qtbase5-private-dev,
* qtmultimedia5-dev,
Expand Down Expand Up @@ -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. 构建:
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions libimageviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

#库目录
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libimageviewer/libimageviewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion libimageviewer/quickprint/printimageloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,15 @@ 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);
imagePtr->state = ContentError;
return false;
}
} else {
#endif
QImageReader reader(imagePtr->filePath);
// jumpToImage 可能返回 false, 但数据正常读取
reader.jumpToImage(imagePtr->frame);
Expand All @@ -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());
Expand Down
165 changes: 107 additions & 58 deletions libimageviewer/unionimage/imageutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QUrl>
#include <QApplication>
#include <QTemporaryDir>
#include <QtMath>

namespace Libutils {

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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());
Expand All @@ -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<double>(bytes) / kb, 'f', 1);
if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) {
return QString::number(static_cast<int>(vs.toDouble())) + " KB";
} else {
return vs + " KB";
}
} else if (bytes < kb * kb * kb) {
QString vs = QString::number(static_cast<double>(bytes) / kb / kb, 'f', 1);
if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) {
return QString::number(static_cast<int>(vs.toDouble())) + " MB";
} else {
return vs + " MB";
}
} else {
//修改了当超过一个G的图片,应该用G返回,不应该返回一堆数字,bug68094
QString vs = QString::number(static_cast<double>(bytes) / kb / kb / kb, 'f', 1);
if (qCeil(vs.toDouble()) == qFloor(vs.toDouble())) {
return QString::number(static_cast<int>(vs.toDouble())) + " GB";
} else {
return vs + " GB";
}
}
}

const QMap<QString, QString> getAllMetaData(const QString &path)
{
/*lmh0724使用USE_UNIONIMAGE*/
#ifdef USE_UNIONIMAGE
return LibUnionImage_NameSpace::getAllMetaData(path);
#else
return freeimage::getAllMetaData(path);

QMap<QString, QString> 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
}

Expand Down Expand Up @@ -726,7 +775,7 @@ bool thumbnailExist(const QString &path, ThumbnailType type)
return false;
}
}
/*

static QStringList fromByteArrayList(const QByteArrayList &list)
{
QStringList sList;
Expand All @@ -748,7 +797,7 @@ static QStringList fromByteArrayList(const QByteArrayList &list)

return sList;
}
*/

QStringList supportedImageFormats()
{
/*lmh0724使用USE_UNIONIMAGE*/
Expand Down
2 changes: 1 addition & 1 deletion libimageviewer/unionimage/imageutils_freeimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef USE_UNIONIMAGE
#ifdef USE_UNIONIMAGE
#include "baseutils.h"
#include <FreeImage.h>
#include <QDateTime>
Expand Down
Loading

0 comments on commit 3c1aa60

Please sign in to comment.