move ppm2pwg to inside seaprint

This commit is contained in:
Anton Thomasson 2020-05-05 20:07:21 +02:00
parent cd31098279
commit 4519f0a13e
7 changed files with 24 additions and 761 deletions

View file

@ -24,11 +24,11 @@ write_file($$$$OUT_PWD/seaprint_version.h, VERSION_H)
SOURCES += src/harbour-seaprint.cpp \
src/convertworker.cpp \
src/ippdiscovery.cpp \
src/bytestream.cpp \
src/ippmsg.cpp \
src/ippprinter.cpp \
src/mimer.cpp
src/mimer.cpp \
ppm2pwg/ppm2pwg.cpp \
ppm2pwg/bytestream/bytestream.cpp
DISTFILES += qml/harbour-seaprint.qml \
qml/cover/CoverPage.qml \
@ -62,18 +62,13 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \
HEADERS += \
src/convertworker.h \
src/ippdiscovery.h \
src/bytestream.h \
src/ippmsg.h \
src/ippprinter.h \
src/mimer.h
src/mimer.h \
ppm2pwg/pwg_pghdr_codable.h \
ppm2pwg/urf_pghdr_codable.h \
ppm2pwg/bytestream/bytestream.h \
ppm2pwg/bytestream/codable.h
QMAKE_EXTRA_TARGETS += PPM2PWG
PRE_TARGETDEPS += PPM2PWG
PPM2PWG.commands = make -C $$PWD/ppm2pwg
PPM2PWG.clean_commands = git submodule foreach git clean -fdxq
PPM2PWG.path = /usr/share/harbour-seaprint/
PPM2PWG.files += $$PWD/ppm2pwg/ppm2pwg
INSTALLS += PPM2PWG
QMAKE_INSTALL_FILE = install -m 755 -p
INCLUDEPATH += ppm2pwg \
ppm2pwg/bytestream

@ -1 +1 @@
Subproject commit a3ea2da52a0b8432ba7e6ec59451ae3887b1a111
Subproject commit ec851c5286fecfdded0bdf76453362a1829cc5c8

View file

@ -1,553 +0,0 @@
#include "bytestream.h"
#include <iostream>
#include <cstdint>
#include <cstring>
using namespace std;
Bytestream::Bytestream()
{
_size = 0;
_pos = 0;
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
_endianness = BigEndian;
}
Bytestream::Bytestream(size_t len)
{
_size = len;
_data = new uint8_t[_size];
memset(_data, 0, _size);
_pos = 0;
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
_endianness = BigEndian;
}
Bytestream::Bytestream(const void* data, size_t len)
{
_size = len;
_data = new uint8_t[_size];
memcpy(_data, data, _size);
_pos = 0;
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
_endianness = BigEndian;
}
Bytestream::Bytestream(const void* data, size_t len, Endianness e)
{
_size = len;
_data = new uint8_t[_size];
memcpy(_data, data, _size);
_pos = 0;
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
_endianness = e;
}
Bytestream::Bytestream(const Bytestream& rhs)
{
_size = rhs._size;
_data = new uint8_t[_size];
memcpy(_data, rhs._data, _size);
_pos = rhs._pos;
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
_endianness = rhs._endianness;
}
Bytestream::~Bytestream()
{
if(_size != 0)
{
delete _data;
}
}
bool Bytestream::operator==(const Bytestream& other) const
{
if(_size != other.size())
{
return false;
}
return memcmp(_data, other.raw(), _size) == 0;
}
bool Bytestream::operator!=(const Bytestream& other) const
{
if(_size != other.size())
{
return true;
}
return memcmp(_data, other.raw(), _size) != 0;
}
Bytestream& Bytestream::operator=(const Bytestream& other)
{
if(_size != 0)
{
delete _data;
}
_pos = other.pos();
_size = other.size();
_data = new uint8_t[_size];
memcpy(_data, other.raw(), _size);
return *this;
}
template <typename T>
T bswap(T u)
{
uint8_t* const p = reinterpret_cast<uint8_t*>(&u);
for (size_t i = 0; i < sizeof(T) / 2; i++)
{
std::swap(p[i], p[sizeof(T) - i - 1]);
}
return u;
}
#define GET(type, shorthand, len) GET_(type##len##_t, shorthand##len, len)
#define GET_(type, shortType, len) \
type Bytestream::get##shortType() \
{type tmp; getBytes(&tmp, sizeof(type));\
if(needsSwap()){tmp=bswap(tmp);} return tmp;}
GET(uint, U, 8)
GET(uint, U, 16)
GET(uint, U, 32)
GET(uint, U, 64)
GET(int, S, 8)
GET(int, S, 16)
GET(int, S, 32)
GET(int, S, 64)
GET(float, F, 32)
GET(float, F, 64)
std::string Bytestream::getString()
{
if(!_noOfNextBytesValid)
{
throw invalid_argument("No length given");
}
char* cs = new char[_noOfNextBytes+1];
cs[_noOfNextBytes] = 0;
getBytes(cs, _noOfNextBytes);
string s = std::string(cs, _noOfNextBytes);
delete cs;
return s;
}
Bytestream Bytestream::getBytestream()
{
if(!_noOfNextBytesValid)
{
throw invalid_argument("No length given");
}
uint8_t* cs = new uint8_t[_noOfNextBytes];
getBytes(cs, _noOfNextBytes);
Bytestream other = Bytestream(cs, _noOfNextBytes);
delete cs;
return other;
}
std::string Bytestream::getString(size_t len)
{
if(_noOfNextBytesValid && len != _noOfNextBytes)
{
throw logic_error("Desired lengths does not match");
}
else if(!_noOfNextBytesValid)
{
setNoOfNextBytes(len);
}
return getString();
}
Bytestream Bytestream::getBytestream(size_t len)
{
if(!_noOfNextBytesValid && len != _noOfNextBytes)
{
throw logic_error("Desired lengths does not match");
}
setNoOfNextBytes(len);
return getBytestream();
}
void Bytestream::getBytes(void* cs, size_t len)
{
_before(len);
memcpy(cs, &(_data[_pos]), len);
_after(len);
}
#define PEEK(type, shorthand, len) PEEK_(type##len##_t, shorthand##len, len)
#define PEEK_(type, shortType, len) \
type Bytestream::peek##shortType() \
{type tmp; getBytes(&tmp, sizeof(type));\
if(needsSwap()){tmp=bswap(tmp);} (*this) -= sizeof(type); return tmp;}
PEEK(uint, U, 8)
PEEK(uint, U, 16)
PEEK(uint, U, 32)
PEEK(uint, U, 64)
PEEK(int, S, 8)
PEEK(int, S, 16)
PEEK(int, S, 32)
PEEK(int, S, 64)
PEEK(float, F, 32)
PEEK(float, F, 64)
std::string Bytestream::peekString()
{
if(!_noOfNextBytesValid)
{
throw invalid_argument("No length given");
}
char* cs = new char[_noOfNextBytes+1];
cs[_noOfNextBytes] = 0;
getBytes(cs, _noOfNextBytes);
string s = std::string(cs, _noOfNextBytes);
delete cs;
(*this) -= _noOfNextBytes;
return s;
}
Bytestream Bytestream::peekBytestream()
{
if(!_noOfNextBytesValid)
{
throw invalid_argument("No length given");
}
uint8_t* cs = new uint8_t[_noOfNextBytes];
getBytes(cs, _noOfNextBytes);
Bytestream other = Bytestream(cs, _noOfNextBytes);
delete cs;
(*this) -= _noOfNextBytes;
return other;
}
std::string Bytestream::peekString(size_t len)
{
if(_noOfNextBytesValid && len != _noOfNextBytes)
{
throw logic_error("Desired lengths does not match");
}
else if(!_noOfNextBytesValid)
{
setNoOfNextBytes(len);
}
return peekString();
}
Bytestream Bytestream::peekBytestream(size_t len)
{
if(!_noOfNextBytesValid && len != _noOfNextBytes)
{
throw logic_error("Desired lengths does not match");
}
setNoOfNextBytes(len);
return peekBytestream();
}
#define NEXT(type, shorthand, len) NEXT_(type##len##_t, shorthand##len)
#define NEXT_(type, shortType) \
bool Bytestream::next##shortType(type u) \
{if(u == get##shortType())\
{return true;} \
else\
{(*this) -= sizeof(type);\
return false;}}
NEXT(uint, U, 8)
NEXT(uint, U, 16)
NEXT(uint, U, 32)
NEXT(uint, U, 64)
NEXT(int, S, 8)
NEXT(int, S, 16)
NEXT(int, S, 32)
NEXT(int, S, 64)
NEXT(float, F, 32)
NEXT(float, F, 64)
bool Bytestream::nextString(const std::string& s)
{
if(_noOfNextBytesValid && getNoOfNextBytes() != s.length())
{
throw logic_error("Desired length does not match const length");
}
else if(!_noOfNextBytesValid)
{
setNoOfNextBytes(s.length());
}
size_t noOfNextBytes = getNoOfNextBytes();
if(noOfNextBytes > remaining())
{
invalidateNoOfNextBytes();
return false;
}
if(getString() == s)
{
return true;
}
else
{
(*this) -= noOfNextBytes;
return false;
}
}
bool Bytestream::nextBytestream(const Bytestream& other)
{
if(_noOfNextBytesValid && getNoOfNextBytes() != other.size())
{
throw logic_error("Desired length does not match const length");
}
else if(!_noOfNextBytesValid)
{
setNoOfNextBytes(other.size());
}
size_t noOfNextBytes = getNoOfNextBytes();
if(noOfNextBytes > remaining())
{
invalidateNoOfNextBytes();
return false;
}
if(getBytestream() == other)
{
return true;
}
else
{
(*this) -= noOfNextBytes;
return false;
}
}
#define PUT(type, shorthand, len) PUT_(type##len##_t, shorthand##len, len)
#define PUT_(type, shortType, len) \
void Bytestream::put##shortType(type u) \
{if(needsSwap()){u=bswap(u);} \
putBytes(&u, sizeof(u));}
PUT(uint, U, 8)
PUT(uint, U, 16)
PUT(uint, U, 32)
PUT(uint, U, 64)
PUT(int, S, 8)
PUT(int, S, 16)
PUT(int, S, 32)
PUT(int, S, 64)
PUT(float, F, 32)
PUT(float, F, 64)
void Bytestream::putString(const std::string& s)
{
putBytes(s.c_str(), s.length());
}
void Bytestream::putBytestream(const Bytestream& other)
{
putBytes(other.raw(), other.size());
}
void Bytestream::putBytes(const void* c, size_t len)
{
uint8_t* old = _data;
_data = new uint8_t[_size+len];
if (_size != 0)
{
memcpy(_data, old, _size);
delete old;
}
memcpy((_data+_size), c, len);
_size += len;
}
void Bytestream::setNoOfNextBytes(size_t n)
{
_noOfNextBytes = n;
_noOfNextBytesValid = true;
}
void Bytestream::invalidateNoOfNextBytes()
{
_noOfNextBytes = 0;
_noOfNextBytesValid = false;
}
void Bytestream::_before(size_t bytesToRead)
{
if(bytesToRead > remaining())
{
invalidateNoOfNextBytes();
throw out_of_range("Tried to read past end");
}
}
void Bytestream::_after(size_t bytesRead)
{
_pos += bytesRead;
_noOfNextBytesValid = false;
}
Bytestream Bytestream::operator[](size_t i)
{
Bytestream tmp(_data+i, _size-i);
return tmp;
}
Bytestream& Bytestream::operator+=(size_t i)
{
if((_pos+i) > _size)
{
invalidateNoOfNextBytes();
throw out_of_range("Tried to address data past end");
}
_pos += i;
return *this;
}
Bytestream& Bytestream::operator-=(size_t i)
{
_pos -= i;
return *this;
}
Bytestream& Bytestream::operator/(int i)
{
setNoOfNextBytes(i);
return *this;
}
#define PUTOP(type, shorthand, len) PUTOP_(type##len##_t, shorthand##len)
#define PUTOP_(type, shortType) \
Bytestream& Bytestream::operator<<(const type& u) \
{put##shortType(u); return *this;}
PUTOP(uint, U, 8)
PUTOP(uint, U, 16)
PUTOP(uint, U, 32)
PUTOP(uint, U, 64)
PUTOP(int, S, 8)
PUTOP(int, S, 16)
PUTOP(int, S, 32)
PUTOP(int, S, 64)
PUTOP(float, F, 32)
PUTOP(float, F, 64)
Bytestream& Bytestream::operator<<(const std::string& s)
{
putString(s);
return *this;
}
Bytestream& Bytestream::operator<<(const Bytestream& other)
{
putBytestream(other);
return *this;
}
#define GETOP(type, shorthand, len) GETOP_(type##len##_t, shorthand##len)
#define GETOP_(type, shortType) \
Bytestream& Bytestream::operator>>(type& u) \
{u = get##shortType(); return *this;}
GETOP(uint, U, 8)
GETOP(uint, U, 16)
GETOP(uint, U, 32)
GETOP(uint, U, 64)
GETOP(int, S, 8)
GETOP(int, S, 16)
GETOP(int, S, 32)
GETOP(int, S, 64)
GETOP(float, F, 32)
GETOP(float, F, 64)
Bytestream& Bytestream::operator>>(std::string& s)
{
s = getString();
return *this;
}
Bytestream& Bytestream::operator>>(Bytestream& other)
{
other = getBytestream();
return *this;
}
#define GETOP_CONST(type, shorthand, len) \
GETOP_CONST_(type##len##_t, shorthand##len)
#define GETOP_CONST_(type, shortType) \
Bytestream& Bytestream::operator>>(const type& u) \
{type v = get##shortType();\
if(u!=v) {(*this) -= sizeof(type);\
throw Badmatch("Does not match const", v, u);}\
else{return *this;}}
GETOP_CONST(uint, U, 8)
GETOP_CONST(uint, U, 16)
GETOP_CONST(uint, U, 32)
GETOP_CONST(uint, U, 64)
GETOP_CONST(int, S, 8)
GETOP_CONST(int, S, 16)
GETOP_CONST(int, S, 32)
GETOP_CONST(int, S, 64)
GETOP_CONST(float, F, 32)
GETOP_CONST(float, F, 64)
Bytestream& Bytestream::operator>>(const std::string& s)
{
if (_noOfNextBytesValid && getNoOfNextBytes() != s.length())
{
throw logic_error("Desired length does not match const length");
}
else if(!_noOfNextBytesValid)
{
setNoOfNextBytes(s.length());
}
std::string sv = getString();
if(sv != s)
{
(*this) -= s.length();
throw Badmatch("Does not match const", sv, s);
}
return *this;
}
#define NEXTOP(type, shorthand, len) NEXTOP_(type##len##_t, shorthand##len)
#define NEXTOP_(type, shortType) \
bool Bytestream::operator>>=(const type& u) \
{return next##shortType(u);}
NEXTOP(uint, U, 8)
NEXTOP(uint, U, 16)
NEXTOP(uint, U, 32)
NEXTOP(uint, U, 64)
NEXTOP(int, S, 8)
NEXTOP(int, S, 16)
NEXTOP(int, S, 32)
NEXTOP(int, S, 64)
NEXTOP(float, F, 32)
NEXTOP(float, F, 64)
bool Bytestream::operator>>=(const std::string& s)
{
return nextString(s);
}
bool Bytestream::operator>>=(const Bytestream& other)
{
return nextBytestream(other);
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
bool Bytestream::needsSwap()
{
return _endianness != Endianness::NativeEndian
&& _endianness != Endianness::LittleEndian;
}
#elif __BYTE_ORDER == __BIG_ENDIAN
bool Bytestream::needsSwap()
{
return _endianness != Endianness::NativeEndian
&& _endianness != Endianness::BigEndian;
}
#else
#error
#endif

View file

@ -1,189 +0,0 @@
#ifndef BYTESTREAM_H
#define BYTESTREAM_H
#include <string>
#include <stdexcept>
#include <byteswap.h>
#ifndef __STDC_IEC_559__
#error "Double must be IEEE 754"
#endif
#define float32_t float
#define float64_t double
class Bytestream
{
public:
class Badmatch : public std::invalid_argument::invalid_argument
{
public:
Badmatch(std::string s, std::string v, std::string u) :
invalid_argument(s+": "+v+" != "+u) {}
template<typename T>
Badmatch(std::string s, T v, T u) :
invalid_argument(s+": "+std::to_string(v)+" != "+std::to_string(u)) {}
};
enum Endianness {
NativeEndian,
BigEndian,
LittleEndian
};
Bytestream();
Bytestream(size_t len);
Bytestream(const void* data, size_t len);
Bytestream(const void* data, size_t len, Endianness e);
Bytestream(const Bytestream& rhs);
~Bytestream();
bool operator==(const Bytestream& other) const;
bool operator!=(const Bytestream& other) const;
Bytestream& operator=(const Bytestream& other);
uint8_t* raw() const {return _data;}
size_t size() const {return _size;}
size_t pos() const {return _pos;}
size_t remaining() const {return _size - _pos;}
bool atEnd() const {return _pos >= _size;}
void setPos(size_t pos) {_pos = pos;}
Endianness getEndianness() {return _endianness;}
void setEndianness(Endianness e) {_endianness = e;}
uint8_t getU8();
uint16_t getU16();
uint32_t getU32();
uint64_t getU64();
int8_t getS8();
int16_t getS16();
int32_t getS32();
int64_t getS64();
float32_t getF32();
float64_t getF64();
std::string getString();
Bytestream getBytestream();
std::string getString(size_t len);
Bytestream getBytestream(size_t len);
void getBytes(void* cs, size_t len);
uint8_t peekU8();
uint16_t peekU16();
uint32_t peekU32();
uint64_t peekU64();
int8_t peekS8();
int16_t peekS16();
int32_t peekS32();
int64_t peekS64();
float32_t peekF32();
float64_t peekF64();
std::string peekString();
Bytestream peekBytestream();
std::string peekString(size_t len);
Bytestream peekBytestream(size_t len);
bool nextU8(uint8_t);
bool nextU16(uint16_t);
bool nextU32(uint32_t);
bool nextU64(uint64_t);
bool nextS8(int8_t);
bool nextS16(int16_t);
bool nextS32(int32_t);
bool nextS64(int64_t);
bool nextF32(float32_t);
bool nextF64(float64_t);
bool nextString(const std::string& bts);
bool nextBytestream(const Bytestream& bts);
void putU8(uint8_t);
void putU16(uint16_t);
void putU32(uint32_t);
void putU64(uint64_t);
void putS8(int8_t);
void putS16(int16_t);
void putS32(int32_t);
void putS64(int64_t);
void putF32(float32_t);
void putF64(float64_t);
void putString(const std::string&);
void putBytestream(const Bytestream&);
void putBytes(const void* c, size_t len);
void setNoOfNextBytes(size_t n);
void invalidateNoOfNextBytes();
size_t getNoOfNextBytes() {return _noOfNextBytes;}
bool noOfNextBytesValid() const {return _noOfNextBytesValid;}
Bytestream operator[](size_t i);
Bytestream& operator+=(size_t i);
Bytestream& operator-=(size_t i);
Bytestream& operator/(int i);
Bytestream& operator<<(const uint8_t& u);
Bytestream& operator<<(const uint16_t& u);
Bytestream& operator<<(const uint32_t& u);
Bytestream& operator<<(const uint64_t& u);
Bytestream& operator<<(const int8_t& u);
Bytestream& operator<<(const int16_t& u);
Bytestream& operator<<(const int32_t& u);
Bytestream& operator<<(const int64_t& u);
Bytestream& operator<<(const float32_t& u);
Bytestream& operator<<(const float64_t& u);
Bytestream& operator<<(const std::string& s);
Bytestream& operator<<(const Bytestream& other);
Bytestream& operator>>(uint8_t& u);
Bytestream& operator>>(uint16_t& u);
Bytestream& operator>>(uint32_t& u);
Bytestream& operator>>(uint64_t& u);
Bytestream& operator>>(int8_t& u);
Bytestream& operator>>(int16_t& u);
Bytestream& operator>>(int32_t& u);
Bytestream& operator>>(int64_t& u);
Bytestream& operator>>(float32_t& u);
Bytestream& operator>>(float64_t& u);
Bytestream& operator>>(std::string& s);
Bytestream& operator>>(Bytestream& other);
Bytestream& operator>>(const uint8_t& u);
Bytestream& operator>>(const uint16_t& u);
Bytestream& operator>>(const uint32_t& u);
Bytestream& operator>>(const uint64_t& u);
Bytestream& operator>>(const int8_t& u);
Bytestream& operator>>(const int16_t& u);
Bytestream& operator>>(const int32_t& u);
Bytestream& operator>>(const int64_t& u);
Bytestream& operator>>(const float32_t& u);
Bytestream& operator>>(const float64_t& u);
Bytestream& operator>>(const std::string& s);
bool operator>>=(const uint8_t& u);
bool operator>>=(const uint16_t& u);
bool operator>>=(const uint32_t& u);
bool operator>>=(const uint64_t& u);
bool operator>>=(const int8_t& u);
bool operator>>=(const int16_t& u);
bool operator>>=(const int32_t& u);
bool operator>>=(const int64_t& u);
bool operator>>=(const float32_t& u);
bool operator>>=(const float64_t& u);
bool operator>>=(const std::string& s);
bool operator>>=(const Bytestream& other);
private:
uint8_t* _data;
size_t _size;
size_t _pos;
size_t _noOfNextBytes;
bool _noOfNextBytesValid;
Endianness _endianness;
bool needsSwap();
void _after(size_t bytesRead);
void _before(size_t bytesToRead);
};
#endif

View file

@ -11,8 +11,9 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename,
QProcess* ppm2pwg = new QProcess(this);
QString Ppm2pwgPath = SailfishApp::pathTo("ppm2pwg").toString().remove("file://");
ppm2pwg->setProgram(Ppm2pwgPath);
// Yo dwag, I heard you like programs...
ppm2pwg->setProgram("harbour-seaprint");
ppm2pwg->setArguments({"ppm2pwg"});
QStringList env; // {"PREPEND_FILE="+tempfile->fileName()};
if(apple)

View file

@ -6,6 +6,9 @@
#include <src/ippprinter.h>
#include <src/mimer.h>
#define PPM2PWG_MAIN ppm2pwg_main
#include <ppm2pwg/ppm2pwg.cpp>
template <class T>
static QObject* singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
@ -19,6 +22,12 @@ static QObject* singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngi
int main(int argc, char *argv[])
{
if(argc >= 1 && QString("ppm2pwg") == argv[1])
{
return ppm2pwg_main(argc-1, &(argv[1]));
}
QGuiApplication* app = SailfishApp::application(argc, argv);
app->setApplicationVersion(QStringLiteral(SEAPRINT_VERSION));

View file

@ -279,7 +279,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
qDebug() << supportedMimeTypes << supportedMimeTypes.contains(mimeType);
if(from == Pdf)
if(from == Pdf /*&& !supportedMimeTypes.contains("application/pdf")*/)
{
if(supportedMimeTypes.contains("image/pwg-raster"))
{