summaryrefslogtreecommitdiff
path: root/externals/stb/stb_image.h
diff options
context:
space:
mode:
Diffstat (limited to 'externals/stb/stb_image.h')
-rw-r--r--externals/stb/stb_image.h772
1 files changed, 772 insertions, 0 deletions
diff --git a/externals/stb/stb_image.h b/externals/stb/stb_image.h
new file mode 100644
index 000000000..f0dfad1c6
--- /dev/null
+++ b/externals/stb/stb_image.h
@@ -0,0 +1,772 @@
1// SPDX-FileCopyrightText: stb http://nothings.org/stb
2// SPDX-License-Identifier: MIT
3
4/* stb_image - v2.28 - public domain image loader - http://nothings.org/stb
5 no warranty implied; use at your own risk
6
7 Do this:
8 #define STB_IMAGE_IMPLEMENTATION
9 before you include this file in *one* C or C++ file to create the implementation.
10
11 // i.e. it should look like this:
12 #include ...
13 #include ...
14 #include ...
15 #define STB_IMAGE_IMPLEMENTATION
16 #include "stb_image.h"
17
18 You can #define STBI_ASSERT(x) before the #include to avoid using assert.h.
19 And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free
20
21
22 QUICK NOTES:
23 Primarily of interest to game developers and other people who can
24 avoid problematic images and only need the trivial interface
25
26 JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
27 PNG 1/2/4/8/16-bit-per-channel
28
29 TGA (not sure what subset, if a subset)
30 BMP non-1bpp, non-RLE
31 PSD (composited view only, no extra channels, 8/16 bit-per-channel)
32
33 GIF (*comp always reports as 4-channel)
34 HDR (radiance rgbE format)
35 PIC (Softimage PIC)
36 PNM (PPM and PGM binary only)
37
38 Animated GIF still needs a proper API, but here's one way to do it:
39 http://gist.github.com/urraka/685d9a6340b26b830d49
40
41 - decode from memory or through FILE (define STBI_NO_STDIO to remove code)
42 - decode from arbitrary I/O callbacks
43 - SIMD acceleration on x86/x64 (SSE2) and ARM (NEON)
44
45 Full documentation under "DOCUMENTATION" below.
46
47
48LICENSE
49
50 See end of file for license information.
51
52RECENT REVISION HISTORY:
53
54 2.28 (2023-01-29) many error fixes, security errors, just tons of stuff
55 2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes
56 2.26 (2020-07-13) many minor fixes
57 2.25 (2020-02-02) fix warnings
58 2.24 (2020-02-02) fix warnings; thread-local failure_reason and flip_vertically
59 2.23 (2019-08-11) fix clang static analysis warning
60 2.22 (2019-03-04) gif fixes, fix warnings
61 2.21 (2019-02-25) fix typo in comment
62 2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
63 2.19 (2018-02-11) fix warning
64 2.18 (2018-01-30) fix warnings
65 2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
66 2.16 (2017-07-23) all functions have 16-bit variants; optimizations; bugfixes
67 2.15 (2017-03-18) fix png-1,2,4; all Imagenet JPGs; no runtime SSE detection on GCC
68 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs
69 2.13 (2016-12-04) experimental 16-bit API, only for PNG so far; fixes
70 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
71 2.11 (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x64
72 RGB-format JPEG; remove white matting in PSD;
73 allocate large structures on the stack;
74 correct channel count for PNG & BMP
75 2.10 (2016-01-22) avoid warning introduced in 2.09
76 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED
77
78 See end of file for full revision history.
79
80
81 ============================ Contributors =========================
82
83 Image formats Extensions, features
84 Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
85 Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
86 Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
87 Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
88 Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
89 Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
90 Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
91 github:urraka (animated gif) Junggon Kim (PNM comments)
92 Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
93 socks-the-fox (16-bit PNG)
94 Jeremy Sawicki (handle all ImageNet JPGs)
95 Optimizations & bugfixes Mikhail Morozov (1-bit BMP)
96 Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
97 Arseny Kapoulkine Simon Breuss (16-bit PNM)
98 John-Mark Allen
99 Carmelo J Fdez-Aguera
100
101 Bug & warning fixes
102 Marc LeBlanc David Woo Guillaume George Martins Mozeiko
103 Christpher Lloyd Jerry Jansson Joseph Thomson Blazej Dariusz Roszkowski
104 Phil Jordan Dave Moore Roy Eltham
105 Hayaki Saito Nathan Reed Won Chun
106 Luke Graham Johan Duparc Nick Verigakis the Horde3D community
107 Thomas Ruf Ronny Chevalier github:rlyeh
108 Janez Zemva John Bartholomew Michal Cichon github:romigrou
109 Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
110 Eugene Golushkov Laurent Gomila Cort Stratton github:snagar
111 Aruelien Pocheville Sergio Gonzalez Thibault Reuille github:Zelex
112 Cass Everitt Ryamond Barbiero github:grim210
113 Paul Du Bois Engin Manap Aldo Culquicondor github:sammyhw
114 Philipp Wiesemann Dale Weiler Oriol Ferrer Mesia github:phprus
115 Josh Tobin Neil Bickford Matthew Gregan github:poppolopoppo
116 Julian Raschke Gregory Mullen Christian Floisand github:darealshinji
117 Baldur Karlsson Kevin Schmidt JR Smith github:Michaelangel007
118 Brad Weinberger Matvey Cherevko github:mosra
119 Luca Sas Alexander Veselov Zack Middleton [reserved]
120 Ryan C. Gordon [reserved] [reserved]
121 DO NOT ADD YOUR NAME HERE
122
123 Jacko Dirks
124
125 To add your name to the credits, pick a random blank space in the middle and fill it.
126 80% of merge conflicts on stb PRs are due to people adding their name at the end
127 of the credits.
128*/
129
130#ifndef STBI_INCLUDE_STB_IMAGE_H
131#define STBI_INCLUDE_STB_IMAGE_H
132
133// DOCUMENTATION
134//
135// Limitations:
136// - no 12-bit-per-channel JPEG
137// - no JPEGs with arithmetic coding
138// - GIF always returns *comp=4
139//
140// Basic usage (see HDR discussion below for HDR usage):
141// int x,y,n;
142// unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
143// // ... process data if not NULL ...
144// // ... x = width, y = height, n = # 8-bit components per pixel ...
145// // ... replace '0' with '1'..'4' to force that many components per pixel
146// // ... but 'n' will always be the number that it would have been if you said 0
147// stbi_image_free(data);
148//
149// Standard parameters:
150// int *x -- outputs image width in pixels
151// int *y -- outputs image height in pixels
152// int *channels_in_file -- outputs # of image components in image file
153// int desired_channels -- if non-zero, # of image components requested in result
154//
155// The return value from an image loader is an 'unsigned char *' which points
156// to the pixel data, or NULL on an allocation failure or if the image is
157// corrupt or invalid. The pixel data consists of *y scanlines of *x pixels,
158// with each pixel consisting of N interleaved 8-bit components; the first
159// pixel pointed to is top-left-most in the image. There is no padding between
160// image scanlines or between pixels, regardless of format. The number of
161// components N is 'desired_channels' if desired_channels is non-zero, or
162// *channels_in_file otherwise. If desired_channels is non-zero,
163// *channels_in_file has the number of components that _would_ have been
164// output otherwise. E.g. if you set desired_channels to 4, you will always
165// get RGBA output, but you can check *channels_in_file to see if it's trivially
166// opaque because e.g. there were only 3 channels in the source image.
167//
168// An output image with N components has the following components interleaved
169// in this order in each pixel:
170//
171// N=#comp components
172// 1 grey
173// 2 grey, alpha
174// 3 red, green, blue
175// 4 red, green, blue, alpha
176//
177// If image loading fails for any reason, the return value will be NULL,
178// and *x, *y, *channels_in_file will be unchanged. The function
179// stbi_failure_reason() can be queried for an extremely brief, end-user
180// unfriendly explanation of why the load failed. Define STBI_NO_FAILURE_STRINGS
181// to avoid compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly
182// more user-friendly ones.
183//
184// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
185//
186// To query the width, height and component count of an image without having to
187// decode the full file, you can use the stbi_info family of functions:
188//
189// int x,y,n,ok;
190// ok = stbi_info(filename, &x, &y, &n);
191// // returns ok=1 and sets x, y, n if image is a supported format,
192// // 0 otherwise.
193//
194// Note that stb_image pervasively uses ints in its public API for sizes,
195// including sizes of memory buffers. This is now part of the API and thus
196// hard to change without causing breakage. As a result, the various image
197// loaders all have certain limits on image size; these differ somewhat
198// by format but generally boil down to either just under 2GB or just under
199// 1GB. When the decoded image would be larger than this, stb_image decoding
200// will fail.
201//
202// Additionally, stb_image will reject image files that have any of their
203// dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS,
204// which defaults to 2**24 = 16777216 pixels. Due to the above memory limit,
205// the only way to have an image with such dimensions load correctly
206// is for it to have a rather extreme aspect ratio. Either way, the
207// assumption here is that such larger images are likely to be malformed
208// or malicious. If you do need to load an image with individual dimensions
209// larger than that, and it still fits in the overall size limit, you can
210// #define STBI_MAX_DIMENSIONS on your own to be something larger.
211//
212// ===========================================================================
213//
214// UNICODE:
215//
216// If compiling for Windows and you wish to use Unicode filenames, compile
217// with
218// #define STBI_WINDOWS_UTF8
219// and pass utf8-encoded filenames. Call stbi_convert_wchar_to_utf8 to convert
220// Windows wchar_t filenames to utf8.
221//
222// ===========================================================================
223//
224// Philosophy
225//
226// stb libraries are designed with the following priorities:
227//
228// 1. easy to use
229// 2. easy to maintain
230// 3. good performance
231//
232// Sometimes I let "good performance" creep up in priority over "easy to maintain",
233// and for best performance I may provide less-easy-to-use APIs that give higher
234// performance, in addition to the easy-to-use ones. Nevertheless, it's important
235// to keep in mind that from the standpoint of you, a client of this library,
236// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.
237//
238// Some secondary priorities arise directly from the first two, some of which
239// provide more explicit reasons why performance can't be emphasized.
240//
241// - Portable ("ease of use")
242// - Small source code footprint ("easy to maintain")
243// - No dependencies ("ease of use")
244//
245// ===========================================================================
246//
247// I/O callbacks
248//
249// I/O callbacks allow you to read from arbitrary sources, like packaged
250// files or some other source. Data read from callbacks are processed
251// through a small internal buffer (currently 128 bytes) to try to reduce
252// overhead.
253//
254// The three functions you must define are "read" (reads some bytes of data),
255// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).
256//
257// ===========================================================================
258//
259// SIMD support
260//
261// The JPEG decoder will try to automatically use SIMD kernels on x86 when
262// supported by the compiler. For ARM Neon support, you must explicitly
263// request it.
264//
265// (The old do-it-yourself SIMD API is no longer supported in the current
266// code.)
267//
268// On x86, SSE2 will automatically be used when available based on a run-time
269// test; if not, the generic C versions are used as a fall-back. On ARM targets,
270// the typical path is to have separate builds for NEON and non-NEON devices
271// (at least this is true for iOS and Android). Therefore, the NEON support is
272// toggled by a build flag: define STBI_NEON to get NEON loops.
273//
274// If for some reason you do not want to use any of SIMD code, or if
275// you have issues compiling it, you can disable it entirely by
276// defining STBI_NO_SIMD.
277//
278// ===========================================================================
279//
280// HDR image support (disable by defining STBI_NO_HDR)
281//
282// stb_image supports loading HDR images in general, and currently the Radiance
283// .HDR file format specifically. You can still load any file through the existing
284// interface; if you attempt to load an HDR file, it will be automatically remapped
285// to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
286// both of these constants can be reconfigured through this interface:
287//
288// stbi_hdr_to_ldr_gamma(2.2f);
289// stbi_hdr_to_ldr_scale(1.0f);
290//
291// (note, do not use _inverse_ constants; stbi_image will invert them
292// appropriately).
293//
294// Additionally, there is a new, parallel interface for loading files as
295// (linear) floats to preserve the full dynamic range:
296//
297// float *data = stbi_loadf(filename, &x, &y, &n, 0);
298//
299// If you load LDR images through this interface, those images will
300// be promoted to floating point values, run through the inverse of
301// constants corresponding to the above:
302//
303// stbi_ldr_to_hdr_scale(1.0f);
304// stbi_ldr_to_hdr_gamma(2.2f);
305//
306// Finally, given a filename (or an open file or memory block--see header
307// file for details) containing image data, you can query for the "most
308// appropriate" interface to use (that is, whether the image is HDR or
309// not), using:
310//
311// stbi_is_hdr(char *filename);
312//
313// ===========================================================================
314//
315// iPhone PNG support:
316//
317// We optionally support converting iPhone-formatted PNGs (which store
318// premultiplied BGRA) back to RGB, even though they're internally encoded
319// differently. To enable this conversion, call
320// stbi_convert_iphone_png_to_rgb(1).
321//
322// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
323// pixel to remove any premultiplied alpha *only* if the image file explicitly
324// says there's premultiplied data (currently only happens in iPhone images,
325// and only if iPhone convert-to-rgb processing is on).
326//
327// ===========================================================================
328//
329// ADDITIONAL CONFIGURATION
330//
331// - You can suppress implementation of any of the decoders to reduce
332// your code footprint by #defining one or more of the following
333// symbols before creating the implementation.
334//
335// STBI_NO_JPEG
336// STBI_NO_PNG
337// STBI_NO_BMP
338// STBI_NO_PSD
339// STBI_NO_TGA
340// STBI_NO_GIF
341// STBI_NO_HDR
342// STBI_NO_PIC
343// STBI_NO_PNM (.ppm and .pgm)
344//
345// - You can request *only* certain decoders and suppress all other ones
346// (this will be more forward-compatible, as addition of new decoders
347// doesn't require you to disable them explicitly):
348//
349// STBI_ONLY_JPEG
350// STBI_ONLY_PNG
351// STBI_ONLY_BMP
352// STBI_ONLY_PSD
353// STBI_ONLY_TGA
354// STBI_ONLY_GIF
355// STBI_ONLY_HDR
356// STBI_ONLY_PIC
357// STBI_ONLY_PNM (.ppm and .pgm)
358//
359// - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still
360// want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
361//
362// - If you define STBI_MAX_DIMENSIONS, stb_image will reject images greater
363// than that size (in either width or height) without further processing.
364// This is to let programs in the wild set an upper bound to prevent
365// denial-of-service attacks on untrusted data, as one could generate a
366// valid image of gigantic dimensions and force stb_image to allocate a
367// huge block of memory and spend disproportionate time decoding it. By
368// default this is set to (1 << 24), which is 16777216, but that's still
369// very big.
370
371#ifndef STBI_NO_STDIO
372#include <stdio.h>
373#endif // STBI_NO_STDIO
374
375#define STBI_VERSION 1
376
377enum
378{
379 STBI_default = 0, // only used for desired_channels
380
381 STBI_grey = 1,
382 STBI_grey_alpha = 2,
383 STBI_rgb = 3,
384 STBI_rgb_alpha = 4
385};
386
387#include <stdlib.h>
388typedef unsigned char stbi_uc;
389typedef unsigned short stbi_us;
390
391#ifdef __cplusplus
392extern "C" {
393#endif
394
395#ifndef STBIDEF
396#ifdef STB_IMAGE_STATIC
397#define STBIDEF static
398#else
399#define STBIDEF extern
400#endif
401#endif
402
403//////////////////////////////////////////////////////////////////////////////
404//
405// PRIMARY API - works on images of any type
406//
407
408//
409// load image by filename, open file, or memory buffer
410//
411
412typedef struct
413{
414 int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read
415 void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
416 int (*eof) (void *user); // returns nonzero if we are at end of file/data
417} stbi_io_callbacks;
418
419////////////////////////////////////
420//
421// 8-bits-per-channel interface
422//
423
424STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
425STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
426
427#ifndef STBI_NO_STDIO
428STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
429STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
430// for stbi_load_from_file, file pointer is left pointing immediately after image
431#endif
432
433#ifndef STBI_NO_GIF
434STBIDEF 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);
435#endif
436
437#ifdef STBI_WINDOWS_UTF8
438STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
439#endif
440
441////////////////////////////////////
442//
443// 16-bits-per-channel interface
444//
445
446STBIDEF stbi_us *stbi_load_16_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
447STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
448
449#ifndef STBI_NO_STDIO
450STBIDEF stbi_us *stbi_load_16 (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
451STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
452#endif
453
454////////////////////////////////////
455//
456// float-per-channel interface
457//
458#ifndef STBI_NO_LINEAR
459 STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);
460 STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels);
461
462 #ifndef STBI_NO_STDIO
463 STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
464 STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
465 #endif
466#endif
467
468#ifndef STBI_NO_HDR
469 STBIDEF void stbi_hdr_to_ldr_gamma(float gamma);
470 STBIDEF void stbi_hdr_to_ldr_scale(float scale);
471#endif // STBI_NO_HDR
472
473#ifndef STBI_NO_LINEAR
474 STBIDEF void stbi_ldr_to_hdr_gamma(float gamma);
475 STBIDEF void stbi_ldr_to_hdr_scale(float scale);
476#endif // STBI_NO_LINEAR
477
478// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
479STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
480STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
481#ifndef STBI_NO_STDIO
482STBIDEF int stbi_is_hdr (char const *filename);
483STBIDEF int stbi_is_hdr_from_file(FILE *f);
484#endif // STBI_NO_STDIO
485
486
487// get a VERY brief reason for failure
488// on most compilers (and ALL modern mainstream compilers) this is threadsafe
489STBIDEF const char *stbi_failure_reason (void);
490
491// free the loaded image -- this is just free()
492STBIDEF void stbi_image_free (void *retval_from_stbi_load);
493
494// get image dimensions & components without fully decoding
495STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
496STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
497STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len);
498STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);
499
500#ifndef STBI_NO_STDIO
501STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
502STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
503STBIDEF int stbi_is_16_bit (char const *filename);
504STBIDEF int stbi_is_16_bit_from_file(FILE *f);
505#endif
506
507
508
509// for image formats that explicitly notate that they have premultiplied alpha,
510// we just return the colors as stored in the file. set this flag to force
511// unpremultiplication. results are undefined if the unpremultiply overflow.
512STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
513
514// indicate whether we should process iphone images back to canonical format,
515// or just pass them through "as-is"
516STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
517
518// flip the image vertically, so the first pixel in the output array is the bottom left
519STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
520
521// as above, but only applies to images loaded on the thread that calls the function
522// this function is only available if your compiler supports thread-local variables;
523// calling it will fail to link if your compiler doesn't
524STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply);
525STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert);
526STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);
527
528// ZLIB client - used by PNG, available for other purposes
529
530STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
531STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);
532STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
533STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
534
535STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
536STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
537
538
539#ifdef __cplusplus
540}
541#endif
542
543//
544//
545//// end header file /////////////////////////////////////////////////////
546#endif // STBI_INCLUDE_STB_IMAGE_H
547
548/*
549 revision history:
550 2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
551 2.19 (2018-02-11) fix warning
552 2.18 (2018-01-30) fix warnings
553 2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
554 1-bit BMP
555 *_is_16_bit api
556 avoid warnings
557 2.16 (2017-07-23) all functions have 16-bit variants;
558 STBI_NO_STDIO works again;
559 compilation fixes;
560 fix rounding in unpremultiply;
561 optimize vertical flip;
562 disable raw_len validation;
563 documentation fixes
564 2.15 (2017-03-18) fix png-1,2,4 bug; now all Imagenet JPGs decode;
565 warning fixes; disable run-time SSE detection on gcc;
566 uniform handling of optional "return" values;
567 thread-safe initialization of zlib tables
568 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs
569 2.13 (2016-11-29) add 16-bit API, only supported for PNG right now
570 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
571 2.11 (2016-04-02) allocate large structures on the stack
572 remove white matting for transparent PSD
573 fix reported channel count for PNG & BMP
574 re-enable SSE2 in non-gcc 64-bit
575 support RGB-formatted JPEG
576 read 16-bit PNGs (only as 8-bit)
577 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED
578 2.09 (2016-01-16) allow comments in PNM files
579 16-bit-per-pixel TGA (not bit-per-component)
580 info() for TGA could break due to .hdr handling
581 info() for BMP to shares code instead of sloppy parse
582 can use STBI_REALLOC_SIZED if allocator doesn't support realloc
583 code cleanup
584 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA
585 2.07 (2015-09-13) fix compiler warnings
586 partial animated GIF support
587 limited 16-bpc PSD support
588 #ifdef unused functions
589 bug with < 92 byte PIC,PNM,HDR,TGA
590 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value
591 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning
592 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit
593 2.03 (2015-04-12) extra corruption checking (mmozeiko)
594 stbi_set_flip_vertically_on_load (nguillemot)
595 fix NEON support; fix mingw support
596 2.02 (2015-01-19) fix incorrect assert, fix warning
597 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2
598 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG
599 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg)
600 progressive JPEG (stb)
601 PGM/PPM support (Ken Miller)
602 STBI_MALLOC,STBI_REALLOC,STBI_FREE
603 GIF bugfix -- seemingly never worked
604 STBI_NO_*, STBI_ONLY_*
605 1.48 (2014-12-14) fix incorrectly-named assert()
606 1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb)
607 optimize PNG (ryg)
608 fix bug in interlaced PNG with user-specified channel count (stb)
609 1.46 (2014-08-26)
610 fix broken tRNS chunk (colorkey-style transparency) in non-paletted PNG
611 1.45 (2014-08-16)
612 fix MSVC-ARM internal compiler error by wrapping malloc
613 1.44 (2014-08-07)
614 various warning fixes from Ronny Chevalier
615 1.43 (2014-07-15)
616 fix MSVC-only compiler problem in code changed in 1.42
617 1.42 (2014-07-09)
618 don't define _CRT_SECURE_NO_WARNINGS (affects user code)
619 fixes to stbi__cleanup_jpeg path
620 added STBI_ASSERT to avoid requiring assert.h
621 1.41 (2014-06-25)
622 fix search&replace from 1.36 that messed up comments/error messages
623 1.40 (2014-06-22)
624 fix gcc struct-initialization warning
625 1.39 (2014-06-15)
626 fix to TGA optimization when req_comp != number of components in TGA;
627 fix to GIF loading because BMP wasn't rewinding (whoops, no GIFs in my test suite)
628 add support for BMP version 5 (more ignored fields)
629 1.38 (2014-06-06)
630 suppress MSVC warnings on integer casts truncating values
631 fix accidental rename of 'skip' field of I/O
632 1.37 (2014-06-04)
633 remove duplicate typedef
634 1.36 (2014-06-03)
635 convert to header file single-file library
636 if de-iphone isn't set, load iphone images color-swapped instead of returning NULL
637 1.35 (2014-05-27)
638 various warnings
639 fix broken STBI_SIMD path
640 fix bug where stbi_load_from_file no longer left file pointer in correct place
641 fix broken non-easy path for 32-bit BMP (possibly never used)
642 TGA optimization by Arseny Kapoulkine
643 1.34 (unknown)
644 use STBI_NOTUSED in stbi__resample_row_generic(), fix one more leak in tga failure case
645 1.33 (2011-07-14)
646 make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements
647 1.32 (2011-07-13)
648 support for "info" function for all supported filetypes (SpartanJ)
649 1.31 (2011-06-20)
650 a few more leak fixes, bug in PNG handling (SpartanJ)
651 1.30 (2011-06-11)
652 added ability to load files via callbacks to accomidate custom input streams (Ben Wenger)
653 removed deprecated format-specific test/load functions
654 removed support for installable file formats (stbi_loader) -- would have been broken for IO callbacks anyway
655 error cases in bmp and tga give messages and don't leak (Raymond Barbiero, grisha)
656 fix inefficiency in decoding 32-bit BMP (David Woo)
657 1.29 (2010-08-16)
658 various warning fixes from Aurelien Pocheville
659 1.28 (2010-08-01)
660 fix bug in GIF palette transparency (SpartanJ)
661 1.27 (2010-08-01)
662 cast-to-stbi_uc to fix warnings
663 1.26 (2010-07-24)
664 fix bug in file buffering for PNG reported by SpartanJ
665 1.25 (2010-07-17)
666 refix trans_data warning (Won Chun)
667 1.24 (2010-07-12)
668 perf improvements reading from files on platforms with lock-heavy fgetc()
669 minor perf improvements for jpeg
670 deprecated type-specific functions so we'll get feedback if they're needed
671 attempt to fix trans_data warning (Won Chun)
672 1.23 fixed bug in iPhone support
673 1.22 (2010-07-10)
674 removed image *writing* support
675 stbi_info support from Jetro Lauha
676 GIF support from Jean-Marc Lienher
677 iPhone PNG-extensions from James Brown
678 warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva)
679 1.21 fix use of 'stbi_uc' in header (reported by jon blow)
680 1.20 added support for Softimage PIC, by Tom Seddon
681 1.19 bug in interlaced PNG corruption check (found by ryg)
682 1.18 (2008-08-02)
683 fix a threading bug (local mutable static)
684 1.17 support interlaced PNG
685 1.16 major bugfix - stbi__convert_format converted one too many pixels
686 1.15 initialize some fields for thread safety
687 1.14 fix threadsafe conversion bug
688 header-file-only version (#define STBI_HEADER_FILE_ONLY before including)
689 1.13 threadsafe
690 1.12 const qualifiers in the API
691 1.11 Support installable IDCT, colorspace conversion routines
692 1.10 Fixes for 64-bit (don't use "unsigned long")
693 optimized upsampling by Fabian "ryg" Giesen
694 1.09 Fix format-conversion for PSD code (bad global variables!)
695 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz
696 1.07 attempt to fix C++ warning/errors again
697 1.06 attempt to fix C++ warning/errors again
698 1.05 fix TGA loading to return correct *comp and use good luminance calc
699 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free
700 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR
701 1.02 support for (subset of) HDR files, float interface for preferred access to them
702 1.01 fix bug: possible bug in handling right-side up bmps... not sure
703 fix bug: the stbi__bmp_load() and stbi__tga_load() functions didn't work at all
704 1.00 interface to zlib that skips zlib header
705 0.99 correct handling of alpha in palette
706 0.98 TGA loader by lonesock; dynamically add loaders (untested)
707 0.97 jpeg errors on too large a file; also catch another malloc failure
708 0.96 fix detection of invalid v value - particleman@mollyrocket forum
709 0.95 during header scan, seek to markers in case of padding
710 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same
711 0.93 handle jpegtran output; verbose errors
712 0.92 read 4,8,16,24,32-bit BMP files of several formats
713 0.91 output 24-bit Windows 3.0 BMP files
714 0.90 fix a few more warnings; bump version number to approach 1.0
715 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd
716 0.60 fix compiling as c++
717 0.59 fix warnings: merge Dave Moore's -Wall fixes
718 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian
719 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available
720 0.56 fix bug: zlib uncompressed mode len vs. nlen
721 0.55 fix bug: restart_interval not initialized to 0
722 0.54 allow NULL for 'int *comp'
723 0.53 fix bug in png 3->4; speedup png decoding
724 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments
725 0.51 obey req_comp requests, 1-component jpegs return as 1-component,
726 on 'test' only check type, not whether we support this variant
727 0.50 (2006-11-19)
728 first released version
729*/
730
731
732/*
733------------------------------------------------------------------------------
734This software is available under 2 licenses -- choose whichever you prefer.
735------------------------------------------------------------------------------
736ALTERNATIVE A - MIT License
737Copyright (c) 2017 Sean Barrett
738Permission is hereby granted, free of charge, to any person obtaining a copy of
739this software and associated documentation files (the "Software"), to deal in
740the Software without restriction, including without limitation the rights to
741use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
742of the Software, and to permit persons to whom the Software is furnished to do
743so, subject to the following conditions:
744The above copyright notice and this permission notice shall be included in all
745copies or substantial portions of the Software.
746THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
747IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
748FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
749AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
750LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
751OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
752SOFTWARE.
753------------------------------------------------------------------------------
754ALTERNATIVE B - Public Domain (www.unlicense.org)
755This is free and unencumbered software released into the public domain.
756Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
757software, either in source code form or as a compiled binary, for any purpose,
758commercial or non-commercial, and by any means.
759In jurisdictions that recognize copyright laws, the author or authors of this
760software dedicate any and all copyright interest in the software to the public
761domain. We make this dedication for the benefit of the public at large and to
762the detriment of our heirs and successors. We intend this dedication to be an
763overt act of relinquishment in perpetuity of all present and future rights to
764this software under copyright law.
765THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
766IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
767FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
768AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
769ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
770WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
771------------------------------------------------------------------------------
772*/