Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to invert rows in spng_encode_image #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion spng/spng.c
Original file line number Diff line number Diff line change
Expand Up @@ -4761,6 +4761,13 @@ int spng_encode_image(spng_ctx *ctx, const void *img, size_t len, int fmt, int f
if(len != ctx->image_size) return SPNG_EBUFSIZ;
}

ssize_t row_stride = (ssize_t) ctx->image_width;
if(flags & SPNG_ENCODE_INVERT_ROWS)
{
img = (char const*) img + (ctx->ihdr.height - 1) * ctx->image_width;
row_stride = -row_stride;
}

ret = spng_encode_chunks(ctx);
if(ret) return encode_err(ctx, ret);

Expand Down Expand Up @@ -4864,7 +4871,7 @@ 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;
ssize_t ioffset = ri->row_num * row_stride;

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

Expand Down
1 change: 1 addition & 0 deletions spng/spng.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_INVERT_ROWS = 4, /* Interpret rows as being bottom-to-top */
};

struct spng_ihdr
Expand Down