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

Progressive image read support #13

Closed
randy408 opened this issue Aug 8, 2019 · 2 comments
Closed

Progressive image read support #13

randy408 opened this issue Aug 8, 2019 · 2 comments
Labels
API Involves additions and/or changes to the API enhancement New feature or request
Milestone

Comments

@randy408
Copy link
Owner

randy408 commented Aug 8, 2019

The code is already structured to handle row callbacks, this depends on #10, the testsuite also needs some refactoring before tests can be added for this.

@randy408 randy408 added enhancement New feature or request API Involves additions and/or changes to the API labels Aug 8, 2019
@randy408 randy408 added this to the 0.6.0 milestone Aug 8, 2019
@randy408
Copy link
Owner Author

Progressive image decoding will be implemented without callbacks, chunk/row callbacks are now tracked by #40.

@randy408 randy408 changed the title Progressive read / row output Progressive image read support Nov 24, 2019
@randy408
Copy link
Owner Author

randy408 commented Dec 19, 2019

The current API is as follows:

struct spng_row_info
{
    uint32_t scanline_idx, row_num;
    int pass;
    uint8_t filter;
};

int spng_decode_scanline(struct spng_ctx *ctx, void *out, size_t size);
int spng_decode_row(struct spng_ctx *ctx, void *out, size_t size);
int spng_get_row_info(struct spng_ctx *ctx, struct spng_row_info *row_info);

spng_decode_scanline() decodes a single scanline, while spng_decode_row() decodes a scanline and deinterlaces it, when the image is not interlaced their behavior is identical.

spng_get_row_info() copies row information for the to-be-decoded scanline to row_info.

struct spng_row_info exposes values that change between spng_decode_row/scanline() calls.
row_num is the row number in the deinterlaced image,
scanline_idx is the scanline index within the current subimage.
pass is the pass number, filter is the scanline's filter byte.

Example usage:

struct spng_row_info row_info;
size_t out_width = image_size / ihdr.height;
size_t offs;

do
{
   if(spng_get_row_info(ctx, &row_info)) goto fail;

   offs = row_info->row_num * out_width;

   ret = spng_decode_scanline(ctx, buf + offs, out_width);
}while(!ret)

if(ret != SPNG_EOI) goto fail;

Row callbacks (not yet implemented) would differ from libpng's, spng_decode_scanline/row() has to be called inside the function and would probably look something like this:

int spng_row_cb(struct spng_ctx *ctx, const struct spng_row_info *row_info);

With libpng the decoded scanline/row has to be copied from an internal buffer before returning from the callback, libspng would decode to a user-supplied buffer directly.

@randy408 randy408 pinned this issue Dec 31, 2019
@randy408 randy408 closed this as completed May 7, 2020
@randy408 randy408 unpinned this issue May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Involves additions and/or changes to the API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant