Add re-encoding of jpegs to baseline profile

This commit is contained in:
Anton Thomasson 2022-03-06 17:16:07 +01:00
parent bb6fa7926d
commit ef3b53abdb
7 changed files with 45 additions and 8 deletions

View file

@ -26,7 +26,7 @@ INSTALLS += i18n
system(lrelease $$PWD/translations/*.ts)
CONFIG += sailfishapp
PKGCONFIG += mlite5 libcurl poppler glib-2.0 cairo
PKGCONFIG += mlite5 libcurl poppler glib-2.0 cairo libjpeg
LIBS += -lcurl -lglib-2.0 -lgobject-2.0 -ldl
DEFINES += MADNESS=1
DEFINES += PDF_CREATOR='\\"SeaPrint\ $$VERSION\\"'
@ -42,6 +42,7 @@ SOURCES += src/harbour-seaprint.cpp \
src/mimer.cpp \
ppm2pwg/ppm2pwg.cpp \
ppm2pwg/pdf2printable.cpp \
ppm2pwg/baselinify.cpp \
ppm2pwg/bytestream/bytestream.cpp \
src/overrider.cpp \
src/printerworker.cpp \
@ -88,6 +89,7 @@ HEADERS += \
src/mimer.h \
ppm2pwg/ppm2pwg.h \
ppm2pwg/pdf2printable.h \
ppm2pwg/baselinify.h \
ppm2pwg/madness.h \
ppm2pwg/PwgPgHdr.h \
ppm2pwg/PwgPgHdr.codable \

@ -1 +1 @@
Subproject commit b36a5cf08687b06498e38f5a79bbe80594ab11ca
Subproject commit 4844ff3ce2b773ae43585039aae146b6d225e0a6

View file

@ -19,6 +19,7 @@ BuildRequires: pkgconfig(poppler)
BuildRequires: pkgconfig(poppler-glib)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(cairo)
BuildRequires: pkgconfig(libjpeg)
%description
Network printing for Sailfish OS

View file

@ -18,6 +18,7 @@ IppPrinter::IppPrinter() : _worker(this)
connect(this, &IppPrinter::doGetJobs, &_worker, &PrinterWorker::getJobs);
connect(this, &IppPrinter::doCancelJob, &_worker, &PrinterWorker::cancelJob);
connect(this, &IppPrinter::doJustUpload, &_worker, &PrinterWorker::justUpload);
connect(this, &IppPrinter::doFixupJpeg, &_worker, &PrinterWorker::fixupJpeg);
connect(this, &IppPrinter::doConvertPdf, &_worker, &PrinterWorker::convertPdf);
connect(this, &IppPrinter::doConvertImage, &_worker, &PrinterWorker::convertImage);
@ -621,11 +622,16 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
IppMsg job = mk_msg(o, jobAttrs);
Bytestream contents = job.encode(IppMsg::PrintJob);
// Shouldn't and can't process these formats respectively
if((mimeType == documentFormat) && (documentFormat == Mimer::JPEG || documentFormat == Mimer::Postscript))
{
setBusyMessage(tr("Preparing"));
if((mimeType == documentFormat) && (documentFormat == Mimer::Postscript))
{ // Can't process Postscript
emit doJustUpload(filename, contents);
}
else if((mimeType == documentFormat) && (documentFormat == Mimer::JPEG))
{ // Just make the jpeg baseline-encoded, don't resize locally
emit doFixupJpeg(filename, contents);
}
else
{
if(PaperSize == "")
@ -652,8 +658,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Tumble = true;
}
setBusyMessage(tr("Preparing"));
if(mimeType == Mimer::PDF)
{
emit doConvertPdf(filename, contents, documentFormat, Colors, Quality,

View file

@ -59,6 +59,7 @@ signals:
void doCancelJob(Bytestream msg);
void doJustUpload(QString filename, Bytestream header);
void doFixupJpeg(QString filename, Bytestream header);
void doConvertPdf(QString filename, Bytestream header,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,

View file

@ -11,6 +11,9 @@
#include "ippprinter.h"
#include "pdf2printable.h"
#include "ppm2pwg.h"
#include "baselinify.h"
#include <fstream>
#include <iostream>
#define OK(call) if(!(call)) throw ConvertFailedException()
@ -75,6 +78,29 @@ catch(const ConvertFailedException& e)
}
}
void PrinterWorker::fixupJpeg(QString filename, Bytestream header)
{
try {
CurlRequester cr(_printer->httpUrl());
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
std::ifstream ifs = std::ifstream(filename.toStdString(), std::ios::in | std::ios::binary);
Bytestream InBts(ifs);
Bytestream OutBts;
baselinify(InBts, OutBts);
emit busyMessage(tr("Printing"));
OK(cr.write((char*)header.raw(), header.size()));
OK(cr.write((char*)OutBts.raw(), OutBts.size()));
}
catch(const ConvertFailedException& e)
{
emit failed(e.what() == QString("") ? tr("Upload error") : e.what());
}
}
void PrinterWorker::convertPdf(QString filename, Bytestream header,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
@ -300,12 +326,13 @@ try {
bool verbose = QLoggingCategory::defaultCategory()->isDebugEnabled();
bmp_to_pwg(inBts, outBts, urf, 1, Colors, Quality, HwResX, HwResY, Width, Height, false, false, PaperSize.toStdString(), false, false, verbose);
emit busyMessage(tr("Printing"));
}
CurlRequester cr(_printer->httpUrl());
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
emit busyMessage(tr("Printing"));
OK(cr.write((char*)header.raw(), header.size()));
OK(cr.write((char*)(outBts.raw()), outBts.size()));
}

View file

@ -38,6 +38,8 @@ public slots:
void justUpload(QString filename, Bytestream header);
void fixupJpeg(QString filename, Bytestream header);
void convertPdf(QString filename, Bytestream header,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,