Rasterizer fix to flip Y axis if it's coordinate origin is in the TOP_LEFT corner.
This commit is contained in:
parent
a5d6064ad6
commit
b82bc5feba
2 changed files with 19 additions and 5 deletions
|
@ -34,6 +34,8 @@ public:
|
||||||
static const TPixel ColorWhite;
|
static const TPixel ColorWhite;
|
||||||
static const TPixel ColorBlack;
|
static const TPixel ColorBlack;
|
||||||
|
|
||||||
|
using Origin = Raster::Origin;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Raster::Resolution resolution_;
|
Raster::Resolution resolution_;
|
||||||
Raster::PixelDim pxdim_;
|
Raster::PixelDim pxdim_;
|
||||||
|
@ -42,8 +44,10 @@ private:
|
||||||
TPixelRenderer pixfmt_;
|
TPixelRenderer pixfmt_;
|
||||||
TRawRenderer raw_renderer_;
|
TRawRenderer raw_renderer_;
|
||||||
TRendererAA renderer_;
|
TRendererAA renderer_;
|
||||||
|
Origin o_;
|
||||||
public:
|
public:
|
||||||
inline Impl(const Raster::Resolution& res, const Raster::PixelDim &pd):
|
inline Impl(const Raster::Resolution& res, const Raster::PixelDim &pd,
|
||||||
|
Origin o = Origin::TOP_LEFT):
|
||||||
resolution_(res), pxdim_(pd),
|
resolution_(res), pxdim_(pd),
|
||||||
buf_(res.pixels()),
|
buf_(res.pixels()),
|
||||||
rbuf_(reinterpret_cast<TPixelRenderer::value_type*>(buf_.data()),
|
rbuf_(reinterpret_cast<TPixelRenderer::value_type*>(buf_.data()),
|
||||||
|
@ -51,7 +55,8 @@ public:
|
||||||
res.width_px*TPixelRenderer::num_components),
|
res.width_px*TPixelRenderer::num_components),
|
||||||
pixfmt_(rbuf_),
|
pixfmt_(rbuf_),
|
||||||
raw_renderer_(pixfmt_),
|
raw_renderer_(pixfmt_),
|
||||||
renderer_(raw_renderer_)
|
renderer_(raw_renderer_),
|
||||||
|
o_(o)
|
||||||
{
|
{
|
||||||
renderer_.color(ColorWhite);
|
renderer_.color(ColorWhite);
|
||||||
|
|
||||||
|
@ -66,10 +71,13 @@ public:
|
||||||
agg::scanline_p8 scanlines;
|
agg::scanline_p8 scanlines;
|
||||||
|
|
||||||
auto&& path = to_path(poly.contour);
|
auto&& path = to_path(poly.contour);
|
||||||
|
if(o_ == Origin::TOP_LEFT) path.flip_y(0, resolution_.height_px);
|
||||||
ras.add_path(path);
|
ras.add_path(path);
|
||||||
|
|
||||||
for(auto h : poly.holes) {
|
for(auto h : poly.holes) {
|
||||||
auto&& holepath = to_path(h);
|
auto&& holepath = to_path(h);
|
||||||
|
if(o_ == Origin::TOP_LEFT)
|
||||||
|
holepath.flip_y(0, resolution_.height_px);
|
||||||
ras.add_path(holepath);
|
ras.add_path(holepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +117,8 @@ private:
|
||||||
const Raster::Impl::TPixel Raster::Impl::ColorWhite = Raster::Impl::TPixel(255);
|
const Raster::Impl::TPixel Raster::Impl::ColorWhite = Raster::Impl::TPixel(255);
|
||||||
const Raster::Impl::TPixel Raster::Impl::ColorBlack = Raster::Impl::TPixel(0);
|
const Raster::Impl::TPixel Raster::Impl::ColorBlack = Raster::Impl::TPixel(0);
|
||||||
|
|
||||||
Raster::Raster(const Resolution &r, const PixelDim &pd):
|
Raster::Raster(const Resolution &r, const PixelDim &pd, Origin o):
|
||||||
impl_(new Impl(r, pd)) {}
|
impl_(new Impl(r, pd, o)) {}
|
||||||
|
|
||||||
Raster::Raster() {}
|
Raster::Raster() {}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,11 @@ public:
|
||||||
PNG //!> PNG compression
|
PNG //!> PNG compression
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Origin {
|
||||||
|
TOP_LEFT,
|
||||||
|
BOTTOM_LEFT
|
||||||
|
};
|
||||||
|
|
||||||
/// Type that represents a resolution in pixels.
|
/// Type that represents a resolution in pixels.
|
||||||
struct Resolution {
|
struct Resolution {
|
||||||
unsigned width_px;
|
unsigned width_px;
|
||||||
|
@ -46,7 +51,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Constructor taking the resolution and the pixel dimension.
|
/// Constructor taking the resolution and the pixel dimension.
|
||||||
explicit Raster(const Resolution& r, const PixelDim& pd );
|
explicit Raster(const Resolution& r, const PixelDim& pd,
|
||||||
|
Origin o = Origin::TOP_LEFT );
|
||||||
Raster();
|
Raster();
|
||||||
Raster(const Raster& cpy) = delete;
|
Raster(const Raster& cpy) = delete;
|
||||||
Raster& operator=(const Raster& cpy) = delete;
|
Raster& operator=(const Raster& cpy) = delete;
|
||||||
|
|
Loading…
Reference in a new issue