From a2defc3d7a273416b306ce2cf2bee49431957f31 Mon Sep 17 00:00:00 2001 From: jon Date: Mon, 28 Nov 2016 16:05:39 -0600 Subject: [PATCH 1/3] added support for RGBE header HDR files --- stb_image.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stb_image.h b/stb_image.h index a3c1129..f9ed5a6 100644 --- a/stb_image.h +++ b/stb_image.h @@ -6147,10 +6147,11 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re int len; unsigned char count, value; int i, j, k, c1,c2, z; - + const char *headerToken; // Check identifier - if (strcmp(stbi__hdr_gettoken(s,buffer), "#?RADIANCE") != 0) + headerToken = stbi__hdr_gettoken(s,buffer); + if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0) return stbi__errpf("not HDR", "Corrupt HDR image"); // Parse header From 2a170daee5dd339bc8f3f81024a97710935c360f Mon Sep 17 00:00:00 2001 From: jon Date: Mon, 28 Nov 2016 16:24:11 -0600 Subject: [PATCH 2/3] warning fixes, more RGBE fix --- stb_image.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/stb_image.h b/stb_image.h index f9ed5a6..e095fb8 100644 --- a/stb_image.h +++ b/stb_image.h @@ -4500,7 +4500,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG"); has_trans = 1; if (z->depth == 16) { - for (k = 0; k < s->img_n; ++k) tc16[k] = stbi__get16be(s); // copy the values as-is + for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is } else { for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger } @@ -5079,16 +5079,16 @@ errorEnd: // read 16bit value and convert to 24bit RGB void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) { - stbi__uint16 px = stbi__get16le(s); + stbi__uint16 px = (stbi__uint16)stbi__get16le(s); stbi__uint16 fiveBitMask = 31; // we have 3 channels with 5bits each int r = (px >> 10) & fiveBitMask; int g = (px >> 5) & fiveBitMask; int b = px & fiveBitMask; // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later - out[0] = (r * 255)/31; - out[1] = (g * 255)/31; - out[2] = (b * 255)/31; + out[0] = (stbi_uc)((r * 255)/31); + out[1] = (stbi_uc)((g * 255)/31); + out[2] = (stbi_uc)((b * 255)/31); // some people claim that the most significant bit might be used for alpha // (possibly if an alpha-bit is set in the "image descriptor byte") @@ -6069,20 +6069,24 @@ static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp) // Radiance RGBE HDR loader // originally by Nicolas Schulz #ifndef STBI_NO_HDR -static int stbi__hdr_test_core(stbi__context *s) +static int stbi__hdr_test_core(stbi__context *s, const char *signature) { - const char *signature = "#?RADIANCE\n"; int i; for (i=0; signature[i]; ++i) if (stbi__get8(s) != signature[i]) - return 0; + return 0; + stbi__rewind(s); return 1; } static int stbi__hdr_test(stbi__context* s) { - int r = stbi__hdr_test_core(s); + int r = stbi__hdr_test_core(s, "#?RADIANCE\n"); stbi__rewind(s); + if(!r) { + r = stbi__hdr_test_core(s, "#?RGBE\n"); + stbi__rewind(s); + } return r; } From 0b2c06a7e17da43283c872c67f4679b92dcebbb6 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Sun, 4 Dec 2016 05:39:35 -0800 Subject: [PATCH 3/3] more STB_IMAGE_STATIC fixes --- tests/stb.dsp | 4 ---- tests/test_vorbis.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/stb.dsp b/tests/stb.dsp index 7fbb0a8..5b32abb 100644 --- a/tests/stb.dsp +++ b/tests/stb.dsp @@ -90,10 +90,6 @@ SOURCE=.\grid_reachability.c # End Source File # Begin Source File -SOURCE=..\docs\other_libs.md -# End Source File -# Begin Source File - SOURCE=.\stb.c # End Source File # Begin Source File diff --git a/tests/test_vorbis.c b/tests/test_vorbis.c index d54ed23..341a102 100644 --- a/tests/test_vorbis.c +++ b/tests/test_vorbis.c @@ -1,3 +1,7 @@ +#define STB_IMAGE_STATIC +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" + #define STB_VORBIS_HEADER_ONLY #include "stb_vorbis.c" #include "stb.h"