Add image-to-raster conversions
This commit is contained in:
parent
16e6d8d766
commit
f7aba42af2
4 changed files with 101 additions and 19 deletions
|
@ -97,3 +97,71 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
||||||
emit done(request, tempfile);
|
emit done(request, tempfile);
|
||||||
qDebug() << "posted";
|
qDebug() << "posted";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConvertWorker::convertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||||
|
bool urf, quint32 Colors, quint32 Quality, quint32 HwResX, quint32 HwResY)
|
||||||
|
{
|
||||||
|
quint32 Width = 210.0/25.4*HwResX;
|
||||||
|
quint32 Height = 297.0/25.4*HwResY;
|
||||||
|
|
||||||
|
QImage inImage;
|
||||||
|
if(!inImage.load(filename))
|
||||||
|
{
|
||||||
|
qDebug() << "failed to load";
|
||||||
|
emit failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inImage.width() > inImage.height())
|
||||||
|
{
|
||||||
|
inImage = inImage.transformed(QMatrix().rotate(90.0));
|
||||||
|
}
|
||||||
|
inImage = inImage.scaled(Width, Height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
QImage outImage = QImage(Width, Height, inImage.format());
|
||||||
|
outImage.fill(Qt::white);
|
||||||
|
QPainter painter(&outImage);
|
||||||
|
painter.drawImage(0,0, inImage);
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
QTemporaryFile tmpImage;
|
||||||
|
tmpImage.open();
|
||||||
|
qDebug() << "Raw image: " << tmpImage.fileName();
|
||||||
|
outImage.save(tmpImage.fileName(), Colors == 1 ? "pgm" : "ppm");
|
||||||
|
tmpImage.close();
|
||||||
|
|
||||||
|
QProcess* ppm2pwg = new QProcess(this);
|
||||||
|
// Yo dawg, I heard you like programs...
|
||||||
|
ppm2pwg->setProgram("harbour-seaprint");
|
||||||
|
ppm2pwg->setArguments({"ppm2pwg"});
|
||||||
|
|
||||||
|
QStringList env;
|
||||||
|
ppm2PwgEnv(env, urf, Quality, HwResX, HwResY, false, false);
|
||||||
|
qDebug() << "ppm2pwg env is " << env;
|
||||||
|
|
||||||
|
ppm2pwg->setEnvironment(env);
|
||||||
|
ppm2pwg->setStandardInputFile(tmpImage.fileName());
|
||||||
|
ppm2pwg->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
|
||||||
|
|
||||||
|
connect(ppm2pwg, SIGNAL(finished(int, QProcess::ExitStatus)), ppm2pwg, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
qDebug() << "All connected";
|
||||||
|
ppm2pwg->start();
|
||||||
|
|
||||||
|
qDebug() << "Starting";
|
||||||
|
|
||||||
|
if(!ppm2pwg->waitForStarted())
|
||||||
|
{
|
||||||
|
qDebug() << "ppm2pwg died";
|
||||||
|
tempfile->deleteLater();
|
||||||
|
emit failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug() << "All started";
|
||||||
|
|
||||||
|
ppm2pwg->waitForFinished();
|
||||||
|
|
||||||
|
qDebug() << "Finished";
|
||||||
|
|
||||||
|
emit done(request, tempfile);
|
||||||
|
qDebug() << "posted";
|
||||||
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@ public slots:
|
||||||
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||||
bool urf, quint32 Colors, quint32 Quality,
|
bool urf, quint32 Colors, quint32 Quality,
|
||||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||||
//convertImage();
|
|
||||||
|
void convertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||||
|
bool urf, quint32 Colors, quint32 Quality, quint32 HwResX, quint32 HwResY);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done(QNetworkRequest request, QTemporaryFile* data);
|
void done(QNetworkRequest request, QTemporaryFile* data);
|
||||||
|
|
|
@ -30,6 +30,7 @@ IppPrinter::IppPrinter()
|
||||||
connect(&_workerThread, &QThread::finished, _worker, &QObject::deleteLater);
|
connect(&_workerThread, &QThread::finished, _worker, &QObject::deleteLater);
|
||||||
|
|
||||||
connect(this, &IppPrinter::doConvertPdf, _worker, &ConvertWorker::convertPdf);
|
connect(this, &IppPrinter::doConvertPdf, _worker, &ConvertWorker::convertPdf);
|
||||||
|
connect(this, &IppPrinter::doConvertImage, _worker, &ConvertWorker::convertImage);
|
||||||
connect(_worker, &ConvertWorker::done, this, &IppPrinter::convertDone);
|
connect(_worker, &ConvertWorker::done, this, &IppPrinter::convertDone);
|
||||||
connect(_worker, &ConvertWorker::failed, this, &IppPrinter::convertFailed);
|
connect(_worker, &ConvertWorker::failed, this, &IppPrinter::convertFailed);
|
||||||
|
|
||||||
|
@ -275,14 +276,14 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
||||||
from = Pdf;
|
from = Pdf;
|
||||||
}
|
}
|
||||||
else if (mimeType.contains("image")) {
|
else if (mimeType.contains("image")) {
|
||||||
// from = Image; TODO: handle image conversions
|
from = Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
||||||
|
|
||||||
qDebug() << supportedMimeTypes << supportedMimeTypes.contains(mimeType);
|
qDebug() << supportedMimeTypes << supportedMimeTypes.contains(mimeType);
|
||||||
|
|
||||||
if(from == Pdf /*&& !supportedMimeTypes.contains("application/pdf")*/)
|
if(from == Image || (from == Pdf /*&& !supportedMimeTypes.contains("application/pdf")*/))
|
||||||
{
|
{
|
||||||
if(supportedMimeTypes.contains("image/pwg-raster"))
|
if(supportedMimeTypes.contains("image/pwg-raster"))
|
||||||
{
|
{
|
||||||
|
@ -303,23 +304,10 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
||||||
QString PrintColorMode = getAttrOrDefault(attrs, "print-color-mode").toString();
|
QString PrintColorMode = getAttrOrDefault(attrs, "print-color-mode").toString();
|
||||||
quint32 Colors = PrintColorMode=="color" ? 3 : PrintColorMode=="monochrome" ? 1 : 0;
|
quint32 Colors = PrintColorMode=="color" ? 3 : PrintColorMode=="monochrome" ? 1 : 0;
|
||||||
|
|
||||||
if(from == Pdf && target != NoConvert)
|
if(target != NoConvert)
|
||||||
{
|
{
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
QString Sides = getAttrOrDefault(attrs, "sides").toString();
|
|
||||||
bool TwoSided = false;
|
|
||||||
bool Tumble = false;
|
|
||||||
if(Sides=="two-sided-long-edge")
|
|
||||||
{
|
|
||||||
TwoSided = true;
|
|
||||||
}
|
|
||||||
else if(Sides=="two-sided-short-edge")
|
|
||||||
{
|
|
||||||
TwoSided = true;
|
|
||||||
Tumble = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTemporaryFile* tempfile = new QTemporaryFile();
|
QTemporaryFile* tempfile = new QTemporaryFile();
|
||||||
tempfile->open();
|
tempfile->open();
|
||||||
tempfile->write(contents);
|
tempfile->write(contents);
|
||||||
|
@ -328,8 +316,29 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
||||||
|
|
||||||
setBusyMessage("Converting");
|
setBusyMessage("Converting");
|
||||||
|
|
||||||
emit doConvertPdf(request, filename, tempfile, target==UrfConvert, Colors, Quality,
|
if(from == Pdf )
|
||||||
HwResX, HwResY, TwoSided, Tumble);
|
{
|
||||||
|
|
||||||
|
QString Sides = getAttrOrDefault(attrs, "sides").toString();
|
||||||
|
bool TwoSided = false;
|
||||||
|
bool Tumble = false;
|
||||||
|
if(Sides=="two-sided-long-edge")
|
||||||
|
{
|
||||||
|
TwoSided = true;
|
||||||
|
}
|
||||||
|
else if(Sides=="two-sided-short-edge")
|
||||||
|
{
|
||||||
|
TwoSided = true;
|
||||||
|
Tumble = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit doConvertPdf(request, filename, tempfile, target==UrfConvert, Colors, Quality,
|
||||||
|
HwResX, HwResY, TwoSided, Tumble);
|
||||||
|
}
|
||||||
|
else if (from == Image)
|
||||||
|
{
|
||||||
|
emit doConvertImage(request, filename, tempfile, target==UrfConvert, Colors, Quality, HwResX, HwResY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,6 +56,9 @@ signals:
|
||||||
bool urf, quint32 Colors, quint32 Quality,
|
bool urf, quint32 Colors, quint32 Quality,
|
||||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||||
|
|
||||||
|
void doConvertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, bool urf,
|
||||||
|
quint32 Colors, quint32 Quality, quint32 HwResX, quint32 HwResY);
|
||||||
|
|
||||||
void busyMessageChanged();
|
void busyMessageChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Reference in a new issue