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

Added option to flip image on encode #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nedelec
Copy link

@nedelec nedelec commented Mar 21, 2022

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!

@randy408
Copy link
Owner

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).

@native-engine
Copy link

native-engine commented Jun 10, 2023

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];

@randy408
Copy link
Owner

@DaniilPetrov without this feature you can still flip it using progressive encode by starting with the last row and going backwards

@nedelec
Copy link
Author

nedelec commented Jun 12, 2023

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

@randy408
Copy link
Owner

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.

@nedelec
Copy link
Author

nedelec commented Jun 12, 2023

That is reasonable. I will try to find time to document the feature later this summer. Thank you very much for libspng!

@native-engine
Copy link

@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?

@randy408
Copy link
Owner

randy408 commented Jun 13, 2023

@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.

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

Successfully merging this pull request may close these issues.

None yet

3 participants