stb_image.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /* stb_image - v2.12 - public domain image loader - http://nothings.org/stb_image.h
  2. no warranty implied; use at your own risk
  3. Do this:
  4. #define STB_IMAGE_IMPLEMENTATION
  5. before you include this file in *one* C or C++ file to create the implementation.
  6. // i.e. it should look like this:
  7. #include ...
  8. #include ...
  9. #include ...
  10. #define STB_IMAGE_IMPLEMENTATION
  11. #include "stb_image.h"
  12. You can #define STBI_ASSERT(x) before the #include to avoid using assert.h.
  13. And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free
  14. QUICK NOTES:
  15. Primarily of interest to game developers and other people who can
  16. avoid problematic images and only need the trivial interface
  17. JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
  18. PNG 1/2/4/8-bit-per-channel (16 bpc not supported)
  19. TGA (not sure what subset, if a subset)
  20. BMP non-1bpp, non-RLE
  21. PSD (composited view only, no extra channels, 8/16 bit-per-channel)
  22. GIF (*comp always reports as 4-channel)
  23. HDR (radiance rgbE format)
  24. PIC (Softimage PIC)
  25. PNM (PPM and PGM binary only)
  26. Animated GIF still needs a proper API, but here's one way to do it:
  27. http://gist.github.com/urraka/685d9a6340b26b830d49
  28. - decode from memory or through FILE (define STBI_NO_STDIO to remove code)
  29. - decode from arbitrary I/O callbacks
  30. - SIMD acceleration on x86/x64 (SSE2) and ARM (NEON)
  31. Full documentation under "DOCUMENTATION" below.
  32. Revision 2.00 release notes:
  33. - Progressive JPEG is now supported.
  34. - PPM and PGM binary formats are now supported, thanks to Ken Miller.
  35. - x86 platforms now make use of SSE2 SIMD instructions for
  36. JPEG decoding, and ARM platforms can use NEON SIMD if requested.
  37. This work was done by Fabian "ryg" Giesen. SSE2 is used by
  38. default, but NEON must be enabled explicitly; see docs.
  39. With other JPEG optimizations included in this version, we see
  40. 2x speedup on a JPEG on an x86 machine, and a 1.5x speedup
  41. on a JPEG on an ARM machine, relative to previous versions of this
  42. library. The same results will not obtain for all JPGs and for all
  43. x86/ARM machines. (Note that progressive JPEGs are significantly
  44. slower to decode than regular JPEGs.) This doesn't mean that this
  45. is the fastest JPEG decoder in the land; rather, it brings it
  46. closer to parity with standard libraries. If you want the fastest
  47. decode, look elsewhere. (See "Philosophy" section of docs below.)
  48. See final bullet items below for more info on SIMD.
  49. - Added STBI_MALLOC, STBI_REALLOC, and STBI_FREE macros for replacing
  50. the memory allocator. Unlike other STBI libraries, these macros don't
  51. support a context parameter, so if you need to pass a context in to
  52. the allocator, you'll have to store it in a global or a thread-local
  53. variable.
  54. - Split existing STBI_NO_HDR flag into two flags, STBI_NO_HDR and
  55. STBI_NO_LINEAR.
  56. STBI_NO_HDR: suppress implementation of .hdr reader format
  57. STBI_NO_LINEAR: suppress high-dynamic-range light-linear float API
  58. - You can suppress implementation of any of the decoders to reduce
  59. your code footprint by #defining one or more of the following
  60. symbols before creating the implementation.
  61. STBI_NO_JPEG
  62. STBI_NO_PNG
  63. STBI_NO_BMP
  64. STBI_NO_PSD
  65. STBI_NO_TGA
  66. STBI_NO_GIF
  67. STBI_NO_HDR
  68. STBI_NO_PIC
  69. STBI_NO_PNM (.ppm and .pgm)
  70. - You can request *only* certain decoders and suppress all other ones
  71. (this will be more forward-compatible, as addition of new decoders
  72. doesn't require you to disable them explicitly):
  73. STBI_ONLY_JPEG
  74. STBI_ONLY_PNG
  75. STBI_ONLY_BMP
  76. STBI_ONLY_PSD
  77. STBI_ONLY_TGA
  78. STBI_ONLY_GIF
  79. STBI_ONLY_HDR
  80. STBI_ONLY_PIC
  81. STBI_ONLY_PNM (.ppm and .pgm)
  82. Note that you can define multiples of these, and you will get all
  83. of them ("only x" and "only y" is interpreted to mean "only x&y").
  84. - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still
  85. want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
  86. - Compilation of all SIMD code can be suppressed with
  87. #define STBI_NO_SIMD
  88. It should not be necessary to disable SIMD unless you have issues
  89. compiling (e.g. using an x86 compiler which doesn't support SSE
  90. intrinsics or that doesn't support the method used to detect
  91. SSE2 support at run-time), and even those can be reported as
  92. bugs so I can refine the built-in compile-time checking to be
  93. smarter.
  94. - The old STBI_SIMD system which allowed installing a user-defined
  95. IDCT etc. has been removed. If you need this, don't upgrade. My
  96. assumption is that almost nobody was doing this, and those who
  97. were will find the built-in SIMD more satisfactory anyway.
  98. - RGB values computed for JPEG images are slightly different from
  99. previous versions of stb_image. (This is due to using less
  100. integer precision in SIMD.) The C code has been adjusted so
  101. that the same RGB values will be computed regardless of whether
  102. SIMD support is available, so your app should always produce
  103. consistent results. But these results are slightly different from
  104. previous versions. (Specifically, about 3% of available YCbCr values
  105. will compute different RGB results from pre-1.49 versions by +-1;
  106. most of the deviating values are one smaller in the G channel.)
  107. - If you must produce consistent results with previous versions of
  108. stb_image, #define STBI_JPEG_OLD and you will get the same results
  109. you used to; however, you will not get the SIMD speedups for
  110. the YCbCr-to-RGB conversion step (although you should still see
  111. significant JPEG speedup from the other changes).
  112. Please note that STBI_JPEG_OLD is a temporary feature; it will be
  113. removed in future versions of the library. It is only intended for
  114. near-term back-compatibility use.
  115. Latest revision history:
  116. 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
  117. 2.11 (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x64
  118. RGB-format JPEG; remove white matting in PSD;
  119. allocate large structures on the stack;
  120. correct channel count for PNG & BMP
  121. 2.10 (2016-01-22) avoid warning introduced in 2.09
  122. 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED
  123. 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA
  124. 2.07 (2015-09-13) partial animated GIF support
  125. limited 16-bit PSD support
  126. minor bugs, code cleanup, and compiler warnings
  127. 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value
  128. 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning
  129. 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit
  130. 2.03 (2015-04-12) additional corruption checking
  131. stbi_set_flip_vertically_on_load
  132. fix NEON support; fix mingw support
  133. 2.02 (2015-01-19) fix incorrect assert, fix warning
  134. 2.01 (2015-01-17) fix various warnings
  135. 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG
  136. 2.00 (2014-12-25) optimize JPEG, including x86 SSE2 & ARM NEON SIMD
  137. progressive JPEG
  138. PGM/PPM support
  139. STBI_MALLOC,STBI_REALLOC,STBI_FREE
  140. STBI_NO_*, STBI_ONLY_*
  141. GIF bugfix
  142. See end of file for full revision history.
  143. ============================ Contributors =========================
  144. Image formats Extensions, features
  145. Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info)
  146. Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info)
  147. Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG)
  148. Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks)
  149. Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG)
  150. Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
  151. Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
  152. urraka@github (animated gif) Junggon Kim (PNM comments)
  153. Daniel Gibson (16-bit TGA)
  154. Optimizations & bugfixes
  155. Fabian "ryg" Giesen
  156. Arseny Kapoulkine
  157. Bug & warning fixes
  158. Marc LeBlanc David Woo Guillaume George Martins Mozeiko
  159. Christpher Lloyd Martin Golini Jerry Jansson Joseph Thomson
  160. Dave Moore Roy Eltham Hayaki Saito Phil Jordan
  161. Won Chun Luke Graham Johan Duparc Nathan Reed
  162. the Horde3D community Thomas Ruf Ronny Chevalier Nick Verigakis
  163. Janez Zemva John Bartholomew Michal Cichon svdijk@github
  164. Jonathan Blow Ken Hamada Tero Hanninen Baldur Karlsson
  165. Laurent Gomila Cort Stratton Sergio Gonzalez romigrou@github
  166. Aruelien Pocheville Thibault Reuille Cass Everitt Matthew Gregan
  167. Ryamond Barbiero Paul Du Bois Engin Manap snagar@github
  168. Michaelangel007@github Oriol Ferrer Mesia socks-the-fox
  169. Blazej Dariusz Roszkowski
  170. LICENSE
  171. This software is dual-licensed to the public domain and under the following
  172. license: you are granted a perpetual, irrevocable license to copy, modify,
  173. publish, and distribute this file as you see fit.
  174. */
  175. #ifndef STBI_INCLUDE_STB_IMAGE_H
  176. #define STBI_INCLUDE_STB_IMAGE_H
  177. // DOCUMENTATION
  178. //
  179. // Limitations:
  180. // - no 16-bit-per-channel PNG
  181. // - no 12-bit-per-channel JPEG
  182. // - no JPEGs with arithmetic coding
  183. // - no 1-bit BMP
  184. // - GIF always returns *comp=4
  185. //
  186. // Basic usage (see HDR discussion below for HDR usage):
  187. // int x,y,n;
  188. // unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
  189. // // ... process data if not NULL ...
  190. // // ... x = width, y = height, n = # 8-bit components per pixel ...
  191. // // ... replace '0' with '1'..'4' to force that many components per pixel
  192. // // ... but 'n' will always be the number that it would have been if you said 0
  193. // stbi_image_free(data)
  194. //
  195. // Standard parameters:
  196. // int *x -- outputs image width in pixels
  197. // int *y -- outputs image height in pixels
  198. // int *comp -- outputs # of image components in image file
  199. // int req_comp -- if non-zero, # of image components requested in result
  200. //
  201. // The return value from an image loader is an 'unsigned char *' which points
  202. // to the pixel data, or NULL on an allocation failure or if the image is
  203. // corrupt or invalid. The pixel data consists of *y scanlines of *x pixels,
  204. // with each pixel consisting of N interleaved 8-bit components; the first
  205. // pixel pointed to is top-left-most in the image. There is no padding between
  206. // image scanlines or between pixels, regardless of format. The number of
  207. // components N is 'req_comp' if req_comp is non-zero, or *comp otherwise.
  208. // If req_comp is non-zero, *comp has the number of components that _would_
  209. // have been output otherwise. E.g. if you set req_comp to 4, you will always
  210. // get RGBA output, but you can check *comp to see if it's trivially opaque
  211. // because e.g. there were only 3 channels in the source image.
  212. //
  213. // An output image with N components has the following components interleaved
  214. // in this order in each pixel:
  215. //
  216. // N=#comp components
  217. // 1 grey
  218. // 2 grey, alpha
  219. // 3 red, green, blue
  220. // 4 red, green, blue, alpha
  221. //
  222. // If image loading fails for any reason, the return value will be NULL,
  223. // and *x, *y, *comp will be unchanged. The function stbi_failure_reason()
  224. // can be queried for an extremely brief, end-user unfriendly explanation
  225. // of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid
  226. // compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly
  227. // more user-friendly ones.
  228. //
  229. // Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
  230. //
  231. // ===========================================================================
  232. //
  233. // Philosophy
  234. //
  235. // stb libraries are designed with the following priorities:
  236. //
  237. // 1. easy to use
  238. // 2. easy to maintain
  239. // 3. good performance
  240. //
  241. // Sometimes I let "good performance" creep up in priority over "easy to maintain",
  242. // and for best performance I may provide less-easy-to-use APIs that give higher
  243. // performance, in addition to the easy to use ones. Nevertheless, it's important
  244. // to keep in mind that from the standpoint of you, a client of this library,
  245. // all you care about is #1 and #3, and stb libraries do not emphasize #3 above all.
  246. //
  247. // Some secondary priorities arise directly from the first two, some of which
  248. // make more explicit reasons why performance can't be emphasized.
  249. //
  250. // - Portable ("ease of use")
  251. // - Small footprint ("easy to maintain")
  252. // - No dependencies ("ease of use")
  253. //
  254. // ===========================================================================
  255. //
  256. // I/O callbacks
  257. //
  258. // I/O callbacks allow you to read from arbitrary sources, like packaged
  259. // files or some other source. Data read from callbacks are processed
  260. // through a small internal buffer (currently 128 bytes) to try to reduce
  261. // overhead.
  262. //
  263. // The three functions you must define are "read" (reads some bytes of data),
  264. // "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).
  265. //
  266. // ===========================================================================
  267. //
  268. // SIMD support
  269. //
  270. // The JPEG decoder will try to automatically use SIMD kernels on x86 when
  271. // supported by the compiler. For ARM Neon support, you must explicitly
  272. // request it.
  273. //
  274. // (The old do-it-yourself SIMD API is no longer supported in the current
  275. // code.)
  276. //
  277. // On x86, SSE2 will automatically be used when available based on a run-time
  278. // test; if not, the generic C versions are used as a fall-back. On ARM targets,
  279. // the typical path is to have separate builds for NEON and non-NEON devices
  280. // (at least this is true for iOS and Android). Therefore, the NEON support is
  281. // toggled by a build flag: define STBI_NEON to get NEON loops.
  282. //
  283. // The output of the JPEG decoder is slightly different from versions where
  284. // SIMD support was introduced (that is, for versions before 1.49). The
  285. // difference is only +-1 in the 8-bit RGB channels, and only on a small
  286. // fraction of pixels. You can force the pre-1.49 behavior by defining
  287. // STBI_JPEG_OLD, but this will disable some of the SIMD decoding path
  288. // and hence cost some performance.
  289. //
  290. // If for some reason you do not want to use any of SIMD code, or if
  291. // you have issues compiling it, you can disable it entirely by
  292. // defining STBI_NO_SIMD.
  293. //
  294. // ===========================================================================
  295. //
  296. // HDR image support (disable by defining STBI_NO_HDR)
  297. //
  298. // stb_image now supports loading HDR images in general, and currently
  299. // the Radiance .HDR file format, although the support is provided
  300. // generically. You can still load any file through the existing interface;
  301. // if you attempt to load an HDR file, it will be automatically remapped to
  302. // LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
  303. // both of these constants can be reconfigured through this interface:
  304. //
  305. // stbi_hdr_to_ldr_gamma(2.2f);
  306. // stbi_hdr_to_ldr_scale(1.0f);
  307. //
  308. // (note, do not use _inverse_ constants; stbi_image will invert them
  309. // appropriately).
  310. //
  311. // Additionally, there is a new, parallel interface for loading files as
  312. // (linear) floats to preserve the full dynamic range:
  313. //
  314. // float *data = stbi_loadf(filename, &x, &y, &n, 0);
  315. //
  316. // If you load LDR images through this interface, those images will
  317. // be promoted to floating point values, run through the inverse of
  318. // constants corresponding to the above:
  319. //
  320. // stbi_ldr_to_hdr_scale(1.0f);
  321. // stbi_ldr_to_hdr_gamma(2.2f);
  322. //
  323. // Finally, given a filename (or an open file or memory block--see header
  324. // file for details) containing image data, you can query for the "most
  325. // appropriate" interface to use (that is, whether the image is HDR or
  326. // not), using:
  327. //
  328. // stbi_is_hdr(char *filename);
  329. //
  330. // ===========================================================================
  331. //
  332. // iPhone PNG support:
  333. //
  334. // By default we convert iphone-formatted PNGs back to RGB, even though
  335. // they are internally encoded differently. You can disable this conversion
  336. // by by calling stbi_convert_iphone_png_to_rgb(0), in which case
  337. // you will always just get the native iphone "format" through (which
  338. // is BGR stored in RGB).
  339. //
  340. // Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
  341. // pixel to remove any premultiplied alpha *only* if the image file explicitly
  342. // says there's premultiplied data (currently only happens in iPhone images,
  343. // and only if iPhone convert-to-rgb processing is on).
  344. //
  345. #ifndef STBI_NO_STDIO
  346. #include <stdio.h>
  347. #endif // STBI_NO_STDIO
  348. #define STBI_VERSION 1
  349. enum
  350. {
  351. STBI_default = 0, // only used for req_comp
  352. STBI_grey = 1,
  353. STBI_grey_alpha = 2,
  354. STBI_rgb = 3,
  355. STBI_rgb_alpha = 4
  356. };
  357. typedef unsigned char stbi_uc;
  358. #ifdef __cplusplus
  359. extern "C" {
  360. #endif
  361. #ifdef STB_IMAGE_STATIC
  362. #define STBIDEF static
  363. #else
  364. #define STBIDEF extern
  365. #endif
  366. //////////////////////////////////////////////////////////////////////////////
  367. //
  368. // PRIMARY API - works on images of any type
  369. //
  370. //
  371. // load image by filename, open file, or memory buffer
  372. //
  373. typedef struct
  374. {
  375. int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read
  376. void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
  377. int (*eof) (void *user); // returns nonzero if we are at end of file/data
  378. } stbi_io_callbacks;
  379. STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp);
  380. STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *comp, int req_comp);
  381. STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *comp, int req_comp);
  382. #ifndef STBI_NO_STDIO
  383. STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
  384. // for stbi_load_from_file, file pointer is left pointing immediately after image
  385. #endif
  386. #ifndef STBI_NO_LINEAR
  387. STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp);
  388. STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
  389. STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
  390. #ifndef STBI_NO_STDIO
  391. STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
  392. #endif
  393. #endif
  394. #ifndef STBI_NO_HDR
  395. STBIDEF void stbi_hdr_to_ldr_gamma(float gamma);
  396. STBIDEF void stbi_hdr_to_ldr_scale(float scale);
  397. #endif // STBI_NO_HDR
  398. #ifndef STBI_NO_LINEAR
  399. STBIDEF void stbi_ldr_to_hdr_gamma(float gamma);
  400. STBIDEF void stbi_ldr_to_hdr_scale(float scale);
  401. #endif // STBI_NO_LINEAR
  402. // stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
  403. STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
  404. STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
  405. #ifndef STBI_NO_STDIO
  406. STBIDEF int stbi_is_hdr (char const *filename);
  407. STBIDEF int stbi_is_hdr_from_file(FILE *f);
  408. #endif // STBI_NO_STDIO
  409. // get a VERY brief reason for failure
  410. // NOT THREADSAFE
  411. STBIDEF const char *stbi_failure_reason (void);
  412. // free the loaded image -- this is just free()
  413. STBIDEF void stbi_image_free (void *retval_from_stbi_load);
  414. // get image dimensions & components without fully decoding
  415. STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
  416. STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
  417. #ifndef STBI_NO_STDIO
  418. STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
  419. STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
  420. #endif
  421. // for image formats that explicitly notate that they have premultiplied alpha,
  422. // we just return the colors as stored in the file. set this flag to force
  423. // unpremultiplication. results are undefined if the unpremultiply overflow.
  424. STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
  425. // indicate whether we should process iphone images back to canonical format,
  426. // or just pass them through "as-is"
  427. STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
  428. // flip the image vertically, so the first pixel in the output array is the bottom left
  429. STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
  430. // ZLIB client - used by PNG, available for other purposes
  431. STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
  432. STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);
  433. STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
  434. STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
  435. STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
  436. STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
  437. #ifdef __cplusplus
  438. }
  439. #endif
  440. //
  441. //
  442. //// end header file /////////////////////////////////////////////////////
  443. #endif // STBI_INCLUDE_STB_IMAGE_H
  444. /*
  445. revision history:
  446. 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
  447. 2.11 (2016-04-02) allocate large structures on the stack
  448. remove white matting for transparent PSD
  449. fix reported channel count for PNG & BMP
  450. re-enable SSE2 in non-gcc 64-bit
  451. support RGB-formatted JPEG
  452. read 16-bit PNGs (only as 8-bit)
  453. 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED
  454. 2.09 (2016-01-16) allow comments in PNM files
  455. 16-bit-per-pixel TGA (not bit-per-component)
  456. info() for TGA could break due to .hdr handling
  457. info() for BMP to shares code instead of sloppy parse
  458. can use STBI_REALLOC_SIZED if allocator doesn't support realloc
  459. code cleanup
  460. 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA
  461. 2.07 (2015-09-13) fix compiler warnings
  462. partial animated GIF support
  463. limited 16-bpc PSD support
  464. #ifdef unused functions
  465. bug with < 92 byte PIC,PNM,HDR,TGA
  466. 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value
  467. 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning
  468. 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit
  469. 2.03 (2015-04-12) extra corruption checking (mmozeiko)
  470. stbi_set_flip_vertically_on_load (nguillemot)
  471. fix NEON support; fix mingw support
  472. 2.02 (2015-01-19) fix incorrect assert, fix warning
  473. 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2
  474. 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG
  475. 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg)
  476. progressive JPEG (stb)
  477. PGM/PPM support (Ken Miller)
  478. STBI_MALLOC,STBI_REALLOC,STBI_FREE
  479. GIF bugfix -- seemingly never worked
  480. STBI_NO_*, STBI_ONLY_*
  481. 1.48 (2014-12-14) fix incorrectly-named assert()
  482. 1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb)
  483. optimize PNG (ryg)
  484. fix bug in interlaced PNG with user-specified channel count (stb)
  485. 1.46 (2014-08-26)
  486. fix broken tRNS chunk (colorkey-style transparency) in non-paletted PNG
  487. 1.45 (2014-08-16)
  488. fix MSVC-ARM internal compiler error by wrapping malloc
  489. 1.44 (2014-08-07)
  490. various warning fixes from Ronny Chevalier
  491. 1.43 (2014-07-15)
  492. fix MSVC-only compiler problem in code changed in 1.42
  493. 1.42 (2014-07-09)
  494. don't define _CRT_SECURE_NO_WARNINGS (affects user code)
  495. fixes to stbi__cleanup_jpeg path
  496. added STBI_ASSERT to avoid requiring assert.h
  497. 1.41 (2014-06-25)
  498. fix search&replace from 1.36 that messed up comments/error messages
  499. 1.40 (2014-06-22)
  500. fix gcc struct-initialization warning
  501. 1.39 (2014-06-15)
  502. fix to TGA optimization when req_comp != number of components in TGA;
  503. fix to GIF loading because BMP wasn't rewinding (whoops, no GIFs in my test suite)
  504. add support for BMP version 5 (more ignored fields)
  505. 1.38 (2014-06-06)
  506. suppress MSVC warnings on integer casts truncating values
  507. fix accidental rename of 'skip' field of I/O
  508. 1.37 (2014-06-04)
  509. remove duplicate typedef
  510. 1.36 (2014-06-03)
  511. convert to header file single-file library
  512. if de-iphone isn't set, load iphone images color-swapped instead of returning NULL
  513. 1.35 (2014-05-27)
  514. various warnings
  515. fix broken STBI_SIMD path
  516. fix bug where stbi_load_from_file no longer left file pointer in correct place
  517. fix broken non-easy path for 32-bit BMP (possibly never used)
  518. TGA optimization by Arseny Kapoulkine
  519. 1.34 (unknown)
  520. use STBI_NOTUSED in stbi__resample_row_generic(), fix one more leak in tga failure case
  521. 1.33 (2011-07-14)
  522. make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements
  523. 1.32 (2011-07-13)
  524. support for "info" function for all supported filetypes (SpartanJ)
  525. 1.31 (2011-06-20)
  526. a few more leak fixes, bug in PNG handling (SpartanJ)
  527. 1.30 (2011-06-11)
  528. added ability to load files via callbacks to accomidate custom input streams (Ben Wenger)
  529. removed deprecated format-specific test/load functions
  530. removed support for installable file formats (stbi_loader) -- would have been broken for IO callbacks anyway
  531. error cases in bmp and tga give messages and don't leak (Raymond Barbiero, grisha)
  532. fix inefficiency in decoding 32-bit BMP (David Woo)
  533. 1.29 (2010-08-16)
  534. various warning fixes from Aurelien Pocheville
  535. 1.28 (2010-08-01)
  536. fix bug in GIF palette transparency (SpartanJ)
  537. 1.27 (2010-08-01)
  538. cast-to-stbi_uc to fix warnings
  539. 1.26 (2010-07-24)
  540. fix bug in file buffering for PNG reported by SpartanJ
  541. 1.25 (2010-07-17)
  542. refix trans_data warning (Won Chun)
  543. 1.24 (2010-07-12)
  544. perf improvements reading from files on platforms with lock-heavy fgetc()
  545. minor perf improvements for jpeg
  546. deprecated type-specific functions so we'll get feedback if they're needed
  547. attempt to fix trans_data warning (Won Chun)
  548. 1.23 fixed bug in iPhone support
  549. 1.22 (2010-07-10)
  550. removed image *writing* support
  551. stbi_info support from Jetro Lauha
  552. GIF support from Jean-Marc Lienher
  553. iPhone PNG-extensions from James Brown
  554. warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva)
  555. 1.21 fix use of 'stbi_uc' in header (reported by jon blow)
  556. 1.20 added support for Softimage PIC, by Tom Seddon
  557. 1.19 bug in interlaced PNG corruption check (found by ryg)
  558. 1.18 (2008-08-02)
  559. fix a threading bug (local mutable static)
  560. 1.17 support interlaced PNG
  561. 1.16 major bugfix - stbi__convert_format converted one too many pixels
  562. 1.15 initialize some fields for thread safety
  563. 1.14 fix threadsafe conversion bug
  564. header-file-only version (#define STBI_HEADER_FILE_ONLY before including)
  565. 1.13 threadsafe
  566. 1.12 const qualifiers in the API
  567. 1.11 Support installable IDCT, colorspace conversion routines
  568. 1.10 Fixes for 64-bit (don't use "unsigned long")
  569. optimized upsampling by Fabian "ryg" Giesen
  570. 1.09 Fix format-conversion for PSD code (bad global variables!)
  571. 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz
  572. 1.07 attempt to fix C++ warning/errors again
  573. 1.06 attempt to fix C++ warning/errors again
  574. 1.05 fix TGA loading to return correct *comp and use good luminance calc
  575. 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free
  576. 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR
  577. 1.02 support for (subset of) HDR files, float interface for preferred access to them
  578. 1.01 fix bug: possible bug in handling right-side up bmps... not sure
  579. fix bug: the stbi__bmp_load() and stbi__tga_load() functions didn't work at all
  580. 1.00 interface to zlib that skips zlib header
  581. 0.99 correct handling of alpha in palette
  582. 0.98 TGA loader by lonesock; dynamically add loaders (untested)
  583. 0.97 jpeg errors on too large a file; also catch another malloc failure
  584. 0.96 fix detection of invalid v value - particleman@mollyrocket forum
  585. 0.95 during header scan, seek to markers in case of padding
  586. 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same
  587. 0.93 handle jpegtran output; verbose errors
  588. 0.92 read 4,8,16,24,32-bit BMP files of several formats
  589. 0.91 output 24-bit Windows 3.0 BMP files
  590. 0.90 fix a few more warnings; bump version number to approach 1.0
  591. 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd
  592. 0.60 fix compiling as c++
  593. 0.59 fix warnings: merge Dave Moore's -Wall fixes
  594. 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian
  595. 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available
  596. 0.56 fix bug: zlib uncompressed mode len vs. nlen
  597. 0.55 fix bug: restart_interval not initialized to 0
  598. 0.54 allow NULL for 'int *comp'
  599. 0.53 fix bug in png 3->4; speedup png decoding
  600. 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments
  601. 0.51 obey req_comp requests, 1-component jpegs return as 1-component,
  602. on 'test' only check type, not whether we support this variant
  603. 0.50 (2006-11-19)
  604. first released version
  605. */