|
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 |
3 | 2 | * no warranty implied; use at your own risk
|
4 | 3 | *
|
5 | 4 | * [heavily modified by justine tunney]
|
6 | 5 | *
|
7 | 6 | * 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 |
9 | 9 | * GIF (*comp always reports as 4-channel)
|
10 |
| - * HDR (radiance rgbE format) |
11 | 10 | * PNM (PPM and PGM binary only)
|
12 | 11 | *
|
13 | 12 | * Animated GIF still needs a proper API, but here's one way to do it:
|
|
18 | 17 | *
|
19 | 18 | * ============================ Contributors =========================
|
20 | 19 | *
|
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) |
38 | 35 | * Carmelo J Fdez-Aguera
|
39 | 36 | *
|
40 | 37 | * 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 ========================= |
60 | 67 | *
|
61 | 68 | * Limitations:
|
62 | 69 | * - no 12-bit-per-channel JPEG
|
|
70 | 77 | * // ... x = width, y = height, n = # 8-bit components per pixel ...
|
71 | 78 | * // ... replace '0' with '1'..'4' to force that many components per pixel
|
72 | 79 | * // ... 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); |
74 | 82 | *
|
75 | 83 | * Standard parameters:
|
76 | 84 | * int *x -- outputs image width in pixels
|
77 | 85 | * int *y -- outputs image height in pixels
|
78 | 86 | * int *channels_in_file -- outputs # of image components in image file
|
79 | 87 | * int desired_channels -- if non-zero, # of image components requested in
|
80 |
| - * result |
| 88 | + * result |
81 | 89 | *
|
82 | 90 | * The return value from an image loader is an 'unsigned char *' which points
|
83 | 91 | * to the pixel data, or NULL on an allocation failure or if the image is
|
|
110 | 118 | *
|
111 | 119 | * Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
|
112 | 120 | *
|
| 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 | + * |
113 | 147 | * ===========================================================================
|
114 | 148 | *
|
115 | 149 | * I/O callbacks
|
|
163 | 197 | *
|
164 | 198 | * iPhone PNG support:
|
165 | 199 | *
|
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). |
171 | 204 | *
|
172 | 205 | * Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
|
173 | 206 | * pixel to remove any premultiplied alpha *only* if the image file explicitly
|
|
191 | 224 | * - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still
|
192 | 225 | * want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
|
193 | 226 | *
|
| 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 | + * |
194 | 236 | */
|
195 | 237 |
|
196 |
| -/* stb_image_resize - v0.96 - public domain image resizing |
| 238 | +/* stb_image_resize - v0.97 - public domain image resizing |
197 | 239 | * by Jorge L Rodriguez (@VinoBS) - 2014
|
198 | 240 | * http://github.com/nothings/stb
|
199 | 241 | *
|
|
214 | 256 | * output_pixels, out_w, out_h, 0,
|
215 | 257 | * num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP)
|
216 | 258 | * // WRAP/REFLECT/ZERO
|
217 |
| - */ |
218 |
| - |
219 |
| -/* |
| 259 | + * |
220 | 260 | * DOCUMENTATION
|
221 | 261 | *
|
222 | 262 | * SRGB & FLOATING POINT REPRESENTATION
|
|
348 | 388 | * Nathan Reed: warning fixes
|
349 | 389 | *
|
350 | 390 | * REVISIONS
|
| 391 | + * 0.97 (2020-02-02) fixed warning |
351 | 392 | * 0.96 (2019-03-04) fixed warnings
|
352 | 393 | * 0.95 (2017-07-23) fixed warnings
|
353 | 394 | * 0.94 (2017-03-18) fixed warnings
|
|
0 commit comments