From 7d5c9910d72c18b09c05138425f1cab0a0ea341f Mon Sep 17 00:00:00 2001 From: Francois Nedelec Date: Mon, 21 Mar 2022 13:15:26 +0000 Subject: [PATCH] Added option to flip image on encode --- spng/spng.c | 6 +++++- spng/spng.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spng/spng.c b/spng/spng.c index aef5e87b..aeee71f8 100644 --- a/spng/spng.c +++ b/spng/spng.c @@ -4863,7 +4863,11 @@ int spng_encode_image(spng_ctx *ctx, const void *img, size_t len, int fmt, int f do { - size_t ioffset = ri->row_num * ctx->image_width; + size_t ioffset; + if ( flags & SPNG_ENCODE_FLIP_Y ) + ioffset = ( ihdr->height - ri->row_num - 1 ) * ctx->image_width; + else + ioffset = ri->row_num * ctx->image_width; ret = encode_row(ctx, (unsigned char*)img + ioffset, ctx->image_width); diff --git a/spng/spng.h b/spng/spng.h index a3fe139d..5f3f7e35 100644 --- a/spng/spng.h +++ b/spng/spng.h @@ -216,6 +216,7 @@ enum spng_encode_flags { SPNG_ENCODE_PROGRESSIVE = 1, /* Initialize for progressive writes */ SPNG_ENCODE_FINALIZE = 2, /* Finalize PNG after encoding image */ + SPNG_ENCODE_FLIP_Y = 4, /* Flip image vertically */ }; struct spng_ihdr