From 7c65d5621f00c3304a3d4dcc8c036b37cf8fec9b Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Mon, 12 Jul 2021 15:57:39 -0700 Subject: [PATCH 1/4] fix compiling with NO_HDR NO_LINEAR --- stb_image.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stb_image.h b/stb_image.h index 0f8459a..08020ac 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1032,7 +1032,7 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add) } // returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow -#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) { return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && @@ -1055,7 +1055,7 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add) return stbi__malloc(a*b*c + add); } -#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) static void *stbi__malloc_mad4(int a, int b, int c, int d, int add) { if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL; From 1401f2257d1c8b6417b442bdf59e7c185be7f9d9 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Mon, 12 Jul 2021 15:58:08 -0700 Subject: [PATCH 2/4] clean up project file --- tests/stb.dsp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/stb.dsp b/tests/stb.dsp index 50fff38..ba13ba1 100644 --- a/tests/stb.dsp +++ b/tests/stb.dsp @@ -154,14 +154,6 @@ SOURCE=..\stb_perlin.h # End Source File # Begin Source File -SOURCE=..\stb_pg.h -# End Source File -# Begin Source File - -SOURCE=.\stb_query.h -# End Source File -# Begin Source File - SOURCE=..\stb_rect_pack.h # End Source File # Begin Source File From c404b789ca01a00cd244240484f7eccdd639ef06 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Mon, 12 Jul 2021 23:47:20 -0700 Subject: [PATCH 3/4] stb_truetype: fix sample code drawing characters upside-down --- stb_truetype.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index 9414a63..f7edfb7 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -271,8 +271,8 @@ //// SAMPLE PROGRAMS //// // -// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless -// +// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless. +// See "tests/truetype_demo_win32.c" for a complete version. #if 0 #define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation #include "stb_truetype.h" @@ -307,10 +307,10 @@ void my_stbtt_print(float x, float y, char *text) if (*text >= 32 && *text < 128) { stbtt_aligned_quad q; stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9 - glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0); - glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0); - glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1); - glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y1); + glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0); + glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0); + glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1); + glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1); } ++text; } From 5ba0baaa269b3fd681828e0e3b3ac0f1472eaf40 Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Sun, 25 Jul 2021 20:24:10 -0700 Subject: [PATCH 4/4] stb_image: Reject fractional JPEG component subsampling ratios The component resamplers are not written to support this and I've never seen it happen in a real (non-crafted) JPEG file so I'm fine rejecting this as outright corrupt. Fixes issue #1178. --- stb_image.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stb_image.h b/stb_image.h index 08020ac..d60371b 100644 --- a/stb_image.h +++ b/stb_image.h @@ -3267,6 +3267,13 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan) if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v; } + // check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios + // and I've never seen a non-corrupted JPEG file actually use them + for (i=0; i < s->img_n; ++i) { + if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H","Corrupt JPEG"); + if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V","Corrupt JPEG"); + } + // compute interleaved mcu info z->img_h_max = h_max; z->img_v_max = v_max;