Skip to content
Myr

stb_image: use thread-locals for vertically_flip flag and g_failure_reason

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent 7cce4c3 · Browse files · 1 file+37 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+37 added−4 removed

  • other:+37 added−4 removed

1 file+37 added−4 removed

modified:stb_image.h+37 added-4 removed
464 unmodified lines
465STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);466467// flip the image vertically, so the first pixel in the output array is the bottom left468STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);469// as above, but only applies to images loaded on the thread that calls the function470// this function is only available if your compiler supports thread-local variables471STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);472473// ZLIB client - used by PNG, available for other purposes474475STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
89 unmodified lines
565#else566 #define stbi_inline __forceinline567#endif568569#ifndef STBI_NO_THREAD_LOCALS570 #if __cplusplus >= 201103L571 #define STBI_THREAD_LOCAL thread_local572 #elif __STDC_VERSION_ >= 201112L573 #define STBI_THREAD_LOCAL _Thread_local574 #elif defined(__GNUC__)575 #define STBI_THREAD_LOCAL __thread576 #elif _MSC_VER577 #define STBI_THREAD_LOCAL __declspec(thread)578#endif579#endif580581#ifdef _MSC_VER582typedef unsigned short stbi__uint16;583typedef signed short stbi__int16;
302 unmodified lines
886static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);887static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);888#endif889876// this is not threadsafe877static const char *stbi__g_failure_reason;890static 891#ifdef STBI_THREAD_LOCAL892STBI_THREAD_LOCAL893#endif894const char *stbi__g_failure_reason;895896STBIDEF const char *stbi_failure_reason(void)897{898 return stbi__g_failure_reason;
112 unmodified lines
1011#ifndef STBI_NO_HDR1012static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp);1013#endif1014998static int stbi__vertically_flip_on_load = 0;1015static int stbi__vertically_flip_on_load_global = 0;10161017STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)1018{1002 stbi__vertically_flip_on_load = flag_true_if_should_flip;1019 stbi__vertically_flip_on_load_global = flag_true_if_should_flip;1020}10211022#ifndef STBI_THREAD_LOCAL1023#define stbi__vertically_flip_on_load stbi__vertically_flip_on_load_global1024#else1025static STBI_THREAD_LOCAL int stbi__vertically_flip_on_load_local, stbi__vertically_flip_on_load_set;10261027STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip)1028{1029 stbi__vertically_flip_on_load_local = flag_true_if_should_flip;1030 stbi__vertically_flip_on_load_set = 1;1031}10321033#define stbi__vertically_flip_on_load (stbi__vertically_flip_on_load_set \1034 ? stbi__vertically_flip_on_load_local \1035 : stbi__vertically_flip_on_load_global)1036#endif // STBI_THREAD_LOCAL10371038static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc)1039{1040 memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields1041 ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed
6557 unmodified lines