Updated external libraries
This commit is contained in:
parent
e996fe2ff5
commit
d00b8f9ffc
6 changed files with 3383 additions and 902 deletions
3645
src/external/cgltf.h
vendored
3645
src/external/cgltf.h
vendored
File diff suppressed because it is too large
Load diff
153
src/external/stb_image.h
vendored
153
src/external/stb_image.h
vendored
|
@ -1,4 +1,4 @@
|
||||||
/* stb_image - v2.19 - public domain image loader - http://nothings.org/stb
|
/* stb_image - v2.20 - public domain image loader - http://nothings.org/stb
|
||||||
no warranty implied; use at your own risk
|
no warranty implied; use at your own risk
|
||||||
|
|
||||||
Do this:
|
Do this:
|
||||||
|
@ -48,6 +48,7 @@ LICENSE
|
||||||
|
|
||||||
RECENT REVISION HISTORY:
|
RECENT REVISION HISTORY:
|
||||||
|
|
||||||
|
2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
2.19 (2018-02-11) fix warning
|
2.19 (2018-02-11) fix warning
|
||||||
2.18 (2018-01-30) fix warnings
|
2.18 (2018-01-30) fix warnings
|
||||||
2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
|
2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
|
||||||
|
@ -84,6 +85,7 @@ RECENT REVISION HISTORY:
|
||||||
Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
|
Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
|
||||||
Arseny Kapoulkine
|
Arseny Kapoulkine
|
||||||
John-Mark Allen
|
John-Mark Allen
|
||||||
|
Carmelo J Fdez-Aguera
|
||||||
|
|
||||||
Bug & warning fixes
|
Bug & warning fixes
|
||||||
Marc LeBlanc David Woo Guillaume George Martins Mozeiko
|
Marc LeBlanc David Woo Guillaume George Martins Mozeiko
|
||||||
|
@ -99,7 +101,7 @@ RECENT REVISION HISTORY:
|
||||||
Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
|
Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
|
||||||
Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
|
Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
|
||||||
Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo
|
Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo
|
||||||
Christian Floisand Kevin Schmidt github:darealshinji
|
Christian Floisand Kevin Schmidt JR Smith github:darealshinji
|
||||||
Blazej Dariusz Roszkowski github:Michaelangel007
|
Blazej Dariusz Roszkowski github:Michaelangel007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -161,6 +163,16 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
//
|
//
|
||||||
|
// UNICODE:
|
||||||
|
//
|
||||||
|
// If compiling for Windows and you wish to use Unicode filenames, compile
|
||||||
|
// with
|
||||||
|
// #define STBI_WINDOWS_UTF8
|
||||||
|
// and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
|
||||||
|
// Windows wchar_t filenames to utf8.
|
||||||
|
//
|
||||||
|
// ===========================================================================
|
||||||
|
//
|
||||||
// Philosophy
|
// Philosophy
|
||||||
//
|
//
|
||||||
// stb libraries are designed with the following priorities:
|
// stb libraries are designed with the following priorities:
|
||||||
|
@ -171,12 +183,12 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// Sometimes I let "good performance" creep up in priority over "easy to maintain",
|
// Sometimes I let "good performance" creep up in priority over "easy to maintain",
|
||||||
// and for best performance I may provide less-easy-to-use APIs that give higher
|
// and for best performance I may provide less-easy-to-use APIs that give higher
|
||||||
// performance, in addition to the easy to use ones. Nevertheless, it's important
|
// performance, in addition to the easy-to-use ones. Nevertheless, it's important
|
||||||
// to keep in mind that from the standpoint of you, a client of this library,
|
// to keep in mind that from the standpoint of you, a client of this library,
|
||||||
// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.
|
// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.
|
||||||
//
|
//
|
||||||
// Some secondary priorities arise directly from the first two, some of which
|
// Some secondary priorities arise directly from the first two, some of which
|
||||||
// make more explicit reasons why performance can't be emphasized.
|
// provide more explicit reasons why performance can't be emphasized.
|
||||||
//
|
//
|
||||||
// - Portable ("ease of use")
|
// - Portable ("ease of use")
|
||||||
// - Small source code footprint ("easy to maintain")
|
// - Small source code footprint ("easy to maintain")
|
||||||
|
@ -219,11 +231,10 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// HDR image support (disable by defining STBI_NO_HDR)
|
// HDR image support (disable by defining STBI_NO_HDR)
|
||||||
//
|
//
|
||||||
// stb_image now supports loading HDR images in general, and currently
|
// stb_image supports loading HDR images in general, and currently the Radiance
|
||||||
// the Radiance .HDR file format, although the support is provided
|
// .HDR file format specifically. You can still load any file through the existing
|
||||||
// generically. You can still load any file through the existing interface;
|
// interface; if you attempt to load an HDR file, it will be automatically remapped
|
||||||
// if you attempt to load an HDR file, it will be automatically remapped to
|
// to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
|
||||||
// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
|
|
||||||
// both of these constants can be reconfigured through this interface:
|
// both of these constants can be reconfigured through this interface:
|
||||||
//
|
//
|
||||||
// stbi_hdr_to_ldr_gamma(2.2f);
|
// stbi_hdr_to_ldr_gamma(2.2f);
|
||||||
|
@ -257,7 +268,7 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// By default we convert iphone-formatted PNGs back to RGB, even though
|
// By default we convert iphone-formatted PNGs back to RGB, even though
|
||||||
// they are internally encoded differently. You can disable this conversion
|
// they are internally encoded differently. You can disable this conversion
|
||||||
// by by calling stbi_convert_iphone_png_to_rgb(0), in which case
|
// by calling stbi_convert_iphone_png_to_rgb(0), in which case
|
||||||
// you will always just get the native iphone "format" through (which
|
// you will always just get the native iphone "format" through (which
|
||||||
// is BGR stored in RGB).
|
// is BGR stored in RGB).
|
||||||
//
|
//
|
||||||
|
@ -319,6 +330,7 @@ enum
|
||||||
STBI_rgb_alpha = 4
|
STBI_rgb_alpha = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
typedef unsigned char stbi_uc;
|
typedef unsigned char stbi_uc;
|
||||||
typedef unsigned short stbi_us;
|
typedef unsigned short stbi_us;
|
||||||
|
|
||||||
|
@ -355,10 +367,6 @@ typedef struct
|
||||||
|
|
||||||
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
#ifndef STBI_NO_GIF
|
|
||||||
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef STBI_NO_STDIO
|
#ifndef STBI_NO_STDIO
|
||||||
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
|
@ -366,6 +374,14 @@ STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in
|
||||||
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBI_NO_GIF
|
||||||
|
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STBI_WINDOWS_UTF8
|
||||||
|
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
//
|
//
|
||||||
// 16-bits-per-channel interface
|
// 16-bits-per-channel interface
|
||||||
|
@ -525,6 +541,12 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
|
||||||
#define STBI_ASSERT(x) assert(x)
|
#define STBI_ASSERT(x) assert(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define STBI_EXTERN extern "C"
|
||||||
|
#else
|
||||||
|
#define STBI_EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -649,14 +671,18 @@ static int stbi__cpuid3(void)
|
||||||
|
|
||||||
#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
|
#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
|
||||||
|
|
||||||
|
#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
|
||||||
static int stbi__sse2_available(void)
|
static int stbi__sse2_available(void)
|
||||||
{
|
{
|
||||||
int info3 = stbi__cpuid3();
|
int info3 = stbi__cpuid3();
|
||||||
return ((info3 >> 26) & 1) != 0;
|
return ((info3 >> 26) & 1) != 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#else // assume GCC-style if not VC++
|
#else // assume GCC-style if not VC++
|
||||||
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
|
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
|
||||||
|
|
||||||
|
#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
|
||||||
static int stbi__sse2_available(void)
|
static int stbi__sse2_available(void)
|
||||||
{
|
{
|
||||||
// If we're even attempting to compile this on GCC/Clang, that means
|
// If we're even attempting to compile this on GCC/Clang, that means
|
||||||
|
@ -664,6 +690,8 @@ static int stbi__sse2_available(void)
|
||||||
// instructions at will, and so are we.
|
// instructions at will, and so are we.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1070,6 +1098,7 @@ static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef STBI_NO_GIF
|
||||||
static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
|
static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
|
||||||
{
|
{
|
||||||
int slice;
|
int slice;
|
||||||
|
@ -1081,6 +1110,7 @@ static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int byt
|
||||||
bytes += slice_size;
|
bytes += slice_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
|
@ -1131,7 +1161,7 @@ static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x,
|
||||||
return (stbi__uint16 *) result;
|
return (stbi__uint16 *) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(STBI_NO_HDR) || !defined(STBI_NO_LINEAR)
|
#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR)
|
||||||
static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
|
static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
if (stbi__vertically_flip_on_load && result != NULL) {
|
if (stbi__vertically_flip_on_load && result != NULL) {
|
||||||
|
@ -1143,10 +1173,38 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
|
||||||
|
|
||||||
#ifndef STBI_NO_STDIO
|
#ifndef STBI_NO_STDIO
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
|
||||||
|
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||||
|
{
|
||||||
|
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static FILE *stbi__fopen(char const *filename, char const *mode)
|
static FILE *stbi__fopen(char const *filename, char const *mode)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
wchar_t wMode[64];
|
||||||
|
wchar_t wFilename[1024];
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1400
|
||||||
|
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||||
|
f = 0;
|
||||||
|
#else
|
||||||
|
f = _wfopen(wFilename, wMode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
if (0 != fopen_s(&f, filename, mode))
|
if (0 != fopen_s(&f, filename, mode))
|
||||||
f=0;
|
f=0;
|
||||||
#else
|
#else
|
||||||
|
@ -1539,18 +1597,18 @@ static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int r
|
||||||
// convert source image with img_n components to one with req_comp components;
|
// convert source image with img_n components to one with req_comp components;
|
||||||
// avoid switch per pixel, so use switch per scanline and massive macros
|
// avoid switch per pixel, so use switch per scanline and massive macros
|
||||||
switch (STBI__COMBO(img_n, req_comp)) {
|
switch (STBI__COMBO(img_n, req_comp)) {
|
||||||
STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break;
|
STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=255; } break;
|
||||||
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break;
|
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=255; } break;
|
||||||
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
||||||
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
|
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
|
||||||
STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break;
|
STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=255; } break;
|
||||||
STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break;
|
STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = 255; } break;
|
||||||
STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break;
|
STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = src[3]; } break;
|
||||||
STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
|
STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
|
||||||
default: STBI_ASSERT(0);
|
default: STBI_ASSERT(0);
|
||||||
}
|
}
|
||||||
#undef STBI__CASE
|
#undef STBI__CASE
|
||||||
|
@ -1588,18 +1646,18 @@ static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int r
|
||||||
// convert source image with img_n components to one with req_comp components;
|
// convert source image with img_n components to one with req_comp components;
|
||||||
// avoid switch per pixel, so use switch per scanline and massive macros
|
// avoid switch per pixel, so use switch per scanline and massive macros
|
||||||
switch (STBI__COMBO(img_n, req_comp)) {
|
switch (STBI__COMBO(img_n, req_comp)) {
|
||||||
STBI__CASE(1,2) { dest[0]=src[0], dest[1]=0xffff; } break;
|
STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff; } break;
|
||||||
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=0xffff; } break;
|
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff; } break;
|
||||||
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
||||||
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
|
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
|
||||||
STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=0xffff; } break;
|
STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff; } break;
|
||||||
STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = 0xffff; } break;
|
STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break;
|
||||||
STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = src[3]; } break;
|
STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break;
|
||||||
STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
|
STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
|
||||||
default: STBI_ASSERT(0);
|
default: STBI_ASSERT(0);
|
||||||
}
|
}
|
||||||
#undef STBI__CASE
|
#undef STBI__CASE
|
||||||
|
@ -1623,7 +1681,11 @@ static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)
|
||||||
for (k=0; k < n; ++k) {
|
for (k=0; k < n; ++k) {
|
||||||
output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
|
output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
|
||||||
}
|
}
|
||||||
if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f;
|
}
|
||||||
|
if (n < comp) {
|
||||||
|
for (i=0; i < x*y; ++i) {
|
||||||
|
output[i*comp + n] = data[i*comp + n]/255.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STBI_FREE(data);
|
STBI_FREE(data);
|
||||||
return output;
|
return output;
|
||||||
|
@ -3717,7 +3779,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
|
for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
|
||||||
else
|
else
|
||||||
for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255;
|
for (i=0; i < z->s->img_x; ++i) { *out++ = y[i]; *out++ = 255; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4731,7 +4793,7 @@ static void stbi__de_iphone(stbi__png *z)
|
||||||
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
||||||
{
|
{
|
||||||
stbi_uc palette[1024], pal_img_n=0;
|
stbi_uc palette[1024], pal_img_n=0;
|
||||||
stbi_uc has_trans=0, tc[3];
|
stbi_uc has_trans=0, tc[3]={0};
|
||||||
stbi__uint16 tc16[3];
|
stbi__uint16 tc16[3];
|
||||||
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
||||||
int first=1,k,interlace=0, color=0, is_iphone=0;
|
int first=1,k,interlace=0, color=0, is_iphone=0;
|
||||||
|
@ -5009,11 +5071,11 @@ static int stbi__high_bit(unsigned int z)
|
||||||
{
|
{
|
||||||
int n=0;
|
int n=0;
|
||||||
if (z == 0) return -1;
|
if (z == 0) return -1;
|
||||||
if (z >= 0x10000) n += 16, z >>= 16;
|
if (z >= 0x10000) { n += 16; z >>= 16; }
|
||||||
if (z >= 0x00100) n += 8, z >>= 8;
|
if (z >= 0x00100) { n += 8; z >>= 8; }
|
||||||
if (z >= 0x00010) n += 4, z >>= 4;
|
if (z >= 0x00010) { n += 4; z >>= 4; }
|
||||||
if (z >= 0x00004) n += 2, z >>= 2;
|
if (z >= 0x00004) { n += 2; z >>= 2; }
|
||||||
if (z >= 0x00002) n += 1, z >>= 1;
|
if (z >= 0x00002) { n += 1; z >>= 1; }
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5030,7 +5092,7 @@ static int stbi__bitcount(unsigned int a)
|
||||||
// extract an arbitrarily-aligned N-bit value (N=bits)
|
// extract an arbitrarily-aligned N-bit value (N=bits)
|
||||||
// from v, and then make it 8-bits long and fractionally
|
// from v, and then make it 8-bits long and fractionally
|
||||||
// extend it to full full range.
|
// extend it to full full range.
|
||||||
static int stbi__shiftsigned(int v, int shift, int bits)
|
static int stbi__shiftsigned(unsigned int v, int shift, int bits)
|
||||||
{
|
{
|
||||||
static unsigned int mul_table[9] = {
|
static unsigned int mul_table[9] = {
|
||||||
0,
|
0,
|
||||||
|
@ -5207,6 +5269,8 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
out[z++] = pal[color][0];
|
out[z++] = pal[color][0];
|
||||||
out[z++] = pal[color][1];
|
out[z++] = pal[color][1];
|
||||||
out[z++] = pal[color][2];
|
out[z++] = pal[color][2];
|
||||||
|
if (target == 4) out[z++] = 255;
|
||||||
|
if (i+1 == (int) s->img_x) break;
|
||||||
if((--bit_offset) < 0) {
|
if((--bit_offset) < 0) {
|
||||||
bit_offset = 7;
|
bit_offset = 7;
|
||||||
v = stbi__get8(s);
|
v = stbi__get8(s);
|
||||||
|
@ -5299,7 +5363,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
stbi_uc *p1 = out + j *s->img_x*target;
|
stbi_uc *p1 = out + j *s->img_x*target;
|
||||||
stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
||||||
for (i=0; i < (int) s->img_x*target; ++i) {
|
for (i=0; i < (int) s->img_x*target; ++i) {
|
||||||
t = p1[i], p1[i] = p2[i], p2[i] = t;
|
t = p1[i]; p1[i] = p2[i]; p2[i] = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5789,7 +5853,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
// Else if n is 128, noop.
|
// Else if n is 128, noop.
|
||||||
// Endloop
|
// Endloop
|
||||||
|
|
||||||
// The RLE-compressed data is preceeded by a 2-byte data count for each row in the data,
|
// The RLE-compressed data is preceded by a 2-byte data count for each row in the data,
|
||||||
// which we're going to just skip.
|
// which we're going to just skip.
|
||||||
stbi__skip(s, h * channelCount * 2 );
|
stbi__skip(s, h * channelCount * 2 );
|
||||||
|
|
||||||
|
@ -6342,6 +6406,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
||||||
int first_frame;
|
int first_frame;
|
||||||
int pi;
|
int pi;
|
||||||
int pcount;
|
int pcount;
|
||||||
|
STBI_NOTUSED(req_comp);
|
||||||
|
|
||||||
// on first frame, any non-written pixels get the background colour (non-transparent)
|
// on first frame, any non-written pixels get the background colour (non-transparent)
|
||||||
first_frame = 0;
|
first_frame = 0;
|
||||||
|
@ -6352,9 +6417,9 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
||||||
g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
|
g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
|
||||||
if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
|
if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
|
||||||
|
|
||||||
// image is treated as "tranparent" at the start - ie, nothing overwrites the current background;
|
// image is treated as "transparent" at the start - ie, nothing overwrites the current background;
|
||||||
// background colour is only used for pixels that are not rendered first frame, after that "background"
|
// background colour is only used for pixels that are not rendered first frame, after that "background"
|
||||||
// color refers to teh color that was there the previous frame.
|
// color refers to the color that was there the previous frame.
|
||||||
memset( g->out, 0x00, 4 * g->w * g->h );
|
memset( g->out, 0x00, 4 * g->w * g->h );
|
||||||
memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
|
memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
|
||||||
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
|
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
|
||||||
|
@ -6565,6 +6630,7 @@ static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
stbi_uc *u = 0;
|
stbi_uc *u = 0;
|
||||||
stbi__gif g;
|
stbi__gif g;
|
||||||
memset(&g, 0, sizeof(g));
|
memset(&g, 0, sizeof(g));
|
||||||
|
STBI_NOTUSED(ri);
|
||||||
|
|
||||||
u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
|
u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
|
||||||
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
|
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
|
||||||
|
@ -7238,6 +7304,7 @@ STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user
|
||||||
|
|
||||||
/*
|
/*
|
||||||
revision history:
|
revision history:
|
||||||
|
2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
2.19 (2018-02-11) fix warning
|
2.19 (2018-02-11) fix warning
|
||||||
2.18 (2018-01-30) fix warnings
|
2.18 (2018-01-30) fix warnings
|
||||||
2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
|
2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
|
||||||
|
|
143
src/external/stb_image_write.h
vendored
143
src/external/stb_image_write.h
vendored
|
@ -1,4 +1,4 @@
|
||||||
/* stb_image_write - v1.09 - public domain - http://nothings.org/stb/stb_image_write.h
|
/* stb_image_write - v1.10 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||||
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
||||||
no warranty implied; use at your own risk
|
no warranty implied; use at your own risk
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@
|
||||||
|
|
||||||
ABOUT:
|
ABOUT:
|
||||||
|
|
||||||
This header file is a library for writing images to C stdio. It could be
|
This header file is a library for writing images to C stdio or a callback.
|
||||||
adapted to write to memory or a general streaming interface; let me know.
|
|
||||||
|
|
||||||
The PNG output is not optimal; it is 20-50% larger than the file
|
The PNG output is not optimal; it is 20-50% larger than the file
|
||||||
written by a decent optimizing implementation; though providing a custom
|
written by a decent optimizing implementation; though providing a custom
|
||||||
|
@ -38,6 +37,14 @@ BUILDING:
|
||||||
The returned data will be freed with STBIW_FREE() (free() by default),
|
The returned data will be freed with STBIW_FREE() (free() by default),
|
||||||
so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
|
so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
|
||||||
|
|
||||||
|
UNICODE:
|
||||||
|
|
||||||
|
If compiling for Windows and you wish to use Unicode filenames, compile
|
||||||
|
with
|
||||||
|
#define STBIW_WINDOWS_UTF8
|
||||||
|
and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
|
||||||
|
Windows wchar_t filenames to utf8.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
|
||||||
There are five functions, one for each image file format:
|
There are five functions, one for each image file format:
|
||||||
|
@ -148,6 +155,8 @@ LICENSE
|
||||||
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
||||||
#define INCLUDE_STB_IMAGE_WRITE_H
|
#define INCLUDE_STB_IMAGE_WRITE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
|
// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
|
||||||
#ifndef STBIWDEF
|
#ifndef STBIWDEF
|
||||||
#ifdef STB_IMAGE_WRITE_STATIC
|
#ifdef STB_IMAGE_WRITE_STATIC
|
||||||
|
@ -173,6 +182,10 @@ STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const
|
||||||
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||||
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
||||||
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
||||||
|
|
||||||
|
#ifdef STBI_WINDOWS_UTF8
|
||||||
|
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void stbi_write_func(void *context, void *data, int size);
|
typedef void stbi_write_func(void *context, void *data, int size);
|
||||||
|
@ -275,15 +288,52 @@ static void stbi__stdio_write(void *context, void *data, int size)
|
||||||
fwrite(data,1,size,(FILE*) context);
|
fwrite(data,1,size,(FILE*) context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stbi__start_write_file(stbi__write_context *s, const char *filename)
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define STBIW_EXTERN extern "C"
|
||||||
|
#else
|
||||||
|
#define STBIW_EXTERN extern
|
||||||
|
#endif
|
||||||
|
STBIW_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
|
||||||
|
STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
|
||||||
|
|
||||||
|
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||||
|
{
|
||||||
|
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static FILE *stbiw__fopen(char const *filename, char const *mode)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
#ifdef STBI_MSC_SECURE_CRT
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
if (fopen_s(&f, filename, "wb"))
|
wchar_t wMode[64];
|
||||||
f = NULL;
|
wchar_t wFilename[1024];
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1400
|
||||||
|
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||||
|
f = 0;
|
||||||
#else
|
#else
|
||||||
f = fopen(filename, "wb");
|
f = _wfopen(wFilename, wMode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
if (0 != fopen_s(&f, filename, mode))
|
||||||
|
f=0;
|
||||||
|
#else
|
||||||
|
f = fopen(filename, mode);
|
||||||
|
#endif
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int stbi__start_write_file(stbi__write_context *s, const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f = stbiw__fopen(filename, "wb");
|
||||||
stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
|
stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
|
||||||
return f != NULL;
|
return f != NULL;
|
||||||
}
|
}
|
||||||
|
@ -552,7 +602,7 @@ STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const
|
||||||
|
|
||||||
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||||
{
|
{
|
||||||
int exponent;
|
int exponent;
|
||||||
float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
|
float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
|
||||||
|
@ -569,7 +619,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
|
static void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
|
||||||
{
|
{
|
||||||
unsigned char lengthbyte = STBIW_UCHAR(length+128);
|
unsigned char lengthbyte = STBIW_UCHAR(length+128);
|
||||||
STBIW_ASSERT(length+128 <= 255);
|
STBIW_ASSERT(length+128 <= 255);
|
||||||
|
@ -577,7 +627,7 @@ void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char dat
|
||||||
s->func(s->context, &databyte, 1);
|
s->func(s->context, &databyte, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
|
static void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
|
||||||
{
|
{
|
||||||
unsigned char lengthbyte = STBIW_UCHAR(length);
|
unsigned char lengthbyte = STBIW_UCHAR(length);
|
||||||
STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
|
STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
|
||||||
|
@ -585,7 +635,7 @@ void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *d
|
||||||
s->func(s->context, data, length);
|
s->func(s->context, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
|
static void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
|
||||||
{
|
{
|
||||||
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
||||||
unsigned char rgbe[4];
|
unsigned char rgbe[4];
|
||||||
|
@ -694,7 +744,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
||||||
s->func(s->context, buffer, len);
|
s->func(s->context, buffer, len);
|
||||||
|
|
||||||
for(i=0; i < y; i++)
|
for(i=0; i < y; i++)
|
||||||
stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)*x);
|
stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i));
|
||||||
STBIW_FREE(scratch);
|
STBIW_FREE(scratch);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -809,7 +859,7 @@ static unsigned int stbiw__zhash(unsigned char *data)
|
||||||
|
|
||||||
#endif // STBIW_ZLIB_COMPRESS
|
#endif // STBIW_ZLIB_COMPRESS
|
||||||
|
|
||||||
unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
||||||
{
|
{
|
||||||
#ifdef STBIW_ZLIB_COMPRESS
|
#ifdef STBIW_ZLIB_COMPRESS
|
||||||
// user provided a zlib compress implementation, use that
|
// user provided a zlib compress implementation, use that
|
||||||
|
@ -923,6 +973,9 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
||||||
|
|
||||||
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
||||||
{
|
{
|
||||||
|
#ifdef STBIW_CRC32
|
||||||
|
return STBIW_CRC32(buffer, len);
|
||||||
|
#else
|
||||||
static unsigned int crc_table[256] =
|
static unsigned int crc_table[256] =
|
||||||
{
|
{
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||||
|
@ -964,6 +1017,7 @@ static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
||||||
for (i=0; i < len; ++i)
|
for (i=0; i < len; ++i)
|
||||||
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
||||||
return ~crc;
|
return ~crc;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
|
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
|
||||||
|
@ -994,9 +1048,15 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
|
||||||
int type = mymap[filter_type];
|
int type = mymap[filter_type];
|
||||||
unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
|
unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
|
||||||
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
|
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
|
||||||
|
|
||||||
|
if (type==0) {
|
||||||
|
memcpy(line_buffer, z, width*n);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first loop isn't optimized since it's just one pixel
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: line_buffer[i] = z[i]; break;
|
|
||||||
case 1: line_buffer[i] = z[i]; break;
|
case 1: line_buffer[i] = z[i]; break;
|
||||||
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
||||||
case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
|
case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
|
||||||
|
@ -1005,20 +1065,17 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
|
||||||
case 6: line_buffer[i] = z[i]; break;
|
case 6: line_buffer[i] = z[i]; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i=n; i < width*n; ++i) {
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: line_buffer[i] = z[i]; break;
|
case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break;
|
||||||
case 1: line_buffer[i] = z[i] - z[i-n]; break;
|
case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
||||||
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
|
||||||
case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
|
case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
|
||||||
case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
|
case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
||||||
case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
|
||||||
case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
||||||
{
|
{
|
||||||
int force_filter = stbi_write_force_png_filter;
|
int force_filter = stbi_write_force_png_filter;
|
||||||
int ctype[5] = { -1, 0, 4, 2, 6 };
|
int ctype[5] = { -1, 0, 4, 2, 6 };
|
||||||
|
@ -1040,11 +1097,11 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||||
int filter_type;
|
int filter_type;
|
||||||
if (force_filter > -1) {
|
if (force_filter > -1) {
|
||||||
filter_type = force_filter;
|
filter_type = force_filter;
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer);
|
||||||
} else { // Estimate the best filter by running through all of them:
|
} else { // Estimate the best filter by running through all of them:
|
||||||
int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
|
int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
|
||||||
for (filter_type = 0; filter_type < 5; filter_type++) {
|
for (filter_type = 0; filter_type < 5; filter_type++) {
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer);
|
||||||
|
|
||||||
// Estimate the entropy of the line using this filter; the less, the better.
|
// Estimate the entropy of the line using this filter; the less, the better.
|
||||||
est = 0;
|
est = 0;
|
||||||
|
@ -1057,7 +1114,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
|
if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer);
|
||||||
filter_type = best_filter;
|
filter_type = best_filter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1109,14 +1166,10 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int len;
|
int len;
|
||||||
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);
|
||||||
if (png == NULL) return 0;
|
if (png == NULL) return 0;
|
||||||
#ifdef STBI_MSC_SECURE_CRT
|
|
||||||
if (fopen_s(&f, filename, "wb"))
|
f = stbiw__fopen(filename, "wb");
|
||||||
f = NULL;
|
|
||||||
#else
|
|
||||||
f = fopen(filename, "wb");
|
|
||||||
#endif
|
|
||||||
if (!f) { STBIW_FREE(png); return 0; }
|
if (!f) { STBIW_FREE(png); return 0; }
|
||||||
fwrite(png, 1, len, f);
|
fwrite(png, 1, len, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -1128,7 +1181,7 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const
|
||||||
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)
|
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);
|
||||||
if (png == NULL) return 0;
|
if (png == NULL) return 0;
|
||||||
func(context, png, len);
|
func(context, png, len);
|
||||||
STBIW_FREE(png);
|
STBIW_FREE(png);
|
||||||
|
@ -1423,15 +1476,17 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||||
for(x = 0; x < width; x += 8) {
|
for(x = 0; x < width; x += 8) {
|
||||||
float YDU[64], UDU[64], VDU[64];
|
float YDU[64], UDU[64], VDU[64];
|
||||||
for(row = y, pos = 0; row < y+8; ++row) {
|
for(row = y, pos = 0; row < y+8; ++row) {
|
||||||
|
int p;
|
||||||
|
if(row < height) {
|
||||||
|
p = (stbi__flip_vertically_on_write ? (height-1-row) : row)*width*comp;
|
||||||
|
} else {
|
||||||
|
// row >= height => use last input row (=> first if flipping)
|
||||||
|
p = stbi__flip_vertically_on_write ? 0 : ((height-1)*width*comp);
|
||||||
|
}
|
||||||
for(col = x; col < x+8; ++col, ++pos) {
|
for(col = x; col < x+8; ++col, ++pos) {
|
||||||
int p = (stbi__flip_vertically_on_write ? height-1-row : row)*width*comp + col*comp;
|
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
if(row >= height) {
|
// if col >= width => use pixel from last input column
|
||||||
p -= width*comp*(row+1 - height);
|
p += ((col < width) ? col : (width-1))*comp;
|
||||||
}
|
|
||||||
if(col >= width) {
|
|
||||||
p -= comp*(col+1 - width);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = imageData[p+0];
|
r = imageData[p+0];
|
||||||
g = imageData[p+ofsG];
|
g = imageData[p+ofsG];
|
||||||
|
@ -1483,6 +1538,8 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
||||||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
/* Revision history
|
/* Revision history
|
||||||
|
1.10 (2019-02-07)
|
||||||
|
support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
1.09 (2018-02-11)
|
1.09 (2018-02-11)
|
||||||
fix typo in zlib quality API, improve STB_I_W_STATIC in C++
|
fix typo in zlib quality API, improve STB_I_W_STATIC in C++
|
||||||
1.08 (2018-01-29)
|
1.08 (2018-01-29)
|
||||||
|
|
148
src/external/stb_perlin.h
vendored
148
src/external/stb_perlin.h
vendored
|
@ -1,4 +1,4 @@
|
||||||
// stb_perlin.h - v0.3 - perlin noise
|
// stb_perlin.h - v0.4 - perlin noise
|
||||||
// public domain single-file C implementation by Sean Barrett
|
// public domain single-file C implementation by Sean Barrett
|
||||||
//
|
//
|
||||||
// LICENSE
|
// LICENSE
|
||||||
|
@ -32,6 +32,19 @@
|
||||||
// details of the implementation, even if you ask for larger or no
|
// details of the implementation, even if you ask for larger or no
|
||||||
// wrapping.)
|
// wrapping.)
|
||||||
//
|
//
|
||||||
|
// float stb_perlin_noise3_seed( float x,
|
||||||
|
// float y,
|
||||||
|
// float z,
|
||||||
|
// int x_wrap=0,
|
||||||
|
// int y_wrap=0,
|
||||||
|
// int z_wrap=0,
|
||||||
|
// int seed)
|
||||||
|
//
|
||||||
|
// As above, but 'seed' selects from multiple different variations of the
|
||||||
|
// noise function. The current implementation only uses the bottom 8 bits
|
||||||
|
// of 'seed', but possibly in the future more bits will be used.
|
||||||
|
//
|
||||||
|
//
|
||||||
// Fractal Noise:
|
// Fractal Noise:
|
||||||
//
|
//
|
||||||
// Three common fractal noise functions are included, which produce
|
// Three common fractal noise functions are included, which produce
|
||||||
|
@ -40,16 +53,13 @@
|
||||||
// 'octaves' times, so this parameter will affect runtime.
|
// 'octaves' times, so this parameter will affect runtime.
|
||||||
//
|
//
|
||||||
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain, float offset, int octaves,
|
// float lacunarity, float gain, float offset, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain, int octaves,
|
// float lacunarity, float gain, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain,int octaves,
|
// float lacunarity, float gain, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// Typical values to start playing with:
|
// Typical values to start playing with:
|
||||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||||
|
@ -60,6 +70,7 @@
|
||||||
//
|
//
|
||||||
// Contributors:
|
// Contributors:
|
||||||
// Jack Mott - additional noise functions
|
// Jack Mott - additional noise functions
|
||||||
|
// Jordan Peck - seeded noise
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,18 +78,19 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
||||||
extern float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves);
|
||||||
extern float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||||
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STB_PERLIN_IMPLEMENTATION
|
#ifdef STB_PERLIN_IMPLEMENTATION
|
||||||
|
|
||||||
|
#include <math.h> // fabs()
|
||||||
|
|
||||||
// not same permutation table as Perlin's reference to avoid copyright issues;
|
// not same permutation table as Perlin's reference to avoid copyright issues;
|
||||||
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
||||||
// @OPTIMIZE: should this be unsigned char instead of int for cache?
|
|
||||||
static unsigned char stb__perlin_randtab[512] =
|
static unsigned char stb__perlin_randtab[512] =
|
||||||
{
|
{
|
||||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||||
|
@ -117,6 +129,51 @@ static unsigned char stb__perlin_randtab[512] =
|
||||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
||||||
|
// and some 2/16ths. We reduce bias by changing those fractions
|
||||||
|
// to 5/64ths and 6/64ths
|
||||||
|
|
||||||
|
// this array is designed to match the previous implementation
|
||||||
|
// of gradient hash: indices[stb__perlin_randtab[i]&63]
|
||||||
|
static unsigned char stb__perlin_randtab_grad_idx[512] =
|
||||||
|
{
|
||||||
|
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||||
|
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||||
|
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||||
|
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||||
|
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||||
|
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||||
|
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||||
|
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||||
|
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||||
|
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||||
|
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||||
|
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||||
|
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||||
|
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||||
|
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||||
|
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||||
|
|
||||||
|
// and a second copy so we don't need an extra mask or static initializer
|
||||||
|
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||||
|
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||||
|
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||||
|
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||||
|
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||||
|
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||||
|
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||||
|
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||||
|
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||||
|
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||||
|
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||||
|
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||||
|
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||||
|
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||||
|
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||||
|
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||||
|
};
|
||||||
|
|
||||||
static float stb__perlin_lerp(float a, float b, float t)
|
static float stb__perlin_lerp(float a, float b, float t)
|
||||||
{
|
{
|
||||||
return a + (b-a) * t;
|
return a + (b-a) * t;
|
||||||
|
@ -129,7 +186,7 @@ static int stb__perlin_fastfloor(float a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// different grad function from Perlin's, but easy to modify to match reference
|
// different grad function from Perlin's, but easy to modify to match reference
|
||||||
static float stb__perlin_grad(int hash, float x, float y, float z)
|
static float stb__perlin_grad(int grad_idx, float x, float y, float z)
|
||||||
{
|
{
|
||||||
static float basis[12][4] =
|
static float basis[12][4] =
|
||||||
{
|
{
|
||||||
|
@ -147,26 +204,11 @@ static float stb__perlin_grad(int hash, float x, float y, float z)
|
||||||
{ 0,-1,-1 },
|
{ 0,-1,-1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
float *grad = basis[grad_idx];
|
||||||
// and some 2/16ths. We reduce bias by changing those fractions
|
|
||||||
// to 5/64ths and 6/64ths, and the same 4 cases get the extra weight.
|
|
||||||
static unsigned char indices[64] =
|
|
||||||
{
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,9,1,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
};
|
|
||||||
|
|
||||||
// if you use reference permutation table, change 63 below to 15 to match reference
|
|
||||||
// (this is why the ordering of the table above is funky)
|
|
||||||
float *grad = basis[indices[hash & 63]];
|
|
||||||
return grad[0]*x + grad[1]*y + grad[2]*z;
|
return grad[0]*x + grad[1]*y + grad[2]*z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_noise3_internal(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed)
|
||||||
{
|
{
|
||||||
float u,v,w;
|
float u,v,w;
|
||||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||||
|
@ -190,22 +232,22 @@ float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z
|
||||||
y -= py; v = stb__perlin_ease(y);
|
y -= py; v = stb__perlin_ease(y);
|
||||||
z -= pz; w = stb__perlin_ease(z);
|
z -= pz; w = stb__perlin_ease(z);
|
||||||
|
|
||||||
r0 = stb__perlin_randtab[x0];
|
r0 = stb__perlin_randtab[x0+seed];
|
||||||
r1 = stb__perlin_randtab[x1];
|
r1 = stb__perlin_randtab[x1+seed];
|
||||||
|
|
||||||
r00 = stb__perlin_randtab[r0+y0];
|
r00 = stb__perlin_randtab[r0+y0];
|
||||||
r01 = stb__perlin_randtab[r0+y1];
|
r01 = stb__perlin_randtab[r0+y1];
|
||||||
r10 = stb__perlin_randtab[r1+y0];
|
r10 = stb__perlin_randtab[r1+y0];
|
||||||
r11 = stb__perlin_randtab[r1+y1];
|
r11 = stb__perlin_randtab[r1+y1];
|
||||||
|
|
||||||
n000 = stb__perlin_grad(stb__perlin_randtab[r00+z0], x , y , z );
|
n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z );
|
||||||
n001 = stb__perlin_grad(stb__perlin_randtab[r00+z1], x , y , z-1 );
|
n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 );
|
||||||
n010 = stb__perlin_grad(stb__perlin_randtab[r01+z0], x , y-1, z );
|
n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z );
|
||||||
n011 = stb__perlin_grad(stb__perlin_randtab[r01+z1], x , y-1, z-1 );
|
n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 );
|
||||||
n100 = stb__perlin_grad(stb__perlin_randtab[r10+z0], x-1, y , z );
|
n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z );
|
||||||
n101 = stb__perlin_grad(stb__perlin_randtab[r10+z1], x-1, y , z-1 );
|
n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 );
|
||||||
n110 = stb__perlin_grad(stb__perlin_randtab[r11+z0], x-1, y-1, z );
|
n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z );
|
||||||
n111 = stb__perlin_grad(stb__perlin_randtab[r11+z1], x-1, y-1, z-1 );
|
n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 );
|
||||||
|
|
||||||
n00 = stb__perlin_lerp(n000,n001,w);
|
n00 = stb__perlin_lerp(n000,n001,w);
|
||||||
n01 = stb__perlin_lerp(n010,n011,w);
|
n01 = stb__perlin_lerp(n010,n011,w);
|
||||||
|
@ -218,7 +260,17 @@ float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z
|
||||||
return stb__perlin_lerp(n0,n1,u);
|
return stb__perlin_lerp(n0,n1,u);
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
||||||
|
{
|
||||||
|
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed)
|
||||||
|
{
|
||||||
|
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap, (unsigned char) seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
@ -227,9 +279,8 @@ float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
float r = (float)(stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap));
|
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i);
|
||||||
r = r<0 ? -r : r; // fabs()
|
r = offset - (float) fabs(r);
|
||||||
r = offset - r;
|
|
||||||
r = r*r;
|
r = r*r;
|
||||||
sum += r*amplitude*prev;
|
sum += r*amplitude*prev;
|
||||||
prev = r;
|
prev = r;
|
||||||
|
@ -239,7 +290,7 @@ float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
@ -247,14 +298,14 @@ float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float ga
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
sum += stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
sum += stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||||
frequency *= lacunarity;
|
frequency *= lacunarity;
|
||||||
amplitude *= gain;
|
amplitude *= gain;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
@ -262,9 +313,8 @@ float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity,
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
float r = stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||||
r = r<0 ? -r : r; // fabs()
|
sum += (float) fabs(r);
|
||||||
sum += r;
|
|
||||||
frequency *= lacunarity;
|
frequency *= lacunarity;
|
||||||
amplitude *= gain;
|
amplitude *= gain;
|
||||||
}
|
}
|
||||||
|
|
9
src/external/stb_rect_pack.h
vendored
9
src/external/stb_rect_pack.h
vendored
|
@ -1,4 +1,4 @@
|
||||||
// stb_rect_pack.h - v0.11 - public domain - rectangle packing
|
// stb_rect_pack.h - v0.99 - public domain - rectangle packing
|
||||||
// Sean Barrett 2014
|
// Sean Barrett 2014
|
||||||
//
|
//
|
||||||
// Useful for e.g. packing rectangular textures into an atlas.
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
@ -34,6 +34,7 @@
|
||||||
//
|
//
|
||||||
// Version history:
|
// Version history:
|
||||||
//
|
//
|
||||||
|
// 0.99 (2019-02-07) warning fixes
|
||||||
// 0.11 (2017-03-03) return packing success/fail result
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||||
// 0.09 (2016-08-27) fix compiler warnings
|
// 0.09 (2016-08-27) fix compiler warnings
|
||||||
|
@ -492,17 +493,14 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
|
||||||
STBRP_ASSERT(cur->next == NULL);
|
STBRP_ASSERT(cur->next == NULL);
|
||||||
|
|
||||||
{
|
{
|
||||||
stbrp_node *L1 = NULL, *L2 = NULL;
|
|
||||||
int count=0;
|
int count=0;
|
||||||
cur = context->active_head;
|
cur = context->active_head;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
L1 = cur;
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
cur = context->free_head;
|
cur = context->free_head;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
L2 = cur;
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
@ -544,9 +542,6 @@ STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int nu
|
||||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||||
for (i=0; i < num_rects; ++i) {
|
for (i=0; i < num_rects; ++i) {
|
||||||
rects[i].was_packed = i;
|
rects[i].was_packed = i;
|
||||||
#ifndef STBRP_LARGE_RECTS
|
|
||||||
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort according to heuristic
|
// sort according to heuristic
|
||||||
|
|
63
src/external/stb_truetype.h
vendored
63
src/external/stb_truetype.h
vendored
|
@ -1,4 +1,4 @@
|
||||||
// stb_truetype.h - v1.19 - public domain
|
// stb_truetype.h - v1.20 - public domain
|
||||||
// authored from 2009-2016 by Sean Barrett / RAD Game Tools
|
// authored from 2009-2016 by Sean Barrett / RAD Game Tools
|
||||||
//
|
//
|
||||||
// This library processes TrueType files:
|
// This library processes TrueType files:
|
||||||
|
@ -49,6 +49,7 @@
|
||||||
//
|
//
|
||||||
// VERSION HISTORY
|
// VERSION HISTORY
|
||||||
//
|
//
|
||||||
|
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
|
||||||
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
|
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
|
||||||
// 1.18 (2018-01-29) add missing function
|
// 1.18 (2018-01-29) add missing function
|
||||||
// 1.17 (2017-07-23) make more arguments const; doc fix
|
// 1.17 (2017-07-23) make more arguments const; doc fix
|
||||||
|
@ -75,7 +76,7 @@
|
||||||
//
|
//
|
||||||
// USAGE
|
// USAGE
|
||||||
//
|
//
|
||||||
// Include this file in whatever places neeed to refer to it. In ONE C/C++
|
// Include this file in whatever places need to refer to it. In ONE C/C++
|
||||||
// file, write:
|
// file, write:
|
||||||
// #define STB_TRUETYPE_IMPLEMENTATION
|
// #define STB_TRUETYPE_IMPLEMENTATION
|
||||||
// before the #include of this file. This expands out the actual
|
// before the #include of this file. This expands out the actual
|
||||||
|
@ -247,8 +248,8 @@
|
||||||
// Documentation & header file 520 LOC \___ 660 LOC documentation
|
// Documentation & header file 520 LOC \___ 660 LOC documentation
|
||||||
// Sample code 140 LOC /
|
// Sample code 140 LOC /
|
||||||
// Truetype parsing 620 LOC ---- 620 LOC TrueType
|
// Truetype parsing 620 LOC ---- 620 LOC TrueType
|
||||||
// Software rasterization 240 LOC \ .
|
// Software rasterization 240 LOC \
|
||||||
// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation
|
// Curve tessellation 120 LOC \__ 550 LOC Bitmap creation
|
||||||
// Bitmap management 100 LOC /
|
// Bitmap management 100 LOC /
|
||||||
// Baked bitmap interface 70 LOC /
|
// Baked bitmap interface 70 LOC /
|
||||||
// Font name matching & access 150 LOC ---- 150
|
// Font name matching & access 150 LOC ---- 150
|
||||||
|
@ -556,6 +557,8 @@ STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int p
|
||||||
//
|
//
|
||||||
// It's inefficient; you might want to c&p it and optimize it.
|
// It's inefficient; you might want to c&p it and optimize it.
|
||||||
|
|
||||||
|
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap);
|
||||||
|
// Query the font vertical metrics without having to create a font first.
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -641,6 +644,12 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
|
||||||
// To use with PackFontRangesGather etc., you must set it before calls
|
// To use with PackFontRangesGather etc., you must set it before calls
|
||||||
// call to PackFontRangesGatherRects.
|
// call to PackFontRangesGatherRects.
|
||||||
|
|
||||||
|
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip);
|
||||||
|
// If skip != 0, this tells stb_truetype to skip any codepoints for which
|
||||||
|
// there is no corresponding glyph. If skip=0, which is the default, then
|
||||||
|
// codepoints without a glyph recived the font's "missing character" glyph,
|
||||||
|
// typically an empty box by convention.
|
||||||
|
|
||||||
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
||||||
int char_index, // character to display
|
int char_index, // character to display
|
||||||
float *xpos, float *ypos, // pointers to current position in screen pixel space
|
float *xpos, float *ypos, // pointers to current position in screen pixel space
|
||||||
|
@ -669,6 +678,7 @@ struct stbtt_pack_context {
|
||||||
int height;
|
int height;
|
||||||
int stride_in_bytes;
|
int stride_in_bytes;
|
||||||
int padding;
|
int padding;
|
||||||
|
int skip_missing;
|
||||||
unsigned int h_oversample, v_oversample;
|
unsigned int h_oversample, v_oversample;
|
||||||
unsigned char *pixels;
|
unsigned char *pixels;
|
||||||
void *nodes;
|
void *nodes;
|
||||||
|
@ -694,7 +704,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
|
||||||
// file will only define one font and it always be at offset 0, so it will
|
// file will only define one font and it always be at offset 0, so it will
|
||||||
// return '0' for index 0, and -1 for all other indices.
|
// return '0' for index 0, and -1 for all other indices.
|
||||||
|
|
||||||
// The following structure is defined publically so you can declare one on
|
// The following structure is defined publicly so you can declare one on
|
||||||
// the stack or as a global or etc, but you should treat it as opaque.
|
// the stack or as a global or etc, but you should treat it as opaque.
|
||||||
struct stbtt_fontinfo
|
struct stbtt_fontinfo
|
||||||
{
|
{
|
||||||
|
@ -733,6 +743,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
|
||||||
// and you want a speed-up, call this function with the character you're
|
// and you want a speed-up, call this function with the character you're
|
||||||
// going to process, then use glyph-based functions instead of the
|
// going to process, then use glyph-based functions instead of the
|
||||||
// codepoint-based functions.
|
// codepoint-based functions.
|
||||||
|
// Returns 0 if the character codepoint is not defined in the font.
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -820,7 +831,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
|
||||||
// returns # of vertices and fills *vertices with the pointer to them
|
// returns # of vertices and fills *vertices with the pointer to them
|
||||||
// these are expressed in "unscaled" coordinates
|
// these are expressed in "unscaled" coordinates
|
||||||
//
|
//
|
||||||
// The shape is a series of countours. Each one starts with
|
// The shape is a series of contours. Each one starts with
|
||||||
// a STBTT_moveto, then consists of a series of mixed
|
// a STBTT_moveto, then consists of a series of mixed
|
||||||
// STBTT_lineto and STBTT_curveto segments. A lineto
|
// STBTT_lineto and STBTT_curveto segments. A lineto
|
||||||
// draws a line from previous endpoint to its x,y; a curveto
|
// draws a line from previous endpoint to its x,y; a curveto
|
||||||
|
@ -916,7 +927,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
||||||
STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff);
|
STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff);
|
||||||
// These functions compute a discretized SDF field for a single character, suitable for storing
|
// These functions compute a discretized SDF field for a single character, suitable for storing
|
||||||
// in a single-channel texture, sampling with bilinear filtering, and testing against
|
// in a single-channel texture, sampling with bilinear filtering, and testing against
|
||||||
// larger than some threshhold to produce scalable fonts.
|
// larger than some threshold to produce scalable fonts.
|
||||||
// info -- the font
|
// info -- the font
|
||||||
// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
|
// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
|
||||||
// glyph/codepoint -- the character to generate the SDF for
|
// glyph/codepoint -- the character to generate the SDF for
|
||||||
|
@ -2463,6 +2474,7 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
||||||
if (valueFormat2 != 0) return 0;
|
if (valueFormat2 != 0) return 0;
|
||||||
|
|
||||||
STBTT_assert(coverageIndex < pairSetCount);
|
STBTT_assert(coverageIndex < pairSetCount);
|
||||||
|
STBTT__NOTUSED(pairSetCount);
|
||||||
|
|
||||||
needle=glyph2;
|
needle=glyph2;
|
||||||
r=pairValueCount-1;
|
r=pairValueCount-1;
|
||||||
|
@ -3160,7 +3172,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
||||||
if (e->y0 != e->y1) {
|
if (e->y0 != e->y1) {
|
||||||
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
||||||
if (z != NULL) {
|
if (z != NULL) {
|
||||||
STBTT_assert(z->ey >= scan_y_top);
|
if (j == 0 && off_y != 0) {
|
||||||
|
if (z->ey < scan_y_top) {
|
||||||
|
// this can happen due to subpixel positioning and some kind of fp rounding error i think
|
||||||
|
z->ey = scan_y_top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds
|
||||||
// insert at front
|
// insert at front
|
||||||
z->next = active;
|
z->next = active;
|
||||||
active = z;
|
active = z;
|
||||||
|
@ -3229,7 +3247,7 @@ static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n)
|
||||||
|
|
||||||
static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n)
|
static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n)
|
||||||
{
|
{
|
||||||
/* threshhold for transitioning to insertion sort */
|
/* threshold for transitioning to insertion sort */
|
||||||
while (n > 12) {
|
while (n > 12) {
|
||||||
stbtt__edge t;
|
stbtt__edge t;
|
||||||
int c01,c12,c,m,i,j;
|
int c01,c12,c,m,i,j;
|
||||||
|
@ -3364,7 +3382,7 @@ static void stbtt__add_point(stbtt__point *points, int n, float x, float y)
|
||||||
points[n].y = y;
|
points[n].y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tesselate until threshhold p is happy... @TODO warped to compensate for non-linear stretching
|
// tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching
|
||||||
static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n)
|
static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n)
|
||||||
{
|
{
|
||||||
// midpoint
|
// midpoint
|
||||||
|
@ -3789,6 +3807,7 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, in
|
||||||
spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw;
|
spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw;
|
||||||
spc->h_oversample = 1;
|
spc->h_oversample = 1;
|
||||||
spc->v_oversample = 1;
|
spc->v_oversample = 1;
|
||||||
|
spc->skip_missing = 0;
|
||||||
|
|
||||||
stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
|
stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
|
||||||
|
|
||||||
|
@ -3814,6 +3833,11 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
|
||||||
spc->v_oversample = v_oversample;
|
spc->v_oversample = v_oversample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip)
|
||||||
|
{
|
||||||
|
spc->skip_missing = skip;
|
||||||
|
}
|
||||||
|
|
||||||
#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)
|
#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)
|
||||||
|
|
||||||
static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)
|
static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)
|
||||||
|
@ -3967,6 +3991,9 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
|
||||||
int x0,y0,x1,y1;
|
int x0,y0,x1,y1;
|
||||||
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
||||||
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
||||||
|
if (glyph == 0 && spc->skip_missing) {
|
||||||
|
rects[k].w = rects[k].h = 0;
|
||||||
|
} else {
|
||||||
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
||||||
scale * spc->h_oversample,
|
scale * spc->h_oversample,
|
||||||
scale * spc->v_oversample,
|
scale * spc->v_oversample,
|
||||||
|
@ -3974,6 +4001,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
|
||||||
&x0,&y0,&x1,&y1);
|
&x0,&y0,&x1,&y1);
|
||||||
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
||||||
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
||||||
|
}
|
||||||
++k;
|
++k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4026,7 +4054,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
|
||||||
sub_y = stbtt__oversample_shift(spc->v_oversample);
|
sub_y = stbtt__oversample_shift(spc->v_oversample);
|
||||||
for (j=0; j < ranges[i].num_chars; ++j) {
|
for (j=0; j < ranges[i].num_chars; ++j) {
|
||||||
stbrp_rect *r = &rects[k];
|
stbrp_rect *r = &rects[k];
|
||||||
if (r->was_packed) {
|
if (r->was_packed && r->w != 0 && r->h != 0) {
|
||||||
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
|
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
|
||||||
int advance, lsb, x0,y0,x1,y1;
|
int advance, lsb, x0,y0,x1,y1;
|
||||||
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
||||||
|
@ -4140,6 +4168,19 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *
|
||||||
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap)
|
||||||
|
{
|
||||||
|
int i_ascent, i_descent, i_lineGap;
|
||||||
|
float scale;
|
||||||
|
stbtt_fontinfo info;
|
||||||
|
stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index));
|
||||||
|
scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size);
|
||||||
|
stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap);
|
||||||
|
*ascent = (float) i_ascent * scale;
|
||||||
|
*descent = (float) i_descent * scale;
|
||||||
|
*lineGap = (float) i_lineGap * scale;
|
||||||
|
}
|
||||||
|
|
||||||
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
|
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
|
||||||
{
|
{
|
||||||
float ipw = 1.0f / pw, iph = 1.0f / ph;
|
float ipw = 1.0f / pw, iph = 1.0f / ph;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue