Skip to content

Commit

Permalink
Update stb
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mataha committed Nov 8, 2023
1 parent 0d748ad commit 746b7d5
Show file tree
Hide file tree
Showing 20 changed files with 1,424 additions and 1,084 deletions.
5 changes: 3 additions & 2 deletions dsp/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ int mulaw(int);
int unmulaw(int);
void *double2byte(long, const void *, double, double) vallocesque;
void *byte2double(long, const void *, double, double) vallocesque;
void *dct(float[8][8], float, float, float, float, float);
void *dctjpeg(float[8][8]);
void *dct(float[restrict hasatleast 8][8], unsigned,
float, float, float, float, float);
void *dctjpeg(float[restrict hasatleast 8][8], unsigned);
double det3(const double[3][3]) nosideeffect;
void *inv3(double[restrict 3][3], const double[restrict 3][3], double);
void *matmul3(double[restrict 3][3], const double[3][3], const double[3][3]);
Expand Down
79 changes: 40 additions & 39 deletions dsp/core/dct.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/core/core.h"

#define DCT(A, B, C, D, E, F, G, H, T, C0, C1, C2, C3, C4) \
do { \
T z1, z2, z3, z4, z5, z11, z13; \
T t0, t1, t2, t3, t4, t5, t6, t7, t10, t11, t12, t13; \
t0 = A + H; \
t7 = A - H; \
t1 = B + G; \
t6 = B - G; \
t2 = C + F; \
t5 = C - F; \
t3 = D + E; \
t4 = D - E; \
t10 = t0 + t3; \
t13 = t0 - t3; \
t11 = t1 + t2; \
t12 = t1 - t2; \
A = t10 + t11; \
E = t10 - t11; \
z1 = (t12 + t13) * C0; \
C = t13 + z1; \
G = t13 - z1; \
t10 = t4 + t5; \
t11 = t5 + t6; \
t12 = t6 + t7; \
z5 = (t10 - t12) * C1; \
z2 = t10 * C2 + z5; \
z4 = t12 * C3 + z5; \
z3 = t11 * C4; \
z11 = t7 + z3; \
z13 = t7 - z3; \
F = z13 + z2; \
D = z13 - z2; \
B = z11 + z4; \
H = z11 - z4; \
#define DCT(A, B, C, D, E, F, G, H, T, C0, C1, C2, C3, C4) \
do { \
T z1, z2, z3, z4, z5, z11, z13; \
T t0, t1, t2, t3, t4, t5, t6, t7, t10, t11, t12, t13; \
t0 = A + H; \
t7 = A - H; \
t1 = B + G; \
t6 = B - G; \
t2 = C + F; \
t5 = C - F; \
t3 = D + E; \
t4 = D - E; \
t10 = t0 + t3; \
t13 = t0 - t3; \
t11 = t1 + t2; \
t12 = t1 - t2; \
A = t10 + t11; \
E = t10 - t11; \
z1 = (t12 + t13) * C0; \
C = t13 + z1; \
G = t13 - z1; \
t10 = t4 + t5; \
t11 = t5 + t6; \
t12 = t6 + t7; \
z5 = (t10 - t12) * C1; \
z2 = t10 * C2 + z5; \
z4 = t12 * C3 + z5; \
z3 = t11 * C4; \
z11 = t7 + z3; \
z13 = t7 - z3; \
F = z13 + z2; \
D = z13 - z2; \
B = z11 + z4; \
H = z11 - z4; \
} while (0)

/**
Expand All @@ -65,20 +65,21 @@
*
* @cost ~100ns
*/
void *dct(float M[8][8], float c0, float c1, float c2, float c3, float c4) {
void *dct(float M[restrict hasatleast 8][8], unsigned stride,
float c0, float c1, float c2, float c3, float c4) {
unsigned y, x;
for (y = 0; y < 8; ++y) {
for (y = 0; y < stride * 8; y += stride) {
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],
float, c0, c1, c2, c3, c4);
}
for (x = 0; x < 8; ++x) {
for (x = 0; x < stride * 8; x += stride) {
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],
float, c0, c1, c2, c3, c4);
}
return M;
}

void *dctjpeg(float M[8][8]) {
return dct(M, .707106781f, .382683433f, .541196100f, 1.306562965f,
void *dctjpeg(float M[restrict hasatleast 8][8], unsigned stride) {
return dct(M, stride, .707106781f, .382683433f, .541196100f, 1.306562965f,
.707106781f);
}
29 changes: 22 additions & 7 deletions third_party/stb/README.cosmo
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,34 @@ LOCAL CHANGES
- Removed undefined behavior
- Removed BMP [endian code made it 100x slower than PNG/JPEG]
- Removed PIC [never heard of it]
- Removed TGA [consider imaagemagick convert command]
- Removed PSD [consider imaagemagick convert command]
- Removed TGA [consider imagemagick convert command]
- Removed PSD [consider imagemagick convert command]
- Removed HDR [mine eyes and wikipedia agree stb gamma math is off]
- Patched PNG loading edge case
- Fixed code C standard says is undefined
- PNG now uses ultra-fast Chromium zlib w/ CLMUL crc32
- Removed unnecessary ifdefs
- Removed MSVC torture code

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

commit f67165c2bb2af3060ecae7d20d6f731173485ad0
Author: Sean Barrett <[email protected]>
Date: Mon Oct 28 09:30:02 2019 -0700
commit 5736b15f7ea0ffb08dd38af21067c314d6a3aae9
Author: Sean Barrett <[email protected]>
Date: Sun Jan 29 10:46:04 2023 -0800

Update README.md
re-add perlin noise again

ADDITIONAL CHANGES/FIXES:

- https://github.com/nothings/stb/pull/1299
- https://github.com/nothings/stb/pull/1402
- https://github.com/nothings/stb/pull/1404
- https://github.com/nothings/stb/pull/1420
- https://github.com/nothings/stb/pull/1445
- https://github.com/nothings/stb/pull/1487
- https://github.com/nothings/stb/pull/1490
- https://github.com/nothings/stb/pull/1496
- https://github.com/nothings/stb/pull/1497
- https://github.com/nothings/stb/pull/1498
- https://github.com/nothings/stb/pull/1499
- https://github.com/nothings/stb/pull/1500
143 changes: 92 additions & 51 deletions third_party/stb/README.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* stb_image - v2.23 - public domain image loader - http://nothings.org/stb
/* stb_image - v2.28 - public domain image loader - http://nothings.org/stb
* no warranty implied; use at your own risk
*
* [heavily modified by justine tunney]
*
* JPEG baseline & progressive (12 bpc/arithmetic not supported, same
* as stock IJG lib) PNG 1/2/4/8/16-bit-per-channel
* as stock IJG lib)
* PNG 1/2/4/8/16-bit-per-channel
* GIF (*comp always reports as 4-channel)
* HDR (radiance rgbE format)
* PNM (PPM and PGM binary only)
*
* Animated GIF still needs a proper API, but here's one way to do it:
Expand All @@ -18,45 +17,53 @@
*
* ============================ Contributors =========================
*
* Image formats Extensions, features
* Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
* Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
* Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
* Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
* Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
* Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
* Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
* github:urraka (animated gif) Junggon Kim (PNM comments)
* Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
* socks-the-fox (16-bit PNG)
* Jeremy Sawicki (ImageNet JPGs)
* Mikhail Morozov (1-bit BMP)
* Optimizations & bugfixes Anael Seghezzi (is-16-bit query)
* Fabian "ryg" Giesen
* Arseny Kapoulkine
* John-Mark Allen
* Image formats Extensions, features
* Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
* Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
* Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
* Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
* Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
* Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
* Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
* github:urraka (animated gif) Junggon Kim (PNM comments)
* Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
* socks-the-fox (16-bit PNG)
* Optimizations & bugfixes Jeremy Sawicki (ImageNet JPGs)
* Fabian "ryg" Giesen Mikhail Morozov (1-bit BMP)
* Arseny Kapoulkine Anael Seghezzi (is-16-bit query)
* John-Mark Allen Simon Breuss (16-bit PNM)
* Carmelo J Fdez-Aguera
*
* Bug & warning fixes
* Marc LeBlanc David Woo Guillaume George Martins Mozeiko
* Christpher Lloyd Jerry Jansson Joseph Thomson Phil Jordan
* Dave Moore Roy Eltham Hayaki Saito Nathan Reed
* Won Chun Luke Graham Johan Duparc Nick Verigakis
* the Horde3D community Thomas Ruf Ronny Chevalier github:rlyeh
* Janez Zemva John Bartholomew Michal Cichon github:romigrou
* Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
* Laurent Gomila Cort Stratton Sergio Gonzalez github:snagar
* Aruelien Pocheville Thibault Reuille Cass Everitt github:Zelex
* Ryamond Barbiero Paul Du Bois Engin Manap github:grim210
* Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
* Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
* Julian Raschke Gregory Mullen Baldur Karlsson
* github:poppolopoppo Christian Floisand Kevin Schmidt JR Smith
* github:darealshinji Blazej Dariusz Roszkowski github:Michaelangel007
*/

/*
* DOCUMENTATION
* Marc LeBlanc Laurent Gomila JR Smith
* Christpher Lloyd Sergio Gonzalez Matvey Cherevko
* Phil Jordan Ryamond Barbiero Zack Middleton
* Hayaki Saito Engin Manap
* Luke Graham Dale Weiler Martins Mozeiko
* Thomas Ruf Neil Bickford Blazej Dariusz Roszkowski
* Janez Zemva Gregory Mullen Roy Eltham
* Jonathan Blow Kevin Schmidt
* Eugene Golushkov Brad Weinberger the Horde3D community
* Aruelien Pocheville Alexander Veselov github:rlyeh
* Cass Everitt [reserved] github:romigrou
* Paul Du Bois github:svdijk
* Philipp Wiesemann Guillaume George github:snagar
* Josh Tobin Joseph Thomson github:Zelex
* Julian Raschke Dave Moore github:grim210
* Baldur Karlsson Won Chun github:sammyhw
* Nick Verigakis github:phprus
* Luca Sas github:poppolopoppo
* Ryan C. Gordon Michal Cichon github:darealshinji
* David Woo Tero Hanninen github:Michaelangel007
* Jerry Jansson Cort Stratton github:mosra
* Thibault Reuille [reserved]
* Nathan Reed [reserved]
* Johan Duparc Aldo Culquicondor
* Ronny Chevalier Oriol Ferrer Jacko Dirks
* John Bartholomew Matthew Gregan
* Ken Hamada Christian Floisand
*
* ============================ Documentation =========================
*
* Limitations:
* - no 12-bit-per-channel JPEG
Expand All @@ -70,14 +77,15 @@
* // ... x = width, y = height, n = # 8-bit components per pixel ...
* // ... replace '0' with '1'..'4' to force that many components per pixel
* // ... but 'n' will always be the number that it would have been if you
* said 0 stbi_image_free(data)
* // ... said 0
* stbi_image_free(data);
*
* Standard parameters:
* int *x -- outputs image width in pixels
* int *y -- outputs image height in pixels
* int *channels_in_file -- outputs # of image components in image file
* int desired_channels -- if non-zero, # of image components requested in
* result
* result
*
* The return value from an image loader is an 'unsigned char *' which points
* to the pixel data, or NULL on an allocation failure or if the image is
Expand Down Expand Up @@ -110,6 +118,32 @@
*
* Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
*
* To query the width, height and component count of an image without having to
* decode the full file, you can use the stbi_info family of functions:
*
* int x,y,n,ok;
* ok = stbi_info(filename, &x, &y, &n);
* // returns ok=1 and sets x, y, n if image is a supported format,
* // 0 otherwise.
*
* Note that stb_image pervasively uses ints in its public API for sizes,
* including sizes of memory buffers. This is now part of the API and thus
* hard to change without causing breakage. As a result, the various image
* loaders all have certain limits on image size; these differ somewhat
* by format but generally boil down to either just under 2GB or just under
* 1GB. When the decoded image would be larger than this, stb_image decoding
* will fail.
*
* Additionally, stb_image will reject image files that have any of their
* dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS,
* which defaults to 2**24 = 16777216 pixels. Due to the above memory limit,
* the only way to have an image with such dimensions load correctly
* is for it to have a rather extreme aspect ratio. Either way, the
* assumption here is that such larger images are likely to be malformed
* or malicious. If you do need to load an image with individual dimensions
* larger than that, and it still fits in the overall size limit, you can
* #define STBI_MAX_DIMENSIONS on your own to be something larger.
*
* ===========================================================================
*
* I/O callbacks
Expand Down Expand Up @@ -163,11 +197,10 @@
*
* iPhone PNG support:
*
* By default we convert iphone-formatted PNGs back to RGB, even though
* they are internally encoded differently. You can disable this conversion
* by calling stbi_convert_iphone_png_to_rgb(0), in which case
* you will always just get the native iphone "format" through (which
* is BGR stored in RGB).
* We optionally support converting iPhone-formatted PNGs (which store
* premultiplied BGRA) back to RGB, even though they're internally encoded
* differently. To enable this conversion, call
* stbi_convert_iphone_png_to_rgb(1).
*
* Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
* pixel to remove any premultiplied alpha *only* if the image file explicitly
Expand All @@ -191,9 +224,18 @@
* - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still
* want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
*
* - If you define STBI_MAX_DIMENSIONS, stb_image will reject images greater
* than that size (in either width or height) without further processing.
* This is to let programs in the wild set an upper bound to prevent
* denial-of-service attacks on untrusted data, as one could generate a
* valid image of gigantic dimensions and force stb_image to allocate a
* huge block of memory and spend disproportionate time decoding it. By
* default this is set to (1 << 24), which is 16777216, but that's still
* very big.
*
*/

/* stb_image_resize - v0.96 - public domain image resizing
/* stb_image_resize - v0.97 - public domain image resizing
* by Jorge L Rodriguez (@VinoBS) - 2014
* http://github.com/nothings/stb
*
Expand All @@ -214,9 +256,7 @@
* output_pixels, out_w, out_h, 0,
* num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP)
* // WRAP/REFLECT/ZERO
*/

/*
*
* DOCUMENTATION
*
* SRGB & FLOATING POINT REPRESENTATION
Expand Down Expand Up @@ -348,6 +388,7 @@
* Nathan Reed: warning fixes
*
* REVISIONS
* 0.97 (2020-02-02) fixed warning
* 0.96 (2019-03-04) fixed warnings
* 0.95 (2017-07-23) fixed warnings
* 0.94 (2017-03-18) fixed warnings
Expand Down
Loading

0 comments on commit 746b7d5

Please sign in to comment.