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

Example for spng_set_png_stream() #258

Open
JanGerber opened this issue Jul 12, 2023 · 1 comment
Open

Example for spng_set_png_stream() #258

JanGerber opened this issue Jul 12, 2023 · 1 comment

Comments

@JanGerber
Copy link

Is there an example how to use the spng_set_png_stream() function?

@randy408
Copy link
Owner

randy408 commented Jul 12, 2023

One example is the spng_set_png_file() function which is essentially spng_set_png_stream(ctx, file_read_fn, file) where file_read_fn looks like this:

libspng/spng/spng.c

Lines 5024 to 5036 in e5c1fc4

static int file_read_fn(spng_ctx *ctx, void *user, void *data, size_t n)
{
FILE *file = user;
(void)ctx;
if(fread(data, n, 1, file) != 1)
{
if(feof(file)) return SPNG_IO_EOF;
else return SPNG_IO_ERROR;
}
return 0;
}

For writing file_write_fn is used, it's right after file_read_fn in the same file.

There is documentation on the read and write callbacks: https://libspng.org/docs/context/#spng_read_fn, https://libspng.org/docs/context/#spng_write_fn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants