Add Reverse-BMP format

This commit is contained in:
Anton Thomasson 2022-05-26 11:57:16 +02:00
parent 6ba065b4b1
commit ab96dc547f
13 changed files with 64 additions and 8 deletions

View file

@ -46,7 +46,7 @@ function supported_formats(printer, considerAdditionalFormats)
mimetypes = mimetypes.concat(Mimer.Mimer.OfficeFormats);
}
if (raster || has(formats, Mimer.Mimer.JPEG) || has(formats, Mimer.Mimer.PNG) ||
if (raster || has(formats, Mimer.Mimer.JPEG) || has(formats, Mimer.Mimer.PNG) || has(formats, Mimer.Mimer.RBMP) ||
has(formats, Mimer.Mimer.PDF) || has(formats, Mimer.Mimer.Postscript))
{
images = true;
@ -259,6 +259,8 @@ function ippName(name, value, printerStrings)
return qsTr("JPEG");
case Mimer.Mimer.GIF:
return qsTr("GIF");
case Mimer.Mimer.RBMP:
return qsTr("Reverse BMP");
default:
return value;
}
@ -407,7 +409,8 @@ function canConvertOfficeDocumentTo(type)
function canConvertImageTo(type)
{
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.JPEG, Mimer.Mimer.PNG, Mimer.Mimer.PWG, Mimer.Mimer.URF, Mimer.Mimer.PDF, Mimer.Mimer.Postscript];
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.JPEG, Mimer.Mimer.PNG, Mimer.Mimer.RBMP,
Mimer.Mimer.PWG, Mimer.Mimer.URF, Mimer.Mimer.PDF, Mimer.Mimer.Postscript];
return has(targets, type)
}

View file

@ -20,7 +20,7 @@ IppPrinter::IppPrinter() : _worker(this)
connect(this, &IppPrinter::doIdentify, &_worker, &PrinterWorker::identify);
connect(this, &IppPrinter::doJustUpload, &_worker, &PrinterWorker::justUpload);
connect(this, &IppPrinter::doFixupPlaintext, &_worker, &PrinterWorker::fixupPlaintext);
connect(this, &IppPrinter::doFixupImage, &_worker, &PrinterWorker::fixupImage);
connect(this, &IppPrinter::doPrintImageAsImage, &_worker, &PrinterWorker::printImageAsImage);
connect(this, &IppPrinter::doConvertPdf, &_worker, &PrinterWorker::convertPdf);
connect(this, &IppPrinter::doConvertImage, &_worker, &PrinterWorker::convertImage);
@ -691,7 +691,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
}
else if(mimer->isImage(targetFormat))
{ // Just make sure the image is in the desired format (and jpeg baseline-encoded), don't resize locally
emit doFixupImage(filename, contents, targetFormat);
emit doPrintImageAsImage(filename, contents, targetFormat);
}
else
{

View file

@ -62,7 +62,7 @@ signals:
void doJustUpload(QString filename, Bytestream header);
void doFixupPlaintext(QString filename, Bytestream header);
void doFixupImage(QString filename, Bytestream header, QString targetFormat);
void doPrintImageAsImage(QString filename, Bytestream header, QString targetFormat);
void doConvertPdf(QString filename, Bytestream header, PrintParameters Params);

View file

@ -11,6 +11,7 @@ const QString Mimer::PNG = "image/png";
const QString Mimer::GIF = "image/gif";
const QString Mimer::JPEG = "image/jpeg";
const QString Mimer::TIFF = "image/tiff";
const QString Mimer::RBMP = "image/reverse-encoding-bmp";
const QString Mimer::DOC = "application/msword";
const QString Mimer::DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

View file

@ -24,6 +24,7 @@ public:
Q_PROPERTY(const QString GIF MEMBER GIF CONSTANT);
Q_PROPERTY(const QString JPEG MEMBER JPEG CONSTANT);
Q_PROPERTY(const QString TIFF MEMBER TIFF CONSTANT);
Q_PROPERTY(const QString RBMP MEMBER RBMP CONSTANT);
Q_PROPERTY(const QString DOC MEMBER DOC CONSTANT);
Q_PROPERTY(const QString DOCX MEMBER DOCX CONSTANT);
@ -49,6 +50,7 @@ public:
static const QString GIF;
static const QString JPEG;
static const QString TIFF;
static const QString RBMP;
static const QString DOC;
static const QString DOCX;

View file

@ -85,13 +85,17 @@ catch(const ConvertFailedException& e)
}
}
void PrinterWorker::fixupImage(QString filename, Bytestream header, QString targetFormat)
void PrinterWorker::printImageAsImage(QString filename, Bytestream header, QString targetFormat)
{
try {
QString imageFormat = "";
QStringList supportedImageFormats = {Mimer::JPEG, Mimer::PNG};
if(supportedImageFormats.contains(targetFormat))
if(targetFormat == Mimer::RBMP)
{
// ok
}
else if(supportedImageFormats.contains(targetFormat))
{
imageFormat = targetFormat.split("/")[1];
}
@ -113,6 +117,28 @@ try {
baselinify(InBts, OutBts);
}
else if(targetFormat == Mimer::RBMP)
{
QImage inImage;
QBuffer buf;
if(!inImage.load(filename))
{
qDebug() << "failed to load";
throw ConvertFailedException(tr("Failed to load image"));
}
// TODO: calculate paper width minus margins
// (depends on understanding/parsing custom paper sizes)
int width = 576;
int height = inImage.height() * ((width*1.0)/inImage.width());
inImage = inImage.scaled(width, height);
inImage = inImage.convertToFormat(QImage::Format_Mono);
inImage = inImage.transformed(QMatrix().scale(1,-1));
buf.open(QIODevice::ReadWrite);
inImage.save(&buf, "bmp");
buf.seek(0);
OutBts = Bytestream(buf.size());
buf.read((char*)(OutBts.raw()), buf.size());
}
else if(targetFormat == mimeType)
{
std::ifstream ifs = std::ifstream(filename.toStdString(), std::ios::in | std::ios::binary);

View file

@ -40,7 +40,7 @@ public slots:
void justUpload(QString filename, Bytestream header);
void fixupImage(QString filename, Bytestream header, QString targetFormat);
void printImageAsImage(QString filename, Bytestream header, QString targetFormat);
void fixupPlaintext(QString filename, Bytestream header);

View file

@ -5501,5 +5501,9 @@ auf diesem Drucker</translation>
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -5500,5 +5500,9 @@
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -5501,5 +5501,9 @@ sur cette imprimante</translation>
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -5500,5 +5500,9 @@
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -5500,5 +5500,9 @@
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -5500,5 +5500,9 @@
<source>Plaintext</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reverse BMP</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>