From 00d69f5f00d152d58892a90f7ceba71429b995dd Mon Sep 17 00:00:00 2001 From: bose-coder <79697089+bose-coder@users.noreply.github.com> Date: Thu, 23 Jun 2022 23:39:58 +0200 Subject: [PATCH] Vertically flipped rasterization Allow to rasterize the image vertically flipped for better compatibility with OpenGL textures. --- src/nanosvgrast.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h index fa3427bd..efab2f24 100644 --- a/src/nanosvgrast.h +++ b/src/nanosvgrast.h @@ -148,6 +148,8 @@ struct NSVGrasterizer unsigned char* bitmap; int width, height, stride; + + bool loadFlipped; }; NSVGrasterizer* nsvgCreateRasterizer() @@ -1196,7 +1198,8 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, fl if (xmin < 0) xmin = 0; if (xmax > r->width-1) xmax = r->width-1; if (xmin <= xmax) { - nsvg__scanlineSolid(&r->bitmap[y * r->stride] + xmin*4, xmax-xmin+1, &r->scanline[xmin], xmin, y, tx,ty, scale, cache); + int yy = r->loadFlipped ? r->height - y - 1 : y; + nsvg__scanlineSolid(&r->bitmap[yy * r->stride] + xmin*4, xmax-xmin+1, &r->scanline[xmin], xmin, y, tx,ty, scale, cache); } }