CoolFace
Modelpublic

Codeprocastinator/optimized-tinyllama-covalent

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes119downloads
stb_image.h7989 linesDownload Raw Back to common
1/* stb_image - v2.30 - public domain image loader - http://nothings.org/stb2                                  no warranty implied; use at your own risk3 4   Do this:5      #define STB_IMAGE_IMPLEMENTATION6   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_IMPLEMENTATION13   #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,free17 18 19   QUICK NOTES:20      Primarily of interest to game developers and other people who can21          avoid problematic images and only need the trivial interface22 23      JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)24      PNG 1/2/4/8/16-bit-per-channel25 26      TGA (not sure what subset, if a subset)27      BMP non-1bpp, non-RLE28      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/685d9a6340b26b830d4937 38      - decode from memory or through FILE (define STBI_NO_STDIO to remove code)39      - decode from arbitrary I/O callbacks40      - SIMD acceleration on x86/x64 (SSE2) and ARM (NEON)41 42   Full documentation under "DOCUMENTATION" below.43 44 45LICENSE46 47  See end of file for license information.48 49RECENT REVISION HISTORY:50 51      2.30  (2024-05-31) avoid erroneous gcc warning52      2.29  (2023-05-xx) optimizations53      2.28  (2023-01-29) many error fixes, security errors, just tons of stuff54      2.27  (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes55      2.26  (2020-07-13) many minor fixes56      2.25  (2020-02-02) fix warnings57      2.24  (2020-02-02) fix warnings; thread-local failure_reason and flip_vertically58      2.23  (2019-08-11) fix clang static analysis warning59      2.22  (2019-03-04) gif fixes, fix warnings60      2.21  (2019-02-25) fix typo in comment61      2.20  (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs62      2.19  (2018-02-11) fix warning63      2.18  (2018-01-30) fix warnings64      2.17  (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings65      2.16  (2017-07-23) all functions have 16-bit variants; optimizations; bugfixes66      2.15  (2017-03-18) fix png-1,2,4; all Imagenet JPGs; no runtime SSE detection on GCC67      2.14  (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs68      2.13  (2016-12-04) experimental 16-bit API, only for PNG so far; fixes69      2.12  (2016-04-02) fix typo in 2.11 PSD fix that caused crashes70      2.11  (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x6471                         RGB-format JPEG; remove white matting in PSD;72                         allocate large structures on the stack;73                         correct channel count for PNG & BMP74      2.10  (2016-01-22) avoid warning introduced in 2.0975      2.09  (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED76 77   See end of file for full revision history.78 79 80 ============================    Contributors    =========================81 82 Image formats                          Extensions, features83    Sean Barrett (jpeg, png, bmp)          Jetro Lauha (stbi_info)84    Nicolas Schulz (hdr, psd)              Martin "SpartanJ" Golini (stbi_info)85    Jonathan Dummer (tga)                  James "moose2000" Brown (iPhone PNG)86    Jean-Marc Lienher (gif)                Ben "Disch" Wenger (io callbacks)87    Tom Seddon (pic)                       Omar Cornut (1/2/4-bit PNG)88    Thatcher Ulrich (psd)                  Nicolas Guillemot (vertical flip)89    Ken Miller (pgm, ppm)                  Richard Mitton (16-bit PSD)90    github:urraka (animated gif)           Junggon Kim (PNM comments)91    Christopher Forseth (animated gif)     Daniel Gibson (16-bit TGA)92                                           socks-the-fox (16-bit PNG)93                                           Jeremy Sawicki (handle all ImageNet JPGs)94 Optimizations & bugfixes                  Mikhail Morozov (1-bit BMP)95    Fabian "ryg" Giesen                    Anael Seghezzi (is-16-bit query)96    Arseny Kapoulkine                      Simon Breuss (16-bit PNM)97    John-Mark Allen98    Carmelo J Fdez-Aguera99 100 Bug & warning fixes101    Marc LeBlanc            David Woo          Guillaume George     Martins Mozeiko102    Christpher Lloyd        Jerry Jansson      Joseph Thomson       Blazej Dariusz Roszkowski103    Phil Jordan                                Dave Moore           Roy Eltham104    Hayaki Saito            Nathan Reed        Won Chun105    Luke Graham             Johan Duparc       Nick Verigakis       the Horde3D community106    Thomas Ruf              Ronny Chevalier                         github:rlyeh107    Janez Zemva             John Bartholomew   Michal Cichon        github:romigrou108    Jonathan Blow           Ken Hamada         Tero Hanninen        github:svdijk109    Eugene Golushkov        Laurent Gomila     Cort Stratton        github:snagar110    Aruelien Pocheville     Sergio Gonzalez    Thibault Reuille     github:Zelex111    Cass Everitt            Ryamond Barbiero                        github:grim210112    Paul Du Bois            Engin Manap        Aldo Culquicondor    github:sammyhw113    Philipp Wiesemann       Dale Weiler        Oriol Ferrer Mesia   github:phprus114    Josh Tobin              Neil Bickford      Matthew Gregan       github:poppolopoppo115    Julian Raschke          Gregory Mullen     Christian Floisand   github:darealshinji116    Baldur Karlsson         Kevin Schmidt      JR Smith             github:Michaelangel007117                            Brad Weinberger    Matvey Cherevko      github:mosra118    Luca Sas                Alexander Veselov  Zack Middleton       [reserved]119    Ryan C. Gordon          [reserved]                              [reserved]120                     DO NOT ADD YOUR NAME HERE121 122                     Jacko Dirks123 124  To add your name to the credits, pick a random blank space in the middle and fill it.125  80% of merge conflicts on stb PRs are due to people adding their name at the end126  of the credits.127*/128 129#ifndef STBI_INCLUDE_STB_IMAGE_H130#define STBI_INCLUDE_STB_IMAGE_H131 132// DOCUMENTATION133//134// Limitations:135//    - no 12-bit-per-channel JPEG136//    - no JPEGs with arithmetic coding137//    - GIF always returns *comp=4138//139// Basic usage (see HDR discussion below for HDR usage):140//    int x,y,n;141//    unsigned char *data = stbi_load(filename, &x, &y, &n, 0);142//    // ... process data if not NULL ...143//    // ... x = width, y = height, n = # 8-bit components per pixel ...144//    // ... replace '0' with '1'..'4' to force that many components per pixel145//    // ... but 'n' will always be the number that it would have been if you said 0146//    stbi_image_free(data);147//148// Standard parameters:149//    int *x                 -- outputs image width in pixels150//    int *y                 -- outputs image height in pixels151//    int *channels_in_file  -- outputs # of image components in image file152//    int desired_channels   -- if non-zero, # of image components requested in result153//154// The return value from an image loader is an 'unsigned char *' which points155// to the pixel data, or NULL on an allocation failure or if the image is156// corrupt or invalid. The pixel data consists of *y scanlines of *x pixels,157// with each pixel consisting of N interleaved 8-bit components; the first158// pixel pointed to is top-left-most in the image. There is no padding between159// image scanlines or between pixels, regardless of format. The number of160// components N is 'desired_channels' if desired_channels is non-zero, or161// *channels_in_file otherwise. If desired_channels is non-zero,162// *channels_in_file has the number of components that _would_ have been163// output otherwise. E.g. if you set desired_channels to 4, you will always164// get RGBA output, but you can check *channels_in_file to see if it's trivially165// opaque because e.g. there were only 3 channels in the source image.166//167// An output image with N components has the following components interleaved168// in this order in each pixel:169//170//     N=#comp     components171//       1           grey172//       2           grey, alpha173//       3           red, green, blue174//       4           red, green, blue, alpha175//176// If image loading fails for any reason, the return value will be NULL,177// and *x, *y, *channels_in_file will be unchanged. The function178// stbi_failure_reason() can be queried for an extremely brief, end-user179// unfriendly explanation of why the load failed. Define STBI_NO_FAILURE_STRINGS180// to avoid compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly181// more user-friendly ones.182//183// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.184//185// To query the width, height and component count of an image without having to186// decode the full file, you can use the stbi_info family of functions:187//188//   int x,y,n,ok;189//   ok = stbi_info(filename, &x, &y, &n);190//   // returns ok=1 and sets x, y, n if image is a supported format,191//   // 0 otherwise.192//193// Note that stb_image pervasively uses ints in its public API for sizes,194// including sizes of memory buffers. This is now part of the API and thus195// hard to change without causing breakage. As a result, the various image196// loaders all have certain limits on image size; these differ somewhat197// by format but generally boil down to either just under 2GB or just under198// 1GB. When the decoded image would be larger than this, stb_image decoding199// will fail.200//201// Additionally, stb_image will reject image files that have any of their202// dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS,203// which defaults to 2**24 = 16777216 pixels. Due to the above memory limit,204// the only way to have an image with such dimensions load correctly205// is for it to have a rather extreme aspect ratio. Either way, the206// assumption here is that such larger images are likely to be malformed207// or malicious. If you do need to load an image with individual dimensions208// larger than that, and it still fits in the overall size limit, you can209// #define STBI_MAX_DIMENSIONS on your own to be something larger.210//211// ===========================================================================212//213// UNICODE:214//215//   If compiling for Windows and you wish to use Unicode filenames, compile216//   with217//       #define STBI_WINDOWS_UTF8218//   and pass utf8-encoded filenames. Call stbi_convert_wchar_to_utf8 to convert219//   Windows wchar_t filenames to utf8.220//221// ===========================================================================222//223// Philosophy224//225// stb libraries are designed with the following priorities:226//227//    1. easy to use228//    2. easy to maintain229//    3. good performance230//231// Sometimes I let "good performance" creep up in priority over "easy to maintain",232// and for best performance I may provide less-easy-to-use APIs that give higher233// performance, in addition to the easy-to-use ones. Nevertheless, it's important234// to keep in mind that from the standpoint of you, a client of this library,235// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.236//237// Some secondary priorities arise directly from the first two, some of which238// provide more explicit reasons why performance can't be emphasized.239//240//    - Portable ("ease of use")241//    - Small source code footprint ("easy to maintain")242//    - No dependencies ("ease of use")243//244// ===========================================================================245//246// I/O callbacks247//248// I/O callbacks allow you to read from arbitrary sources, like packaged249// files or some other source. Data read from callbacks are processed250// through a small internal buffer (currently 128 bytes) to try to reduce251// overhead.252//253// The three functions you must define are "read" (reads some bytes of data),254// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).255//256// ===========================================================================257//258// SIMD support259//260// The JPEG decoder will try to automatically use SIMD kernels on x86 when261// supported by the compiler. For ARM Neon support, you must explicitly262// request it.263//264// (The old do-it-yourself SIMD API is no longer supported in the current265// code.)266//267// On x86, SSE2 will automatically be used when available based on a run-time268// test; if not, the generic C versions are used as a fall-back. On ARM targets,269// the typical path is to have separate builds for NEON and non-NEON devices270// (at least this is true for iOS and Android). Therefore, the NEON support is271// toggled by a build flag: define STBI_NEON to get NEON loops.272//273// If for some reason you do not want to use any of SIMD code, or if274// you have issues compiling it, you can disable it entirely by275// defining STBI_NO_SIMD.276//277// ===========================================================================278//279// HDR image support   (disable by defining STBI_NO_HDR)280//281// stb_image supports loading HDR images in general, and currently the Radiance282// .HDR file format specifically. You can still load any file through the existing283// interface; if you attempt to load an HDR file, it will be automatically remapped284// to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;285// both of these constants can be reconfigured through this interface:286//287//     stbi_hdr_to_ldr_gamma(2.2f);288//     stbi_hdr_to_ldr_scale(1.0f);289//290// (note, do not use _inverse_ constants; stbi_image will invert them291// appropriately).292//293// Additionally, there is a new, parallel interface for loading files as294// (linear) floats to preserve the full dynamic range:295//296//    float *data = stbi_loadf(filename, &x, &y, &n, 0);297//298// If you load LDR images through this interface, those images will299// be promoted to floating point values, run through the inverse of300// constants corresponding to the above:301//302//     stbi_ldr_to_hdr_scale(1.0f);303//     stbi_ldr_to_hdr_gamma(2.2f);304//305// Finally, given a filename (or an open file or memory block--see header306// file for details) containing image data, you can query for the "most307// appropriate" interface to use (that is, whether the image is HDR or308// not), using:309//310//     stbi_is_hdr(char *filename);311//312// ===========================================================================313//314// iPhone PNG support:315//316// We optionally support converting iPhone-formatted PNGs (which store317// premultiplied BGRA) back to RGB, even though they're internally encoded318// differently. To enable this conversion, call319// stbi_convert_iphone_png_to_rgb(1).320//321// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per322// pixel to remove any premultiplied alpha *only* if the image file explicitly323// says there's premultiplied data (currently only happens in iPhone images,324// and only if iPhone convert-to-rgb processing is on).325//326// ===========================================================================327//328// ADDITIONAL CONFIGURATION329//330//  - You can suppress implementation of any of the decoders to reduce331//    your code footprint by #defining one or more of the following332//    symbols before creating the implementation.333//334//        STBI_NO_JPEG335//        STBI_NO_PNG336//        STBI_NO_BMP337//        STBI_NO_PSD338//        STBI_NO_TGA339//        STBI_NO_GIF340//        STBI_NO_HDR341//        STBI_NO_PIC342//        STBI_NO_PNM   (.ppm and .pgm)343//344//  - You can request *only* certain decoders and suppress all other ones345//    (this will be more forward-compatible, as addition of new decoders346//    doesn't require you to disable them explicitly):347//348//        STBI_ONLY_JPEG349//        STBI_ONLY_PNG350//        STBI_ONLY_BMP351//        STBI_ONLY_PSD352//        STBI_ONLY_TGA353//        STBI_ONLY_GIF354//        STBI_ONLY_HDR355//        STBI_ONLY_PIC356//        STBI_ONLY_PNM   (.ppm and .pgm)357//358//   - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still359//     want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB360//361//  - If you define STBI_MAX_DIMENSIONS, stb_image will reject images greater362//    than that size (in either width or height) without further processing.363//    This is to let programs in the wild set an upper bound to prevent364//    denial-of-service attacks on untrusted data, as one could generate a365//    valid image of gigantic dimensions and force stb_image to allocate a366//    huge block of memory and spend disproportionate time decoding it. By367//    default this is set to (1 << 24), which is 16777216, but that's still368//    very big.369 370#ifndef STBI_NO_STDIO371#include <stdio.h>372#endif // STBI_NO_STDIO373 374#define STBI_VERSION 1375 376enum377{378   STBI_default = 0, // only used for desired_channels379 380   STBI_grey       = 1,381   STBI_grey_alpha = 2,382   STBI_rgb        = 3,383   STBI_rgb_alpha  = 4384};385 386#include <stdlib.h>387typedef unsigned char stbi_uc;388typedef unsigned short stbi_us;389 390#ifdef __cplusplus391extern "C" {392#endif393 394#ifndef STBIDEF395#ifdef STB_IMAGE_STATIC396#define STBIDEF static397#else398#define STBIDEF extern399#endif400#endif401 402//////////////////////////////////////////////////////////////////////////////403//404// PRIMARY API - works on images of any type405//406 407//408// load image by filename, open file, or memory buffer409//410 411typedef struct412{413   int      (*read)  (void *user,char *data,int size);   // fill 'data' with 'size' bytes.  return number of bytes actually read414   void     (*skip)  (void *user,int n);                 // skip the next 'n' bytes, or 'unget' the last -n bytes if negative415   int      (*eof)   (void *user);                       // returns nonzero if we are at end of file/data416} stbi_io_callbacks;417 418////////////////////////////////////419//420// 8-bits-per-channel interface421//422 423STBIDEF stbi_uc *stbi_load_from_memory   (stbi_uc           const *buffer, int len   , int *x, int *y, int *channels_in_file, int desired_channels);424STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk  , void *user, int *x, int *y, int *channels_in_file, int desired_channels);425 426#ifndef STBI_NO_STDIO427STBIDEF stbi_uc *stbi_load            (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);428STBIDEF stbi_uc *stbi_load_from_file  (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);429// for stbi_load_from_file, file pointer is left pointing immediately after image430#endif431 432#ifndef STBI_NO_GIF433STBIDEF 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);434#endif435 436#ifdef STBI_WINDOWS_UTF8437STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);438#endif439 440////////////////////////////////////441//442// 16-bits-per-channel interface443//444 445STBIDEF stbi_us *stbi_load_16_from_memory   (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);446STBIDEF 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);447 448#ifndef STBI_NO_STDIO449STBIDEF stbi_us *stbi_load_16          (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);450STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);451#endif452 453////////////////////////////////////454//455// float-per-channel interface456//457#ifndef STBI_NO_LINEAR458   STBIDEF float *stbi_loadf_from_memory     (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels);459   STBIDEF float *stbi_loadf_from_callbacks  (stbi_io_callbacks const *clbk, void *user, int *x, int *y,  int *channels_in_file, int desired_channels);460 461   #ifndef STBI_NO_STDIO462   STBIDEF float *stbi_loadf            (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);463   STBIDEF float *stbi_loadf_from_file  (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);464   #endif465#endif466 467#ifndef STBI_NO_HDR468   STBIDEF void   stbi_hdr_to_ldr_gamma(float gamma);469   STBIDEF void   stbi_hdr_to_ldr_scale(float scale);470#endif // STBI_NO_HDR471 472#ifndef STBI_NO_LINEAR473   STBIDEF void   stbi_ldr_to_hdr_gamma(float gamma);474   STBIDEF void   stbi_ldr_to_hdr_scale(float scale);475#endif // STBI_NO_LINEAR476 477// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR478STBIDEF int    stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);479STBIDEF int    stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);480#ifndef STBI_NO_STDIO481STBIDEF int      stbi_is_hdr          (char const *filename);482STBIDEF int      stbi_is_hdr_from_file(FILE *f);483#endif // STBI_NO_STDIO484 485 486// get a VERY brief reason for failure487// on most compilers (and ALL modern mainstream compilers) this is threadsafe488STBIDEF const char *stbi_failure_reason  (void);489 490// free the loaded image -- this is just free()491STBIDEF void     stbi_image_free      (void *retval_from_stbi_load);492 493// get image dimensions & components without fully decoding494STBIDEF int      stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);495STBIDEF int      stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);496STBIDEF int      stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len);497STBIDEF int      stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);498 499#ifndef STBI_NO_STDIO500STBIDEF int      stbi_info               (char const *filename,     int *x, int *y, int *comp);501STBIDEF int      stbi_info_from_file     (FILE *f,                  int *x, int *y, int *comp);502STBIDEF int      stbi_is_16_bit          (char const *filename);503STBIDEF int      stbi_is_16_bit_from_file(FILE *f);504#endif505 506 507 508// for image formats that explicitly notate that they have premultiplied alpha,509// we just return the colors as stored in the file. set this flag to force510// unpremultiplication. results are undefined if the unpremultiply overflow.511STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);512 513// indicate whether we should process iphone images back to canonical format,514// or just pass them through "as-is"515STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);516 517// flip the image vertically, so the first pixel in the output array is the bottom left518STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);519 520// as above, but only applies to images loaded on the thread that calls the function521// this function is only available if your compiler supports thread-local variables;522// calling it will fail to link if your compiler doesn't523STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply);524STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert);525STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);526 527// ZLIB client - used by PNG, available for other purposes528 529STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);530STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);531STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);532STBIDEF int   stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);533 534STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);535STBIDEF int   stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);536 537 538#ifdef __cplusplus539}540#endif541 542//543//544////   end header file   /////////////////////////////////////////////////////545#endif // STBI_INCLUDE_STB_IMAGE_H546 547#ifdef STB_IMAGE_IMPLEMENTATION548 549#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) \550  || defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \551  || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \552  || defined(STBI_ONLY_ZLIB)553   #ifndef STBI_ONLY_JPEG554   #define STBI_NO_JPEG555   #endif556   #ifndef STBI_ONLY_PNG557   #define STBI_NO_PNG558   #endif559   #ifndef STBI_ONLY_BMP560   #define STBI_NO_BMP561   #endif562   #ifndef STBI_ONLY_PSD563   #define STBI_NO_PSD564   #endif565   #ifndef STBI_ONLY_TGA566   #define STBI_NO_TGA567   #endif568   #ifndef STBI_ONLY_GIF569   #define STBI_NO_GIF570   #endif571   #ifndef STBI_ONLY_HDR572   #define STBI_NO_HDR573   #endif574   #ifndef STBI_ONLY_PIC575   #define STBI_NO_PIC576   #endif577   #ifndef STBI_ONLY_PNM578   #define STBI_NO_PNM579   #endif580#endif581 582#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB)583#define STBI_NO_ZLIB584#endif585 586 587#include <stdarg.h>588#include <stddef.h> // ptrdiff_t on osx589#include <stdlib.h>590#include <string.h>591#include <limits.h>592 593#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)594#include <math.h>  // ldexp, pow595#endif596 597#ifndef STBI_NO_STDIO598#include <stdio.h>599#endif600 601#ifndef STBI_ASSERT602#include <assert.h>603#define STBI_ASSERT(x) assert(x)604#endif605 606#ifdef __cplusplus607#define STBI_EXTERN extern "C"608#else609#define STBI_EXTERN extern610#endif611 612 613#ifndef _MSC_VER614   #ifdef __cplusplus615   #define stbi_inline inline616   #else617   #define stbi_inline618   #endif619#else620   #define stbi_inline __forceinline621#endif622 623#ifndef STBI_NO_THREAD_LOCALS624   #if defined(__cplusplus) &&  __cplusplus >= 201103L625      #define STBI_THREAD_LOCAL       thread_local626   #elif defined(__GNUC__) && __GNUC__ < 5627      #define STBI_THREAD_LOCAL       __thread628   #elif defined(_MSC_VER)629      #define STBI_THREAD_LOCAL       __declspec(thread)630   #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)631      #define STBI_THREAD_LOCAL       _Thread_local632   #endif633 634   #ifndef STBI_THREAD_LOCAL635      #if defined(__GNUC__)636        #define STBI_THREAD_LOCAL       __thread637      #endif638   #endif639#endif640 641#if defined(_MSC_VER) || defined(__SYMBIAN32__)642typedef unsigned short stbi__uint16;643typedef   signed short stbi__int16;644typedef unsigned int   stbi__uint32;645typedef   signed int   stbi__int32;646#else647#include <stdint.h>648typedef uint16_t stbi__uint16;649typedef int16_t  stbi__int16;650typedef uint32_t stbi__uint32;651typedef int32_t  stbi__int32;652#endif653 654// should produce compiler error if size is wrong655typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];656 657#ifdef _MSC_VER658#define STBI_NOTUSED(v)  (void)(v)659#else660#define STBI_NOTUSED(v)  (void)sizeof(v)661#endif662 663#ifdef _MSC_VER664#define STBI_HAS_LROTL665#endif666 667#ifdef STBI_HAS_LROTL668   #define stbi_lrot(x,y)  _lrotl(x,y)669#else670   #define stbi_lrot(x,y)  (((x) << (y)) | ((x) >> (-(y) & 31)))671#endif672 673#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED))674// ok675#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED)676// ok677#else678#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)."679#endif680 681#ifndef STBI_MALLOC682#define STBI_MALLOC(sz)           malloc(sz)683#define STBI_REALLOC(p,newsz)     realloc(p,newsz)684#define STBI_FREE(p)              free(p)685#endif686 687#ifndef STBI_REALLOC_SIZED688#define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz)689#endif690 691// x86/x64 detection692#if defined(__x86_64__) || defined(_M_X64)693#define STBI__X64_TARGET694#elif defined(__i386) || defined(_M_IX86)695#define STBI__X86_TARGET696#endif697 698#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)699// gcc doesn't support sse2 intrinsics unless you compile with -msse2,700// which in turn means it gets to use SSE2 everywhere. This is unfortunate,701// but previous attempts to provide the SSE2 functions with runtime702// detection caused numerous issues. The way architecture extensions are703// exposed in GCC/Clang is, sadly, not really suited for one-file libs.704// New behavior: if compiled with -msse2, we use SSE2 without any705// detection; if not, we don't use it at all.706#define STBI_NO_SIMD707#endif708 709#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD)710// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET711//712// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the713// Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant.714// As a result, enabling SSE2 on 32-bit MinGW is dangerous when not715// simultaneously enabling "-mstackrealign".716//717// See https://github.com/nothings/stb/issues/81 for more information.718//719// So default to no SSE2 on 32-bit MinGW. If you've read this far and added720// -mstackrealign to your build settings, feel free to #define STBI_MINGW_ENABLE_SSE2.721#define STBI_NO_SIMD722#endif723 724#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET))725#define STBI_SSE2726#include <emmintrin.h>727 728#ifdef _MSC_VER729 730#if _MSC_VER >= 1400  // not VC6731#include <intrin.h> // __cpuid732static int stbi__cpuid3(void)733{734   int info[4];735   __cpuid(info,1);736   return info[3];737}738#else739static int stbi__cpuid3(void)740{741   int res;742   __asm {743      mov  eax,1744      cpuid745      mov  res,edx746   }747   return res;748}749#endif750 751#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name752 753#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)754static int stbi__sse2_available(void)755{756   int info3 = stbi__cpuid3();757   return ((info3 >> 26) & 1) != 0;758}759#endif760 761#else // assume GCC-style if not VC++762#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))763 764#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)765static int stbi__sse2_available(void)766{767   // If we're even attempting to compile this on GCC/Clang, that means768   // -msse2 is on, which means the compiler is allowed to use SSE2769   // instructions at will, and so are we.770   return 1;771}772#endif773 774#endif775#endif776 777// ARM NEON778#if defined(STBI_NO_SIMD) && defined(STBI_NEON)779#undef STBI_NEON780#endif781 782#ifdef STBI_NEON783#include <arm_neon.h>784#ifdef _MSC_VER785#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name786#else787#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))788#endif789#endif790 791#ifndef STBI_SIMD_ALIGN792#define STBI_SIMD_ALIGN(type, name) type name793#endif794 795#ifndef STBI_MAX_DIMENSIONS796#define STBI_MAX_DIMENSIONS (1 << 24)797#endif798 799///////////////////////////////////////////////800//801//  stbi__context struct and start_xxx functions802 803// stbi__context structure is our basic context used by all images, so it804// contains all the IO context, plus some basic image information805typedef struct806{807   stbi__uint32 img_x, img_y;808   int img_n, img_out_n;809 810   stbi_io_callbacks io;811   void *io_user_data;812 813   int read_from_callbacks;814   int buflen;815   stbi_uc buffer_start[128];816   int callback_already_read;817 818   stbi_uc *img_buffer, *img_buffer_end;819   stbi_uc *img_buffer_original, *img_buffer_original_end;820} stbi__context;821 822 823static void stbi__refill_buffer(stbi__context *s);824 825// initialize a memory-decode context826static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len)827{828   s->io.read = NULL;829   s->read_from_callbacks = 0;830   s->callback_already_read = 0;831   s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer;832   s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len;833}834 835// initialize a callback-based context836static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user)837{838   s->io = *c;839   s->io_user_data = user;840   s->buflen = sizeof(s->buffer_start);841   s->read_from_callbacks = 1;842   s->callback_already_read = 0;843   s->img_buffer = s->img_buffer_original = s->buffer_start;844   stbi__refill_buffer(s);845   s->img_buffer_original_end = s->img_buffer_end;846}847 848#ifndef STBI_NO_STDIO849 850static int stbi__stdio_read(void *user, char *data, int size)851{852   return (int) fread(data,1,size,(FILE*) user);853}854 855static void stbi__stdio_skip(void *user, int n)856{857   int ch;858   fseek((FILE*) user, n, SEEK_CUR);859   ch = fgetc((FILE*) user);  /* have to read a byte to reset feof()'s flag */860   if (ch != EOF) {861      ungetc(ch, (FILE *) user);  /* push byte back onto stream if valid. */862   }863}864 865static int stbi__stdio_eof(void *user)866{867   return feof((FILE*) user) || ferror((FILE *) user);868}869 870static stbi_io_callbacks stbi__stdio_callbacks =871{872   stbi__stdio_read,873   stbi__stdio_skip,874   stbi__stdio_eof,875};876 877static void stbi__start_file(stbi__context *s, FILE *f)878{879   stbi__start_callbacks(s, &stbi__stdio_callbacks, (void *) f);880}881 882//static void stop_file(stbi__context *s) { }883 884#endif // !STBI_NO_STDIO885 886static void stbi__rewind(stbi__context *s)887{888   // conceptually rewind SHOULD rewind to the beginning of the stream,889   // but we just rewind to the beginning of the initial buffer, because890   // we only use it after doing 'test', which only ever looks at at most 92 bytes891   s->img_buffer = s->img_buffer_original;892   s->img_buffer_end = s->img_buffer_original_end;893}894 895enum896{897   STBI_ORDER_RGB,898   STBI_ORDER_BGR899};900 901typedef struct902{903   int bits_per_channel;904   int num_channels;905   int channel_order;906} stbi__result_info;907 908#ifndef STBI_NO_JPEG909static int      stbi__jpeg_test(stbi__context *s);910static void    *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);911static int      stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);912#endif913 914#ifndef STBI_NO_PNG915static int      stbi__png_test(stbi__context *s);916static void    *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);917static int      stbi__png_info(stbi__context *s, int *x, int *y, int *comp);918static int      stbi__png_is16(stbi__context *s);919#endif920 921#ifndef STBI_NO_BMP922static int      stbi__bmp_test(stbi__context *s);923static void    *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);924static int      stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp);925#endif926 927#ifndef STBI_NO_TGA928static int      stbi__tga_test(stbi__context *s);929static void    *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);930static int      stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);931#endif932 933#ifndef STBI_NO_PSD934static int      stbi__psd_test(stbi__context *s);935static void    *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc);936static int      stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);937static int      stbi__psd_is16(stbi__context *s);938#endif939 940#ifndef STBI_NO_HDR941static int      stbi__hdr_test(stbi__context *s);942static float   *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);943static int      stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp);944#endif945 946#ifndef STBI_NO_PIC947static int      stbi__pic_test(stbi__context *s);948static void    *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);949static int      stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);950#endif951 952#ifndef STBI_NO_GIF953static int      stbi__gif_test(stbi__context *s);954static void    *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);955static void    *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp);956static int      stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);957#endif958 959#ifndef STBI_NO_PNM960static int      stbi__pnm_test(stbi__context *s);961static void    *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);962static int      stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);963static int      stbi__pnm_is16(stbi__context *s);964#endif965 966static967#ifdef STBI_THREAD_LOCAL968STBI_THREAD_LOCAL969#endif970const char *stbi__g_failure_reason;971 972STBIDEF const char *stbi_failure_reason(void)973{974   return stbi__g_failure_reason;975}976 977#ifndef STBI_NO_FAILURE_STRINGS978static int stbi__err(const char *str)979{980   stbi__g_failure_reason = str;981   return 0;982}983#endif984 985static void *stbi__malloc(size_t size)986{987    return STBI_MALLOC(size);988}989 990// stb_image uses ints pervasively, including for offset calculations.991// therefore the largest decoded image size we can support with the992// current code, even on 64-bit targets, is INT_MAX. this is not a993// significant limitation for the intended use case.994//995// we do, however, need to make sure our size calculations don't996// overflow. hence a few helper functions for size calculations that997// multiply integers together, making sure that they're non-negative998// and no overflow occurs.999 1000// return 1 if the sum is valid, 0 on overflow.1001// negative terms are considered invalid.1002static int stbi__addsizes_valid(int a, int b)1003{1004   if (b < 0) return 0;1005   // now 0 <= b <= INT_MAX, hence also1006   // 0 <= INT_MAX - b <= INTMAX.1007   // And "a + b <= INT_MAX" (which might overflow) is the1008   // same as a <= INT_MAX - b (no overflow)1009   return a <= INT_MAX - b;1010}1011 1012// returns 1 if the product is valid, 0 on overflow.1013// negative factors are considered invalid.1014static int stbi__mul2sizes_valid(int a, int b)1015{1016   if (a < 0 || b < 0) return 0;1017   if (b == 0) return 1; // mul-by-0 is always safe1018   // portable way to check for no overflows in a*b1019   return a <= INT_MAX/b;1020}1021 1022#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)1023// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow1024static int stbi__mad2sizes_valid(int a, int b, int add)1025{1026   return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a*b, add);1027}1028#endif1029 1030// returns 1 if "a*b*c + add" has no negative terms/factors and doesn't overflow1031static int stbi__mad3sizes_valid(int a, int b, int c, int add)1032{1033   return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&1034      stbi__addsizes_valid(a*b*c, add);1035}1036 1037// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow1038#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)1039static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)1040{1041   return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&1042      stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add);1043}1044#endif1045 1046#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)1047// mallocs with size overflow checking1048static void *stbi__malloc_mad2(int a, int b, int add)1049{1050   if (!stbi__mad2sizes_valid(a, b, add)) return NULL;1051   return stbi__malloc(a*b + add);1052}1053#endif1054 1055static void *stbi__malloc_mad3(int a, int b, int c, int add)1056{1057   if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL;1058   return stbi__malloc(a*b*c + add);1059}1060 1061#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)1062static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)1063{1064   if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;1065   return stbi__malloc(a*b*c*d + add);1066}1067#endif1068 1069// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.1070static int stbi__addints_valid(int a, int b)1071{1072   if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow1073   if (a < 0 && b < 0) return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0.1074   return a <= INT_MAX - b;1075}1076 1077// returns 1 if the product of two ints fits in a signed short, 0 on overflow.1078static int stbi__mul2shorts_valid(int a, int b)1079{1080   if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow1081   if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid1082   if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN1083   return a >= SHRT_MIN / b;1084}1085 1086// stbi__err - error1087// stbi__errpf - error returning pointer to float1088// stbi__errpuc - error returning pointer to unsigned char1089 1090#ifdef STBI_NO_FAILURE_STRINGS1091   #define stbi__err(x,y)  01092#elif defined(STBI_FAILURE_USERMSG)1093   #define stbi__err(x,y)  stbi__err(y)1094#else1095   #define stbi__err(x,y)  stbi__err(x)1096#endif1097 1098#define stbi__errpf(x,y)   ((float *)(size_t) (stbi__err(x,y)?NULL:NULL))1099#define stbi__errpuc(x,y)  ((unsigned char *)(size_t) (stbi__err(x,y)?NULL:NULL))1100 1101STBIDEF void stbi_image_free(void *retval_from_stbi_load)1102{1103   STBI_FREE(retval_from_stbi_load);1104}1105 1106#ifndef STBI_NO_LINEAR1107static float   *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp);1108#endif1109 1110#ifndef STBI_NO_HDR1111static stbi_uc *stbi__hdr_to_ldr(float   *data, int x, int y, int comp);1112#endif1113 1114static int stbi__vertically_flip_on_load_global = 0;1115 1116STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)1117{1118   stbi__vertically_flip_on_load_global = flag_true_if_should_flip;1119}1120 1121#ifndef STBI_THREAD_LOCAL1122#define stbi__vertically_flip_on_load  stbi__vertically_flip_on_load_global1123#else1124static STBI_THREAD_LOCAL int stbi__vertically_flip_on_load_local, stbi__vertically_flip_on_load_set;1125 1126STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip)1127{1128   stbi__vertically_flip_on_load_local = flag_true_if_should_flip;1129   stbi__vertically_flip_on_load_set = 1;1130}1131 1132#define stbi__vertically_flip_on_load  (stbi__vertically_flip_on_load_set       \1133                                         ? stbi__vertically_flip_on_load_local  \1134                                         : stbi__vertically_flip_on_load_global)1135#endif // STBI_THREAD_LOCAL1136 1137static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc)1138{1139   memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields1140   ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed1141   ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order1142   ri->num_channels = 0;1143 1144   // test the formats with a very explicit header first (at least a FOURCC1145   // or distinctive magic number first)1146   #ifndef STBI_NO_PNG1147   if (stbi__png_test(s))  return stbi__png_load(s,x,y,comp,req_comp, ri);1148   #endif1149   #ifndef STBI_NO_BMP1150   if (stbi__bmp_test(s))  return stbi__bmp_load(s,x,y,comp,req_comp, ri);1151   #endif1152   #ifndef STBI_NO_GIF1153   if (stbi__gif_test(s))  return stbi__gif_load(s,x,y,comp,req_comp, ri);1154   #endif1155   #ifndef STBI_NO_PSD1156   if (stbi__psd_test(s))  return stbi__psd_load(s,x,y,comp,req_comp, ri, bpc);1157   #else1158   STBI_NOTUSED(bpc);1159   #endif1160   #ifndef STBI_NO_PIC1161   if (stbi__pic_test(s))  return stbi__pic_load(s,x,y,comp,req_comp, ri);1162   #endif1163 1164   // then the formats that can end up attempting to load with just 1 or 21165   // bytes matching expectations; these are prone to false positives, so1166   // try them later1167   #ifndef STBI_NO_JPEG1168   if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri);1169   #endif1170   #ifndef STBI_NO_PNM1171   if (stbi__pnm_test(s))  return stbi__pnm_load(s,x,y,comp,req_comp, ri);1172   #endif1173 1174   #ifndef STBI_NO_HDR1175   if (stbi__hdr_test(s)) {1176      float *hdr = stbi__hdr_load(s, x,y,comp,req_comp, ri);1177      return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp);1178   }1179   #endif1180 1181   #ifndef STBI_NO_TGA1182   // test tga last because it's a crappy test!1183   if (stbi__tga_test(s))1184      return stbi__tga_load(s,x,y,comp,req_comp, ri);1185   #endif1186 1187   return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");1188}1189 1190static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels)1191{1192   int i;1193   int img_len = w * h * channels;1194   stbi_uc *reduced;1195 1196   reduced = (stbi_uc *) stbi__malloc(img_len);1197   if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory");1198 1199   for (i = 0; i < img_len; ++i)1200      reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling

Showing the first 1,200 of 7989 lines. Download the file for the rest.