chore: improved jpeg format checking, port away from win32only code

This commit is contained in:
Gary Wang 2021-10-06 09:14:14 +08:00
parent a9171d1963
commit 9136e75e26
5 changed files with 20 additions and 17 deletions

View File

@ -1572,7 +1572,7 @@ void Caesium::runPreview()
} }
else if (ui->formatComboBox->currentIndex() == 3) 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()); image.save(tempFolder + "/_caesium_/" + rndString + ".cae", "jpg", ui->qualitySlider->value());
} }

View File

@ -1,6 +1,7 @@
/******************************************************************************* /*******************************************************************************
# #
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com> # Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
# 2021 Gary Wang <wzc782970009@gmail.com>
# #
# This file is part of the Caesium distribution. # This file is part of the Caesium distribution.
# #
@ -150,7 +151,7 @@ void CompressionThread::run()
if (sameFormat) if (sameFormat)
{ {
t_format = info.suffix(); t_format = info.suffix();
if (t_format.toLower() != "jpg") if (!isJpegSuffix(t_format))
{ {
t_quality.replace(i, "1"); t_quality.replace(i, "1");
} }
@ -268,7 +269,7 @@ void CompressionThread::noEnlarge()
if (sameFormat) if (sameFormat)
{ {
t_format = info.suffix(); t_format = info.suffix();
if (t_format.toLower() != "jpg") if (!isJpegSuffix(t_format))
{ {
t_quality.replace(i, "1"); 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; QFile origFile(orig), destFile(dest);
destFile.open(QIODevice::Append);
FILETIME ftCreate, ftAccess, ftWrite; destFile.setFileTime(origFile.fileTime(QFileDevice::FileAccessTime), QFileDevice::FileAccessTime);
hFile = CreateFile(qStringToWideChar(orig), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); destFile.setFileTime(origFile.fileTime(QFileDevice::FileBirthTime), QFileDevice::FileBirthTime);
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite); destFile.setFileTime(origFile.fileTime(QFileDevice::FileModificationTime), QFileDevice::FileModificationTime);
destFile.close();
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);
} }
void CompressionThread::optimizePNG(QString file, int level) void CompressionThread::optimizePNG(QString file, int level)

View File

@ -13,8 +13,7 @@ public:
QObject *parent); QObject *parent);
void run(); void run();
void noEnlarge(); void noEnlarge();
void writeToFile(QString orig, QString dest); void keepDate(const QString & orig, const QString & dest);
void keepDate(QString, QString);
void optimizePNG(QString file, int level); void optimizePNG(QString file, int level);
private: private:

View File

@ -33,3 +33,9 @@ bool same_folder_flag = false;
const int version_build = 170; const int version_build = 170;
const QString version_string = "1.7.0"; const QString version_string = "1.7.0";
QString opened_list = ""; QString opened_list = "";
bool isJpegSuffix(const QString &suffix)
{
const QStringList jpegSuffix({"jpg", "jpeg", "jfif"});
return (jpegSuffix.contains(suffix.toLower()));
}

View File

@ -11,4 +11,6 @@ extern const int version_build;
extern const QString version_string; extern const QString version_string;
extern QString opened_list; extern QString opened_list;
bool isJpegSuffix(const QString & suffix);
#endif // GLOBAL_H #endif // GLOBAL_H