polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

stb_image.h (32933B)


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