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 ColorBlack;
|
||||
|
||||
using Origin = Raster::Origin;
|
||||
|
||||
private:
|
||||
Raster::Resolution resolution_;
|
||||
Raster::PixelDim pxdim_;
|
||||
|
@ -42,8 +44,10 @@ private:
|
|||
TPixelRenderer pixfmt_;
|
||||
TRawRenderer raw_renderer_;
|
||||
TRendererAA renderer_;
|
||||
Origin o_;
|
||||
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),
|
||||
buf_(res.pixels()),
|
||||
rbuf_(reinterpret_cast<TPixelRenderer::value_type*>(buf_.data()),
|
||||
|
@ -51,7 +55,8 @@ public:
|
|||
res.width_px*TPixelRenderer::num_components),
|
||||
pixfmt_(rbuf_),
|
||||
raw_renderer_(pixfmt_),
|
||||
renderer_(raw_renderer_)
|
||||
renderer_(raw_renderer_),
|
||||
o_(o)
|
||||
{
|
||||
renderer_.color(ColorWhite);
|
||||
|
||||
|
@ -66,10 +71,13 @@ public:
|
|||
agg::scanline_p8 scanlines;
|
||||
|
||||
auto&& path = to_path(poly.contour);
|
||||
if(o_ == Origin::TOP_LEFT) path.flip_y(0, resolution_.height_px);
|
||||
ras.add_path(path);
|
||||
|
||||
for(auto h : poly.holes) {
|
||||
auto&& holepath = to_path(h);
|
||||
if(o_ == Origin::TOP_LEFT)
|
||||
holepath.flip_y(0, resolution_.height_px);
|
||||
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::ColorBlack = Raster::Impl::TPixel(0);
|
||||
|
||||
Raster::Raster(const Resolution &r, const PixelDim &pd):
|
||||
impl_(new Impl(r, pd)) {}
|
||||
Raster::Raster(const Resolution &r, const PixelDim &pd, Origin o):
|
||||
impl_(new Impl(r, pd, o)) {}
|
||||
|
||||
Raster::Raster() {}
|
||||
|
||||
|
|
|
@ -27,6 +27,11 @@ public:
|
|||
PNG //!> PNG compression
|
||||
};
|
||||
|
||||
enum class Origin {
|
||||
TOP_LEFT,
|
||||
BOTTOM_LEFT
|
||||
};
|
||||
|
||||
/// Type that represents a resolution in pixels.
|
||||
struct Resolution {
|
||||
unsigned width_px;
|
||||
|
@ -46,7 +51,8 @@ public:
|
|||
};
|
||||
|
||||
/// 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(const Raster& cpy) = delete;
|
||||
Raster& operator=(const Raster& cpy) = delete;
|
||||
|
|
Loading…
Reference in a new issue