chore: improved jpeg format checking, port away from win32only code
This commit is contained in:
parent
a9171d1963
commit
9136e75e26
@ -1572,7 +1572,7 @@ void Caesium::runPreview()
|
||||
}
|
||||
else if (ui->formatComboBox->currentIndex() == 3)
|
||||
{
|
||||
if (orig.suffix().toLatin1().toLower() == "jpg")
|
||||
if (isJpegSuffix(orig.suffix()))
|
||||
{
|
||||
image.save(tempFolder + "/_caesium_/" + rndString + ".cae", "jpg", ui->qualitySlider->value());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*******************************************************************************
|
||||
#
|
||||
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
|
||||
# 2021 Gary Wang <wzc782970009@gmail.com>
|
||||
#
|
||||
# This file is part of the Caesium distribution.
|
||||
#
|
||||
@ -150,7 +151,7 @@ void CompressionThread::run()
|
||||
if (sameFormat)
|
||||
{
|
||||
t_format = info.suffix();
|
||||
if (t_format.toLower() != "jpg")
|
||||
if (!isJpegSuffix(t_format))
|
||||
{
|
||||
t_quality.replace(i, "1");
|
||||
}
|
||||
@ -268,7 +269,7 @@ void CompressionThread::noEnlarge()
|
||||
if (sameFormat)
|
||||
{
|
||||
t_format = info.suffix();
|
||||
if (t_format.toLower() != "jpg")
|
||||
if (!isJpegSuffix(t_format))
|
||||
{
|
||||
t_quality.replace(i, "1");
|
||||
}
|
||||
@ -365,19 +366,14 @@ void CompressionThread::noEnlarge()
|
||||
}
|
||||
}
|
||||
|
||||
void CompressionThread::keepDate(QString orig, QString dest)
|
||||
void CompressionThread::keepDate(const QString & orig, const QString & dest)
|
||||
{
|
||||
HANDLE hFile, hFile2;
|
||||
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(qStringToWideChar(orig), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
|
||||
hFile2 = CreateFile(qStringToWideChar(dest), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
SetFileTime(hFile2, &ftCreate, &ftAccess, &ftWrite);
|
||||
|
||||
CloseHandle(hFile);
|
||||
CloseHandle(hFile2);
|
||||
QFile origFile(orig), destFile(dest);
|
||||
destFile.open(QIODevice::Append);
|
||||
destFile.setFileTime(origFile.fileTime(QFileDevice::FileAccessTime), QFileDevice::FileAccessTime);
|
||||
destFile.setFileTime(origFile.fileTime(QFileDevice::FileBirthTime), QFileDevice::FileBirthTime);
|
||||
destFile.setFileTime(origFile.fileTime(QFileDevice::FileModificationTime), QFileDevice::FileModificationTime);
|
||||
destFile.close();
|
||||
}
|
||||
|
||||
void CompressionThread::optimizePNG(QString file, int level)
|
||||
|
@ -13,8 +13,7 @@ public:
|
||||
QObject *parent);
|
||||
void run();
|
||||
void noEnlarge();
|
||||
void writeToFile(QString orig, QString dest);
|
||||
void keepDate(QString, QString);
|
||||
void keepDate(const QString & orig, const QString & dest);
|
||||
void optimizePNG(QString file, int level);
|
||||
|
||||
private:
|
||||
|
@ -33,3 +33,9 @@ bool same_folder_flag = false;
|
||||
const int version_build = 170;
|
||||
const QString version_string = "1.7.0";
|
||||
QString opened_list = "";
|
||||
|
||||
bool isJpegSuffix(const QString &suffix)
|
||||
{
|
||||
const QStringList jpegSuffix({"jpg", "jpeg", "jfif"});
|
||||
return (jpegSuffix.contains(suffix.toLower()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user