Skip to content

Commit

Permalink
tmxrasterizer: Use smooth pixmap transform by default
Browse files Browse the repository at this point in the history
This is to increase the default quality of the rendered map, especially
when rendering thumbnails. It can be turned off separately from anti-
aliasing using the new --no-smoothing parameter.

Anti-aliasing remains off by default since it is usually not what you
want. It applies anti-aliasing to edges of primitives, including tiles.
This creates visible seems at tile boundaries when the tiles are not
pixel-aligned.
  • Loading branch information
bjorn committed Sep 30, 2016
1 parent 2a78eba commit dfa2b81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/tmxrasterizer/main.cpp
Expand Up @@ -43,6 +43,7 @@ struct CommandLineOptions {
, tileSize(0)
, size(0)
, useAntiAliasing(false)
, smoothImages(true)
, ignoreVisibility(false)
{}

Expand All @@ -54,6 +55,7 @@ struct CommandLineOptions {
int tileSize;
int size;
bool useAntiAliasing;
bool smoothImages;
bool ignoreVisibility;
QStringList layersToHide;
};
Expand All @@ -75,7 +77,8 @@ static void showHelp()
" Overrides the --scale option\n"
" --size SIZE : The output image fits within a SIZE x SIZE square\n"
" Overrides the --scale and --tilesize options\n"
" -a --anti-aliasing : Smooth the output image using anti-aliasing\n"
" -a --anti-aliasing : Antialias edges of primitives\n"
" --no-smoothing : Use nearest neighbour instead of smooth blending of pixels\n"
" --ignore-visibility : Ignore all layer visibility flags in the map file, and render all\n"
" layers in the output (default is to omit invisible layers)\n"
" --hide-layer : Specifies a layer to omit from the output image\n"
Expand Down Expand Up @@ -147,6 +150,8 @@ static void parseCommandLineArguments(CommandLineOptions &options)
} else if (arg == QLatin1String("--anti-aliasing")
|| arg == QLatin1String("-a")) {
options.useAntiAliasing = true;
} else if (arg == QLatin1String("--no-smoothing")) {
options.smoothImages = false;
} else if (arg == QLatin1String("--ignore-visibility")) {
options.ignoreVisibility = true;
} else if (arg.isEmpty()) {
Expand Down Expand Up @@ -195,6 +200,7 @@ int main(int argc, char *argv[])

TmxRasterizer w;
w.setAntiAliasing(options.useAntiAliasing);
w.setSmoothImages(options.smoothImages);
w.setIgnoreVisibility(options.ignoreVisibility);
w.setLayersToHide(options.layersToHide);

Expand All @@ -208,4 +214,3 @@ int main(int argc, char *argv[])

return w.render(options.fileToOpen, options.fileToSave);
}

13 changes: 5 additions & 8 deletions src/tmxrasterizer/tmxrasterizer.cpp
Expand Up @@ -47,7 +47,8 @@ TmxRasterizer::TmxRasterizer():
mScale(1.0),
mTileSize(0),
mSize(0),
mUseAntiAliasing(true),
mUseAntiAliasing(false),
mSmoothImages(true),
mIgnoreVisibility(false)
{
}
Expand Down Expand Up @@ -124,13 +125,9 @@ int TmxRasterizer::render(const QString &mapFileName,
image.fill(Qt::transparent);
QPainter painter(&image);

if (xScale != qreal(1) || yScale != qreal(1)) {
if (mUseAntiAliasing) {
painter.setRenderHints(QPainter::SmoothPixmapTransform |
QPainter::Antialiasing);
}
painter.setTransform(QTransform::fromScale(xScale, yScale));
}
painter.setRenderHint(QPainter::Antialiasing, mUseAntiAliasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform, mSmoothImages);
painter.setTransform(QTransform::fromScale(xScale, yScale));

painter.translate(margins.left(), margins.top());

Expand Down
3 changes: 3 additions & 0 deletions src/tmxrasterizer/tmxrasterizer.h
Expand Up @@ -46,12 +46,14 @@ class TmxRasterizer
qreal scale() const { return mScale; }
int tileSize() const { return mTileSize; }
bool useAntiAliasing() const { return mUseAntiAliasing; }
bool smoothImages() const { return mSmoothImages; }
bool IgnoreVisibility() const { return mIgnoreVisibility; }

void setScale(qreal scale) { mScale = scale; }
void setTileSize(int tileSize) { mTileSize = tileSize; }
void setSize(int size) { mSize = size; }
void setAntiAliasing(bool useAntiAliasing) { mUseAntiAliasing = useAntiAliasing; }
void setSmoothImages(bool smoothImages) { mSmoothImages = smoothImages; }
void setIgnoreVisibility(bool IgnoreVisibility) { mIgnoreVisibility = IgnoreVisibility; }

void setLayersToHide(QStringList layersToHide) { mLayersToHide = layersToHide; }
Expand All @@ -63,6 +65,7 @@ class TmxRasterizer
int mTileSize;
int mSize;
bool mUseAntiAliasing;
bool mSmoothImages;
bool mIgnoreVisibility;
QStringList mLayersToHide;

Expand Down

0 comments on commit dfa2b81

Please sign in to comment.