diff options
Diffstat (limited to 'thirdparty/misc')
-rw-r--r-- | thirdparty/misc/base64.h | 4 | ||||
-rw-r--r-- | thirdparty/misc/clipper-exceptions.patch | 154 | ||||
-rw-r--r-- | thirdparty/misc/clipper.cpp | 68 | ||||
-rw-r--r-- | thirdparty/misc/pcg.cpp | 10 | ||||
-rw-r--r-- | thirdparty/misc/pcg.h | 1 | ||||
-rw-r--r-- | thirdparty/misc/stb_truetype.h | 87 | ||||
-rw-r--r-- | thirdparty/misc/stb_vorbis.c | 31 | ||||
-rw-r--r-- | thirdparty/misc/yuv2rgb.h | 121 |
8 files changed, 338 insertions, 138 deletions
diff --git a/thirdparty/misc/base64.h b/thirdparty/misc/base64.h index 4c300382c1..ffcd0af973 100644 --- a/thirdparty/misc/base64.h +++ b/thirdparty/misc/base64.h @@ -11,8 +11,8 @@ extern "C" { -uint32_t base64_encode(char *to, char *from, uint32_t len); -uint32_t base64_decode(char *to, char *from, uint32_t len); +long base64_encode(char *to, char *from, unsigned int len); +long base64_decode(char *to, char *from, unsigned int len); }; #endif /* BASE64_H */ diff --git a/thirdparty/misc/clipper-exceptions.patch b/thirdparty/misc/clipper-exceptions.patch new file mode 100644 index 0000000000..537afd59b3 --- /dev/null +++ b/thirdparty/misc/clipper-exceptions.patch @@ -0,0 +1,154 @@ +diff --git a/thirdparty/misc/clipper.cpp b/thirdparty/misc/clipper.cpp +index 8c3a59c4ca..c67045d113 100644 +--- a/thirdparty/misc/clipper.cpp ++++ b/thirdparty/misc/clipper.cpp +@@ -48,6 +48,38 @@ + #include <ostream> + #include <functional> + ++//Explicitly disables exceptions handling for target platform ++//#define CLIPPER_NOEXCEPTION ++ ++#define CLIPPER_THROW(exception) std::abort() ++#define CLIPPER_TRY if(true) ++#define CLIPPER_CATCH(exception) if(false) ++ ++#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) ++ #ifndef CLIPPER_NOEXCEPTION ++ #undef CLIPPER_THROW ++ #define CLIPPER_THROW(exception) throw exception ++ #undef CLIPPER_TRY ++ #define CLIPPER_TRY try ++ #undef CLIPPER_CATCH ++ #define CLIPPER_CATCH(exception) catch(exception) ++ #endif ++#endif ++ ++//Optionally allows to override exception macros ++#if defined(CLIPPER_THROW_USER) ++ #undef CLIPPER_THROW ++ #define CLIPPER_THROW CLIPPER_THROW_USER ++#endif ++#if defined(CLIPPER_TRY_USER) ++ #undef CLIPPER_TRY ++ #define CLIPPER_TRY CLIPPER_TRY_USER ++#endif ++#if defined(CLIPPER_CATCH_USER) ++ #undef CLIPPER_CATCH ++ #define CLIPPER_CATCH CLIPPER_CATCH_USER ++#endif ++ + namespace ClipperLib { + + static double const pi = 3.141592653589793238; +@@ -898,7 +930,7 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange) + if (useFullRange) + { + if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) +- throw clipperException("Coordinate outside allowed range"); ++ CLIPPER_THROW(clipperException("Coordinate outside allowed range")); + } + else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) + { +@@ -1046,10 +1078,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) + { + #ifdef use_lines + if (!Closed && PolyTyp == ptClip) +- throw clipperException("AddPath: Open paths must be subject."); ++ CLIPPER_THROW(clipperException("AddPath: Open paths must be subject.")); + #else + if (!Closed) +- throw clipperException("AddPath: Open paths have been disabled."); ++ CLIPPER_THROW(clipperException("AddPath: Open paths have been disabled.")); + #endif + + int highI = (int)pg.size() -1; +@@ -1062,7 +1094,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) + + bool IsFlat = true; + //1. Basic (first) edge initialization ... +- try ++ CLIPPER_TRY + { + edges[1].Curr = pg[1]; + RangeTest(pg[0], m_UseFullRange); +@@ -1075,10 +1107,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) + InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]); + } + } +- catch(...) ++ CLIPPER_CATCH(...) + { + delete [] edges; +- throw; //range test fails ++ CLIPPER_THROW(); //range test fails + } + TEdge *eStart = &edges[0]; + +@@ -1442,7 +1474,7 @@ void ClipperBase::SwapPositionsInAEL(TEdge *Edge1, TEdge *Edge2) + void ClipperBase::UpdateEdgeIntoAEL(TEdge *&e) + { + if (!e->NextInLML) +- throw clipperException("UpdateEdgeIntoAEL: invalid call"); ++ CLIPPER_THROW(clipperException("UpdateEdgeIntoAEL: invalid call")); + + e->NextInLML->OutIdx = e->OutIdx; + TEdge* AelPrev = e->PrevInAEL; +@@ -1510,7 +1542,7 @@ bool Clipper::Execute(ClipType clipType, Paths &solution, + { + if( m_ExecuteLocked ) return false; + if (m_HasOpenPaths) +- throw clipperException("Error: PolyTree struct is needed for open path clipping."); ++ CLIPPER_THROW(clipperException("Error: PolyTree struct is needed for open path clipping.")); + m_ExecuteLocked = true; + solution.resize(0); + m_SubjFillType = subjFillType; +@@ -1560,7 +1592,7 @@ void Clipper::FixHoleLinkage(OutRec &outrec) + bool Clipper::ExecuteInternal() + { + bool succeeded = true; +- try { ++ CLIPPER_TRY { + Reset(); + m_Maxima = MaximaList(); + m_SortedEdges = 0; +@@ -1583,7 +1615,7 @@ bool Clipper::ExecuteInternal() + InsertLocalMinimaIntoAEL(botY); + } + } +- catch(...) ++ CLIPPER_CATCH(...) + { + succeeded = false; + } +@@ -2827,18 +2859,18 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) + bool Clipper::ProcessIntersections(const cInt topY) + { + if( !m_ActiveEdges ) return true; +- try { ++ CLIPPER_TRY { + BuildIntersectList(topY); + size_t IlSize = m_IntersectList.size(); + if (IlSize == 0) return true; + if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList(); + else return false; + } +- catch(...) ++ CLIPPER_CATCH(...) + { + m_SortedEdges = 0; + DisposeIntersectNodes(); +- throw clipperException("ProcessIntersections error"); ++ CLIPPER_THROW(clipperException("ProcessIntersections error")); + } + m_SortedEdges = 0; + return true; +@@ -3002,7 +3034,7 @@ void Clipper::DoMaxima(TEdge *e) + DeleteFromAEL(eMaxPair); + } + #endif +- else throw clipperException("DoMaxima error"); ++ else CLIPPER_THROW(clipperException("DoMaxima error")); + } + //------------------------------------------------------------------------------ + diff --git a/thirdparty/misc/clipper.cpp b/thirdparty/misc/clipper.cpp index d3143fe5ab..c67045d113 100644 --- a/thirdparty/misc/clipper.cpp +++ b/thirdparty/misc/clipper.cpp @@ -48,6 +48,38 @@ #include <ostream> #include <functional> +//Explicitly disables exceptions handling for target platform +//#define CLIPPER_NOEXCEPTION + +#define CLIPPER_THROW(exception) std::abort() +#define CLIPPER_TRY if(true) +#define CLIPPER_CATCH(exception) if(false) + +#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) + #ifndef CLIPPER_NOEXCEPTION + #undef CLIPPER_THROW + #define CLIPPER_THROW(exception) throw exception + #undef CLIPPER_TRY + #define CLIPPER_TRY try + #undef CLIPPER_CATCH + #define CLIPPER_CATCH(exception) catch(exception) + #endif +#endif + +//Optionally allows to override exception macros +#if defined(CLIPPER_THROW_USER) + #undef CLIPPER_THROW + #define CLIPPER_THROW CLIPPER_THROW_USER +#endif +#if defined(CLIPPER_TRY_USER) + #undef CLIPPER_TRY + #define CLIPPER_TRY CLIPPER_TRY_USER +#endif +#if defined(CLIPPER_CATCH_USER) + #undef CLIPPER_CATCH + #define CLIPPER_CATCH CLIPPER_CATCH_USER +#endif + namespace ClipperLib { static double const pi = 3.141592653589793238; @@ -898,7 +930,7 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange) if (useFullRange) { if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) - throw clipperException("Coordinate outside allowed range"); + CLIPPER_THROW(clipperException("Coordinate outside allowed range")); } else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) { @@ -1046,10 +1078,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) { #ifdef use_lines if (!Closed && PolyTyp == ptClip) - throw clipperException("AddPath: Open paths must be subject."); + CLIPPER_THROW(clipperException("AddPath: Open paths must be subject.")); #else if (!Closed) - throw clipperException("AddPath: Open paths have been disabled."); + CLIPPER_THROW(clipperException("AddPath: Open paths have been disabled.")); #endif int highI = (int)pg.size() -1; @@ -1062,7 +1094,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) bool IsFlat = true; //1. Basic (first) edge initialization ... - try + CLIPPER_TRY { edges[1].Curr = pg[1]; RangeTest(pg[0], m_UseFullRange); @@ -1075,10 +1107,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]); } } - catch(...) + CLIPPER_CATCH(...) { delete [] edges; - throw; //range test fails + CLIPPER_THROW(); //range test fails } TEdge *eStart = &edges[0]; @@ -1442,7 +1474,7 @@ void ClipperBase::SwapPositionsInAEL(TEdge *Edge1, TEdge *Edge2) void ClipperBase::UpdateEdgeIntoAEL(TEdge *&e) { if (!e->NextInLML) - throw clipperException("UpdateEdgeIntoAEL: invalid call"); + CLIPPER_THROW(clipperException("UpdateEdgeIntoAEL: invalid call")); e->NextInLML->OutIdx = e->OutIdx; TEdge* AelPrev = e->PrevInAEL; @@ -1510,7 +1542,7 @@ bool Clipper::Execute(ClipType clipType, Paths &solution, { if( m_ExecuteLocked ) return false; if (m_HasOpenPaths) - throw clipperException("Error: PolyTree struct is needed for open path clipping."); + CLIPPER_THROW(clipperException("Error: PolyTree struct is needed for open path clipping.")); m_ExecuteLocked = true; solution.resize(0); m_SubjFillType = subjFillType; @@ -1560,7 +1592,7 @@ void Clipper::FixHoleLinkage(OutRec &outrec) bool Clipper::ExecuteInternal() { bool succeeded = true; - try { + CLIPPER_TRY { Reset(); m_Maxima = MaximaList(); m_SortedEdges = 0; @@ -1583,7 +1615,7 @@ bool Clipper::ExecuteInternal() InsertLocalMinimaIntoAEL(botY); } } - catch(...) + CLIPPER_CATCH(...) { succeeded = false; } @@ -2827,18 +2859,18 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) bool Clipper::ProcessIntersections(const cInt topY) { if( !m_ActiveEdges ) return true; - try { + CLIPPER_TRY { BuildIntersectList(topY); size_t IlSize = m_IntersectList.size(); if (IlSize == 0) return true; if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList(); else return false; } - catch(...) + CLIPPER_CATCH(...) { m_SortedEdges = 0; DisposeIntersectNodes(); - throw clipperException("ProcessIntersections error"); + CLIPPER_THROW(clipperException("ProcessIntersections error")); } m_SortedEdges = 0; return true; @@ -3002,7 +3034,7 @@ void Clipper::DoMaxima(TEdge *e) DeleteFromAEL(eMaxPair); } #endif - else throw clipperException("DoMaxima error"); + else CLIPPER_THROW(clipperException("DoMaxima error")); } //------------------------------------------------------------------------------ @@ -4329,10 +4361,10 @@ double DistanceFromLineSqrd( const IntPoint& pt, const IntPoint& ln1, const IntPoint& ln2) { //The equation of a line in general form (Ax + By + C = 0) - //given 2 points (x¹,y¹) & (x²,y²) is ... - //(y¹ - y²)x + (x² - x¹)y + (y² - y¹)x¹ - (x² - x¹)y¹ = 0 - //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹ - //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²) + //given 2 points (x¹,y¹) & (x²,y²) is ... + //(y¹ - y²)x + (x² - x¹)y + (y² - y¹)x¹ - (x² - x¹)y¹ = 0 + //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹ + //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²) //see http://en.wikipedia.org/wiki/Perpendicular_distance double A = double(ln1.Y - ln2.Y); double B = double(ln2.X - ln1.X); diff --git a/thirdparty/misc/pcg.cpp b/thirdparty/misc/pcg.cpp index eac3b36d36..c421e16f89 100644 --- a/thirdparty/misc/pcg.cpp +++ b/thirdparty/misc/pcg.cpp @@ -13,3 +13,13 @@ uint32_t pcg32_random_r(pcg32_random_t* rng) uint32_t rot = oldstate >> 59u; return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); } + +// Source from http://www.pcg-random.org/downloads/pcg-c-basic-0.9.zip +void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq) +{ + rng->state = 0U; + rng->inc = (initseq << 1u) | 1u; + pcg32_random_r(rng); + rng->state += initstate; + pcg32_random_r(rng); +} diff --git a/thirdparty/misc/pcg.h b/thirdparty/misc/pcg.h index e2d66d51d5..6f42b3b094 100644 --- a/thirdparty/misc/pcg.h +++ b/thirdparty/misc/pcg.h @@ -10,5 +10,6 @@ typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t; uint32_t pcg32_random_r(pcg32_random_t* rng); +void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq); #endif // RANDOM_H diff --git a/thirdparty/misc/stb_truetype.h b/thirdparty/misc/stb_truetype.h index e2efae2285..72299ea86d 100644 --- a/thirdparty/misc/stb_truetype.h +++ b/thirdparty/misc/stb_truetype.h @@ -1,4 +1,4 @@ -// stb_truetype.h - v1.19 - public domain +// stb_truetype.h - v1.21 - public domain // authored from 2009-2016 by Sean Barrett / RAD Game Tools // // This library processes TrueType files: @@ -49,6 +49,8 @@ // // VERSION HISTORY // +// 1.21 (2019-02-25) fix warning +// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() // 1.19 (2018-02-11) GPOS kerning, STBTT_fmod // 1.18 (2018-01-29) add missing function // 1.17 (2017-07-23) make more arguments const; doc fix @@ -75,7 +77,7 @@ // // 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: // #define STB_TRUETYPE_IMPLEMENTATION // before the #include of this file. This expands out the actual @@ -242,19 +244,6 @@ // recommend it. // // -// SOURCE STATISTICS (based on v0.6c, 2050 LOC) -// -// Documentation & header file 520 LOC \___ 660 LOC documentation -// Sample code 140 LOC / -// Truetype parsing 620 LOC ---- 620 LOC TrueType -// Software rasterization 240 LOC \ . -// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation -// Bitmap management 100 LOC / -// Baked bitmap interface 70 LOC / -// Font name matching & access 150 LOC ---- 150 -// C runtime library abstraction 60 LOC ---- 60 -// -// // PERFORMANCE MEASUREMENTS FOR 1.06: // // 32-bit 64-bit @@ -556,6 +545,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. +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 +632,12 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h // To use with PackFontRangesGather etc., you must set it before calls // 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 int char_index, // character to display float *xpos, float *ypos, // pointers to current position in screen pixel space @@ -669,6 +666,7 @@ struct stbtt_pack_context { int height; int stride_in_bytes; int padding; + int skip_missing; unsigned int h_oversample, v_oversample; unsigned char *pixels; void *nodes; @@ -694,7 +692,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 // 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. struct stbtt_fontinfo { @@ -733,6 +731,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 // going to process, then use glyph-based functions instead of the // codepoint-based functions. +// Returns 0 if the character codepoint is not defined in the font. ////////////////////////////////////////////////////////////////////////////// @@ -820,7 +819,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 // 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 // STBTT_lineto and STBTT_curveto segments. A lineto // draws a line from previous endpoint to its x,y; a curveto @@ -916,7 +915,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); // 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 -// larger than some threshhold to produce scalable fonts. +// larger than some threshold to produce scalable fonts. // info -- the font // 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 @@ -2463,6 +2462,7 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i if (valueFormat2 != 0) return 0; STBTT_assert(coverageIndex < pairSetCount); + STBTT__NOTUSED(pairSetCount); needle=glyph2; r=pairValueCount-1; @@ -3160,7 +3160,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, if (e->y0 != e->y1) { stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata); 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 z->next = active; active = z; @@ -3229,7 +3235,7 @@ static void stbtt__sort_edges_ins_sort(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) { stbtt__edge t; int c01,c12,c,m,i,j; @@ -3364,7 +3370,7 @@ static void stbtt__add_point(stbtt__point *points, int n, float x, float 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) { // midpoint @@ -3789,6 +3795,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->h_oversample = 1; spc->v_oversample = 1; + spc->skip_missing = 0; stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes); @@ -3814,6 +3821,11 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h 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) static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) @@ -3967,13 +3979,17 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb 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 glyph = stbtt_FindGlyphIndex(info, codepoint); - stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, - scale * spc->h_oversample, - scale * spc->v_oversample, - 0,0, - &x0,&y0,&x1,&y1); - 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); + if (glyph == 0 && spc->skip_missing) { + rects[k].w = rects[k].h = 0; + } else { + stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, + scale * spc->h_oversample, + scale * spc->v_oversample, + 0,0, + &x0,&y0,&x1,&y1); + 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); + } ++k; } } @@ -4026,7 +4042,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const sub_y = stbtt__oversample_shift(spc->v_oversample); for (j=0; j < ranges[i].num_chars; ++j) { 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]; 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]; @@ -4140,6 +4156,19 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char * 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) { float ipw = 1.0f / pw, iph = 1.0f / ph; diff --git a/thirdparty/misc/stb_vorbis.c b/thirdparty/misc/stb_vorbis.c index 8edcf0f38a..88276026ef 100644 --- a/thirdparty/misc/stb_vorbis.c +++ b/thirdparty/misc/stb_vorbis.c @@ -1,4 +1,4 @@ -// Ogg Vorbis audio decoder - v1.14 - public domain +// Ogg Vorbis audio decoder - v1.15 - public domain // http://nothings.org/stb_vorbis/ // // Original version written by Sean Barrett in 2007. @@ -33,6 +33,7 @@ // Timur Gagiev // // Partial history: +// 1.15 - 2019-02-07 - explicit failure if Ogg Skeleton data is found // 1.14 - 2018-02-11 - delete bogus dealloca usage // 1.13 - 2018-01-29 - fix truncation of last frame (hopefully) // 1.12 - 2017-11-21 - limit residue begin/end to blocksize/2 to avoid large temp allocs in bad/corrupt files @@ -253,7 +254,7 @@ extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close, // create an ogg vorbis decoder from an open FILE *, looking for a stream at // the _current_ seek point (ftell). on failure, returns NULL and sets *error. // note that stb_vorbis must "own" this stream; if you seek it in between -// calls to stb_vorbis, it will become confused. Morever, if you attempt to +// calls to stb_vorbis, it will become confused. Moreover, if you attempt to // perform stb_vorbis_seek_*() operations on this file, it will assume it // owns the _entire_ rest of the file after the start point. Use the next // function, stb_vorbis_open_file_section(), to limit it. @@ -374,7 +375,8 @@ enum STBVorbisError VORBIS_invalid_first_page, VORBIS_bad_packet_type, VORBIS_cant_find_last_page, - VORBIS_seek_failed + VORBIS_seek_failed, + VORBIS_ogg_skeleton_not_supported }; @@ -1073,7 +1075,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) assert(z >= 0 && z < 32); available[z] = 0; add_entry(c, bit_reverse(res), i, m++, len[i], values); - // propogate availability up the tree + // propagate availability up the tree if (z != len[i]) { assert(len[i] >= 0 && len[i] < 32); for (y=len[i]; y > z; --y) { @@ -2637,7 +2639,7 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) // once I combined the passes. // so there's a missing 'times 2' here (for adding X to itself). - // this propogates through linearly to the end, where the numbers + // this propagates through linearly to the end, where the numbers // are 1/2 too small, and need to be compensated for. { @@ -3578,7 +3580,22 @@ static int start_decoder(vorb *f) if (f->page_flag & PAGEFLAG_continued_packet) return error(f, VORBIS_invalid_first_page); // check for expected packet length if (f->segment_count != 1) return error(f, VORBIS_invalid_first_page); - if (f->segments[0] != 30) return error(f, VORBIS_invalid_first_page); + if (f->segments[0] != 30) { + // check for the Ogg skeleton fishead identifying header to refine our error + if (f->segments[0] == 64 && + getn(f, header, 6) && + header[0] == 'f' && + header[1] == 'i' && + header[2] == 's' && + header[3] == 'h' && + header[4] == 'e' && + header[5] == 'a' && + get8(f) == 'd' && + get8(f) == '\0') return error(f, VORBIS_ogg_skeleton_not_supported); + else + return error(f, VORBIS_invalid_first_page); + } + // read packet // check packet header if (get8(f) != VORBIS_packet_id) return error(f, VORBIS_invalid_first_page); @@ -4566,7 +4583,7 @@ static int get_seek_page_info(stb_vorbis *f, ProbedPage *z) return 1; } -// rarely used function to seek back to the preceeding page while finding the +// rarely used function to seek back to the preceding page while finding the // start of a packet static int go_to_page_before(stb_vorbis *f, unsigned int limit_offset) { diff --git a/thirdparty/misc/yuv2rgb.h b/thirdparty/misc/yuv2rgb.h index 3ec8388246..d8f7fd6de2 100644 --- a/thirdparty/misc/yuv2rgb.h +++ b/thirdparty/misc/yuv2rgb.h @@ -24,6 +24,14 @@ does not infringe any patents that apply in your area before you ship it. */ +/* + * Please note that this version has been modified for various reasons: + * 1. Using the Godot core typedefs + * 2. At some point or another the code relied on the byte order of a uint32_t, this has been fixed + * 3. Output has been reordered to struct { uint8_t r, g, b, a; } precisely in accordance with the function names + * 4. Removing unused 'dither' parameter + */ + #ifndef YUV2RGB_H #define YUV2RGB_H @@ -803,6 +811,8 @@ static const uint32_t tables[256*3] = { 0xE6365800U }; +/* -- Common -- */ + #define FLAGS 0x40080100 #define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) #define READY(Y) tables[Y] @@ -820,12 +830,14 @@ do { \ #define STORE(Y,DSTPTR) \ do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ + *(DSTPTR)++ = (Y)>>22; \ + *(DSTPTR)++ = (Y); \ + *(DSTPTR)++ = 255; \ } while (0 == 1) +/* -- End Common -- */ + static void yuv422_2_rgb8888(uint8_t *dst_ptr, const uint8_t *y_ptr, const uint8_t *u_ptr, @@ -834,8 +846,7 @@ static void yuv422_2_rgb8888(uint8_t *dst_ptr, int32_t height, int32_t y_span, int32_t uv_span, - int32_t dst_span, - int32_t dither) + int32_t dst_span) { height -= 1; while (height > 0) @@ -909,35 +920,7 @@ static void yuv422_2_rgb8888(uint8_t *dst_ptr, } } - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - (DSTPTR) = 0xFF000000 | (Y & 0xFF) | (0xFF00 & (Y>>14)) | (0xFF0000 & (Y<<5));\ -} while (0 == 1) - -static void yuv420_2_rgb8888(uint8_t *dst_ptr_, +static void yuv420_2_rgb8888(uint8_t *dst_ptr, const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, @@ -945,12 +928,9 @@ static void yuv420_2_rgb8888(uint8_t *dst_ptr_, int32_t height, int32_t y_span, int32_t uv_span, - int32_t dst_span, - int32_t dither) + int32_t dst_span) { - uint32_t *dst_ptr = (uint32_t *)(void *)dst_ptr_; - dst_span >>= 2; - + /* The 'dst_ptr as uint32_t' thing is not endianness-aware, so that's been removed. */ height -= 1; while (height > 0) { @@ -960,36 +940,38 @@ static void yuv420_2_rgb8888(uint8_t *dst_ptr_, { /* Do 2 column pairs */ uint32_t uv, y0, y1; + uint8_t * dst_ptr_1span = dst_ptr + dst_span; uv = READUV(*u_ptr++,*v_ptr++); y1 = uv + READY(y_ptr[y_span]); y0 = uv + READY(*y_ptr++); FIXUP(y1); FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); + STORE(y1, dst_ptr_1span); + STORE(y0, dst_ptr); y1 = uv + READY(y_ptr[y_span]); y0 = uv + READY(*y_ptr++); FIXUP(y1); FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); + STORE(y1, dst_ptr_1span); + STORE(y0, dst_ptr); height += (2<<16); } if ((height>>16) == 0) { /* Trailing column pair */ uint32_t uv, y0, y1; + uint8_t * dst_ptr_1span = dst_ptr + dst_span; uv = READUV(*u_ptr,*v_ptr); y1 = uv + READY(y_ptr[y_span]); y0 = uv + READY(*y_ptr++); FIXUP(y1); FIXUP(y0); - STORE(y0, dst_ptr[dst_span]); - STORE(y1, *dst_ptr++); + STORE(y0, dst_ptr_1span); + STORE(y1, dst_ptr); } - dst_ptr += dst_span*2-width; + dst_ptr += (dst_span * 2) - (width * 4); y_ptr += y_span*2-width; u_ptr += uv_span-(width>>1); v_ptr += uv_span-(width>>1); @@ -1011,8 +993,8 @@ static void yuv420_2_rgb8888(uint8_t *dst_ptr_, y0 = uv + READY(*y_ptr++); FIXUP(y1); FIXUP(y0); - STORE(y1, *dst_ptr++); - STORE(y0, *dst_ptr++); + STORE(y1, dst_ptr); + STORE(y0, dst_ptr); height += (2<<16); } if ((height>>16) == 0) @@ -1023,42 +1005,11 @@ static void yuv420_2_rgb8888(uint8_t *dst_ptr_, uv = READUV(*u_ptr++,*v_ptr++); y0 = uv + READY(*y_ptr++); FIXUP(y0); - STORE(y0, *dst_ptr++); + STORE(y0, dst_ptr); } } } - - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ - *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ -} while (0 == 1) - static void yuv444_2_rgb8888(uint8_t *dst_ptr, const uint8_t *y_ptr, const uint8_t *u_ptr, @@ -1067,8 +1018,7 @@ static void yuv444_2_rgb8888(uint8_t *dst_ptr, int32_t height, int32_t y_span, int32_t uv_span, - int32_t dst_span, - int32_t dither) + int32_t dst_span) { height -= 1; while (height > 0) @@ -1143,4 +1093,11 @@ static void yuv444_2_rgb8888(uint8_t *dst_ptr, height -= 1; } } + +#undef FLAGS +#undef READUV +#undef READY +#undef FIXUP +#undef STORE + #endif // YUV2RGB_H |