Skip to content

Commit 7d5c991

Browse files
author
Francois Nedelec
committed
Added option to flip image on encode
1 parent c61b888 commit 7d5c991

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

spng/spng.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -4863,7 +4863,11 @@ int spng_encode_image(spng_ctx *ctx, const void *img, size_t len, int fmt, int f
48634863

48644864
do
48654865
{
4866-
size_t ioffset = ri->row_num * ctx->image_width;
4866+
size_t ioffset;
4867+
if ( flags & SPNG_ENCODE_FLIP_Y )
4868+
ioffset = ( ihdr->height - ri->row_num - 1 ) * ctx->image_width;
4869+
else
4870+
ioffset = ri->row_num * ctx->image_width;
48674871

48684872
ret = encode_row(ctx, (unsigned char*)img + ioffset, ctx->image_width);
48694873

spng/spng.h

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ enum spng_encode_flags
216216
{
217217
SPNG_ENCODE_PROGRESSIVE = 1, /* Initialize for progressive writes */
218218
SPNG_ENCODE_FINALIZE = 2, /* Finalize PNG after encoding image */
219+
SPNG_ENCODE_FLIP_Y = 4, /* Flip image vertically */
219220
};
220221

221222
struct spng_ihdr

0 commit comments

Comments
 (0)