gosu 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 329642b7e24e9c77f4c02b58102ff2ffe748a8a7f86ef7616134e4b77f58b298
4
- data.tar.gz: 0bc9d762ab3f10c2e42f743c3f20994f5678392559eddf68dd618f422f5d6c07
3
+ metadata.gz: 11cad0cf3c250ded2f28767de4b16a3813fe9344ab7ae4fced8fc175c84f1a45
4
+ data.tar.gz: 1ed49eebd7f989d77af063d9ba72a39623f61ce2ef0ad650c670cbe41ebe2c77
5
5
  SHA512:
6
- metadata.gz: a19bbb4cc5ad36ae91e7c4d941945e74e4dad1311509ae8d06e002f9a09c6b5ec5b9c4e4e1ad3700c61b6b7d3b251677835abd2b3c88770153259f7b5043f672
7
- data.tar.gz: 2cc60ca886da56558f6347bc7f9e4d1c341e800c3e5a2d8599709cdd6aaa5198715b52a502d65f91285cc25f3ebc16194fe37c4ac31076905375c86bea5b47ac
6
+ metadata.gz: 70dc3a30a7bda5cb80f3ec61f51869ee764e18a96f0403ce592b10b8c66124b7d190ca5585c8fa8ad530adafe723d901775c0e45995d18b5f91f431b213fc43a
7
+ data.tar.gz: 04c99a303c628114457eba9b4f3f770a3ca9278862b86ea15bd3f0fa30dad3cd3155f054ee98e95d2c844efd2869b0ef29bda63553061ca167caa10631723947
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2001-2017 Julian Raschke, Jan Lücker and all contributors.
1
+ Copyright (C) 2001-2018 Julian Raschke, Jan Lücker and all contributors.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a
4
4
  copy of this software and associated documentation files (the "Software"),
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 0
6
6
  #define GOSU_MINOR_VERSION 13
7
- #define GOSU_POINT_VERSION 2
7
+ #define GOSU_POINT_VERSION 3
8
8
 
9
9
  namespace Gosu
10
10
  {
data/README.md CHANGED
@@ -19,9 +19,9 @@ Community
19
19
  ---------
20
20
 
21
21
  - Visit our [message board](https://www.libgosu.org/cgi-bin/mwf/forum.pl) or the [r/gosu subreddit](https://reddit.com/r/gosu).
22
- - There’s also an IRC room, [#gosu on freenode](https://webchat.freenode.net/?channels=gosu). The regulars are spread across many timezones, so you’ll need some patience.
23
- - You can file bugs and feature requests as [issues on GitHub](https://github.com/gosu/gosu/issues).
24
- - Or [simply email me](mailto:julian@raschke.de) :)
22
+ - There’s also an IRC room, [#gosu on freenode](https://webchat.freenode.net/?channels=gosu).
23
+ The regulars are spread across many timezones, so you’ll need some patience.
24
+ - Please file bugs and request features [on GitHub](https://github.com/gosu/gosu/issues).
25
25
 
26
26
  Build Status
27
27
  ------------
@@ -11656,7 +11656,7 @@ SWIGEXPORT void Init_gosu(void) {
11656
11656
  rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
11657
11657
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11658
11658
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(13)));
11659
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(2)));
11659
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(3)));
11660
11660
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11661
11661
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11662
11662
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -1,5 +1,5 @@
1
- /* stb_image - v2.16 - public domain image loader - http://nothings.org/stb_image.h
2
- no warranty implied; use at your own risk
1
+ /* stb_image - v2.18 - public domain image loader - http://nothings.org/stb
2
+ no warranty implied; use at your own risk
3
3
 
4
4
  Do this:
5
5
  #define STB_IMAGE_IMPLEMENTATION
@@ -48,6 +48,8 @@ LICENSE
48
48
 
49
49
  RECENT REVISION HISTORY:
50
50
 
51
+ 2.18 (2018-01-30) fix warnings
52
+ 2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
51
53
  2.16 (2017-07-23) all functions have 16-bit variants; optimizations; bugfixes
52
54
  2.15 (2017-03-18) fix png-1,2,4; all Imagenet JPGs; no runtime SSE detection on GCC
53
55
  2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs
@@ -74,11 +76,11 @@ RECENT REVISION HISTORY:
74
76
  Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip)
75
77
  Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD)
76
78
  github:urraka (animated gif) Junggon Kim (PNM comments)
77
- Daniel Gibson (16-bit TGA)
79
+ Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA)
78
80
  socks-the-fox (16-bit PNG)
79
81
  Jeremy Sawicki (handle all ImageNet JPGs)
80
- Optimizations & bugfixes
81
- Fabian "ryg" Giesen
82
+ Optimizations & bugfixes Mikhail Morozov (1-bit BMP)
83
+ Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
82
84
  Arseny Kapoulkine
83
85
  John-Mark Allen
84
86
 
@@ -87,16 +89,17 @@ RECENT REVISION HISTORY:
87
89
  Christpher Lloyd Jerry Jansson Joseph Thomson Phil Jordan
88
90
  Dave Moore Roy Eltham Hayaki Saito Nathan Reed
89
91
  Won Chun Luke Graham Johan Duparc Nick Verigakis
90
- the Horde3D community Thomas Ruf Ronny Chevalier Baldur Karlsson
91
- Janez Zemva John Bartholomew Michal Cichon github:rlyeh
92
- Jonathan Blow Ken Hamada Tero Hanninen github:romigrou
93
- Laurent Gomila Cort Stratton Sergio Gonzalez github:svdijk
94
- Aruelien Pocheville Thibault Reuille Cass Everitt github:snagar
95
- Ryamond Barbiero Paul Du Bois Engin Manap github:Zelex
96
- Michaelangel007@github Philipp Wiesemann Dale Weiler github:grim210
97
- Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:sammyhw
98
- Blazej Dariusz Roszkowski Gregory Mullen github:phprus
99
- Christian Floisand Kevin Schmidt github:poppolopoppo
92
+ the Horde3D community Thomas Ruf Ronny Chevalier github:rlyeh
93
+ Janez Zemva John Bartholomew Michal Cichon github:romigrou
94
+ Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
95
+ Laurent Gomila Cort Stratton Sergio Gonzalez github:snagar
96
+ Aruelien Pocheville Thibault Reuille Cass Everitt github:Zelex
97
+ Ryamond Barbiero Paul Du Bois Engin Manap github:grim210
98
+ Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
99
+ Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
100
+ Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo
101
+ Christian Floisand Kevin Schmidt github:darealshinji
102
+ Blazej Dariusz Roszkowski github:Michaelangel007
100
103
  */
101
104
 
102
105
  #ifndef STBI_INCLUDE_STB_IMAGE_H
@@ -105,10 +108,8 @@ RECENT REVISION HISTORY:
105
108
  // DOCUMENTATION
106
109
  //
107
110
  // Limitations:
108
- // - no 16-bit-per-channel PNG
109
111
  // - no 12-bit-per-channel JPEG
110
112
  // - no JPEGs with arithmetic coding
111
- // - no 1-bit BMP
112
113
  // - GIF always returns *comp=4
113
114
  //
114
115
  // Basic usage (see HDR discussion below for HDR usage):
@@ -353,6 +354,10 @@ typedef struct
353
354
 
354
355
  STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
355
356
  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);
357
+ #ifndef STBI_NO_GIF
358
+ 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);
359
+ #endif
360
+
356
361
 
357
362
  #ifndef STBI_NO_STDIO
358
363
  STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
@@ -416,11 +421,14 @@ STBIDEF void stbi_image_free (void *retval_from_stbi_load);
416
421
  // get image dimensions & components without fully decoding
417
422
  STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
418
423
  STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
424
+ STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len);
425
+ STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);
419
426
 
420
427
  #ifndef STBI_NO_STDIO
421
- STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
422
- STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
423
-
428
+ STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
429
+ STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
430
+ STBIDEF int stbi_is_16_bit (char const *filename);
431
+ STBIDEF int stbi_is_16_bit_from_file(FILE *f);
424
432
  #endif
425
433
 
426
434
 
@@ -504,7 +512,7 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
504
512
  #include <limits.h>
505
513
 
506
514
  #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
507
- #include <math.h> // ldexp
515
+ #include <math.h> // ldexp, pow
508
516
  #endif
509
517
 
510
518
  #ifndef STBI_NO_STDIO
@@ -784,6 +792,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
784
792
  static int stbi__png_test(stbi__context *s);
785
793
  static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
786
794
  static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
795
+ static int stbi__png_is16(stbi__context *s);
787
796
  #endif
788
797
 
789
798
  #ifndef STBI_NO_BMP
@@ -802,6 +811,7 @@ static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
802
811
  static int stbi__psd_test(stbi__context *s);
803
812
  static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc);
804
813
  static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
814
+ static int stbi__psd_is16(stbi__context *s);
805
815
  #endif
806
816
 
807
817
  #ifndef STBI_NO_HDR
@@ -819,6 +829,7 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);
819
829
  #ifndef STBI_NO_GIF
820
830
  static int stbi__gif_test(stbi__context *s);
821
831
  static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
832
+ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
822
833
  static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
823
834
  #endif
824
835
 
@@ -893,11 +904,13 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add)
893
904
  }
894
905
 
895
906
  // returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
907
+ #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
896
908
  static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
897
909
  {
898
910
  return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
899
911
  stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add);
900
912
  }
913
+ #endif
901
914
 
902
915
  // mallocs with size overflow checking
903
916
  static void *stbi__malloc_mad2(int a, int b, int add)
@@ -912,11 +925,13 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add)
912
925
  return stbi__malloc(a*b*c + add);
913
926
  }
914
927
 
928
+ #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
915
929
  static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
916
930
  {
917
931
  if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
918
932
  return stbi__malloc(a*b*c*d + add);
919
933
  }
934
+ #endif
920
935
 
921
936
  // stbi__err - error
922
937
  // stbi__errpf - error returning pointer to float
@@ -1054,6 +1069,18 @@ static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel)
1054
1069
  }
1055
1070
  }
1056
1071
 
1072
+ static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
1073
+ {
1074
+ int slice;
1075
+ int slice_size = w * h * bytes_per_pixel;
1076
+
1077
+ stbi_uc *bytes = (stbi_uc *)image;
1078
+ for (slice = 0; slice < z; ++slice) {
1079
+ stbi__vertical_flip(bytes, w, h, bytes_per_pixel);
1080
+ bytes += slice_size;
1081
+ }
1082
+ }
1083
+
1057
1084
  static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
1058
1085
  {
1059
1086
  stbi__result_info ri;
@@ -1103,7 +1130,7 @@ static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x,
1103
1130
  return (stbi__uint16 *) result;
1104
1131
  }
1105
1132
 
1106
- #if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR)
1133
+ #if !defined(STBI_NO_HDR) || !defined(STBI_NO_LINEAR)
1107
1134
  static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
1108
1135
  {
1109
1136
  if (stbi__vertically_flip_on_load && result != NULL) {
@@ -1205,6 +1232,22 @@ STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *u
1205
1232
  return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp);
1206
1233
  }
1207
1234
 
1235
+ #ifndef STBI_NO_GIF
1236
+ 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)
1237
+ {
1238
+ unsigned char *result;
1239
+ stbi__context s;
1240
+ stbi__start_mem(&s,buffer,len);
1241
+
1242
+ result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp);
1243
+ if (stbi__vertically_flip_on_load) {
1244
+ stbi__vertical_flip_slices( result, *x, *y, *z, *comp );
1245
+ }
1246
+
1247
+ return result;
1248
+ }
1249
+ #endif
1250
+
1208
1251
  #ifndef STBI_NO_LINEAR
1209
1252
  static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)
1210
1253
  {
@@ -1288,12 +1331,16 @@ STBIDEF int stbi_is_hdr (char const *filename)
1288
1331
  return result;
1289
1332
  }
1290
1333
 
1291
- STBIDEF int stbi_is_hdr_from_file(FILE *f)
1334
+ STBIDEF int stbi_is_hdr_from_file(FILE *f)
1292
1335
  {
1293
1336
  #ifndef STBI_NO_HDR
1337
+ long pos = ftell(f);
1338
+ int res;
1294
1339
  stbi__context s;
1295
1340
  stbi__start_file(&s,f);
1296
- return stbi__hdr_test(&s);
1341
+ res = stbi__hdr_test(&s);
1342
+ fseek(f, pos, SEEK_SET);
1343
+ return res;
1297
1344
  #else
1298
1345
  STBI_NOTUSED(f);
1299
1346
  return 0;
@@ -1705,7 +1752,8 @@ typedef struct
1705
1752
 
1706
1753
  static int stbi__build_huffman(stbi__huffman *h, int *count)
1707
1754
  {
1708
- int i,j,k=0,code;
1755
+ int i,j,k=0;
1756
+ unsigned int code;
1709
1757
  // build size list for each symbol (from JPEG spec)
1710
1758
  for (i=0; i < 16; ++i)
1711
1759
  for (j=0; j < count[i]; ++j)
@@ -1721,7 +1769,7 @@ static int stbi__build_huffman(stbi__huffman *h, int *count)
1721
1769
  if (h->size[k] == j) {
1722
1770
  while (h->size[k] == j)
1723
1771
  h->code[k++] = (stbi__uint16) (code++);
1724
- if (code-1 >= (1 << j)) return stbi__err("bad code lengths","Corrupt JPEG");
1772
+ if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG");
1725
1773
  }
1726
1774
  // compute largest code + 1 for this size, preshifted as needed later
1727
1775
  h->maxcode[j] = code << (16-j);
@@ -1765,7 +1813,7 @@ static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h)
1765
1813
  if (k < m) k += (~0U << magbits) + 1;
1766
1814
  // if the result is small enough, we can fit it in fast_ac table
1767
1815
  if (k >= -128 && k <= 127)
1768
- fast_ac[i] = (stbi__int16) ((k << 8) + (run << 4) + (len + magbits));
1816
+ fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits));
1769
1817
  }
1770
1818
  }
1771
1819
  }
@@ -1774,7 +1822,7 @@ static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h)
1774
1822
  static void stbi__grow_buffer_unsafe(stbi__jpeg *j)
1775
1823
  {
1776
1824
  do {
1777
- int b = j->nomore ? 0 : stbi__get8(j->s);
1825
+ unsigned int b = j->nomore ? 0 : stbi__get8(j->s);
1778
1826
  if (b == 0xff) {
1779
1827
  int c = stbi__get8(j->s);
1780
1828
  while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes
@@ -1790,7 +1838,7 @@ static void stbi__grow_buffer_unsafe(stbi__jpeg *j)
1790
1838
  }
1791
1839
 
1792
1840
  // (1 << n) - 1
1793
- static stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535};
1841
+ static const stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535};
1794
1842
 
1795
1843
  // decode a jpeg huffman value from the bitstream
1796
1844
  stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h)
@@ -1843,7 +1891,7 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h)
1843
1891
  }
1844
1892
 
1845
1893
  // bias[n] = (-1<<n) + 1
1846
- static int const stbi__jbias[16] = {0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767};
1894
+ static const int stbi__jbias[16] = {0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767};
1847
1895
 
1848
1896
  // combined JPEG 'receive' and JPEG 'extend', since baseline
1849
1897
  // always extends everything it receives.
@@ -1886,7 +1934,7 @@ stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j)
1886
1934
 
1887
1935
  // given a value that's at position X in the zigzag stream,
1888
1936
  // where does it appear in the 8x8 matrix coded as row-major?
1889
- static stbi_uc stbi__jpeg_dezigzag[64+15] =
1937
+ static const stbi_uc stbi__jpeg_dezigzag[64+15] =
1890
1938
  {
1891
1939
  0, 1, 8, 16, 9, 2, 3, 10,
1892
1940
  17, 24, 32, 25, 18, 11, 4, 5,
@@ -2112,7 +2160,7 @@ stbi_inline static stbi_uc stbi__clamp(int x)
2112
2160
  }
2113
2161
 
2114
2162
  #define stbi__f2f(x) ((int) (((x) * 4096 + 0.5)))
2115
- #define stbi__fsh(x) ((x) << 12)
2163
+ #define stbi__fsh(x) ((x) * 4096)
2116
2164
 
2117
2165
  // derived from jidctint -- DCT_ISLOW
2118
2166
  #define STBI__IDCT_1D(s0,s1,s2,s3,s4,s5,s6,s7) \
@@ -2167,7 +2215,7 @@ static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64])
2167
2215
  // (1|2|3|4|5|6|7)==0 0 seconds
2168
2216
  // all separate -0.047 seconds
2169
2217
  // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds
2170
- int dcterm = d[0] << 2;
2218
+ int dcterm = d[0]*4;
2171
2219
  v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm;
2172
2220
  } else {
2173
2221
  STBI__IDCT_1D(d[ 0],d[ 8],d[16],d[24],d[32],d[40],d[48],d[56])
@@ -2968,7 +3016,7 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan)
2968
3016
 
2969
3017
  z->rgb = 0;
2970
3018
  for (i=0; i < s->img_n; ++i) {
2971
- static unsigned char rgb[3] = { 'R', 'G', 'B' };
3019
+ static const unsigned char rgb[3] = { 'R', 'G', 'B' };
2972
3020
  z->img_comp[i].id = stbi__get8(s);
2973
3021
  if (s->img_n == 3 && z->img_comp[i].id == rgb[i])
2974
3022
  ++z->rgb;
@@ -3093,8 +3141,8 @@ static int stbi__decode_jpeg_image(stbi__jpeg *j)
3093
3141
  } else if (stbi__DNL(m)) {
3094
3142
  int Ld = stbi__get16be(j->s);
3095
3143
  stbi__uint32 NL = stbi__get16be(j->s);
3096
- if (Ld != 4) stbi__err("bad DNL len", "Corrupt JPEG");
3097
- if (NL != j->s->img_y) stbi__err("bad DNL height", "Corrupt JPEG");
3144
+ if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG");
3145
+ if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
3098
3146
  } else {
3099
3147
  if (!stbi__process_marker(j, m)) return 0;
3100
3148
  }
@@ -3912,18 +3960,18 @@ static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room
3912
3960
  return 1;
3913
3961
  }
3914
3962
 
3915
- static int stbi__zlength_base[31] = {
3963
+ static const int stbi__zlength_base[31] = {
3916
3964
  3,4,5,6,7,8,9,10,11,13,
3917
3965
  15,17,19,23,27,31,35,43,51,59,
3918
3966
  67,83,99,115,131,163,195,227,258,0,0 };
3919
3967
 
3920
- static int stbi__zlength_extra[31]=
3968
+ static const int stbi__zlength_extra[31]=
3921
3969
  { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
3922
3970
 
3923
- static int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
3971
+ static const int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
3924
3972
  257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
3925
3973
 
3926
- static int stbi__zdist_extra[32] =
3974
+ static const int stbi__zdist_extra[32] =
3927
3975
  { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
3928
3976
 
3929
3977
  static int stbi__parse_huffman_block(stbi__zbuf *a)
@@ -3970,7 +4018,7 @@ static int stbi__parse_huffman_block(stbi__zbuf *a)
3970
4018
 
3971
4019
  static int stbi__compute_huffman_codes(stbi__zbuf *a)
3972
4020
  {
3973
- static stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
4021
+ static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
3974
4022
  stbi__zhuffman z_codelength;
3975
4023
  stbi_uc lencodes[286+32+137];//padding for maximum single op
3976
4024
  stbi_uc codelength_sizes[19];
@@ -4229,7 +4277,7 @@ static stbi__pngchunk stbi__get_chunk_header(stbi__context *s)
4229
4277
 
4230
4278
  static int stbi__check_png_header(stbi__context *s)
4231
4279
  {
4232
- static stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 };
4280
+ static const stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 };
4233
4281
  int i;
4234
4282
  for (i=0; i < 8; ++i)
4235
4283
  if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG");
@@ -4275,7 +4323,7 @@ static int stbi__paeth(int a, int b, int c)
4275
4323
  return c;
4276
4324
  }
4277
4325
 
4278
- static stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 };
4326
+ static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 };
4279
4327
 
4280
4328
  // create the png data from post-deflated data
4281
4329
  static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color)
@@ -4295,8 +4343,10 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r
4295
4343
  a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into
4296
4344
  if (!a->out) return stbi__err("outofmem", "Out of memory");
4297
4345
 
4346
+ if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG");
4298
4347
  img_width_bytes = (((img_n * x * depth) + 7) >> 3);
4299
4348
  img_len = (img_width_bytes + 1) * y;
4349
+
4300
4350
  // we used to check for exact match between raw_len and img_len on non-interlaced PNGs,
4301
4351
  // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros),
4302
4352
  // so just check for raw_len < img_len always.
@@ -4675,7 +4725,7 @@ static void stbi__de_iphone(stbi__png *z)
4675
4725
  }
4676
4726
  }
4677
4727
 
4678
- #define STBI__PNG_TYPE(a,b,c,d) (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
4728
+ #define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d))
4679
4729
 
4680
4730
  static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
4681
4731
  {
@@ -4912,6 +4962,19 @@ static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp)
4912
4962
  p.s = s;
4913
4963
  return stbi__png_info_raw(&p, x, y, comp);
4914
4964
  }
4965
+
4966
+ static int stbi__png_is16(stbi__context *s)
4967
+ {
4968
+ stbi__png p;
4969
+ p.s = s;
4970
+ if (!stbi__png_info_raw(&p, NULL, NULL, NULL))
4971
+ return 0;
4972
+ if (p.depth != 16) {
4973
+ stbi__rewind(p.s);
4974
+ return 0;
4975
+ }
4976
+ return 1;
4977
+ }
4915
4978
  #endif
4916
4979
 
4917
4980
  // Microsoft/Windows BMP image
@@ -4963,24 +5026,27 @@ static int stbi__bitcount(unsigned int a)
4963
5026
  return a & 0xff;
4964
5027
  }
4965
5028
 
5029
+ // extract an arbitrarily-aligned N-bit value (N=bits)
5030
+ // from v, and then make it 8-bits long and fractionally
5031
+ // extend it to full full range.
4966
5032
  static int stbi__shiftsigned(int v, int shift, int bits)
4967
5033
  {
4968
- static unsigned int mul_table[9] = {
4969
- 0,
4970
- 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/,
4971
- 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/,
4972
- };
4973
- static unsigned int shift_table[9] = {
4974
- 0, 0,0,1,0,2,4,6,0,
4975
- };
4976
- if (shift < 0)
4977
- v <<= -shift;
4978
- else
4979
- v >>= shift;
4980
- assert(v >= 0 && v < 256);
4981
- v >>= (8-bits);
4982
- assert(bits >= 0 && bits <= 8);
4983
- return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits];
5034
+ static unsigned int mul_table[9] = {
5035
+ 0,
5036
+ 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/,
5037
+ 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/,
5038
+ };
5039
+ static unsigned int shift_table[9] = {
5040
+ 0, 0,0,1,0,2,4,6,0,
5041
+ };
5042
+ if (shift < 0)
5043
+ v <<= -shift;
5044
+ else
5045
+ v >>= shift;
5046
+ STBI_ASSERT(v >= 0 && v < 256);
5047
+ v >>= (8-bits);
5048
+ STBI_ASSERT(bits >= 0 && bits <= 8);
5049
+ return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits];
4984
5050
  }
4985
5051
 
4986
5052
  typedef struct
@@ -5010,7 +5076,6 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
5010
5076
  }
5011
5077
  if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
5012
5078
  info->bpp = stbi__get16le(s);
5013
- if (info->bpp == 1) return stbi__errpuc("monochrome", "BMP type not supported: 1-bit");
5014
5079
  if (hsz != 12) {
5015
5080
  int compress = stbi__get32le(s);
5016
5081
  if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
@@ -5128,29 +5193,47 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
5128
5193
  pal[i][3] = 255;
5129
5194
  }
5130
5195
  stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4));
5131
- if (info.bpp == 4) width = (s->img_x + 1) >> 1;
5196
+ if (info.bpp == 1) width = (s->img_x + 7) >> 3;
5197
+ else if (info.bpp == 4) width = (s->img_x + 1) >> 1;
5132
5198
  else if (info.bpp == 8) width = s->img_x;
5133
5199
  else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); }
5134
5200
  pad = (-width)&3;
5135
- for (j=0; j < (int) s->img_y; ++j) {
5136
- for (i=0; i < (int) s->img_x; i += 2) {
5137
- int v=stbi__get8(s),v2=0;
5138
- if (info.bpp == 4) {
5139
- v2 = v & 15;
5140
- v >>= 4;
5201
+ if (info.bpp == 1) {
5202
+ for (j=0; j < (int) s->img_y; ++j) {
5203
+ int bit_offset = 7, v = stbi__get8(s);
5204
+ for (i=0; i < (int) s->img_x; ++i) {
5205
+ int color = (v>>bit_offset)&0x1;
5206
+ out[z++] = pal[color][0];
5207
+ out[z++] = pal[color][1];
5208
+ out[z++] = pal[color][2];
5209
+ if((--bit_offset) < 0) {
5210
+ bit_offset = 7;
5211
+ v = stbi__get8(s);
5212
+ }
5141
5213
  }
5142
- out[z++] = pal[v][0];
5143
- out[z++] = pal[v][1];
5144
- out[z++] = pal[v][2];
5145
- if (target == 4) out[z++] = 255;
5146
- if (i+1 == (int) s->img_x) break;
5147
- v = (info.bpp == 8) ? stbi__get8(s) : v2;
5148
- out[z++] = pal[v][0];
5149
- out[z++] = pal[v][1];
5150
- out[z++] = pal[v][2];
5151
- if (target == 4) out[z++] = 255;
5214
+ stbi__skip(s, pad);
5215
+ }
5216
+ } else {
5217
+ for (j=0; j < (int) s->img_y; ++j) {
5218
+ for (i=0; i < (int) s->img_x; i += 2) {
5219
+ int v=stbi__get8(s),v2=0;
5220
+ if (info.bpp == 4) {
5221
+ v2 = v & 15;
5222
+ v >>= 4;
5223
+ }
5224
+ out[z++] = pal[v][0];
5225
+ out[z++] = pal[v][1];
5226
+ out[z++] = pal[v][2];
5227
+ if (target == 4) out[z++] = 255;
5228
+ if (i+1 == (int) s->img_x) break;
5229
+ v = (info.bpp == 8) ? stbi__get8(s) : v2;
5230
+ out[z++] = pal[v][0];
5231
+ out[z++] = pal[v][1];
5232
+ out[z++] = pal[v][2];
5233
+ if (target == 4) out[z++] = 255;
5234
+ }
5235
+ stbi__skip(s, pad);
5152
5236
  }
5153
- stbi__skip(s, pad);
5154
5237
  }
5155
5238
  } else {
5156
5239
  int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0;
@@ -5191,7 +5274,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
5191
5274
  int bpp = info.bpp;
5192
5275
  for (i=0; i < (int) s->img_x; ++i) {
5193
5276
  stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s));
5194
- int a;
5277
+ unsigned int a;
5195
5278
  out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
5196
5279
  out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
5197
5280
  out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));
@@ -5239,14 +5322,14 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
5239
5322
  static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int* is_rgb16)
5240
5323
  {
5241
5324
  // only RGB or RGBA (incl. 16bit) or grey allowed
5242
- if(is_rgb16) *is_rgb16 = 0;
5325
+ if (is_rgb16) *is_rgb16 = 0;
5243
5326
  switch(bits_per_pixel) {
5244
5327
  case 8: return STBI_grey;
5245
5328
  case 16: if(is_grey) return STBI_grey_alpha;
5246
- // else: fall-through
5329
+ // fallthrough
5247
5330
  case 15: if(is_rgb16) *is_rgb16 = 1;
5248
- return STBI_rgb;
5249
- case 24: // fall-through
5331
+ return STBI_rgb;
5332
+ case 24: // fallthrough
5250
5333
  case 32: return bits_per_pixel/8;
5251
5334
  default: return 0;
5252
5335
  }
@@ -6041,11 +6124,13 @@ typedef struct
6041
6124
  typedef struct
6042
6125
  {
6043
6126
  int w,h;
6044
- stbi_uc *out, *old_out; // output buffer (always 4 components)
6045
- int flags, bgindex, ratio, transparent, eflags, delay;
6127
+ stbi_uc *out; // output buffer (always 4 components)
6128
+ stbi_uc *background; // The current "background" as far as a gif is concerned
6129
+ stbi_uc *history;
6130
+ int flags, bgindex, ratio, transparent, eflags;
6046
6131
  stbi_uc pal[256][4];
6047
6132
  stbi_uc lpal[256][4];
6048
- stbi__gif_lzw codes[4096];
6133
+ stbi__gif_lzw codes[8192];
6049
6134
  stbi_uc *color_table;
6050
6135
  int parse, step;
6051
6136
  int lflags;
@@ -6053,6 +6138,7 @@ typedef struct
6053
6138
  int max_x, max_y;
6054
6139
  int cur_x, cur_y;
6055
6140
  int line_size;
6141
+ int delay;
6056
6142
  } stbi__gif;
6057
6143
 
6058
6144
  static int stbi__gif_test_raw(stbi__context *s)
@@ -6128,6 +6214,7 @@ static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp)
6128
6214
  static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code)
6129
6215
  {
6130
6216
  stbi_uc *p, *c;
6217
+ int idx;
6131
6218
 
6132
6219
  // recurse to decode the prefixes, since the linked-list is backwards,
6133
6220
  // and working backwards through an interleaved image would be nasty
@@ -6136,10 +6223,12 @@ static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code)
6136
6223
 
6137
6224
  if (g->cur_y >= g->max_y) return;
6138
6225
 
6139
- p = &g->out[g->cur_x + g->cur_y];
6140
- c = &g->color_table[g->codes[code].suffix * 4];
6226
+ idx = g->cur_x + g->cur_y;
6227
+ p = &g->out[idx];
6228
+ g->history[idx / 4] = 1;
6141
6229
 
6142
- if (c[3] >= 128) {
6230
+ c = &g->color_table[g->codes[code].suffix * 4];
6231
+ if (c[3] > 128) { // don't render transparent pixels;
6143
6232
  p[0] = c[2];
6144
6233
  p[1] = c[1];
6145
6234
  p[2] = c[0];
@@ -6213,11 +6302,16 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
6213
6302
  stbi__skip(s,len);
6214
6303
  return g->out;
6215
6304
  } else if (code <= avail) {
6216
- if (first) return stbi__errpuc("no clear code", "Corrupt GIF");
6305
+ if (first) {
6306
+ return stbi__errpuc("no clear code", "Corrupt GIF");
6307
+ }
6217
6308
 
6218
6309
  if (oldcode >= 0) {
6219
6310
  p = &g->codes[avail++];
6220
- if (avail > 4096) return stbi__errpuc("too many codes", "Corrupt GIF");
6311
+ if (avail > 8192) {
6312
+ return stbi__errpuc("too many codes", "Corrupt GIF");
6313
+ }
6314
+
6221
6315
  p->prefix = (stbi__int16) oldcode;
6222
6316
  p->first = g->codes[oldcode].first;
6223
6317
  p->suffix = (code == avail) ? p->first : g->codes[code].first;
@@ -6239,62 +6333,72 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
6239
6333
  }
6240
6334
  }
6241
6335
 
6242
- static void stbi__fill_gif_background(stbi__gif *g, int x0, int y0, int x1, int y1)
6243
- {
6244
- int x, y;
6245
- stbi_uc *c = g->pal[g->bgindex];
6246
- for (y = y0; y < y1; y += 4 * g->w) {
6247
- for (x = x0; x < x1; x += 4) {
6248
- stbi_uc *p = &g->out[y + x];
6249
- p[0] = c[2];
6250
- p[1] = c[1];
6251
- p[2] = c[0];
6252
- p[3] = 0;
6253
- }
6254
- }
6255
- }
6256
-
6257
6336
  // this function is designed to support animated gifs, although stb_image doesn't support it
6258
- static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp)
6259
- {
6260
- int i;
6261
- stbi_uc *prev_out = 0;
6262
-
6263
- if (g->out == 0 && !stbi__gif_header(s, g, comp,0))
6264
- return 0; // stbi__g_failure_reason set by stbi__gif_header
6265
-
6266
- if (!stbi__mad3sizes_valid(g->w, g->h, 4, 0))
6267
- return stbi__errpuc("too large", "GIF too large");
6337
+ // two back is the image from two frames ago, used for a very specific disposal format
6338
+ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back)
6339
+ {
6340
+ int dispose;
6341
+ int first_frame;
6342
+ int pi;
6343
+ int pcount;
6344
+
6345
+ // on first frame, any non-written pixels get the background colour (non-transparent)
6346
+ first_frame = 0;
6347
+ if (g->out == 0) {
6348
+ if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
6349
+ g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
6350
+ g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
6351
+ g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
6352
+ if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
6353
+
6354
+ // image is treated as "tranparent" at the start - ie, nothing overwrites the current background;
6355
+ // background colour is only used for pixels that are not rendered first frame, after that "background"
6356
+ // color refers to teh color that was there the previous frame.
6357
+ memset( g->out, 0x00, 4 * g->w * g->h );
6358
+ memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
6359
+ memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
6360
+ first_frame = 1;
6361
+ } else {
6362
+ // second frame - how do we dispoase of the previous one?
6363
+ dispose = (g->eflags & 0x1C) >> 2;
6364
+ pcount = g->w * g->h;
6268
6365
 
6269
- prev_out = g->out;
6270
- g->out = (stbi_uc *) stbi__malloc_mad3(4, g->w, g->h, 0);
6271
- if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
6366
+ if ((dispose == 3) && (two_back == 0)) {
6367
+ dispose = 2; // if I don't have an image to revert back to, default to the old background
6368
+ }
6272
6369
 
6273
- switch ((g->eflags & 0x1C) >> 2) {
6274
- case 0: // unspecified (also always used on 1st frame)
6275
- stbi__fill_gif_background(g, 0, 0, 4 * g->w, 4 * g->w * g->h);
6276
- break;
6277
- case 1: // do not dispose
6278
- if (prev_out) memcpy(g->out, prev_out, 4 * g->w * g->h);
6279
- g->old_out = prev_out;
6280
- break;
6281
- case 2: // dispose to background
6282
- if (prev_out) memcpy(g->out, prev_out, 4 * g->w * g->h);
6283
- stbi__fill_gif_background(g, g->start_x, g->start_y, g->max_x, g->max_y);
6284
- break;
6285
- case 3: // dispose to previous
6286
- if (g->old_out) {
6287
- for (i = g->start_y; i < g->max_y; i += 4 * g->w)
6288
- memcpy(&g->out[i + g->start_x], &g->old_out[i + g->start_x], g->max_x - g->start_x);
6370
+ if (dispose == 3) { // use previous graphic
6371
+ for (pi = 0; pi < pcount; ++pi) {
6372
+ if (g->history[pi]) {
6373
+ memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 );
6374
+ }
6289
6375
  }
6290
- break;
6376
+ } else if (dispose == 2) {
6377
+ // restore what was changed last frame to background before that frame;
6378
+ for (pi = 0; pi < pcount; ++pi) {
6379
+ if (g->history[pi]) {
6380
+ memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 );
6381
+ }
6382
+ }
6383
+ } else {
6384
+ // This is a non-disposal case eithe way, so just
6385
+ // leave the pixels as is, and they will become the new background
6386
+ // 1: do not dispose
6387
+ // 0: not specified.
6388
+ }
6389
+
6390
+ // background is what out is after the undoing of the previou frame;
6391
+ memcpy( g->background, g->out, 4 * g->w * g->h );
6291
6392
  }
6292
6393
 
6394
+ // clear my history;
6395
+ memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
6396
+
6293
6397
  for (;;) {
6294
- switch (stbi__get8(s)) {
6398
+ int tag = stbi__get8(s);
6399
+ switch (tag) {
6295
6400
  case 0x2C: /* Image Descriptor */
6296
6401
  {
6297
- int prev_trans = -1;
6298
6402
  stbi__int32 x, y, w, h;
6299
6403
  stbi_uc *o;
6300
6404
 
@@ -6327,19 +6431,24 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
6327
6431
  stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
6328
6432
  g->color_table = (stbi_uc *) g->lpal;
6329
6433
  } else if (g->flags & 0x80) {
6330
- if (g->transparent >= 0 && (g->eflags & 0x01)) {
6331
- prev_trans = g->pal[g->transparent][3];
6332
- g->pal[g->transparent][3] = 0;
6333
- }
6334
6434
  g->color_table = (stbi_uc *) g->pal;
6335
6435
  } else
6336
- return stbi__errpuc("missing color table", "Corrupt GIF");
6337
-
6436
+ return stbi__errpuc("missing color table", "Corrupt GIF");
6437
+
6338
6438
  o = stbi__process_gif_raster(s, g);
6339
6439
  if (o == NULL) return NULL;
6340
6440
 
6341
- if (prev_trans != -1)
6342
- g->pal[g->transparent][3] = (stbi_uc) prev_trans;
6441
+ // if this was the first frame,
6442
+ pcount = g->w * g->h;
6443
+ if (first_frame && (g->bgindex > 0)) {
6444
+ // if first frame, any pixel not drawn to gets the background color
6445
+ for (pi = 0; pi < pcount; ++pi) {
6446
+ if (g->history[pi] == 0) {
6447
+ g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be;
6448
+ memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 );
6449
+ }
6450
+ }
6451
+ }
6343
6452
 
6344
6453
  return o;
6345
6454
  }
@@ -6347,19 +6456,35 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
6347
6456
  case 0x21: // Comment Extension.
6348
6457
  {
6349
6458
  int len;
6350
- if (stbi__get8(s) == 0xF9) { // Graphic Control Extension.
6459
+ int ext = stbi__get8(s);
6460
+ if (ext == 0xF9) { // Graphic Control Extension.
6351
6461
  len = stbi__get8(s);
6352
6462
  if (len == 4) {
6353
6463
  g->eflags = stbi__get8(s);
6354
- g->delay = stbi__get16le(s);
6355
- g->transparent = stbi__get8(s);
6464
+ g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths.
6465
+
6466
+ // unset old transparent
6467
+ if (g->transparent >= 0) {
6468
+ g->pal[g->transparent][3] = 255;
6469
+ }
6470
+ if (g->eflags & 0x01) {
6471
+ g->transparent = stbi__get8(s);
6472
+ if (g->transparent >= 0) {
6473
+ g->pal[g->transparent][3] = 0;
6474
+ }
6475
+ } else {
6476
+ // don't need transparent
6477
+ stbi__skip(s, 1);
6478
+ g->transparent = -1;
6479
+ }
6356
6480
  } else {
6357
6481
  stbi__skip(s, len);
6358
6482
  break;
6359
6483
  }
6360
- }
6361
- while ((len = stbi__get8(s)) != 0)
6484
+ }
6485
+ while ((len = stbi__get8(s)) != 0) {
6362
6486
  stbi__skip(s, len);
6487
+ }
6363
6488
  break;
6364
6489
  }
6365
6490
 
@@ -6370,28 +6495,92 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
6370
6495
  return stbi__errpuc("unknown code", "Corrupt GIF");
6371
6496
  }
6372
6497
  }
6498
+ }
6373
6499
 
6374
- STBI_NOTUSED(req_comp);
6500
+ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
6501
+ {
6502
+ if (stbi__gif_test(s)) {
6503
+ int layers = 0;
6504
+ stbi_uc *u = 0;
6505
+ stbi_uc *out = 0;
6506
+ stbi_uc *two_back = 0;
6507
+ stbi__gif g;
6508
+ int stride;
6509
+ memset(&g, 0, sizeof(g));
6510
+ if (delays) {
6511
+ *delays = 0;
6512
+ }
6513
+
6514
+ do {
6515
+ u = stbi__gif_load_next(s, &g, comp, req_comp, two_back);
6516
+ if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
6517
+
6518
+ if (u) {
6519
+ *x = g.w;
6520
+ *y = g.h;
6521
+ ++layers;
6522
+ stride = g.w * g.h * 4;
6523
+
6524
+ if (out) {
6525
+ out = (stbi_uc*) STBI_REALLOC( out, layers * stride );
6526
+ if (delays) {
6527
+ *delays = (int*) STBI_REALLOC( *delays, sizeof(int) * layers );
6528
+ }
6529
+ } else {
6530
+ out = (stbi_uc*)stbi__malloc( layers * stride );
6531
+ if (delays) {
6532
+ *delays = (int*) stbi__malloc( layers * sizeof(int) );
6533
+ }
6534
+ }
6535
+ memcpy( out + ((layers - 1) * stride), u, stride );
6536
+ if (layers >= 2) {
6537
+ two_back = out - 2 * stride;
6538
+ }
6539
+
6540
+ if (delays) {
6541
+ (*delays)[layers - 1U] = g.delay;
6542
+ }
6543
+ }
6544
+ } while (u != 0);
6545
+
6546
+ // free temp buffer;
6547
+ STBI_FREE(g.out);
6548
+ STBI_FREE(g.history);
6549
+ STBI_FREE(g.background);
6550
+
6551
+ // do the final conversion after loading everything;
6552
+ if (req_comp && req_comp != 4)
6553
+ out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h);
6554
+
6555
+ *z = layers;
6556
+ return out;
6557
+ } else {
6558
+ return stbi__errpuc("not GIF", "Image was not as a gif type.");
6559
+ }
6375
6560
  }
6376
6561
 
6377
6562
  static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
6378
6563
  {
6379
6564
  stbi_uc *u = 0;
6380
- stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif));
6381
- memset(g, 0, sizeof(*g));
6382
- STBI_NOTUSED(ri);
6565
+ stbi__gif g;
6566
+ memset(&g, 0, sizeof(g));
6383
6567
 
6384
- u = stbi__gif_load_next(s, g, comp, req_comp);
6568
+ u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
6385
6569
  if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
6386
6570
  if (u) {
6387
- *x = g->w;
6388
- *y = g->h;
6571
+ *x = g.w;
6572
+ *y = g.h;
6573
+
6574
+ // moved conversion to after successful load so that the same
6575
+ // can be done for multiple frames.
6389
6576
  if (req_comp && req_comp != 4)
6390
- u = stbi__convert_format(u, 4, req_comp, g->w, g->h);
6577
+ u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
6391
6578
  }
6392
- else if (g->out)
6393
- STBI_FREE(g->out);
6394
- STBI_FREE(g);
6579
+
6580
+ // free buffers needed for multiple frame loading;
6581
+ STBI_FREE(g.history);
6582
+ STBI_FREE(g.background);
6583
+
6395
6584
  return u;
6396
6585
  }
6397
6586
 
@@ -6670,7 +6859,7 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
6670
6859
  #ifndef STBI_NO_PSD
6671
6860
  static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
6672
6861
  {
6673
- int channelCount, dummy;
6862
+ int channelCount, dummy, depth;
6674
6863
  if (!x) x = &dummy;
6675
6864
  if (!y) y = &dummy;
6676
6865
  if (!comp) comp = &dummy;
@@ -6690,7 +6879,8 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
6690
6879
  }
6691
6880
  *y = stbi__get32be(s);
6692
6881
  *x = stbi__get32be(s);
6693
- if (stbi__get16be(s) != 8) {
6882
+ depth = stbi__get16be(s);
6883
+ if (depth != 8 && depth != 16) {
6694
6884
  stbi__rewind( s );
6695
6885
  return 0;
6696
6886
  }
@@ -6701,6 +6891,33 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
6701
6891
  *comp = 4;
6702
6892
  return 1;
6703
6893
  }
6894
+
6895
+ static int stbi__psd_is16(stbi__context *s)
6896
+ {
6897
+ int channelCount, dummy, depth;
6898
+ if (stbi__get32be(s) != 0x38425053) {
6899
+ stbi__rewind( s );
6900
+ return 0;
6901
+ }
6902
+ if (stbi__get16be(s) != 1) {
6903
+ stbi__rewind( s );
6904
+ return 0;
6905
+ }
6906
+ stbi__skip(s, 6);
6907
+ channelCount = stbi__get16be(s);
6908
+ if (channelCount < 0 || channelCount > 16) {
6909
+ stbi__rewind( s );
6910
+ return 0;
6911
+ }
6912
+ dummy = stbi__get32be(s);
6913
+ dummy = stbi__get32be(s);
6914
+ depth = stbi__get16be(s);
6915
+ if (depth != 16) {
6916
+ stbi__rewind( s );
6917
+ return 0;
6918
+ }
6919
+ return 1;
6920
+ }
6704
6921
  #endif
6705
6922
 
6706
6923
  #ifndef STBI_NO_PIC
@@ -6931,6 +7148,19 @@ static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
6931
7148
  return stbi__err("unknown image type", "Image not of any known type, or corrupt");
6932
7149
  }
6933
7150
 
7151
+ static int stbi__is_16_main(stbi__context *s)
7152
+ {
7153
+ #ifndef STBI_NO_PNG
7154
+ if (stbi__png_is16(s)) return 1;
7155
+ #endif
7156
+
7157
+ #ifndef STBI_NO_PSD
7158
+ if (stbi__psd_is16(s)) return 1;
7159
+ #endif
7160
+
7161
+ return 0;
7162
+ }
7163
+
6934
7164
  #ifndef STBI_NO_STDIO
6935
7165
  STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp)
6936
7166
  {
@@ -6952,6 +7182,27 @@ STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp)
6952
7182
  fseek(f,pos,SEEK_SET);
6953
7183
  return r;
6954
7184
  }
7185
+
7186
+ STBIDEF int stbi_is_16_bit(char const *filename)
7187
+ {
7188
+ FILE *f = stbi__fopen(filename, "rb");
7189
+ int result;
7190
+ if (!f) return stbi__err("can't fopen", "Unable to open file");
7191
+ result = stbi_is_16_bit_from_file(f);
7192
+ fclose(f);
7193
+ return result;
7194
+ }
7195
+
7196
+ STBIDEF int stbi_is_16_bit_from_file(FILE *f)
7197
+ {
7198
+ int r;
7199
+ stbi__context s;
7200
+ long pos = ftell(f);
7201
+ stbi__start_file(&s, f);
7202
+ r = stbi__is_16_main(&s);
7203
+ fseek(f,pos,SEEK_SET);
7204
+ return r;
7205
+ }
6955
7206
  #endif // !STBI_NO_STDIO
6956
7207
 
6957
7208
  STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp)
@@ -6968,10 +7219,28 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int
6968
7219
  return stbi__info_main(&s,x,y,comp);
6969
7220
  }
6970
7221
 
7222
+ STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len)
7223
+ {
7224
+ stbi__context s;
7225
+ stbi__start_mem(&s,buffer,len);
7226
+ return stbi__is_16_main(&s);
7227
+ }
7228
+
7229
+ STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user)
7230
+ {
7231
+ stbi__context s;
7232
+ stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
7233
+ return stbi__is_16_main(&s);
7234
+ }
7235
+
6971
7236
  #endif // STB_IMAGE_IMPLEMENTATION
6972
7237
 
6973
7238
  /*
6974
7239
  revision history:
7240
+ 2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
7241
+ 1-bit BMP
7242
+ *_is_16_bit api
7243
+ avoid warnings
6975
7244
  2.16 (2017-07-23) all functions have 16-bit variants;
6976
7245
  STBI_NO_STDIO works again;
6977
7246
  compilation fixes;