From 4d3227b604e1805f74c00691c76569fa8df90e7d Mon Sep 17 00:00:00 2001 From: Mihir Date: Sun, 2 May 2021 11:08:16 -0500 Subject: [PATCH] Add flip vertical feature on decode --- docs/decode.md | 1 + spng/spng.c | 5 +++++ spng/spng.h | 1 + 3 files changed, 7 insertions(+) diff --git a/docs/decode.md b/docs/decode.md index f7efc6b4..e3a7b5d6 100644 --- a/docs/decode.md +++ b/docs/decode.md @@ -40,6 +40,7 @@ enum spng_decode_flags SPNG_DECODE_TRNS = 1, /* Apply transparency */ SPNG_DECODE_GAMMA = 2, /* Apply gamma correction */ + SPNG_DECODE_FLIP_Y = 16, /* Flip the image vertically */ SPNG_DECODE_PROGRESSIVE = 256 /* Initialize for progressive reads */ }; ``` diff --git a/spng/spng.c b/spng/spng.c index 8d459e18..a8076dd5 100644 --- a/spng/spng.c +++ b/spng/spng.c @@ -3216,6 +3216,11 @@ int spng_decode_image(spng_ctx *ctx, void *out, size_t len, int fmt, int flags) { size_t ioffset = ri->row_num * ctx->out_width; + if(flags & SPNG_DECODE_FLIP_Y) + { + ioffset = len - ctx->out_width - ioffset; + } + ret = spng_decode_row(ctx, (unsigned char*)out + ioffset, ctx->out_width); }while(!ret); diff --git a/spng/spng.h b/spng/spng.h index e89bd7cd..2de477f8 100644 --- a/spng/spng.h +++ b/spng/spng.h @@ -172,6 +172,7 @@ enum spng_decode_flags SPNG_DECODE_TRNS = 1, /* Apply transparency */ SPNG_DECODE_GAMMA = 2, /* Apply gamma correction */ + SPNG_DECODE_FLIP_Y = 16, /* Flip the image vertically */ SPNG_DECODE_PROGRESSIVE = 256 /* Initialize for progressive reads */ };