Compare commits

..

No commits in common. "252ca8542a1a5746ae01784870d94f8891505e44" and "c12c2b44975ea0bbfe962eff22a64f855f3d8790" have entirely different histories.

3 changed files with 24 additions and 60 deletions

6
.gitignore vendored
View File

@ -1,6 +1,10 @@
# Object files
*.o
# Protobuf stuff
protobuf/vector_tile.pb.cc
protobuf/vector_tile.pb.h
# Qt stuff
/.qmake.stash
moc_*.cpp
@ -10,4 +14,4 @@ Makefile*
# lib
libpbf.so
libpbf.dylib
pbf.dylib

View File

@ -96,7 +96,7 @@ algorithm to work properly.
* Expressions are not supported in the styles, only property functions are implemented.
## Changelog
[Changelog](https://build.opensuse.org/projects/home:tumic:QtPBFImagePlugin/packages/QtPBFImagePlugin/files/qt6-qtpbfimageformat.changes)
[Changelog](https://build.opensuse.org/package/view_file/home:tumic:QtPBFImagePlugin/QtPBFImagePlugin/libqt5-qtpbfimageformat.changes)
## Status
A picture is worth a thousand words.

View File

@ -3,11 +3,6 @@
#define TYPE(tag) (tag & 0x07)
#define FIELD(tag) (tag >> 3)
#define VARINT 0
#define I64 1
#define LEN 2
#define I32 5
struct CTX
{
CTX(const QByteArray &ba)
@ -15,7 +10,7 @@ struct CTX
const char *bp;
const char *be;
quint32 tag;
quint64 tag;
};
static inline qint64 zigzag64decode(quint64 value)
@ -29,8 +24,9 @@ static bool varint(CTX &ctx, T &val)
{
val = 0;
uint shift = 0;
const char *end = qMin(ctx.be, ctx.bp + sizeof(val));
while (ctx.bp < ctx.be) {
while (ctx.bp < end) {
val |= ((quint8)*ctx.bp & 0x7F) << shift;
shift += 7;
if (!((quint8)*ctx.bp++ & 0x80))
@ -42,15 +38,12 @@ static bool varint(CTX &ctx, T &val)
static bool str(CTX &ctx, QByteArray &val)
{
qint32 len;
quint64 len;
if (TYPE(ctx.tag) != LEN)
return false;
if (!varint(ctx, len))
return false;
if (ctx.bp + len > ctx.be)
return false;
val = QByteArray::fromRawData(ctx.bp, len);
ctx.bp += len;
@ -59,26 +52,20 @@ static bool str(CTX &ctx, QByteArray &val)
static bool dbl(CTX &ctx, double &val)
{
if (TYPE(ctx.tag) != I64)
return false;
if (ctx.bp + sizeof(val) > ctx.be)
return false;
memcpy(&val, ctx.bp, sizeof(val));
ctx.bp += sizeof(val);
return true;
}
static bool flt(CTX &ctx, float &val)
{
if (TYPE(ctx.tag) != I32)
return false;
if (ctx.bp + sizeof(val) > ctx.be)
return false;
memcpy(&val, ctx.bp, sizeof(val));
ctx.bp += sizeof(val);
return true;
}
@ -87,8 +74,8 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
{
quint32 v;
if (TYPE(ctx.tag) == LEN) {
qint32 len;
if (TYPE(ctx.tag) == 2) {
quint64 len;
if (!varint(ctx, len))
return false;
const char *ee = ctx.bp + len;
@ -100,7 +87,7 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
vals.append(v);
}
return (ctx.bp == ee);
} else if (TYPE(ctx.tag) == VARINT) {
} else if (TYPE(ctx.tag) == 0) {
if (!varint(ctx, v))
return false;
vals.append(v);
@ -111,19 +98,19 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
static bool skip(CTX &ctx)
{
qint32 len = 0;
quint64 len = 0;
switch (TYPE(ctx.tag)) {
case VARINT:
case 0:
return varint(ctx, len);
case I64:
case 1:
len = 8;
break;
case LEN:
case 2:
if (!varint(ctx, len))
return false;
break;
case I32:
case 5:
len = 4;
break;
default:
@ -139,12 +126,8 @@ static bool skip(CTX &ctx)
static bool value(CTX &ctx, QVariant &val)
{
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
QByteArray ba;
quint64 num;
quint64 len, num;
double dnum;
float fnum;
@ -176,29 +159,21 @@ static bool value(CTX &ctx, QVariant &val)
val = QVariant(dnum);
break;
case 4:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(static_cast<qint64>(num));
break;
case 5:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(num);
break;
case 6:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(zigzag64decode(num));
break;
case 7:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, num))
return false;
val = QVariant(num ? true : false);
@ -214,12 +189,8 @@ static bool value(CTX &ctx, QVariant &val)
static bool feature(CTX &ctx, Data::Feature &f)
{
quint32 e;
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
quint64 len;
quint8 e;
if (!varint(ctx, len))
return false;
@ -233,8 +204,6 @@ static bool feature(CTX &ctx, Data::Feature &f)
switch (FIELD(ctx.tag)) {
case 1:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, f.id))
return false;
break;
@ -243,13 +212,11 @@ static bool feature(CTX &ctx, Data::Feature &f)
return false;
break;
case 3:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, e))
return false;
if (e > Data::GeomType::POLYGON)
return false;
f.type = static_cast<Data::GeomType>(e);
f.type = (Data::GeomType)e;
break;
case 4:
if (!packed(ctx, f.geometry))
@ -266,11 +233,8 @@ static bool feature(CTX &ctx, Data::Feature &f)
static bool layer(CTX &ctx, Data::Layer &l)
{
if (FIELD(ctx.tag) == 3) {
if (TYPE(ctx.tag) != LEN)
return false;
qint32 len;
if (ctx.tag == 0x1a) {
quint64 len;
if (!varint(ctx, len))
return false;
@ -303,14 +267,10 @@ static bool layer(CTX &ctx, Data::Layer &l)
return false;
break;
case 5:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, l.extent))
return false;
break;
case 15:
if (TYPE(ctx.tag) != VARINT)
return false;
if (!varint(ctx, l.version))
return false;
break;