Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable tiff picture auto transform #137

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libimageviewer/quickprint/printimageloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ bool PrintImageLoader::loadImageData(PrintImageData::Ptr &imagePtr)
}
} else {
QImageReader reader(imagePtr->filePath);

// TIFF 图片不根据EXIF信息旋转
QString format = reader.format().toLower();
if ("tiff" == format || "tif" == format) {
reader.setAutoTransform(false);
}

// jumpToImage 可能返回 false, 但数据正常读取
reader.jumpToImage(imagePtr->frame);
if (!reader.canRead()) {
Expand Down
7 changes: 5 additions & 2 deletions libimageviewer/unionimage/unionimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,18 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage
} else {
reader.setFormat(format_bar.toLatin1());
}
reader.setAutoTransform(true);
// Tiff 图片不根据EXIF信息旋转
reader.setAutoTransform(FIF_TIFF != f);

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);
readerF.setAutoTransform(FIF_TIFF != f);

if (readerF.canRead()) {
try_res = readerF.read();
} else {
Expand Down
30 changes: 28 additions & 2 deletions libimageviewer/viewpanel/scen/imagegraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,20 @@ void LibImageGraphicsView::slotsUp()
scene()->clear();

resetTransform();
QPixmap pixmap = QPixmap::fromImage(m_imageReader->read());
QPixmap pixmap;

// FIXME: 临时修改,TIFF 图片不根据EXIF信息旋转
// 且由于 libqtiff 插件缓存的旋转信息可能错误,缓存数据会导致内存占用升高,调整为单次新建读取
QString format = m_imageReader->format().toLower();
if ("tiff" == format || "tif" == format) {
QImageReader tmpReader(m_imageReader->fileName());
tmpReader.setAutoTransform(false);
tmpReader.jumpToImage(m_imageReader->currentImageNumber());
pixmap = QPixmap::fromImage(tmpReader.read());
} else {
pixmap = QPixmap::fromImage(m_imageReader->read());
}

pixmap.setDevicePixelRatio(devicePixelRatioF());
m_pixmapItem = new LibGraphicsPixmapItem(pixmap);
scene()->addItem(m_pixmapItem);
Expand Down Expand Up @@ -884,7 +897,20 @@ void LibImageGraphicsView::slotsDown()
m_imgSvgItem = nullptr;
scene()->clear();
resetTransform();
QPixmap pixmap = QPixmap::fromImage(m_imageReader->read());
QPixmap pixmap;

// FIXME: 临时修改,TIFF 图片不根据EXIF信息旋转
// 且由于 libqtiff 插件缓存的旋转信息可能错误,缓存数据会导致内存占用升高,调整为单次新建读取
QString format = m_imageReader->format().toLower();
if ("tiff" == format || "tif" == format) {
QImageReader tmpReader(m_imageReader->fileName());
tmpReader.setAutoTransform(false);
tmpReader.jumpToImage(m_imageReader->currentImageNumber());
pixmap = QPixmap::fromImage(tmpReader.read());
} else {
pixmap = QPixmap::fromImage(m_imageReader->read());
}

pixmap.setDevicePixelRatio(devicePixelRatioF());
m_pixmapItem = new LibGraphicsPixmapItem(pixmap);
scene()->addItem(m_pixmapItem);
Expand Down
7 changes: 7 additions & 0 deletions libimageviewer/widgets/printhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
for (const QString &path : paths) {
QString errMsg;
QImageReader imgReadreder(path);

// TIFF 图片不根据EXIF信息旋转
QString format = imgReadreder.format().toLower();
if ("tiff" == format || "tif" == format) {
imgReadreder.setAutoTransform(false);
}

if (imgReadreder.imageCount() > 1) {
for (int imgindex = 0; imgindex < imgReadreder.imageCount(); imgindex++) {
imgReadreder.jumpToImage(imgindex);
Expand Down
Loading