libspng
libspng copied to clipboard
Added option to flip image on encode
This is adding an option to flip the image vertically upon encoding. I do not understand the structure of the code, but the modifications are local to spng_encode_image(), and they work for me. All the best!
FYI this (and the other vertical flip PR) need more work to be merged: the flag should be rejected in progressive mode, updates to documentation and at least one unit test (annoying I know).
Now it is possible to flip the image, if yes, how? And then when saving an OGL-screenshot you have to flip the image manually:
for (int i = 0; i < Screenshot.screenHeight; ++i)
for (int j = 0; j < Screenshot.screenWidth * 3; ++j)
image[i * Screenshot.screenWidth * 3 + j] = Screenshot.dataBuffer[image_size - (i + 1) * Screenshot.screenWidth * 3 + j];
@daniilpetrov without this feature you can still flip it using progressive encode by starting with the last row and going backwards
Yes, that is true, but it will be slow and is more lines of code than the modification I did on your code. Besides, I can see that other people are possibly using OpenGL and would benefit from this, so from my point of view that seems like an interesting feature to have. Sorry I have little time
I agree it is a useful feature but right now I'm working on APNG support, I'll try to include this some time after.
That is reasonable. I will try to find time to document the feature later this summer. Thank you very much for libspng!
@daniilpetrov without this feature you can still flip it using progressive encode by starting with the last row and going backwards
How to do this?
@daniilpetrov without this feature you can still flip it using progressive encode by starting with the last row and going backwards
How to do this?
You have to add the SPNG_ENCODE_PROGRESSIVE
flag for spng_encode_image()
and call spng_encode_row()
for each row, it would look something like this:
spng_encode_image(ctx, NULL, 0, fmt, SPNG_ENCODE_PROGRESSIVE | SPNG_ENCODE_FINALIZE);
size_t image_width = image_size / Screenshot.screenHeight;
size_t image_offset = image_size;
do
{
image_offset -= image_width;
ret = spng_encode_row(ctx, image + image_offset, image_width);
}while(!ret)
if(ret != SPNG_EOI) /* error */
Note this code assumes you're not setting ihdr.interlace_method
to 1, with interlaced images it's slightly more complicated.