Skip to content

Commit e36c25c

Browse files
committed
Update stb
This commit and, by extension, PR attempts to update `stb` in the most straightforward way possible as well as include fixes from main repo's unmerged PRs for cases rearing their ugly heads during everyday usage: - stb#1299: stb_rect_pack: Make rect_height_compare a stable sort - stb#1402: stb_image: Fix "unused invalid_chunk" with STBI_FAILURE_USERMSG - stb#1404: stb_image: Fix gif two_back memory address - stb#1420: stb_image: Improve error reporting if file operations fail within *_from_file functions - stb#1445: stb_vorbis: Few static analyzers fixes - stb#1487: stb_vorbis: Fix residue classdata bounding for f->temp_memory_required - stb#1490: stb_vorbis: Fix broken clamp in codebook_decode_deinterleave_repeat - stb#1496: stb_image: Fix pnm only build - stb#1497: stb_image: Fix memory leaks if stbi__convert failed - stb#1498: stb_vorbis: Fix memory leaks in stb_vorbis - stb#1499: stb_vorbis: Minor change to prevent the undefined behavior - left shift of a negative value - stb#1500: stb_vorbis: Fix signed integer overflow Includes additional small fixes that I felt didn't warrant a separate PR. Signed-off-by: mataha <mataha@users.noreply.github.com>
1 parent 0d748ad commit e36c25c

20 files changed

+1440
-1108
lines changed

dsp/core/core.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ int mulaw(int);
99
int unmulaw(int);
1010
void *double2byte(long, const void *, double, double) vallocesque;
1111
void *byte2double(long, const void *, double, double) vallocesque;
12-
void *dct(float[8][8], float, float, float, float, float);
13-
void *dctjpeg(float[8][8]);
12+
void *dct(float[restrict hasatleast 8][8], unsigned,
13+
float, float, float, float, float);
14+
void *dctjpeg(float[restrict hasatleast 8][8], unsigned);
1415
double det3(const double[3][3]) nosideeffect;
1516
void *inv3(double[restrict 3][3], const double[restrict 3][3], double);
1617
void *matmul3(double[restrict 3][3], const double[3][3], const double[3][3]);

dsp/core/dct.c

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,40 @@
1818
╚─────────────────────────────────────────────────────────────────────────────*/
1919
#include "dsp/core/core.h"
2020

21-
#define DCT(A, B, C, D, E, F, G, H, T, C0, C1, C2, C3, C4) \
22-
do { \
23-
T z1, z2, z3, z4, z5, z11, z13; \
24-
T t0, t1, t2, t3, t4, t5, t6, t7, t10, t11, t12, t13; \
25-
t0 = A + H; \
26-
t7 = A - H; \
27-
t1 = B + G; \
28-
t6 = B - G; \
29-
t2 = C + F; \
30-
t5 = C - F; \
31-
t3 = D + E; \
32-
t4 = D - E; \
33-
t10 = t0 + t3; \
34-
t13 = t0 - t3; \
35-
t11 = t1 + t2; \
36-
t12 = t1 - t2; \
37-
A = t10 + t11; \
38-
E = t10 - t11; \
39-
z1 = (t12 + t13) * C0; \
40-
C = t13 + z1; \
41-
G = t13 - z1; \
42-
t10 = t4 + t5; \
43-
t11 = t5 + t6; \
44-
t12 = t6 + t7; \
45-
z5 = (t10 - t12) * C1; \
46-
z2 = t10 * C2 + z5; \
47-
z4 = t12 * C3 + z5; \
48-
z3 = t11 * C4; \
49-
z11 = t7 + z3; \
50-
z13 = t7 - z3; \
51-
F = z13 + z2; \
52-
D = z13 - z2; \
53-
B = z11 + z4; \
54-
H = z11 - z4; \
21+
#define DCT(A, B, C, D, E, F, G, H, T, C0, C1, C2, C3, C4) \
22+
do { \
23+
T z1, z2, z3, z4, z5, z11, z13; \
24+
T t0, t1, t2, t3, t4, t5, t6, t7, t10, t11, t12, t13; \
25+
t0 = A + H; \
26+
t7 = A - H; \
27+
t1 = B + G; \
28+
t6 = B - G; \
29+
t2 = C + F; \
30+
t5 = C - F; \
31+
t3 = D + E; \
32+
t4 = D - E; \
33+
t10 = t0 + t3; \
34+
t13 = t0 - t3; \
35+
t11 = t1 + t2; \
36+
t12 = t1 - t2; \
37+
A = t10 + t11; \
38+
E = t10 - t11; \
39+
z1 = (t12 + t13) * C0; \
40+
C = t13 + z1; \
41+
G = t13 - z1; \
42+
t10 = t4 + t5; \
43+
t11 = t5 + t6; \
44+
t12 = t6 + t7; \
45+
z5 = (t10 - t12) * C1; \
46+
z2 = t10 * C2 + z5; \
47+
z4 = t12 * C3 + z5; \
48+
z3 = t11 * C4; \
49+
z11 = t7 + z3; \
50+
z13 = t7 - z3; \
51+
F = z13 + z2; \
52+
D = z13 - z2; \
53+
B = z11 + z4; \
54+
H = z11 - z4; \
5555
} while (0)
5656

5757
/**
@@ -65,20 +65,21 @@
6565
*
6666
* @cost ~100ns
6767
*/
68-
void *dct(float M[8][8], float c0, float c1, float c2, float c3, float c4) {
68+
void *dct(float M[restrict hasatleast 8][8], unsigned stride,
69+
float c0, float c1, float c2, float c3, float c4) {
6970
unsigned y, x;
70-
for (y = 0; y < 8; ++y) {
71+
for (y = 0; y < stride * 8; y += stride) {
7172
DCT(M[y][0], M[y][1], M[y][2], M[y][3], M[y][4], M[y][5], M[y][6], M[y][7],
7273
float, c0, c1, c2, c3, c4);
7374
}
74-
for (x = 0; x < 8; ++x) {
75+
for (x = 0; x < stride * 8; x += stride) {
7576
DCT(M[0][x], M[1][x], M[2][x], M[3][x], M[4][x], M[5][x], M[6][x], M[7][x],
7677
float, c0, c1, c2, c3, c4);
7778
}
7879
return M;
7980
}
8081

81-
void *dctjpeg(float M[8][8]) {
82-
return dct(M, .707106781f, .382683433f, .541196100f, 1.306562965f,
82+
void *dctjpeg(float M[restrict hasatleast 8][8], unsigned stride) {
83+
return dct(M, stride, .707106781f, .382683433f, .541196100f, 1.306562965f,
8384
.707106781f);
8485
}

third_party/stb/README.cosmo

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,34 @@ LOCAL CHANGES
55
- Removed undefined behavior
66
- Removed BMP [endian code made it 100x slower than PNG/JPEG]
77
- Removed PIC [never heard of it]
8-
- Removed TGA [consider imaagemagick convert command]
9-
- Removed PSD [consider imaagemagick convert command]
8+
- Removed TGA [consider imagemagick convert command]
9+
- Removed PSD [consider imagemagick convert command]
1010
- Removed HDR [mine eyes and wikipedia agree stb gamma math is off]
1111
- Patched PNG loading edge case
1212
- Fixed code C standard says is undefined
1313
- PNG now uses ultra-fast Chromium zlib w/ CLMUL crc32
1414
- Removed unnecessary ifdefs
1515
- Removed MSVC torture code
1616

17-
SYNCHRONIZATION POINT
17+
SYNCHRONIZATION POINT (`--date=format:"%a %b %d %H:%M:%S %Y %z"`)
1818

19-
commit f67165c2bb2af3060ecae7d20d6f731173485ad0
20-
Author: Sean Barrett <sean2@nothings.org>
21-
Date: Mon Oct 28 09:30:02 2019 -0700
19+
commit 5736b15f7ea0ffb08dd38af21067c314d6a3aae9
20+
Author: Sean Barrett <seanb@radgametools.com>
21+
Date: Sun Jan 29 10:46:04 2023 -0800
2222

23-
Update README.md
23+
re-add perlin noise again
24+
25+
ADDITIONAL CHANGES/FIXES:
26+
27+
- https://github.com/nothings/stb/pull/1299
28+
- https://github.com/nothings/stb/pull/1402
29+
- https://github.com/nothings/stb/pull/1404
30+
- https://github.com/nothings/stb/pull/1420
31+
- https://github.com/nothings/stb/pull/1445
32+
- https://github.com/nothings/stb/pull/1487
33+
- https://github.com/nothings/stb/pull/1490
34+
- https://github.com/nothings/stb/pull/1496
35+
- https://github.com/nothings/stb/pull/1497
36+
- https://github.com/nothings/stb/pull/1498
37+
- https://github.com/nothings/stb/pull/1499
38+
- https://github.com/nothings/stb/pull/1500

third_party/stb/README.txt

Lines changed: 92 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
/*
2-
* stb_image - v2.23 - public domain image loader - http://nothings.org/stb
1+
/* stb_image - v2.28 - public domain image loader - http://nothings.org/stb
32
* no warranty implied; use at your own risk
43
*
54
* [heavily modified by justine tunney]
65
*
76
* JPEG baseline & progressive (12 bpc/arithmetic not supported, same
8-
* as stock IJG lib) PNG 1/2/4/8/16-bit-per-channel
7+
* as stock IJG lib)
8+
* PNG 1/2/4/8/16-bit-per-channel
99
* GIF (*comp always reports as 4-channel)
10-
* HDR (radiance rgbE format)
1110
* PNM (PPM and PGM binary only)
1211
*
1312
* Animated GIF still needs a proper API, but here's one way to do it:
@@ -18,45 +17,53 @@
1817
*
1918
* ============================ Contributors =========================
2019
*
21-
* Image formats Extensions, features
22-
* Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
23-
* Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
24-
* Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
25-
* Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
26-
* Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
27-
* Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
28-
* Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
29-
* github:urraka (animated gif) Junggon Kim (PNM comments)
30-
* Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
31-
* socks-the-fox (16-bit PNG)
32-
* Jeremy Sawicki (ImageNet JPGs)
33-
* Mikhail Morozov (1-bit BMP)
34-
* Optimizations & bugfixes Anael Seghezzi (is-16-bit query)
35-
* Fabian "ryg" Giesen
36-
* Arseny Kapoulkine
37-
* John-Mark Allen
20+
* Image formats Extensions, features
21+
* Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
22+
* Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
23+
* Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
24+
* Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
25+
* Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
26+
* Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
27+
* Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
28+
* github:urraka (animated gif) Junggon Kim (PNM comments)
29+
* Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
30+
* socks-the-fox (16-bit PNG)
31+
* Optimizations & bugfixes Jeremy Sawicki (ImageNet JPGs)
32+
* Fabian "ryg" Giesen Mikhail Morozov (1-bit BMP)
33+
* Arseny Kapoulkine Anael Seghezzi (is-16-bit query)
34+
* John-Mark Allen Simon Breuss (16-bit PNM)
3835
* Carmelo J Fdez-Aguera
3936
*
4037
* Bug & warning fixes
41-
* Marc LeBlanc David Woo Guillaume George Martins Mozeiko
42-
* Christpher Lloyd Jerry Jansson Joseph Thomson Phil Jordan
43-
* Dave Moore Roy Eltham Hayaki Saito Nathan Reed
44-
* Won Chun Luke Graham Johan Duparc Nick Verigakis
45-
* the Horde3D community Thomas Ruf Ronny Chevalier github:rlyeh
46-
* Janez Zemva John Bartholomew Michal Cichon github:romigrou
47-
* Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
48-
* Laurent Gomila Cort Stratton Sergio Gonzalez github:snagar
49-
* Aruelien Pocheville Thibault Reuille Cass Everitt github:Zelex
50-
* Ryamond Barbiero Paul Du Bois Engin Manap github:grim210
51-
* Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
52-
* Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
53-
* Julian Raschke Gregory Mullen Baldur Karlsson
54-
* github:poppolopoppo Christian Floisand Kevin Schmidt JR Smith
55-
* github:darealshinji Blazej Dariusz Roszkowski github:Michaelangel007
56-
*/
57-
58-
/*
59-
* DOCUMENTATION
38+
* Marc LeBlanc Laurent Gomila JR Smith
39+
* Christpher Lloyd Sergio Gonzalez Matvey Cherevko
40+
* Phil Jordan Ryamond Barbiero Zack Middleton
41+
* Hayaki Saito Engin Manap
42+
* Luke Graham Dale Weiler Martins Mozeiko
43+
* Thomas Ruf Neil Bickford Blazej Dariusz Roszkowski
44+
* Janez Zemva Gregory Mullen Roy Eltham
45+
* Jonathan Blow Kevin Schmidt
46+
* Eugene Golushkov Brad Weinberger the Horde3D community
47+
* Aruelien Pocheville Alexander Veselov github:rlyeh
48+
* Cass Everitt [reserved] github:romigrou
49+
* Paul Du Bois github:svdijk
50+
* Philipp Wiesemann Guillaume George github:snagar
51+
* Josh Tobin Joseph Thomson github:Zelex
52+
* Julian Raschke Dave Moore github:grim210
53+
* Baldur Karlsson Won Chun github:sammyhw
54+
* Nick Verigakis github:phprus
55+
* Luca Sas github:poppolopoppo
56+
* Ryan C. Gordon Michal Cichon github:darealshinji
57+
* David Woo Tero Hanninen github:Michaelangel007
58+
* Jerry Jansson Cort Stratton github:mosra
59+
* Thibault Reuille [reserved]
60+
* Nathan Reed [reserved]
61+
* Johan Duparc Aldo Culquicondor
62+
* Ronny Chevalier Oriol Ferrer Jacko Dirks
63+
* John Bartholomew Matthew Gregan
64+
* Ken Hamada Christian Floisand
65+
*
66+
* ============================ Documentation =========================
6067
*
6168
* Limitations:
6269
* - no 12-bit-per-channel JPEG
@@ -70,14 +77,15 @@
7077
* // ... x = width, y = height, n = # 8-bit components per pixel ...
7178
* // ... replace '0' with '1'..'4' to force that many components per pixel
7279
* // ... but 'n' will always be the number that it would have been if you
73-
* said 0 stbi_image_free(data)
80+
* // ... said 0
81+
* stbi_image_free(data);
7482
*
7583
* Standard parameters:
7684
* int *x -- outputs image width in pixels
7785
* int *y -- outputs image height in pixels
7886
* int *channels_in_file -- outputs # of image components in image file
7987
* int desired_channels -- if non-zero, # of image components requested in
80-
* result
88+
* result
8189
*
8290
* The return value from an image loader is an 'unsigned char *' which points
8391
* to the pixel data, or NULL on an allocation failure or if the image is
@@ -110,6 +118,32 @@
110118
*
111119
* Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
112120
*
121+
* To query the width, height and component count of an image without having to
122+
* decode the full file, you can use the stbi_info family of functions:
123+
*
124+
* int x,y,n,ok;
125+
* ok = stbi_info(filename, &x, &y, &n);
126+
* // returns ok=1 and sets x, y, n if image is a supported format,
127+
* // 0 otherwise.
128+
*
129+
* Note that stb_image pervasively uses ints in its public API for sizes,
130+
* including sizes of memory buffers. This is now part of the API and thus
131+
* hard to change without causing breakage. As a result, the various image
132+
* loaders all have certain limits on image size; these differ somewhat
133+
* by format but generally boil down to either just under 2GB or just under
134+
* 1GB. When the decoded image would be larger than this, stb_image decoding
135+
* will fail.
136+
*
137+
* Additionally, stb_image will reject image files that have any of their
138+
* dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS,
139+
* which defaults to 2**24 = 16777216 pixels. Due to the above memory limit,
140+
* the only way to have an image with such dimensions load correctly
141+
* is for it to have a rather extreme aspect ratio. Either way, the
142+
* assumption here is that such larger images are likely to be malformed
143+
* or malicious. If you do need to load an image with individual dimensions
144+
* larger than that, and it still fits in the overall size limit, you can
145+
* #define STBI_MAX_DIMENSIONS on your own to be something larger.
146+
*
113147
* ===========================================================================
114148
*
115149
* I/O callbacks
@@ -163,11 +197,10 @@
163197
*
164198
* iPhone PNG support:
165199
*
166-
* By default we convert iphone-formatted PNGs back to RGB, even though
167-
* they are internally encoded differently. You can disable this conversion
168-
* by calling stbi_convert_iphone_png_to_rgb(0), in which case
169-
* you will always just get the native iphone "format" through (which
170-
* is BGR stored in RGB).
200+
* We optionally support converting iPhone-formatted PNGs (which store
201+
* premultiplied BGRA) back to RGB, even though they're internally encoded
202+
* differently. To enable this conversion, call
203+
* stbi_convert_iphone_png_to_rgb(1).
171204
*
172205
* Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
173206
* pixel to remove any premultiplied alpha *only* if the image file explicitly
@@ -191,9 +224,18 @@
191224
* - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still
192225
* want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
193226
*
227+
* - If you define STBI_MAX_DIMENSIONS, stb_image will reject images greater
228+
* than that size (in either width or height) without further processing.
229+
* This is to let programs in the wild set an upper bound to prevent
230+
* denial-of-service attacks on untrusted data, as one could generate a
231+
* valid image of gigantic dimensions and force stb_image to allocate a
232+
* huge block of memory and spend disproportionate time decoding it. By
233+
* default this is set to (1 << 24), which is 16777216, but that's still
234+
* very big.
235+
*
194236
*/
195237

196-
/* stb_image_resize - v0.96 - public domain image resizing
238+
/* stb_image_resize - v0.97 - public domain image resizing
197239
* by Jorge L Rodriguez (@VinoBS) - 2014
198240
* http://github.com/nothings/stb
199241
*
@@ -214,9 +256,7 @@
214256
* output_pixels, out_w, out_h, 0,
215257
* num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP)
216258
* // WRAP/REFLECT/ZERO
217-
*/
218-
219-
/*
259+
*
220260
* DOCUMENTATION
221261
*
222262
* SRGB & FLOATING POINT REPRESENTATION
@@ -348,6 +388,7 @@
348388
* Nathan Reed: warning fixes
349389
*
350390
* REVISIONS
391+
* 0.97 (2020-02-02) fixed warning
351392
* 0.96 (2019-03-04) fixed warnings
352393
* 0.95 (2017-07-23) fixed warnings
353394
* 0.94 (2017-03-18) fixed warnings

0 commit comments

Comments
 (0)