Open flriancu opened 3 years ago
why
One immediate advantage is, you can call stbi_write_png_prefs
from multiple threads with different compression levels. Unless something major escapes me, these *_prefs
functions are thread-safe (except for the remaining issue of stbi__flip_vertically_on_write
).
If the goal is to introduce thread-compatability for these global variables, I'd prefer to do it the way we do it in stb_image.c with thread-locals, rather than by significantly increasing the number of main API entrypoints, which adds a lot of complexity for users to understand with very little benefit.
But really it might be better just to remove these variables from the public API (but possibly keep them as undocumented), as I doubt they receive signifcant usage.
If the goal is to introduce thread-compatability for these global variables
Yes, sorry for not mentioning that from the start.
I can file a PR with thread-local variables, would that be okay for the short term?
Like I said, I think it's probably better to remove the public API to these entirely, as I doubt they're used at all except in special circumstances.
@nothings If it's helpful to know, I use stbi_write_png_compression_level
to set a lower (and hopefully faster?) quality for in-memory compression and another for disk.
Hi!
Currently, there are some global variables in
stb_image_write
, including:To avoid using these three particular variables, I made a patch that:
STBIWDEF int stbi_write_png_to_func_prefs(stbi_write_func func, void context, int w, int h, int comp, const void data, int stride_bytes, const stbiw_png_prefs prefs); STBIWDEF int stbi_write_tga_to_func_prefs(stbi_write_func func, void context, int w, int h, int comp, const void data, const stbiw_tga_prefs prefs);
STBIWDEF unsigned char stbi_write_png_to_mem_prefs(const unsigned char pixels, int stride_bytes, int x, int y, int n, int out_len, const stbiw_png_prefs prefs)
static int stbi_write_tga_core(stbi__write_context s, int x, int y, int comp, void data, const stbiw_tga_prefs *prefs)