No need to pass all those parameters. Also long longs aren't 8 digits
long. I don't know how to find out the length of a size_t at
compile-time in a way I can use with a format specifier.
I ran into a couple of problems while trying to use this with my
program:
My compiler (MinGW-w64 GCC 8.2.0) complained about not recognising %lld
format specifiers.
The compiler also warned about non-guarding 'if's. I ignored it at
first, but then I noticed my program crashed when it ran
stb_leakcheck_dumpmem. Making the 'if's guard fixed that.
After that, the lib worked until I changed how it was included: instead
of tacking a debug-only #include at the start of every file, I switched
to using GCC's '-include' option to force-include it in every file. But
doing that gave me errors about size_t not being defined. And after
fixing that, I instead got errors about the #defines messing with
stdlib.h. So to fix those I made the declaration-only part of the header
include stdlib.h.
JPG always encodes 8x8 pixel blocks. If the input image does not have
a width or height that's a multiple of 8, the last column or row is just
used multiple times for the remaining pixels of the block.
The original code first calculated p (the index into the pixel data)
with the "imaginary" row/colum (that might be up to 7 pixels too far
into each direction) and then subtracted the necessary amount of bytes
it if row >= height or col >= width.
That was a bit cryptic (IMHO), and didn't get more readable/obvious when
vertical flipping was added - which introduced a bug, by not taking
stbi__flip_vertically_on_write into account when adjusting p for
row >= height...
The code should be more obvious (and less buggy) now.
This fixes bug #592
The PNG filters of the pixels row N are computed using row N-1 of the final image. If the image should be flipped when saving, this corresponds to row N+1 of the initial image.