Skip to content
Myr

various warning fixes, STBI_SIMD compile error, incorrect file-pointer state for one API

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent ecff8d5 · Browse files · 2 files+61 added−38 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+61 added−38 removed

  • other:+61 added−38 removed

2 files+61 added−38 removed

modified:stb_image_write.h+4 added-2 removed
1/* stbiw-0.92 - public domain - http://nothings.org/stb/stb_image_write.h1/* stbiw-0.93 - public domain - http://nothings.org/stb/stb_image_write.h2 writes out PNG/BMP/TGA images to C stdio - Sean Barrett 20103 no warranty implied; use at your own risk45
311 unmodified lines
317 }318 }319320 if (bestloc) {321 int d = data+i - bestloc; // distance back321 int d = (int) (data+i - bestloc); // distance back322 assert(d <= 32767 && best <= 258);323 for (j=0; best > lengthc[j+1]-1; ++j);324 stbi__zlib_huff(j+257);325 if (lengtheb[j]) stbi__zlib_add(best - lengthc[j], lengtheb[j]);
176 unmodified lines
502#endif // STB_IMAGE_WRITE_IMPLEMENTATION503504/* Revision history505506 0.93 (2014-05-27)507 warning fixes508 0.92 (2010-08-01)509 casts to unsigned char to fix warnings510 0.91 (2010-07-17)511 first public release
2 unmodified lines
modified:stb_image.c+57 added-36 removed
1/* stbi-1.33 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c1/* stbi-1.35 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c2 when you control the images you're loading3 no warranty implied; use at your own risk45 QUICK NOTES:
15 unmodified lines
21 - decode from arbitrary I/O callbacks22 - overridable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD)2324 Latest revisions:25 1.35 (2014-05-27) warnings, bugfixes, etc26 1.34 (unknown ) warning fix27 1.33 (2011-07-14) minor fixes suggested by Dave Moore28 1.32 (2011-07-13) info support for all filetypes (SpartanJ)29 1.31 (2011-06-19) a few more leak fixes, bug in PNG handling (SpartanJ)30 1.30 (2011-06-11) added ability to load files via io callbacks (Ben Wenger)31 1.29 (2010-08-16) various warning fixes from Aurelien Pocheville 32 1.28 (2010-08-01) fix bug in GIF palette transparency (SpartanJ)32 1.27 (2010-08-01) cast-to-stbi__uint8 to fix warnings (Laurent Gomila)33 allow trailing 0s at end of image data (Laurent Gomila)34 1.26 (2010-07-24) fix bug in file buffering for PNG reported by SpartanJ3334 See end of file for full revision history.3536 TODO:
1 unmodified line
383940 ============================ Contributors =========================41 44 Image formats Optimizations & bugfixes45 Sean Barrett (jpeg, png, bmp) Fabian "ryg" Giesen46 Nicolas Schulz (hdr, psd) 47 Jonathan Dummer (tga) Bug fixes & warning fixes 48 Jean-Marc Lienher (gif) Marc LeBlanc 49 Tom Seddon (pic) Christpher Lloyd 50 Thatcher Ulrich (psd) Dave Moore 51 Won Chun 52 the Horde3D community 53 Extensions, features Janez Zemva 54 Jetro Lauha (stbi_info) Jonathan Blow 55 James "moose2000" Brown (iPhone PNG) Laurent Gomila 56 Ben "Disch" Wenger (io callbacks) Aruelien Pocheville57 Martin "SpartanJ" Golini Ryamond Barbiero58 David Woo42 Image formats Bug fixes & warning fixes43 Sean Barrett (jpeg, png, bmp) Marc LeBlanc44 Nicolas Schulz (hdr, psd) Christpher Lloyd45 Jonathan Dummer (tga) Dave Moore46 Jean-Marc Lienher (gif) Won Chun47 Tom Seddon (pic) the Horde3D community48 Thatcher Ulrich (psd) Janez Zemva49 Jonathan Blow50 Laurent Gomila51 Extensions, features Aruelien Pocheville52 Jetro Lauha (stbi_info) Ryamond Barbiero53 James "moose2000" Brown (iPhone PNG) David Woo54 Ben "Disch" Wenger (io callbacks) Roy Eltham55 Martin "SpartanJ" Golini Luke Graham56 Thomas Ruf57 John Bartholomew58 Optimizations & bugfixes Ken Hamada59 Fabian "ryg" Giesen Cort Stratton606061 62 If your name should be here but isn't, let Sean know.6364*/65
121 unmodified lines
187188189#ifndef STBI_NO_STDIO190190#if defined(_MSC_VER) && _MSC_VER >= 0x1400191#define _CRT_SECURE_NO_WARNINGS // suppress bogus warnings about fopen()191#if defined(_MSC_VER) && _MSC_VER >= 1400192#define _CRT_SECURE_NO_WARNINGS // suppress warnings about fopen()193#pragma warning(push)194#pragma warning(disable:4996) // suppress even more warnings about fopen()195#endif193196#include <stdio.h>195#endif197#endif // STBI_NO_STDIO198199#define STBI_VERSION 1200201enum
31 unmodified lines
233234typedef struct235{236 int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read 235 void (*skip) (void *user,unsigned n); // skip the next 'n' bytes237 void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative238 int (*eof) (void *user); // returns nonzero if we are at end of file/data239} stbi_io_callbacks;240241extern stbi_uc *stbi_load_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
55 unmodified lines
297298// ZLIB client - used by PNG, available for other purposes299300extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);301extern char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);302extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);303extern int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);304305extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
64 unmodified lines
370371// should produce compiler error if size is wrong372typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];373371#if defined(STBI_NO_STDIO) && !defined(STBI_NO_WRITE)372#define STBI_NO_WRITE374#ifdef _MSC_VER375#define STBI_NOTUSED(v) (void)(v)376#else377#define STBI_NOTUSED(v) (void)sizeof(v)378#endif379375#define STBI_NOTUSED(v) (void)sizeof(v)376380#ifdef _MSC_VER381#define STBI_HAS_LROTL382#endif383
54 unmodified lines
438{439 return (int) fread(data,1,size,(FILE*) user);440}441439static void stdio_skip(void *user, unsigned n)442static void stdio_skip(void *user, int n)443{444 fseek((FILE*) user, n, SEEK_CUR);445}446
38 unmodified lines
485static stbi_uc *stbi_tga_load(stbi *s, int *x, int *y, int *comp, int req_comp);486static int stbi_tga_info(stbi *s, int *x, int *y, int *comp);487static int stbi_psd_test(stbi *s);488static stbi_uc *stbi_psd_load(stbi *s, int *x, int *y, int *comp, int req_comp);489#ifndef STBI_NO_HDR490static int stbi_hdr_test(stbi *s);491static float *stbi_hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp);492#endif493static int stbi_pic_test(stbi *s);494static stbi_uc *stbi_pic_load(stbi *s, int *x, int *y, int *comp, int req_comp);495static int stbi_gif_test(stbi *s);496static stbi_uc *stbi_gif_load(stbi *s, int *x, int *y, int *comp, int req_comp);
73 unmodified lines
570}571572unsigned char *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)573{574 unsigned char *result;575 stbi s;576 start_file(&s,f);571 return stbi_load_main(&s,x,y,comp,req_comp);577 result = stbi_load_main(&s,x,y,comp,req_comp);578 if (result) {579 // need to 'unget' all the characters in the IO buffer580 fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);581 }582 return result;583}584#endif //!STBI_NO_STDIO585586unsigned char *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
139 unmodified lines
726static void refill_buffer(stbi *s)727{728 int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen);729 if (n == 0) {719 // at end of file, treat same as if from memory730 // at end of file, treat same as if from memory, but need731 // to handle case where s->img_buffer isn't pointing to safe memory732 s->read_from_callbacks = 0;721 s->img_buffer = s->img_buffer_end-1;733 s->img_buffer = s->buffer_start;734 s->img_buffer_end = s->buffer_start+1;735 *s->img_buffer = 0;736 } else {737 s->img_buffer = s->buffer_start;738 s->img_buffer_end = s->buffer_start + n;
30 unmodified lines
769770static void skip(stbi *s, int n)771{772 if (s->io.read) {760 int blen = s->img_buffer_end - s->img_buffer;773 int blen = (int) (s->img_buffer_end - s->img_buffer);774 if (blen < n) {775 s->img_buffer = s->img_buffer_end;776 (s->io.skip)(s->io_user_data, n - blen);777 return;
4 unmodified lines
782783static int getn(stbi *s, stbi_uc *buffer, int n)784{785 if (s->io.read) {773 int blen = s->img_buffer_end - s->img_buffer;786 int blen = (int) (s->img_buffer_end - s->img_buffer);787 if (blen < n) {788 int res, count;789790 memcpy(buffer, s->img_buffer, blen);
1100 unmodified lines
1891 if (n >= 3) {1892 stbi__uint8 *y = coutput[0];1893 if (z->s->img_n == 3) {1894 #ifdef STBI_SIMD1882 stbi_YCbCr_installed(out, y, coutput[1], coutput[2], z->s.img_x, n);1895 stbi_YCbCr_installed(out, y, coutput[1], coutput[2], z->s->img_x, n);1896 #else1897 YCbCr_to_RGB_row(out, y, coutput[1], coutput[2], z->s->img_x, n);1898 #endif1899 } else
2700 unmodified lines
4600}46014602#endif // STBI_HEADER_FILE_ONLY46034604#if !defined(STBI_NO_STDIO) && defined(_MSC_VER) && _MSC_VER >= 14004605#pragma warning(pop)4606#endif460746084609/*4610 revision history:4611 1.35 (2014-05-27)4612 various warnings4613 fix broken STBI_SIMD path4614 fix bug where stbi_load_from_file no longer left file pointer in correct place4615 1.34 (unknown)4616 use STBI_NOTUSED in resample_row_generic(), fix one more leak in tga failure case4617 1.33 (2011-07-14)4618 make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements
82 unmodified lines